documentation cleanups, code cleanup

* removed one unnecessary restart
* added warning if the ROM directory could not be opened
This commit is contained in:
Jannik 2018-02-18 13:57:30 +01:00
parent 3a6a7b7cce
commit 061f58105a
2 changed files with 40 additions and 16 deletions

View File

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

View File

@ -230,7 +230,7 @@ public class DBController {
// for all elements in the games table check if it's already present, else add it // for all elements in the games table check if it's already present, else add it
while (rs.next()) { while (rs.next()) {
if (checkEntry(rs.getString(2))) { if (checkAddEntry(rs.getString(2))) {
LOGGER.info(rs.getString(2) + ": game already in database"); LOGGER.info(rs.getString(2) + ": game already in database");
} else { } else {
LOGGER.info("adding cover to cache ..."); 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(); Statement stmt = connection.createStatement();
boolean check = false; boolean check = false;
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms WHERE title = '"+title+"';"); ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms WHERE title = '"+title+"';");