From 980b684ee93c5681309207c30ddaf8a95e4cb9af Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Fri, 28 Aug 2020 14:11:49 +0200 Subject: [PATCH] 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 @@