Rename Steam's DLLs and copy CreamAPI's DLLs to target path

This commit is contained in:
Jeddunk 2019-11-15 05:11:41 +01:00
parent c7911a1eef
commit aca5c4b8ef
5 changed files with 51 additions and 5 deletions

5
.gitignore vendored
View File

@ -155,6 +155,7 @@ $RECYCLE.BIN/
# End of https://www.gitignore.io/api/java,maven,windows,intellij # End of https://www.gitignore.io/api/java,maven,windows,intellij
cream_api.ini /cream_api.ini
steamapps.json /steamapps.json
/test.json /test.json
/steam_api.md5

View File

@ -4,6 +4,7 @@ import javafx.collections.FXCollections;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Tooltip; import javafx.scene.control.Tooltip;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.configuration2.ex.ConfigurationException; import org.apache.commons.configuration2.ex.ConfigurationException;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -13,12 +14,19 @@ import pojo.App;
import java.io.File; import java.io.File;
import java.io.IOException; 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.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Controller { 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 CreamApiConfig config = CreamApiConfig.getInstance();
private SteamAppsListCache cache = new SteamAppsListCache(); private SteamAppsListCache cache = new SteamAppsListCache();
@FXML @FXML
@ -47,6 +55,7 @@ public class Controller {
public JFXButton path_button; public JFXButton path_button;
@FXML @FXML
public JFXButton retrieveDlcList_button; public JFXButton retrieveDlcList_button;
private String steamApiPathString;
public Controller() { public Controller() {
} }
@ -105,6 +114,11 @@ public class Controller {
} }
public void save() { public void save() {
try {
setUpCreamApi();
} catch (IOException e) {
e.printStackTrace();
}
config.setDlcListFromString(dlc_textarea.getText()); config.setDlcListFromString(dlc_textarea.getText());
config.setAppId(Integer.parseInt(appId_textfield.getText())); config.setAppId(Integer.parseInt(appId_textfield.getText()));
config.setExtraProtection(extra_protection_checkbox.isSelected()); config.setExtraProtection(extra_protection_checkbox.isSelected());
@ -196,8 +210,41 @@ public class Controller {
try { try {
config.setConfig(file.getParent() + "\\cream_api.ini"); config.setConfig(file.getParent() + "\\cream_api.ini");
path_textfield.setText(file.getParent()); path_textfield.setText(file.getParent());
steamApiPathString = file.getAbsolutePath();
} catch (ConfigurationException | IOException e) { } catch (ConfigurationException | IOException e) {
e.printStackTrace(); 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("(?<steamApiDll>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);
}
}
}
} }

View File

@ -148,9 +148,7 @@ public class CreamApiConfig {
public void setConfig(String path) throws ConfigurationException, IOException { public void setConfig(String path) throws ConfigurationException, IOException {
File file = new File(path); File file = new File(path);
if (!file.exists()) { boolean fileCreated = file.createNewFile();
final boolean newFile = file.createNewFile();
}
this.config = CONFIGS.ini(path); this.config = CONFIGS.ini(path);
this.config.setCommentLeadingCharsUsedInInput(";"); this.config.setCommentLeadingCharsUsedInInput(";");
this.path = path; this.path = path;

BIN
steam_api.dll Normal file

Binary file not shown.

BIN
steam_api64.dll Normal file

Binary file not shown.