If a second SteamAPI DLL has been found, it will now automatically be patched too.

Now handles error if file chooser was canceled.
Now handles error if cream_api.ini file was not found, which would be the case if CreamAPI is going to be set up for the first time.
This commit is contained in:
Jeddunk 2020-08-23 14:00:46 +02:00
parent a03246a98f
commit c76ad989f9
3 changed files with 59 additions and 24 deletions

View File

@ -35,6 +35,10 @@ Download the latest release and extract it into any folder (e.g. `%USERPROFILE%\
* Select a language and tick the options if needed.
* Click on *"Save"*.
### Java 11
## License
Auto-CreamAPI itself is licensed under the GNU General Public License v3.0

View File

@ -37,6 +37,7 @@ import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Map;
import java.util.Objects;
@ -283,12 +284,15 @@ public class Controller {
state_label.setText("Ready.");
} catch (ConfigurationException | IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
System.err.println("Could not set config file location! Did you cancel the file chooser?");
}
}
/**
* check if creamapi version of dll is there, if not, rename original to steam_api(64)_o.dll and copy
* creamapi one to the path.
* creamapi dll to the path. also looks for alternative steam dll (which means it patches both 64 and 32 bit
* dlls at once if found)
*
* @throws IOException If file is missing or not accessible/modifiable.
*/
@ -299,21 +303,43 @@ public class Controller {
if (path.endsWith("steam_api64.dll")) {
is64Bit = true;
}
InputStream is = Files.newInputStream(path);
String md5 = DigestUtils.md5Hex(is);
boolean isSameFile = Objects.equals(md5, handler.getDllMd5(is64Bit));
if (!isSameFile) {
String pathOrigString = steamApiPathString;
pathOrigString =
pathOrigString
.replaceFirst(REGEX, is64Bit ? "steam_api64_o.dll" : "steam_api_o.dll");
Path pathOrig = Paths.get(pathOrigString);
if (!Files.exists(pathOrig)) {
Files.move(path, pathOrig);
}
Files.deleteIfExists(path);
Files.copy(handler.getDllPath(is64Bit), path);
copyDllFile(is64Bit, path);
findAdditionalDll(is64Bit, path);
}
}
private void findAdditionalDll(boolean is64Bit, Path path) throws IOException {
String secondDllString = is64Bit ? "\\steam_api.dll" : "\\steam_api64.dll";
Path dir = path.getParent();
Path secondDll = Paths.get(dir.toString() + secondDllString);
if (Files.exists(secondDll)) {
System.out.println("Alternative DLL found!");
copyDllFile(!is64Bit, secondDll);
}
}
private void copyDllFile(boolean is64Bit, Path path) throws IOException {
InputStream is = Files.newInputStream(path);
String md5 = DigestUtils.md5Hex(is);
boolean isSameFile = Objects.equals(md5, handler.getDllMd5(is64Bit));
if (!isSameFile) {
String pathOrigString = steamApiPathString;
pathOrigString =
pathOrigString
.replaceFirst(REGEX, is64Bit ? "steam_api64_o.dll" : "steam_api_o.dll");
Path pathOrig = Paths.get(pathOrigString);
if (!Files.exists(pathOrig)) {
Files.move(path, pathOrig);
} else {
String pathBakString = steamApiPathString;
pathBakString =
pathBakString
.replaceFirst(REGEX, is64Bit ? "steam_api64.dll.backup" : "steam_api.dll.backup");
Path pathBak = Paths.get(pathBakString);
Files.move(path, pathBak, StandardCopyOption.REPLACE_EXISTING);
}
//Files.deleteIfExists(path);
Files.copy(handler.getDllPath(is64Bit), path);
}
}

View File

@ -70,16 +70,21 @@ public class CreamApiConfig {
}
public void read() throws NullPointerException {
appId = config.getInt("steam.appid");
language = config.getString("steam.language");
if (language == null) {
language = "english";
try {
appId = config.getInt("steam.appid");
language = config.getString("steam.language");
if (language == null) {
language = "english";
}
unlockAll = config.getBoolean("steam.unlockall");
extraProtection = config.getBoolean("steam.extraprotection");
forceOffline = config.getBoolean("steam.forceoffline");
final SubnodeConfiguration dlc_section = config.getSection("dlc");
dlc_section.getKeys().forEachRemaining(k -> dlc.put(Integer.parseInt(k), dlc_section.getString(k)));
} catch (NoSuchElementException e) {
System.err.println("Error reading cream_api.ini! " +
"This can be ignored if setting up CreamAPI for the first time.");
}
unlockAll = config.getBoolean("steam.unlockall");
extraProtection = config.getBoolean("steam.extraprotection");
forceOffline = config.getBoolean("steam.forceoffline");
final SubnodeConfiguration dlc_section = config.getSection("dlc");
dlc_section.getKeys().forEachRemaining(k -> dlc.put(Integer.parseInt(k), dlc_section.getString(k)));
}
public void sync() throws ConfigurationException {