Browse Source

documentation cleanups, code cleanup

* removed one unnecessary restart
* added warning if the ROM directory could not be opened
pull/18/head
Jannik 4 years ago
parent
commit
061f58105a
  1. 46
      src/main/java/com/cemu_UI/application/MainWindowController.java
  2. 10
      src/main/java/com/cemu_UI/controller/DBController.java

46
src/main/java/com/cemu_UI/application/MainWindowController.java

@ -811,6 +811,15 @@ public class MainWindowController {
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
setRomDirectoryPath(romTextField.getText());
saveSettings();
if (new File(romTextField.getText()).exists()) {
reloadRoms();
} else {
String bodyText = "No such file or directory";
JFXInfoDialog fileErrorDialog = new JFXInfoDialog("Waring!", bodyText, dialogBtnStyle, 190, 150, main.getPane());
fileErrorDialog.show();
LOGGER.warn("Directory does not exist");
}
}
});
@ -905,14 +914,14 @@ public class MainWindowController {
@FXML
void lastTimePlayedBtnAction(ActionEvent event) {
System.out.println(lastTimePlayedBtn.getWidth());
}
@FXML
void cemuTFBtnAction(ActionEvent event) {
File cemuDirectory = directoryChooser.showDialog(main.getPrimaryStage());
if (cemuDirectory == null) {
LOGGER.info("No Directory selected");
LOGGER.warn("No Directory selected");
} else {
setCemuPath(cemuDirectory.getAbsolutePath());
saveSettings();
@ -929,18 +938,17 @@ public class MainWindowController {
@FXML
void romTFBtnAction(ActionEvent event) {
File romDirectory = directoryChooser.showDialog(main.getPrimaryStage());
if (romDirectory == null) {
LOGGER.info("No Directory selected");
setRomDirectoryPath(romDirectory.getAbsolutePath());
saveSettings();
romTextField.setText(getRomDirectoryPath());
if (romDirectory.exists()) {
reloadRoms();
} else {
setRomDirectoryPath(romDirectory.getAbsolutePath());
saveSettings();
cemuTextField.setText(getCemuPath());
try {
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); // start again
System.exit(0); // finishes itself
} catch (IOException e) {
LOGGER.error("an error occurred", e);
}
String bodyText = "No such file or directory";
JFXInfoDialog fileErrorDialog = new JFXInfoDialog("Waring!", bodyText, dialogBtnStyle, 190, 150, main.getPane());
fileErrorDialog.show();
LOGGER.warn("Directory does not exist");
}
}
@ -1269,6 +1277,9 @@ public class MainWindowController {
games.add(uiROMElement);
}
/**
* reload all ROMs from the ROM directory
*/
public void reloadRoms() {
JFXSpinner spinner = new JFXSpinner();
spinner.setPrefSize(30, 30);
@ -1323,6 +1334,7 @@ public class MainWindowController {
}
}
// set the selected local strings to all needed elements
void setUILanguage(){
switch(getLanguage()){
case "en_US":
@ -1405,6 +1417,7 @@ public class MainWindowController {
smmdbDownloadBtnDownload = bundle.getString("smmdbDownloadBtnDownload");
}
// if AutoUpdate, then check for updates
private void checkAutoUpdate() {
if (isAutoUpdate()) {
@ -1574,6 +1587,7 @@ public class MainWindowController {
// System.out.println("xPos: " + xPos);
}
// change the color of all needed GUI elements
private void applyColor() {
String boxStyle = "-fx-background-color: #"+getColor()+";";
String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #"+getColor()+"; -fx-text-fill: BLACK;";
@ -1636,7 +1650,10 @@ public class MainWindowController {
games.get(i).getButton().setRipplerFill(Paint.valueOf(getColor()));
}
}
/**
* save settings to the config.xml file
*/
public void saveSettings(){
LOGGER.info("saving Settings ...");
@ -1658,6 +1675,7 @@ public class MainWindowController {
props.setProperty("lastLocalSync", String.valueOf(getLastLocalSync()));
props.setProperty("windowWidth", String.valueOf(mainAnchorPane.getWidth()));
props.setProperty("windowHeight", String.valueOf(mainAnchorPane.getHeight()));
OutputStream outputStream = new FileOutputStream(main.getConfigFile()); //new output-stream
props.storeToXML(outputStream, "cemu_UI settings"); //write new .xml
outputStream.close();

10
src/main/java/com/cemu_UI/controller/DBController.java

@ -230,7 +230,7 @@ public class DBController {
// for all elements in the games table check if it's already present, else add it
while (rs.next()) {
if (checkEntry(rs.getString(2))) {
if (checkAddEntry(rs.getString(2))) {
LOGGER.info(rs.getString(2) + ": game already in database");
} else {
LOGGER.info("adding cover to cache ...");
@ -252,7 +252,13 @@ public class DBController {
}
}
private boolean checkEntry(String title) throws SQLException{
/**
* check if there is a game with the given name already in the database
* @param title game title
* @return true if the game exists, false if not
* @throws SQLException
*/
private boolean checkAddEntry(String title) throws SQLException{
Statement stmt = connection.createStatement();
boolean check = false;
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms WHERE title = '"+title+"';");

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close