Visual indicators should work properly now

This commit is contained in:
Jeddunk 2020-08-28 14:11:49 +02:00
parent efa6fd29bc
commit 4c8400aa00
2 changed files with 31 additions and 11 deletions

View File

@ -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 = "(?<steamApiDll>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");
}
}

View File

@ -99,7 +99,7 @@
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<Label maxHeight="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity"
text="CreamAPI DLL applied">
text="CreamAPI DLL applied" fx:id="creamApiDllApplied">
<font>
<Font size="14.0"/>
</font>
@ -108,12 +108,13 @@
</graphic>
</Label>
<Label layoutX="20.0" layoutY="20.0" maxHeight="1.7976931348623157E308" minHeight="-Infinity"
minWidth="-Infinity" text="CreamAPI configuration file exists" GridPane.rowIndex="1">
minWidth="-Infinity" text="CreamAPI configuration file exists" GridPane.rowIndex="1"
fx:id="creamApiConfigExists">
<font>
<Font size="14.0"/>
</font>
<graphic>
<FontAwesomeIconView fx:id="creamApiConfigExists" glyphName="TIMES" size="20"/>
<FontAwesomeIconView fx:id="creamApiConfigExistsIcon" glyphName="TIMES" size="20"/>
</graphic>
</Label>
</GridPane>