From 619d774ad1f8793b11cbc55350f7ec5fc818ea35 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Mon, 24 Aug 2020 19:21:59 +0200 Subject: [PATCH] Refactoring 2nd dll's md5 wasn't checked before copying, this is now fixed --- src/main/java/Controller.java | 37 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index 9617b77..30a6128 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -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 =