From 2e5399971e1bcf6f455161d2077673ef9893f93e Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sun, 10 May 2020 14:27:33 +0200 Subject: [PATCH 1/7] Added visual checks if dlls and config are ok (WIP) Other improvements (might need to be backported to 1.0.x) --- .idea/encodings.xml | 2 + src/main/java/Controller.java | 40 ++++-- src/main/java/util/CreamApiConfig.java | 6 +- src/main/java/util/SteamAppsListCache.java | 28 ++--- src/main/resources/mainWindow.fxml | 135 ++++++++++++++------- 5 files changed, 144 insertions(+), 67 deletions(-) diff --git a/.idea/encodings.xml b/.idea/encodings.xml index c0bce70..6589dfe 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -2,6 +2,8 @@ + + \ No newline at end of file diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index 48a6b1c..e167065 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -1,4 +1,5 @@ import com.jfoenix.controls.*; +import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView; import javafx.beans.value.ChangeListener; import javafx.collections.FXCollections; import javafx.concurrent.Service; @@ -9,6 +10,7 @@ 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.HttpStatusException; import pojo.App; import util.CreamApiConfig; import util.CreamApiDllHandler; @@ -26,9 +28,11 @@ import java.util.Objects; public class Controller { private static final String REGEX = "(?steam_api(?:64)?.dll)$"; - private CreamApiDllHandler handler = CreamApiDllHandler.getInstance(); - private CreamApiConfig config = CreamApiConfig.getInstance(); - private SteamAppsListCache cache = new SteamAppsListCache(); + public FontAwesomeIconView creamApiDllAppliedIcon; + public FontAwesomeIconView creamApiConfigExists; + private final CreamApiDllHandler handler = CreamApiDllHandler.getInstance(); + private final CreamApiConfig config = CreamApiConfig.getInstance(); + private final SteamAppsListCache cache = new SteamAppsListCache(); @FXML public Label state_label; @FXML @@ -69,6 +73,7 @@ public class Controller { generate_tooltips(); fix_dlc_textarea_prompt_text(); reset(true); + state_label.setText("Ready."); } private void read() { @@ -148,8 +153,10 @@ public class Controller { config.sync(); } catch (IOException | ConfigurationException e) { e.printStackTrace(); + cancel(); } catch (NullPointerException e) { System.err.println("No configuration file set!"); + cancel(); } return null; } @@ -164,6 +171,10 @@ public class Controller { setDisableAllButtons(false); state_label.setText("Saved successfully!"); }); + s.setOnCancelled(event -> { + setDisableAllButtons(false); + state_label.setText("Could not save configuration file!"); + }); s.start(); } @@ -192,10 +203,20 @@ public class Controller { return new Task() { @Override protected Void call() { - Map collect = cache.getDlcMap(appId_textfield.getText()); - StringBuilder sb = new StringBuilder(); - collect.forEach((k, v) -> sb.append(k).append("=").append(v).append("\n")); - dlc_textarea.setText(sb.toString()); + try { + Map collect = cache.getDlcMap(appId_textfield.getText()); + StringBuilder sb = new StringBuilder(); + collect.forEach((k, v) -> sb.append(k).append("=").append(v).append("\n")); + dlc_textarea.setText(sb.toString()); + } catch (HttpStatusException e) { + if (e.getStatusCode() == 404) { + System.err.println("App ID empty or not found! (HTTP Status Code: 404)"); + } + cancel(); + } catch (IOException e) { + e.printStackTrace(); + cancel(); + } return null; } }; @@ -209,6 +230,10 @@ public class Controller { setDisableAllButtons(false); state_label.setText("Got list of DLCs successfully!"); }); + s.setOnCancelled(event -> { + setDisableAllButtons(false); + state_label.setText("Could not get list of DLCs!"); + }); s.start(); } @@ -225,6 +250,7 @@ public class Controller { path_textfield.setText(file.getParent()); steamApiPathString = file.getAbsolutePath(); reset(true); + state_label.setText("Ready."); } catch (ConfigurationException | IOException e) { e.printStackTrace(); } diff --git a/src/main/java/util/CreamApiConfig.java b/src/main/java/util/CreamApiConfig.java index 6100f5d..53ae0f5 100644 --- a/src/main/java/util/CreamApiConfig.java +++ b/src/main/java/util/CreamApiConfig.java @@ -20,8 +20,8 @@ public class CreamApiConfig { private Boolean unlockAll; private Boolean extraProtection; private Boolean forceOffline; - private Map dlc = new HashMap<>(); - private List languages = new ArrayList<>(); + private final Map dlc = new HashMap<>(); + private final List languages = new ArrayList<>(); private CreamApiConfig() { try { @@ -35,7 +35,7 @@ public class CreamApiConfig { File langFile = new File("languages.txt"); try { BufferedReader fIn = new BufferedReader(new FileReader(langFile)); - fIn.lines().filter(line -> !line.isEmpty() && !line.startsWith("#")).forEach(line -> languages.add(line)); + fIn.lines().filter(line -> !line.isEmpty() && !line.startsWith("#")).forEach(languages::add); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/util/SteamAppsListCache.java b/src/main/java/util/SteamAppsListCache.java index d7422d5..8a1534e 100644 --- a/src/main/java/util/SteamAppsListCache.java +++ b/src/main/java/util/SteamAppsListCache.java @@ -4,7 +4,6 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import kong.unirest.HttpResponse; import kong.unirest.Unirest; -import org.jsoup.HttpStatusException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -26,29 +25,31 @@ import java.util.stream.Collectors; public class SteamAppsListCache { private SteamAppsList list = new SteamAppsList(); - private File cacheFile = new File("steamapps.json"); + private final File cacheFile = new File("steamapps.json"); private MainEnv env; //private String key; public SteamAppsListCache() { try { - Class envDefault = Class.forName("util.env.Default"); + Class envDefault = Class.forName("util.env.Default"); env = (MainEnv) envDefault.newInstance(); - //System.out.println(env.getKey()); + // System.out.println(env.getKey()); } catch (ClassNotFoundException e) { env = new MainEnv(); } catch (IllegalAccessException | InstantiationException e) { // Only thrown by newInstance() e.printStackTrace(); } - boolean fileFound = true; + //boolean fileFound = true; try { getListFromFile(); } catch (FileNotFoundException e) { System.err.println("File does not exist, trying to create steamapps.json for the first time..."); - fileFound = false; + //fileFound = false; + sync(); } - if (!fileFound || Instant.now().isAfter(list.getTimestamp().plus(Duration.ofDays(3)))) { + if (Instant.now().isAfter(list.getTimestamp().plus(Duration.ofDays(3)))) { + System.err.println("List in file is not recent!"); sync(); } } @@ -89,6 +90,7 @@ public class SteamAppsListCache { } private void getListFromApi() { + System.out.println("Trying to get SteamAppList from API..."); List apps = getApps(); list.setTimestamp(Instant.now()); list.setSteamAppsList(apps); @@ -104,23 +106,27 @@ public class SteamAppsListCache { } private void saveListToFile() throws IOException { + System.out.println("Trying to save SteamAppList to file (" + cacheFile.getAbsolutePath() + ")..."); Gson gson = new Gson(); String jsonString = gson.toJson(list); BufferedWriter fOut = new BufferedWriter(new FileWriter(cacheFile)); fOut.write(jsonString); fOut.close(); + System.out.println("Successfully saved SteamAppList to file (" + cacheFile.getAbsolutePath() + ")..."); } private void getListFromFile() throws FileNotFoundException { + System.out.println("Trying to get SteamAppList from file (" + cacheFile.getAbsolutePath() + ")..."); BufferedReader fIn = new BufferedReader(new FileReader(cacheFile)); String json = fIn.lines().collect(Collectors.joining()); final Type type = new TypeToken() { }.getType(); Gson gson = new Gson(); list = gson.fromJson(json, type); + System.out.println("Successfully got SteamAppList from file (" + cacheFile.getAbsolutePath() + ")..."); } - public LinkedHashMap getDlcMap(String appId) { + public LinkedHashMap getDlcMap(String appId) throws IOException{ Map steamStoreDLCs = new HashMap<>(); Map steamDbDLCs = new HashMap<>(); //StringBuilder sb = new StringBuilder(); @@ -152,12 +158,6 @@ public class SteamAppsListCache { } steamDbDLCs.put(Integer.parseInt(dlc_id), dlc_name); } - } catch (HttpStatusException e) { - if (e.getStatusCode() == 404) { - System.err.println("App ID empty or not found! (HTTP Status Code: 404)"); - } - } catch (IOException e) { - e.printStackTrace(); } catch (NullPointerException e) { // ignore } diff --git a/src/main/resources/mainWindow.fxml b/src/main/resources/mainWindow.fxml index 244d629..e0c98c7 100644 --- a/src/main/resources/mainWindow.fxml +++ b/src/main/resources/mainWindow.fxml @@ -8,50 +8,99 @@ + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
From f578529bbe1a495159c3bb7adb99abf85f1f7f1f Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Sun, 10 May 2020 18:51:23 +0200 Subject: [PATCH 2/7] Added missing import --- src/main/java/Controller.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index ea94846..387576d 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -1,4 +1,5 @@ import com.jfoenix.controls.*; +import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView; import javafx.beans.value.ChangeListener; import javafx.collections.FXCollections; import javafx.concurrent.Service; From 622046120aa645672484092bafd9b56c164a3d75 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Mon, 24 Aug 2020 19:20:31 +0200 Subject: [PATCH 3/7] Visual indicators are now functional --- src/main/java/Controller.java | 54 ++++++++++++++++++++++++-- src/main/java/util/CreamApiConfig.java | 33 +++++++++------- src/main/resources/mainWindow.fxml | 4 +- 3 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index 1366912..9617b77 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -40,6 +40,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Objects; public class Controller { @@ -118,6 +119,18 @@ public class Controller { unlockAll_disableDlcTextArea(); } + private void emptyFields() { + creamApiDllAppliedIcon.setGlyphName("TIMES"); + creamApiConfigExists.setGlyphName("TIMES"); + appId_textfield.setText(""); + dlc_textarea.setText(""); + game_name_textfield.setText(""); + extra_protection_checkbox.setSelected(false); + offline_checkbox.setSelected(false); + unlock_all_checkbox.setSelected(false); + unlockAll_disableDlcTextArea(); + } + private void fix_dlc_textarea_prompt_text() { dlc_textarea.setPromptText("List of DLC...\r0000 = DLC Name"); } @@ -154,9 +167,13 @@ public class Controller { try { config.read(); read(); + updateIndicators(); if (!silent) { state_label.setText("Successfully reset all fields!"); } + } catch (NoSuchElementException e) { + System.err.println("Error reading cream_api.ini! " + + "This can be ignored if setting up CreamAPI for the first time."); } catch (NullPointerException e) { System.err.println("Can't fill out fields, no configuration file set!"); if (!silent) { @@ -165,6 +182,34 @@ public class Controller { } } + private void updateIndicators() { + try { + boolean is64Bit = false; + if (!steamApiPathString.isEmpty()) { + Path dllPath = Paths.get(steamApiPathString); + if (dllPath.endsWith("steam_api64.dll")) { + is64Bit = true; + } + InputStream is = Files.newInputStream(dllPath); + String md5 = DigestUtils.md5Hex(is); + boolean isSameFile = Objects.equals(md5, handler.getDllMd5(is64Bit)); + if (isSameFile) { + creamApiDllAppliedIcon.setGlyphName("CHECK"); + } else { + creamApiDllAppliedIcon.setGlyphName("TIMES"); + } + Path configPath = Paths.get(config.getPath()); + if (Files.exists(configPath) && Files.size(configPath) != 0L) { + creamApiConfigExists.setGlyphName("CHECK"); + } else { + creamApiConfigExists.setGlyphName("TIMES"); + } + } + } catch (IOException e) { + System.err.println("No file found, could not update visual indicators!"); + } + } + public void save() { Service s = new Service() { @Override @@ -280,15 +325,16 @@ public class Controller { final File file = chooser.showOpenDialog(path_button.getScene().getWindow()); try { config.setConfig(file.getParent() + "\\cream_api.ini"); - path_textfield.setText(file.getParent()); - steamApiPathString = file.getAbsolutePath(); - reset(true); - state_label.setText("Ready."); } catch (ConfigurationException | IOException e) { e.printStackTrace(); } catch (NullPointerException e) { System.err.println("Could not set config file location! Did you cancel the file chooser?"); } + path_textfield.setText(file.getParent()); + steamApiPathString = file.getAbsolutePath(); + emptyFields(); + reset(true); + state_label.setText("Ready."); } /** diff --git a/src/main/java/util/CreamApiConfig.java b/src/main/java/util/CreamApiConfig.java index 6355e54..45a9ef9 100644 --- a/src/main/java/util/CreamApiConfig.java +++ b/src/main/java/util/CreamApiConfig.java @@ -29,6 +29,11 @@ public class CreamApiConfig { private static final Configurations CONFIGS = new Configurations(); private INIConfiguration config; + + public String getPath() { + return path; + } + private String path = "cream_api.ini"; private Integer appId; private String language; @@ -57,6 +62,9 @@ public class CreamApiConfig { try { read(); + } catch (NoSuchElementException e) { + System.err.println("Error reading cream_api.ini! " + + "This can be ignored if setting up CreamAPI for the first time."); } catch (NullPointerException e) { System.err.println("Can't fill out fields, no configuration file set!"); } @@ -69,22 +77,17 @@ public class CreamApiConfig { return configInstance; } - public void read() throws NullPointerException { - try { - appId = config.getInt("steam.appid"); - language = config.getString("steam.language"); - if (language == null) { - language = "english"; - } - unlockAll = config.getBoolean("steam.unlockall"); - extraProtection = config.getBoolean("steam.extraprotection"); - forceOffline = config.getBoolean("steam.forceoffline"); - final SubnodeConfiguration dlc_section = config.getSection("dlc"); - dlc_section.getKeys().forEachRemaining(k -> dlc.put(Integer.parseInt(k), dlc_section.getString(k))); - } catch (NoSuchElementException e) { - System.err.println("Error reading cream_api.ini! " + - "This can be ignored if setting up CreamAPI for the first time."); + public void read() throws NullPointerException, NoSuchElementException { + appId = config.getInt("steam.appid"); + language = config.getString("steam.language"); + if (language == null) { + language = "english"; } + unlockAll = config.getBoolean("steam.unlockall"); + extraProtection = config.getBoolean("steam.extraprotection"); + forceOffline = config.getBoolean("steam.forceoffline"); + final SubnodeConfiguration dlc_section = config.getSection("dlc"); + dlc_section.getKeys().forEachRemaining(k -> dlc.put(Integer.parseInt(k), dlc_section.getString(k))); } public void sync() throws ConfigurationException { diff --git a/src/main/resources/mainWindow.fxml b/src/main/resources/mainWindow.fxml index 6e916ce..a3355a6 100644 --- a/src/main/resources/mainWindow.fxml +++ b/src/main/resources/mainWindow.fxml @@ -104,7 +104,7 @@ - + - + From 619d774ad1f8793b11cbc55350f7ec5fc818ea35 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Mon, 24 Aug 2020 19:21:59 +0200 Subject: [PATCH 4/7] 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 = From efa6fd29bc14744b9427149d96f516f93c874770 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Tue, 25 Aug 2020 13:51:33 +0200 Subject: [PATCH 5/7] Fixed second DLL not patching properly. --- src/main/java/Controller.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index 30a6128..a62ed86 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -350,7 +350,7 @@ public class Controller { */ private void setUpCreamApi() throws IOException { Path path = Paths.get(steamApiPathString); - copyDllFile(path); + copyDllFile(path, isSameFile); findAdditionalDll(path); } @@ -363,14 +363,11 @@ public class Controller { 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); - } + copyDllFile(secondDll, isSameFile1); } } - private void copyDllFile(Path path) throws IOException { + private void copyDllFile(Path path, boolean isSameFile) throws IOException { if (!isSameFile) { String pathOrigString = steamApiPathString; pathOrigString = From 4c8400aa005fb7f8c1027c7437196ae024187f1b Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Fri, 28 Aug 2020 14:11:49 +0200 Subject: [PATCH 6/7] Visual indicators should work properly now --- src/main/java/Controller.java | 35 +++++++++++++++++++++++------- src/main/resources/mainWindow.fxml | 7 +++--- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index a62ed86..6476e49 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -23,6 +23,7 @@ import javafx.fxml.FXML; import javafx.scene.control.Alert; import javafx.scene.control.Label; import javafx.scene.control.Tooltip; +import javafx.scene.paint.Color; import javafx.stage.FileChooser; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.configuration2.ex.ConfigurationException; @@ -46,8 +47,10 @@ import java.util.Objects; public class Controller { private static final String REGEX = "(?steam_api(?:64)?.dll)$"; + public Label creamApiDllApplied; + public Label creamApiConfigExists; public FontAwesomeIconView creamApiDllAppliedIcon; - public FontAwesomeIconView creamApiConfigExists; + public FontAwesomeIconView creamApiConfigExistsIcon; private CreamApiDllHandler handler = null; private boolean is64Bit; private boolean isSameFile; @@ -124,7 +127,7 @@ public class Controller { private void emptyFields() { creamApiDllAppliedIcon.setGlyphName("TIMES"); - creamApiConfigExists.setGlyphName("TIMES"); + creamApiConfigExistsIcon.setGlyphName("TIMES"); appId_textfield.setText(""); dlc_textarea.setText(""); game_name_textfield.setText(""); @@ -170,7 +173,6 @@ public class Controller { try { config.read(); read(); - updateIndicators(); if (!silent) { state_label.setText("Successfully reset all fields!"); } @@ -183,9 +185,12 @@ public class Controller { state_label.setText("Could not reset fields, no configuration file set!"); } } + updateIndicators(); } private void updateIndicators() { + Color green = Color.web("#43A047"); + Color black = Color.web("#E53935"); try { is64Bit = false; if (!steamApiPathString.isEmpty()) { @@ -197,19 +202,33 @@ public class Controller { String md5 = DigestUtils.md5Hex(is); isSameFile = Objects.equals(md5, handler.getDllMd5(is64Bit)); if (isSameFile) { + creamApiDllApplied.setTextFill(green); + creamApiDllAppliedIcon.setFill(green); creamApiDllAppliedIcon.setGlyphName("CHECK"); } else { + creamApiDllApplied.setTextFill(black); + creamApiDllAppliedIcon.setFill(black); creamApiDllAppliedIcon.setGlyphName("TIMES"); } Path configPath = Paths.get(config.getPath()); - if (Files.exists(configPath) && Files.size(configPath) != 0L) { - creamApiConfigExists.setGlyphName("CHECK"); + if (Files.exists(configPath) && Files.size(configPath) > 0L) { + creamApiConfigExists.setTextFill(green); + creamApiConfigExistsIcon.setFill(green); + creamApiConfigExistsIcon.setGlyphName("CHECK"); } else { - creamApiConfigExists.setGlyphName("TIMES"); + creamApiConfigExists.setTextFill(black); + creamApiConfigExistsIcon.setFill(black); + creamApiConfigExistsIcon.setGlyphName("TIMES"); } } - } catch (IOException e) { - System.err.println("No file found, could not update visual indicators!"); + } catch (Exception e) { + System.err.println("Error! Resetting visual indicators!"); + creamApiDllApplied.setTextFill(black); + creamApiDllAppliedIcon.setFill(black); + creamApiDllAppliedIcon.setGlyphName("TIMES"); + creamApiConfigExists.setTextFill(black); + creamApiConfigExistsIcon.setFill(black); + creamApiConfigExistsIcon.setGlyphName("TIMES"); } } diff --git a/src/main/resources/mainWindow.fxml b/src/main/resources/mainWindow.fxml index a3355a6..24f2cea 100644 --- a/src/main/resources/mainWindow.fxml +++ b/src/main/resources/mainWindow.fxml @@ -99,7 +99,7 @@ From 980b684ee93c5681309207c30ddaf8a95e4cb9af Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Fri, 28 Aug 2020 14:11:49 +0200 Subject: [PATCH 7/7] Visual indicators should work properly now --- src/main/java/Controller.java | 35 +++++++++++++++++++++++------- src/main/resources/mainWindow.fxml | 7 +++--- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/main/java/Controller.java b/src/main/java/Controller.java index a62ed86..ad4de1a 100644 --- a/src/main/java/Controller.java +++ b/src/main/java/Controller.java @@ -23,6 +23,7 @@ import javafx.fxml.FXML; import javafx.scene.control.Alert; import javafx.scene.control.Label; import javafx.scene.control.Tooltip; +import javafx.scene.paint.Color; import javafx.stage.FileChooser; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.configuration2.ex.ConfigurationException; @@ -46,8 +47,10 @@ import java.util.Objects; public class Controller { private static final String REGEX = "(?steam_api(?:64)?.dll)$"; + public Label creamApiDllApplied; + public Label creamApiConfigExists; public FontAwesomeIconView creamApiDllAppliedIcon; - public FontAwesomeIconView creamApiConfigExists; + public FontAwesomeIconView creamApiConfigExistsIcon; private CreamApiDllHandler handler = null; private boolean is64Bit; private boolean isSameFile; @@ -124,7 +127,7 @@ public class Controller { private void emptyFields() { creamApiDllAppliedIcon.setGlyphName("TIMES"); - creamApiConfigExists.setGlyphName("TIMES"); + creamApiConfigExistsIcon.setGlyphName("TIMES"); appId_textfield.setText(""); dlc_textarea.setText(""); game_name_textfield.setText(""); @@ -170,7 +173,6 @@ public class Controller { try { config.read(); read(); - updateIndicators(); if (!silent) { state_label.setText("Successfully reset all fields!"); } @@ -183,9 +185,12 @@ public class Controller { state_label.setText("Could not reset fields, no configuration file set!"); } } + updateIndicators(); } private void updateIndicators() { + Color colorSuccess = Color.web("#43A047"); + Color colorFailure = Color.web("#E53935"); try { is64Bit = false; if (!steamApiPathString.isEmpty()) { @@ -197,19 +202,33 @@ public class Controller { String md5 = DigestUtils.md5Hex(is); isSameFile = Objects.equals(md5, handler.getDllMd5(is64Bit)); if (isSameFile) { + creamApiDllApplied.setTextFill(colorSuccess); + creamApiDllAppliedIcon.setFill(colorSuccess); creamApiDllAppliedIcon.setGlyphName("CHECK"); } else { + creamApiDllApplied.setTextFill(colorFailure); + creamApiDllAppliedIcon.setFill(colorFailure); creamApiDllAppliedIcon.setGlyphName("TIMES"); } Path configPath = Paths.get(config.getPath()); - if (Files.exists(configPath) && Files.size(configPath) != 0L) { - creamApiConfigExists.setGlyphName("CHECK"); + if (Files.exists(configPath) && Files.size(configPath) > 0L) { + creamApiConfigExists.setTextFill(colorSuccess); + creamApiConfigExistsIcon.setFill(colorSuccess); + creamApiConfigExistsIcon.setGlyphName("CHECK"); } else { - creamApiConfigExists.setGlyphName("TIMES"); + creamApiConfigExists.setTextFill(colorFailure); + creamApiConfigExistsIcon.setFill(colorFailure); + creamApiConfigExistsIcon.setGlyphName("TIMES"); } } - } catch (IOException e) { - System.err.println("No file found, could not update visual indicators!"); + } catch (Exception e) { + System.err.println("Error! Resetting visual indicators!"); + creamApiDllApplied.setTextFill(colorFailure); + creamApiDllAppliedIcon.setFill(colorFailure); + creamApiDllAppliedIcon.setGlyphName("TIMES"); + creamApiConfigExists.setTextFill(colorFailure); + creamApiConfigExistsIcon.setFill(colorFailure); + creamApiConfigExistsIcon.setGlyphName("TIMES"); } } diff --git a/src/main/resources/mainWindow.fxml b/src/main/resources/mainWindow.fxml index a3355a6..24f2cea 100644 --- a/src/main/resources/mainWindow.fxml +++ b/src/main/resources/mainWindow.fxml @@ -99,7 +99,7 @@