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. * Select a language and tick the options if needed.
* Click on *"Save"*. * Click on *"Save"*.
### Java 11
## License ## License
Auto-CreamAPI itself is licensed under the GNU General Public License v3.0 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.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -283,12 +284,15 @@ public class Controller {
state_label.setText("Ready."); state_label.setText("Ready.");
} catch (ConfigurationException | IOException e) { } catch (ConfigurationException | IOException e) {
e.printStackTrace(); 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 * 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. * @throws IOException If file is missing or not accessible/modifiable.
*/ */
@ -299,21 +303,43 @@ public class Controller {
if (path.endsWith("steam_api64.dll")) { if (path.endsWith("steam_api64.dll")) {
is64Bit = true; is64Bit = true;
} }
InputStream is = Files.newInputStream(path); copyDllFile(is64Bit, path);
String md5 = DigestUtils.md5Hex(is); findAdditionalDll(is64Bit, path);
boolean isSameFile = Objects.equals(md5, handler.getDllMd5(is64Bit)); }
if (!isSameFile) { }
String pathOrigString = steamApiPathString;
pathOrigString = private void findAdditionalDll(boolean is64Bit, Path path) throws IOException {
pathOrigString String secondDllString = is64Bit ? "\\steam_api.dll" : "\\steam_api64.dll";
.replaceFirst(REGEX, is64Bit ? "steam_api64_o.dll" : "steam_api_o.dll"); Path dir = path.getParent();
Path pathOrig = Paths.get(pathOrigString); Path secondDll = Paths.get(dir.toString() + secondDllString);
if (!Files.exists(pathOrig)) { if (Files.exists(secondDll)) {
Files.move(path, pathOrig); System.out.println("Alternative DLL found!");
} copyDllFile(!is64Bit, secondDll);
Files.deleteIfExists(path); }
Files.copy(handler.getDllPath(is64Bit), path); }
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 { public void read() throws NullPointerException {
appId = config.getInt("steam.appid"); try {
language = config.getString("steam.language"); appId = config.getInt("steam.appid");
if (language == null) { language = config.getString("steam.language");
language = "english"; 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 { public void sync() throws ConfigurationException {