diff --git a/.gitignore b/.gitignore index a463f20..863e013 100644 --- a/.gitignore +++ b/.gitignore @@ -155,6 +155,7 @@ $RECYCLE.BIN/ # End of https://www.gitignore.io/api/java,maven,windows,intellij -cream_api.ini -steamapps.json +/cream_api.ini +/steamapps.json /test.json +/steam_api.md5 diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index c8145f4..6231ada 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -4,6 +4,7 @@ import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.scene.control.Tooltip; import javafx.stage.FileChooser; +import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.configuration2.ex.ConfigurationException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -13,12 +14,19 @@ import pojo.App; import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; public class Controller { + private static final String X86_MD5_HASH = "c6f267a2d10b891ed352ed849a28d69b"; + private static final String X64_MD5_HASH = "645c728a6117946294130d07cf6c0cae"; private CreamApiConfig config = CreamApiConfig.getInstance(); private SteamAppsListCache cache = new SteamAppsListCache(); @FXML @@ -47,6 +55,7 @@ public class Controller { public JFXButton path_button; @FXML public JFXButton retrieveDlcList_button; + private String steamApiPathString; public Controller() { } @@ -105,6 +114,11 @@ public class Controller { } public void save() { + try { + setUpCreamApi(); + } catch (IOException e) { + e.printStackTrace(); + } config.setDlcListFromString(dlc_textarea.getText()); config.setAppId(Integer.parseInt(appId_textfield.getText())); config.setExtraProtection(extra_protection_checkbox.isSelected()); @@ -196,8 +210,41 @@ public class Controller { try { config.setConfig(file.getParent() + "\\cream_api.ini"); path_textfield.setText(file.getParent()); + steamApiPathString = file.getAbsolutePath(); } catch (ConfigurationException | IOException e) { e.printStackTrace(); } } + + /** + * 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. + * + * @throws IOException If file is missing or not accessible/modifiable. + */ + private void setUpCreamApi() throws IOException { + boolean is64Bit = false; + if (!steamApiPathString.isEmpty()) { + Path path = Paths.get(steamApiPathString); + if (path.endsWith("steam_api64.dll")) { + is64Bit = true; + } + InputStream is = Files.newInputStream(path); + String md5 = DigestUtils.md5Hex(is); + boolean isSameFile = Objects.equals(md5, is64Bit ? X64_MD5_HASH : X86_MD5_HASH); + if (!isSameFile) { + String pathOrigString = steamApiPathString; + pathOrigString = + pathOrigString + .replaceFirst("(?steam_api(?:64)?.dll)$", + 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(Paths.get(is64Bit ? "steam_api64.dll" : "steam_api.dll"), path); + } + } + } } diff --git a/src/main/java/CreamApiConfig.java b/src/main/java/CreamApiConfig.java index 4c9c45d..a3f7752 100644 --- a/src/main/java/CreamApiConfig.java +++ b/src/main/java/CreamApiConfig.java @@ -148,9 +148,7 @@ public class CreamApiConfig { public void setConfig(String path) throws ConfigurationException, IOException { File file = new File(path); - if (!file.exists()) { - final boolean newFile = file.createNewFile(); - } + boolean fileCreated = file.createNewFile(); this.config = CONFIGS.ini(path); this.config.setCommentLeadingCharsUsedInInput(";"); this.path = path; diff --git a/steam_api.dll b/steam_api.dll new file mode 100644 index 0000000..117c18f Binary files /dev/null and b/steam_api.dll differ diff --git a/steam_api64.dll b/steam_api64.dll new file mode 100644 index 0000000..f27c80f Binary files /dev/null and b/steam_api64.dll differ