Merge branch 'visual-indicators' into 1.1
# Conflicts: # src/main/java/Controller.java # src/main/resources/mainWindow.fxml
This commit is contained in:
commit
36a05fcd8e
@ -13,11 +13,13 @@
|
|||||||
* <https://www.gnu.org/licenses/>.
|
* <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.concurrent.Service;
|
import javafx.concurrent.Service;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
@ -40,12 +42,20 @@ import java.nio.file.Paths;
|
|||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Controller {
|
public class Controller {
|
||||||
|
|
||||||
private static final String REGEX = "(?<steamApiDll>steam_api(?:64)?.dll)$";
|
private static final String REGEX = "(?<steamApiDll>steam_api(?:64)?.dll)$";
|
||||||
|
public Label creamApiDllApplied;
|
||||||
|
public Label creamApiConfigExists;
|
||||||
|
public FontAwesomeIconView creamApiDllAppliedIcon;
|
||||||
|
public FontAwesomeIconView creamApiConfigExistsIcon;
|
||||||
private CreamApiDllHandler handler = null;
|
private CreamApiDllHandler handler = null;
|
||||||
|
private boolean is64Bit;
|
||||||
|
private boolean isSameFile;
|
||||||
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
handler = CreamApiDllHandler.getInstance();
|
handler = CreamApiDllHandler.getInstance();
|
||||||
@ -102,7 +112,6 @@ public class Controller {
|
|||||||
generate_tooltips();
|
generate_tooltips();
|
||||||
fix_dlc_textarea_prompt_text();
|
fix_dlc_textarea_prompt_text();
|
||||||
reset(true);
|
reset(true);
|
||||||
state_label.setText("Ready.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void read() {
|
private void read() {
|
||||||
@ -117,6 +126,18 @@ public class Controller {
|
|||||||
unlockAll_disableDlcTextArea();
|
unlockAll_disableDlcTextArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void emptyFields() {
|
||||||
|
creamApiDllAppliedIcon.setGlyphName("TIMES");
|
||||||
|
creamApiConfigExistsIcon.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() {
|
private void fix_dlc_textarea_prompt_text() {
|
||||||
dlc_textarea.setPromptText("List of DLC...\r0000 = DLC Name");
|
dlc_textarea.setPromptText("List of DLC...\r0000 = DLC Name");
|
||||||
}
|
}
|
||||||
@ -156,12 +177,60 @@ public class Controller {
|
|||||||
if (!silent) {
|
if (!silent) {
|
||||||
state_label.setText("Successfully reset all fields!");
|
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) {
|
} catch (NullPointerException e) {
|
||||||
System.err.println("Can't fill out fields, no configuration file set!");
|
System.err.println("Can't fill out fields, no configuration file set!");
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
state_label.setText("Could not reset fields, no configuration file set!");
|
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()) {
|
||||||
|
Path dllPath = Paths.get(steamApiPathString);
|
||||||
|
if (dllPath.endsWith("steam_api64.dll")) {
|
||||||
|
is64Bit = true;
|
||||||
|
}
|
||||||
|
InputStream is = Files.newInputStream(dllPath);
|
||||||
|
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.setTextFill(colorSuccess);
|
||||||
|
creamApiConfigExistsIcon.setFill(colorSuccess);
|
||||||
|
creamApiConfigExistsIcon.setGlyphName("CHECK");
|
||||||
|
} else {
|
||||||
|
creamApiConfigExists.setTextFill(colorFailure);
|
||||||
|
creamApiConfigExistsIcon.setFill(colorFailure);
|
||||||
|
creamApiConfigExistsIcon.setGlyphName("TIMES");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} 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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
@ -187,6 +256,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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -301,15 +371,16 @@ public class Controller {
|
|||||||
final File file = chooser.showOpenDialog(path_button.getScene().getWindow());
|
final File file = chooser.showOpenDialog(path_button.getScene().getWindow());
|
||||||
try {
|
try {
|
||||||
config.setConfig(file.getParent() + "\\cream_api.ini");
|
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) {
|
} catch (ConfigurationException | IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
System.err.println("Could not set config file location! Did you cancel the file chooser?");
|
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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -320,31 +391,25 @@ 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, isSameFile);
|
||||||
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));
|
||||||
|
copyDllFile(secondDll, isSameFile1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyDllFile(boolean is64Bit, Path path) throws IOException {
|
private void copyDllFile(Path path, boolean isSameFile) 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 =
|
||||||
|
@ -29,6 +29,11 @@ public class CreamApiConfig {
|
|||||||
private static final Configurations CONFIGS = new Configurations();
|
private static final Configurations CONFIGS = new Configurations();
|
||||||
|
|
||||||
private INIConfiguration config;
|
private INIConfiguration config;
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
private String path = "cream_api.ini";
|
private String path = "cream_api.ini";
|
||||||
private Integer appId;
|
private Integer appId;
|
||||||
private String language;
|
private String language;
|
||||||
@ -57,6 +62,9 @@ public class CreamApiConfig {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
read();
|
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) {
|
} catch (NullPointerException e) {
|
||||||
System.err.println("Can't fill out fields, no configuration file set!");
|
System.err.println("Can't fill out fields, no configuration file set!");
|
||||||
}
|
}
|
||||||
@ -69,8 +77,7 @@ public class CreamApiConfig {
|
|||||||
return configInstance;
|
return configInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read() throws NullPointerException {
|
public void read() throws NullPointerException, NoSuchElementException {
|
||||||
try {
|
|
||||||
appId = config.getInt("steam.appid");
|
appId = config.getInt("steam.appid");
|
||||||
language = config.getString("steam.language");
|
language = config.getString("steam.language");
|
||||||
if (language == null) {
|
if (language == null) {
|
||||||
@ -81,10 +88,6 @@ public class CreamApiConfig {
|
|||||||
forceOffline = config.getBoolean("steam.forceoffline");
|
forceOffline = config.getBoolean("steam.forceoffline");
|
||||||
final SubnodeConfiguration dlc_section = config.getSection("dlc");
|
final SubnodeConfiguration dlc_section = config.getSection("dlc");
|
||||||
dlc_section.getKeys().forEachRemaining(k -> dlc.put(Integer.parseInt(k), dlc_section.getString(k)));
|
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 sync() throws ConfigurationException {
|
public void sync() throws ConfigurationException {
|
||||||
|
@ -8,9 +8,11 @@
|
|||||||
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
|
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.layout.BorderPane?>
|
||||||
<?import javafx.scene.layout.ColumnConstraints?>
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
<?import javafx.scene.layout.GridPane?>
|
<?import javafx.scene.layout.GridPane?>
|
||||||
<?import javafx.scene.layout.RowConstraints?>
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Auto-CreamAPI
|
~ Auto-CreamAPI
|
||||||
@ -28,8 +30,9 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<?import java.net.URL?>
|
<?import java.net.URL?>
|
||||||
<GridPane hgap="10.0" minHeight="400.0" minWidth="655.0" vgap="10.0" xmlns="http://javafx.com/javafx/8.0.171"
|
<BorderPane prefHeight="361.0" prefWidth="693.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller">
|
||||||
xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller">
|
<center>
|
||||||
|
<GridPane hgap="10.0" minHeight="360.0" minWidth="655.0" vgap="10.0">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="-Infinity" prefWidth="375.0"/>
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="-Infinity" prefWidth="375.0"/>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="120.0"/>
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="120.0"/>
|
||||||
@ -86,9 +89,58 @@
|
|||||||
<JFXButton fx:id="reset_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
|
<JFXButton fx:id="reset_button" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
|
||||||
minHeight="-Infinity" minWidth="-Infinity" onAction="#resetFromButton" ripplerFill="BLACK"
|
minHeight="-Infinity" minWidth="-Infinity" onAction="#resetFromButton" ripplerFill="BLACK"
|
||||||
text="Reset" GridPane.columnIndex="2" GridPane.rowIndex="7"/>
|
text="Reset" GridPane.columnIndex="2" GridPane.rowIndex="7"/>
|
||||||
<Label fx:id="state_label" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
|
<BorderPane.margin>
|
||||||
minHeight="-Infinity" minWidth="-Infinity" GridPane.columnSpan="2147483647" GridPane.rowIndex="8"/>
|
<Insets />
|
||||||
|
</BorderPane.margin>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||||
|
</padding>
|
||||||
|
</GridPane>
|
||||||
|
</center>
|
||||||
|
<bottom>
|
||||||
|
<Label fx:id="state_label" maxWidth="1.7976931348623157E308" minHeight="25.0" minWidth="-Infinity" style="-fx-background-color: #ddd; -fx-border-color: #aaa;" text="Ready." textFill="#555555" BorderPane.alignment="CENTER">
|
||||||
|
<BorderPane.margin>
|
||||||
|
<Insets />
|
||||||
|
</BorderPane.margin>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||||
|
</padding></Label>
|
||||||
|
</bottom>
|
||||||
|
<right>
|
||||||
|
<GridPane maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="250.0"
|
||||||
|
BorderPane.alignment="CENTER">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
|
||||||
|
</rowConstraints>
|
||||||
|
<padding>
|
||||||
|
<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" fx:id="creamApiDllApplied">
|
||||||
|
<font>
|
||||||
|
<Font size="14.0"/>
|
||||||
|
</font>
|
||||||
|
<graphic>
|
||||||
|
<FontAwesomeIconView fx:id="creamApiDllAppliedIcon" glyphName="TIMES" size="20"/>
|
||||||
|
</graphic>
|
||||||
|
</Label>
|
||||||
|
<Label layoutX="20.0" layoutY="20.0" maxHeight="1.7976931348623157E308" minHeight="-Infinity"
|
||||||
|
minWidth="-Infinity" text="CreamAPI configuration file exists" GridPane.rowIndex="1"
|
||||||
|
fx:id="creamApiConfigExists">
|
||||||
|
<font>
|
||||||
|
<Font size="14.0"/>
|
||||||
|
</font>
|
||||||
|
<graphic>
|
||||||
|
<FontAwesomeIconView fx:id="creamApiConfigExistsIcon" glyphName="TIMES" size="20"/>
|
||||||
|
</graphic>
|
||||||
|
</Label>
|
||||||
|
</GridPane>
|
||||||
|
</right>
|
||||||
<stylesheets>
|
<stylesheets>
|
||||||
<URL value="@stylesheet.css" />
|
<URL value="@stylesheet.css" />
|
||||||
</stylesheets>
|
</stylesheets>
|
||||||
</GridPane>
|
</BorderPane>
|
Loading…
Reference in New Issue
Block a user