code cleanup

removed some unnecessary save calls
* removed some unnecessary things after opening a directorychooser
* typo fixes
This commit is contained in:
Jannik 2018-02-18 18:27:36 +01:00
parent 061f58105a
commit b4fc36621a
4 changed files with 72 additions and 91 deletions

View File

@ -241,7 +241,7 @@ public class Main extends Application {
saveTask = new TimerTask() { saveTask = new TimerTask() {
@Override @Override
public void run() { public void run() {
mainWindowController.saveSettings(); mainWindowController.saveSettings();
} }
}; };
@ -262,7 +262,7 @@ public class Main extends Application {
saveTask = new TimerTask() { saveTask = new TimerTask() {
@Override @Override
public void run() { public void run() {
mainWindowController.saveSettings(); mainWindowController.saveSettings();
} }
}; };

View File

@ -54,9 +54,9 @@ import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.cemu_UI.controller.DBController;
import com.cemu_UI.controller.SmmdbAPIController; import com.cemu_UI.controller.SmmdbAPIController;
import com.cemu_UI.controller.UpdateController; import com.cemu_UI.controller.UpdateController;
import com.cemu_UI.controller.DBController;
import com.cemu_UI.datatypes.CourseTableDataType; import com.cemu_UI.datatypes.CourseTableDataType;
import com.cemu_UI.datatypes.SmmdbApiDataType; import com.cemu_UI.datatypes.SmmdbApiDataType;
import com.cemu_UI.datatypes.UIROMDataType; import com.cemu_UI.datatypes.UIROMDataType;
@ -801,24 +801,30 @@ public class MainWindowController {
cemuTextField.textProperty().addListener(new ChangeListener<String>() { cemuTextField.textProperty().addListener(new ChangeListener<String>() {
@Override @Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
setCemuPath(cemuTextField.getText()); if (new File(newValue).exists()) {
saveSettings(); setCemuPath(newValue);
saveSettings();
} else {
String bodyText = newValue + ": No such file or directory";
JFXInfoDialog fileErrorDialog = new JFXInfoDialog("Waring!", bodyText, dialogBtnStyle, 190, 150, main.getPane());
fileErrorDialog.show();
LOGGER.warn(newValue + ": No such file or directory");
}
} }
}); });
romTextField.textProperty().addListener(new ChangeListener<String>() { romTextField.textProperty().addListener(new ChangeListener<String>() {
@Override @Override
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()); if (new File(newValue).exists()) {
saveSettings(); setRomDirectoryPath(newValue);
saveSettings();
if (new File(romTextField.getText()).exists()) {
reloadRoms(); reloadRoms();
} else { } else {
String bodyText = "No such file or directory"; String bodyText = newValue + ": No such file or directory";
JFXInfoDialog fileErrorDialog = new JFXInfoDialog("Waring!", bodyText, dialogBtnStyle, 190, 150, main.getPane()); JFXInfoDialog fileErrorDialog = new JFXInfoDialog("Waring!", bodyText, dialogBtnStyle, 190, 150, main.getPane());
fileErrorDialog.show(); fileErrorDialog.show();
LOGGER.warn("Directory does not exist"); LOGGER.warn(newValue + ": No such file or directory");
} }
} }
}); });
@ -827,7 +833,7 @@ public class MainWindowController {
} }
@FXML @FXML
void detailsSlideoutBtnAction(ActionEvent event) { void detailsSlideoutBtnAction() {
playBtnSlideOut(); playBtnSlideOut();
} }
@ -840,7 +846,7 @@ public class MainWindowController {
} }
@FXML @FXML
void settingsBtnAction(ActionEvent event) { void settingsBtnAction() {
if (smmdbTrue) { if (smmdbTrue) {
smmdbAnchorPane.setVisible(false); smmdbAnchorPane.setVisible(false);
smmdbTrue = false; smmdbTrue = false;
@ -900,7 +906,7 @@ public class MainWindowController {
} }
@FXML @FXML
void playBtnAction(ActionEvent event) throws InterruptedException, IOException { void playBtnAction() throws InterruptedException, IOException {
dbController.setLastPlayed(selectedGameTitleID); dbController.setLastPlayed(selectedGameTitleID);
playGame = new playGame(this, dbController); playGame = new playGame(this, dbController);
@ -908,52 +914,33 @@ public class MainWindowController {
} }
@FXML @FXML
void totalPlaytimeBtnAction(ActionEvent event) { void totalPlaytimeBtnAction() {
} }
@FXML @FXML
void lastTimePlayedBtnAction(ActionEvent event) { void lastTimePlayedBtnAction() {
} }
@FXML @FXML
void cemuTFBtnAction(ActionEvent event) { void cemuTFBtnAction() {
File cemuDirectory = directoryChooser.showDialog(main.getPrimaryStage()); File cemuDirectory = directoryChooser.showDialog(main.getPrimaryStage());
if (cemuDirectory == null) { if (cemuDirectory != null) {
LOGGER.warn("No Directory selected"); cemuTextField.setText(cemuDirectory.getAbsolutePath());
} else {
setCemuPath(cemuDirectory.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);
}
} }
} }
@FXML @FXML
void romTFBtnAction(ActionEvent event) { void romTFBtnAction() {
File romDirectory = directoryChooser.showDialog(main.getPrimaryStage()); File romDirectory = directoryChooser.showDialog(main.getPrimaryStage());
setRomDirectoryPath(romDirectory.getAbsolutePath()); if (romDirectory != null) {
saveSettings(); romTextField.setText(romDirectory.getAbsolutePath());
romTextField.setText(getRomDirectoryPath());
if (romDirectory.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");
} }
} }
@FXML @FXML
void updateBtnAction(ActionEvent event) { void updateBtnAction() {
updateController = new UpdateController(this, buildNumber, useBeta); updateController = new UpdateController(this, buildNumber, useBeta);
Thread updateThread = new Thread(updateController); Thread updateThread = new Thread(updateController);
updateThread.setName("Updater"); updateThread.setName("Updater");
@ -961,7 +948,7 @@ public class MainWindowController {
} }
@FXML @FXML
void autoUpdateToggleBtnAction(ActionEvent event) { void autoUpdateToggleBtnAction() {
if (isAutoUpdate()) { if (isAutoUpdate()) {
setAutoUpdate(false); setAutoUpdate(false);
} else { } else {
@ -971,12 +958,12 @@ public class MainWindowController {
} }
@FXML @FXML
void courseSearchTextFiledAction(ActionEvent event) { void courseSearchTextFiledAction() {
// not in use // not in use
} }
@FXML @FXML
void smmdbDownloadBtnAction(ActionEvent event) { void smmdbDownloadBtnAction() {
String downloadUrl = "http://smmdb.ddns.net/api/downloadcourse?id=" + id + "&type=zip"; String downloadUrl = "http://smmdb.ddns.net/api/downloadcourse?id=" + id + "&type=zip";
String downloadFileURL = getCemuPath() + "/" + id + ".zip"; // getCemuPath() + "/" + smmID + "/" + id + ".rar" String downloadFileURL = getCemuPath() + "/" + id + ".zip"; // getCemuPath() + "/" + smmID + "/" + id + ".rar"
String outputFile = getCemuPath() + "/"; String outputFile = getCemuPath() + "/";
@ -1044,7 +1031,7 @@ public class MainWindowController {
} }
@FXML @FXML
void fullscreenToggleBtnAction(ActionEvent event) { void fullscreenToggleBtnAction() {
if (fullscreen) { if (fullscreen) {
fullscreen = false; fullscreen = false;
} else { } else {
@ -1054,7 +1041,7 @@ public class MainWindowController {
} }
@FXML @FXML
void cloudSyncToggleBtnAction(ActionEvent event) { void cloudSyncToggleBtnAction() {
if(cloudSync) { if(cloudSync) {
cloudSync = false; cloudSync = false;
} else { } else {
@ -1103,13 +1090,13 @@ public class MainWindowController {
} }
@FXML @FXML
void colorPickerAction(ActionEvent event) { void colorPickerAction() {
editColor(colorPicker.getValue().toString()); editColor(colorPicker.getValue().toString());
applyColor(); applyColor();
} }
@FXML @FXML
void addBtnAction(ActionEvent event) { void addBtnAction() {
String headingText = addGameBtnHeadingText; String headingText = addGameBtnHeadingText;
String bodyText = addGameBtnBodyText; String bodyText = addGameBtnBodyText;
JFXEditGameDialog addGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450, 300, 0, JFXEditGameDialog addGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450, 300, 0,
@ -1308,15 +1295,9 @@ public class MainWindowController {
thread.start(); thread.start();
} }
// add all games saved in games(ArrayList) to gamesAnchorPane
void addUIData() {
for (int i = 0; i < games.size(); i++) {
gamesAnchorPane.getChildren().add(games.get(i).getVBox());
}
}
//remove all games from gamesAnchorPane and add them afterwards //remove all games from gamesAnchorPane and add them afterwards
public void refreshUIData() { public void refreshUIData() {
System.out.println("refresh");
//remove all games form gamesAnchorPane //remove all games form gamesAnchorPane
gamesAnchorPane.getChildren().removeAll(gamesAnchorPane.getChildren()); gamesAnchorPane.getChildren().removeAll(gamesAnchorPane.getChildren());
@ -1654,11 +1635,11 @@ public class MainWindowController {
/** /**
* save settings to the config.xml file * save settings to the config.xml file
*/ */
public void saveSettings(){ public void saveSettings() {
LOGGER.info("saving Settings ..."); LOGGER.info("saving Settings ...");
try { try {
props.setProperty("cemuPath", getCemuPath()); props.setProperty("cemuPath", getCemuPath());
props.setProperty("romPath", getRomDirectoryPath()); props.setProperty("romPath", getRomDirectoryPath());
props.setProperty("color", getColor()); props.setProperty("color", getColor());
props.setProperty("language", getLanguage()); props.setProperty("language", getLanguage());
@ -1675,89 +1656,89 @@ 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();
LOGGER.info("saving Settings done!"); LOGGER.info("saving Settings done!");
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("an error occured", e); LOGGER.error("an error occured", e);
} }
} }
/** /**
* loading saved settings from the config.xml file * loading saved settings from the config.xml file
* if a value is not present, default is used instead * if a value is not present, default is used instead
*/ */
private void loadSettings(){ private void loadSettings() {
LOGGER.info("loading settings ..."); LOGGER.info("loading settings ...");
try { try {
InputStream inputStream = new FileInputStream(main.getConfigFile()); InputStream inputStream = new FileInputStream(main.getConfigFile());
props.loadFromXML(inputStream); //new input-stream from .xml props.loadFromXML(inputStream); // new input-stream from .xml
try { try {
setCemuPath(props.getProperty("cemuPath")); setCemuPath(props.getProperty("cemuPath"));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("cloud not load cemuPath", e); LOGGER.error("cloud not load cemuPath", e);
setCemuPath(""); setCemuPath("");
} }
try { try {
setRomDirectoryPath(props.getProperty("romPath")); setRomDirectoryPath(props.getProperty("romPath"));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("could not load romPath", e); LOGGER.error("could not load romPath", e);
setRomDirectoryPath(""); setRomDirectoryPath("");
} }
try { try {
setColor(props.getProperty("color")); setColor(props.getProperty("color"));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("could not load color value, setting default instead", e); LOGGER.error("could not load color value, setting default instead", e);
setColor("00a8cc"); setColor("00a8cc");
} }
if (props.getProperty("language") == null) { if (props.getProperty("language") == null) {
LOGGER.error("cloud not load language, setting default instead"); LOGGER.error("cloud not load language, setting default instead");
setLanguage("en_US"); setLanguage("en_US");
} else { } else {
setLanguage(props.getProperty("language")); setLanguage(props.getProperty("language"));
} }
try { try {
setFullscreen(Boolean.parseBoolean(props.getProperty("fullscreen"))); setFullscreen(Boolean.parseBoolean(props.getProperty("fullscreen")));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("could not load fullscreen, setting default instead", e); LOGGER.error("could not load fullscreen, setting default instead", e);
setFullscreen(false); setFullscreen(false);
} }
try { try {
setCloudSync(Boolean.parseBoolean(props.getProperty("cloudSync"))); setCloudSync(Boolean.parseBoolean(props.getProperty("cloudSync")));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("could not load cloudSync, setting default instead", e); LOGGER.error("could not load cloudSync, setting default instead", e);
setCloudSync(false); setCloudSync(false);
} }
try { try {
setAutoUpdate(Boolean.parseBoolean(props.getProperty("autoUpdate"))); setAutoUpdate(Boolean.parseBoolean(props.getProperty("autoUpdate")));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("cloud not load autoUpdate", e); LOGGER.error("cloud not load autoUpdate", e);
setAutoUpdate(false); setAutoUpdate(false);
} }
try { try {
setUseBeta(Boolean.parseBoolean(props.getProperty("useBeta"))); setUseBeta(Boolean.parseBoolean(props.getProperty("useBeta")));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("cloud not load autoUpdate", e); LOGGER.error("cloud not load autoUpdate", e);
setUseBeta(false); setUseBeta(false);
} }
try { try {
setCloudService(props.getProperty("cloudService")); setCloudService(props.getProperty("cloudService"));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("could not load cloudSync", e); LOGGER.error("could not load cloudSync", e);
setCloudService(""); setCloudService("");
} }
try { try {
main.getCloudController().setFolderID(props.getProperty("folderID"), getCloudService()); main.getCloudController().setFolderID(props.getProperty("folderID"), getCloudService());
} catch (Exception e) { } catch (Exception e) {
@ -1771,27 +1752,27 @@ public class MainWindowController {
LOGGER.error("could not load lastSuccessSync, setting default instead", e); LOGGER.error("could not load lastSuccessSync, setting default instead", e);
setLastLocalSync(0); setLastLocalSync(0);
} }
try { try {
setWindowWidth(Double.parseDouble(props.getProperty("windowWidth"))); setWindowWidth(Double.parseDouble(props.getProperty("windowWidth")));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("could not load windowWidth, setting default instead", e); LOGGER.error("could not load windowWidth, setting default instead", e);
setWindowWidth(904); setWindowWidth(904);
} }
try { try {
setWindowHeight(Double.parseDouble(props.getProperty("windowHeight"))); setWindowHeight(Double.parseDouble(props.getProperty("windowHeight")));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("could not load windowHeight, setting default instead", e); LOGGER.error("could not load windowHeight, setting default instead", e);
setWindowHeight(600); setWindowHeight(600);
} }
inputStream.close(); inputStream.close();
LOGGER.info("loading settings done!"); LOGGER.info("loading settings done!");
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("an error occured", e); LOGGER.error("an error occured", e);
} }
} }
private void sideMenuSlideIn(){ private void sideMenuSlideIn(){
sideMenuVBox.setVisible(true); sideMenuVBox.setVisible(true);

View File

@ -57,7 +57,7 @@ public class playGame extends Thread{
mainWindowController.main.getPrimaryStage().setIconified(true); // minimize cemu_UI mainWindowController.main.getPrimaryStage().setIconified(true); // minimize cemu_UI
}); });
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
try { try {
if (System.getProperty("os.name").equals("Linux")) { if (System.getProperty("os.name").equals("Linux")) {
if(mainWindowController.isFullscreen()){ if(mainWindowController.isFullscreen()){
p = new ProcessBuilder("wine", cemuBin, "-f", "-g", gameExec).start(); p = new ProcessBuilder("wine", cemuBin, "-f", "-g", gameExec).start();

View File

@ -2,7 +2,7 @@
# Buttons # Buttons
aboutBtn = About aboutBtn = About
settingsBtn = Setting settingsBtn = Settings
addBtn = Add new Game addBtn = Add new Game
reloadRomsBtn = reload ROMs reloadRomsBtn = reload ROMs
smmdbBtn = smmdb smmdbBtn = smmdb