Rename Steam's DLLs and copy CreamAPI's DLLs to target path
This commit is contained in:
parent
c7911a1eef
commit
aca5c4b8ef
5
.gitignore
vendored
5
.gitignore
vendored
@ -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
|
||||
|
@ -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("(?<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
BIN
steam_api.dll
Normal file
BIN
steam_api.dll
Normal file
Binary file not shown.
BIN
steam_api64.dll
Normal file
BIN
steam_api64.dll
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user