Refactoring

2nd dll's md5 wasn't checked before copying, this is now fixed
This commit is contained in:
Jeddunk 2020-08-24 19:21:59 +02:00
parent 622046120a
commit 619d774ad1

View File

@ -49,6 +49,9 @@ public class Controller {
public FontAwesomeIconView creamApiDllAppliedIcon; public FontAwesomeIconView creamApiDllAppliedIcon;
public FontAwesomeIconView creamApiConfigExists; public FontAwesomeIconView creamApiConfigExists;
private CreamApiDllHandler handler = null; private CreamApiDllHandler handler = null;
private boolean is64Bit;
private boolean isSameFile;
{ {
try { try {
handler = CreamApiDllHandler.getInstance(); handler = CreamApiDllHandler.getInstance();
@ -184,7 +187,7 @@ public class Controller {
private void updateIndicators() { private void updateIndicators() {
try { try {
boolean is64Bit = false; is64Bit = false;
if (!steamApiPathString.isEmpty()) { if (!steamApiPathString.isEmpty()) {
Path dllPath = Paths.get(steamApiPathString); Path dllPath = Paths.get(steamApiPathString);
if (dllPath.endsWith("steam_api64.dll")) { if (dllPath.endsWith("steam_api64.dll")) {
@ -192,7 +195,7 @@ public class Controller {
} }
InputStream is = Files.newInputStream(dllPath); InputStream is = Files.newInputStream(dllPath);
String md5 = DigestUtils.md5Hex(is); String md5 = DigestUtils.md5Hex(is);
boolean isSameFile = Objects.equals(md5, handler.getDllMd5(is64Bit)); isSameFile = Objects.equals(md5, handler.getDllMd5(is64Bit));
if (isSameFile) { if (isSameFile) {
creamApiDllAppliedIcon.setGlyphName("CHECK"); creamApiDllAppliedIcon.setGlyphName("CHECK");
} else { } else {
@ -233,6 +236,7 @@ public class Controller {
System.err.println("No configuration file set!"); System.err.println("No configuration file set!");
cancel(); cancel();
} }
updateIndicators();
return null; return null;
} }
}; };
@ -345,31 +349,28 @@ public class Controller {
* @throws IOException If file is missing or not accessible/modifiable. * @throws IOException If file is missing or not accessible/modifiable.
*/ */
private void setUpCreamApi() throws IOException { private void setUpCreamApi() throws IOException {
boolean is64Bit = false;
if (!steamApiPathString.isEmpty()) {
Path path = Paths.get(steamApiPathString); Path path = Paths.get(steamApiPathString);
if (path.endsWith("steam_api64.dll")) { copyDllFile(path);
is64Bit = true; findAdditionalDll(path);
}
copyDllFile(is64Bit, path);
findAdditionalDll(is64Bit, 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"; String secondDllString = is64Bit ? "\\steam_api.dll" : "\\steam_api64.dll";
Path dir = path.getParent(); Path dir = path.getParent();
Path secondDll = Paths.get(dir.toString() + secondDllString); Path secondDll = Paths.get(dir.toString() + secondDllString);
if (Files.exists(secondDll)) { if (Files.exists(secondDll)) {
System.out.println("Alternative DLL found!"); 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 { private void copyDllFile(Path path) throws IOException {
InputStream is = Files.newInputStream(path);
String md5 = DigestUtils.md5Hex(is);
boolean isSameFile = Objects.equals(md5, handler.getDllMd5(is64Bit));
if (!isSameFile) { if (!isSameFile) {
String pathOrigString = steamApiPathString; String pathOrigString = steamApiPathString;
pathOrigString = pathOrigString =