Refactoring
2nd dll's md5 wasn't checked before copying, this is now fixed
This commit is contained in:
parent
622046120a
commit
619d774ad1
@ -49,6 +49,9 @@ public class Controller {
|
||||
public FontAwesomeIconView creamApiDllAppliedIcon;
|
||||
public FontAwesomeIconView creamApiConfigExists;
|
||||
private CreamApiDllHandler handler = null;
|
||||
private boolean is64Bit;
|
||||
private boolean isSameFile;
|
||||
|
||||
{
|
||||
try {
|
||||
handler = CreamApiDllHandler.getInstance();
|
||||
@ -162,7 +165,7 @@ public class Controller {
|
||||
if (silent) {
|
||||
state_label.setText("");
|
||||
} else {
|
||||
state_label.setText("Resetting fields...");
|
||||
state_label.setText("Resetting fields...");
|
||||
}
|
||||
try {
|
||||
config.read();
|
||||
@ -184,7 +187,7 @@ public class Controller {
|
||||
|
||||
private void updateIndicators() {
|
||||
try {
|
||||
boolean is64Bit = false;
|
||||
is64Bit = false;
|
||||
if (!steamApiPathString.isEmpty()) {
|
||||
Path dllPath = Paths.get(steamApiPathString);
|
||||
if (dllPath.endsWith("steam_api64.dll")) {
|
||||
@ -192,7 +195,7 @@ public class Controller {
|
||||
}
|
||||
InputStream is = Files.newInputStream(dllPath);
|
||||
String md5 = DigestUtils.md5Hex(is);
|
||||
boolean isSameFile = Objects.equals(md5, handler.getDllMd5(is64Bit));
|
||||
isSameFile = Objects.equals(md5, handler.getDllMd5(is64Bit));
|
||||
if (isSameFile) {
|
||||
creamApiDllAppliedIcon.setGlyphName("CHECK");
|
||||
} else {
|
||||
@ -233,6 +236,7 @@ public class Controller {
|
||||
System.err.println("No configuration file set!");
|
||||
cancel();
|
||||
}
|
||||
updateIndicators();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@ -345,31 +349,28 @@ public class Controller {
|
||||
* @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;
|
||||
}
|
||||
copyDllFile(is64Bit, path);
|
||||
findAdditionalDll(is64Bit, path);
|
||||
}
|
||||
Path path = Paths.get(steamApiPathString);
|
||||
copyDllFile(path);
|
||||
findAdditionalDll(path);
|
||||
}
|
||||
|
||||
private void findAdditionalDll(boolean is64Bit, Path path) throws IOException {
|
||||
private void findAdditionalDll(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);
|
||||
InputStream is = Files.newInputStream(secondDll);
|
||||
String md5 = DigestUtils.md5Hex(is);
|
||||
boolean isSameFile1 = Objects.equals(md5, handler.getDllMd5(!is64Bit));
|
||||
if (isSameFile1) {
|
||||
System.out.println("Alternative DLL not patched! Patching...");
|
||||
copyDllFile(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));
|
||||
private void copyDllFile(Path path) throws IOException {
|
||||
if (!isSameFile) {
|
||||
String pathOrigString = steamApiPathString;
|
||||
pathOrigString =
|
||||
|
Loading…
Reference in New Issue
Block a user