reworked loadSettings

* loadSettings() should be 100% bulletproof
* replaced a few more syso with logger
This commit is contained in:
Jannik
2017-08-30 11:29:58 +02:00
parent 71cf0316ec
commit 6c1663f386
25 changed files with 117 additions and 81 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+5 -2
View File
@@ -53,7 +53,8 @@ public class CloudController {
main.mainWindowController.saveSettings(); main.mainWindowController.saveSettings();
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
public void run() { @Override
public void run() {
Platform.runLater(() -> { Platform.runLater(() -> {
main.mainWindowController.getPlayBtn().setText("syncing..."); main.mainWindowController.getPlayBtn().setText("syncing...");
}); });
@@ -82,6 +83,7 @@ public class CloudController {
//running sync in a new thread, instead of blocking the main thread //running sync in a new thread, instead of blocking the main thread
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
@Override
public void run() { public void run() {
Platform.runLater(() -> { Platform.runLater(() -> {
main.mainWindowController.getPlayBtn().setText("syncing..."); main.mainWindowController.getPlayBtn().setText("syncing...");
@@ -113,7 +115,8 @@ public class CloudController {
//running uploadFile in a new thread, instead of blocking the main thread //running uploadFile in a new thread, instead of blocking the main thread
new Thread() { new Thread() {
public void run() { @Override
public void run() {
System.out.println("starting uploadFile in new thread..."); System.out.println("starting uploadFile in new thread...");
if(cloudService.equals("GoogleDrive")) { if(cloudService.equals("GoogleDrive")) {
-7
View File
@@ -91,7 +91,6 @@ public class Main extends Application {
//check if client_secret.jason is present //check if client_secret.jason is present
if (Main.class.getResourceAsStream("/resources/client_secret.json") == null) { if (Main.class.getResourceAsStream("/resources/client_secret.json") == null) {
LOGGER.error("client_secret is missing!!!!!"); LOGGER.error("client_secret is missing!!!!!");
// System.err.println("client_secret is missing!!!!!");
Alert alert = new Alert(AlertType.ERROR); Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("cemu_UI"); alert.setTitle("cemu_UI");
@@ -102,18 +101,14 @@ public class Main extends Application {
LOGGER.info("Directory: " + directory.exists()); LOGGER.info("Directory: " + directory.exists());
LOGGER.info("Configfile: " + configFile.exists()); LOGGER.info("Configfile: " + configFile.exists());
// System.out.println("Directory: " + directory.exists());
// System.out.println("configfile: " + configFile.exists());
if(!directory.exists()){ if(!directory.exists()){
LOGGER.info("creating cemu_UI directory"); LOGGER.info("creating cemu_UI directory");
// System.out.println("mkdir all");
directory.mkdir(); directory.mkdir();
pictureCache.mkdir(); pictureCache.mkdir();
} }
if(!configFile.exists()){ if(!configFile.exists()){
LOGGER.info("firststart, setting default values"); LOGGER.info("firststart, setting default values");
// System.out.println("firststart");
firstStart(); firstStart();
mainWindowController.setColor("00a8cc"); mainWindowController.setColor("00a8cc");
mainWindowController.setxPosHelper(0); mainWindowController.setxPosHelper(0);
@@ -129,14 +124,12 @@ public class Main extends Application {
if(gamesDBFile.exists() != true){ if(gamesDBFile.exists() != true){
try { try {
LOGGER.info("downloading games.db... "); LOGGER.info("downloading games.db... ");
// System.out.print("downloading games.db... ");
URL website = new URL(gamesDBdownloadURL); URL website = new URL(gamesDBdownloadURL);
ReadableByteChannel rbc = Channels.newChannel(website.openStream()); ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(gamesDBFile); FileOutputStream fos = new FileOutputStream(gamesDBFile);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close(); fos.close();
LOGGER.info("finished downloading games.db"); LOGGER.info("finished downloading games.db");
// System.out.println("done!");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
+102 -68
View File
@@ -229,8 +229,8 @@ public class MainWindowController {
private DirectoryChooser directoryChooser = new DirectoryChooser(); private DirectoryChooser directoryChooser = new DirectoryChooser();
private File dirWin = new File(System.getProperty("user.home") + "/Documents/cemu_UI"); private File dirWin = new File(System.getProperty("user.home") + "/Documents/cemu_UI");
private File dirLinux = new File(System.getProperty("user.home") + "/cemu_UI"); private File dirLinux = new File(System.getProperty("user.home") + "/cemu_UI");
private File fileWin = new File(dirWin + "/config.xml"); private File configFileWin = new File(dirWin + "/config.xml");
private File fileLinux = new File(dirLinux + "/config.xml"); private File configFileLinux = new File(dirLinux + "/config.xml");
File pictureCacheWin = new File(dirWin+"/picture_cache"); File pictureCacheWin = new File(dirWin+"/picture_cache");
File pictureCacheLinux = new File(dirLinux+"/picture_cache"); File pictureCacheLinux = new File(dirLinux+"/picture_cache");
private ObservableList<String> smmIDs = FXCollections.observableArrayList("fe31b7f2", "44fc5929"); //TODO add more IDs private ObservableList<String> smmIDs = FXCollections.observableArrayList("fe31b7f2", "44fc5929"); //TODO add more IDs
@@ -301,7 +301,6 @@ public class MainWindowController {
*/ */
void initActions() { void initActions() {
LOGGER.info("initializing Actions... "); LOGGER.info("initializing Actions... ");
// System.out.println("initializing Actions... ");
HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam); HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam);
menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{ menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{
@@ -409,7 +408,7 @@ public class MainWindowController {
String updatePath; String updatePath;
System.out.println("update: "+selectedGameTitleID); System.out.println("update: "+selectedGameTitleID);
if(selectedGameTitleID == null){ if(selectedGameTitleID == null){
System.out.println("trying to update null! null is not valid!"); LOGGER.error("trying to update null! null is not valid!");
Alert alert = new Alert(AlertType.WARNING); Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("edit"); alert.setTitle("edit");
alert.setHeaderText("cemu_UI"); alert.setHeaderText("cemu_UI");
@@ -433,21 +432,21 @@ public class MainWindowController {
File srcDir = new File(updatePath); File srcDir = new File(updatePath);
File destDir = new File(cemuPath+"\\mlc01\\usr\\title\\"+parts[0]+"\\"+parts[1]); File destDir = new File(cemuPath+"\\mlc01\\usr\\title\\"+parts[0]+"\\"+parts[1]);
System.out.println(updatePath); LOGGER.info(updatePath);
System.out.println(destDir.toString()); LOGGER.info(destDir.toString());
if(destDir.exists() != true){ if(destDir.exists() != true){
destDir.mkdir(); destDir.mkdir();
} }
try { try {
System.out.println("copying files..."); LOGGER.info("copying files...");
playBtn.setText("updating..."); playBtn.setText("updating...");
playBtn.setDisable(true); playBtn.setDisable(true);
FileUtils.copyDirectory(srcDir, destDir); //TODO progress indicator FileUtils.copyDirectory(srcDir, destDir); //TODO progress indicator
playBtn.setText("play"); playBtn.setText("play");
playBtn.setDisable(false); playBtn.setDisable(false);
System.out.println("done!"); LOGGER.info("copying files done!");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -464,7 +463,7 @@ public class MainWindowController {
String titleID = selectedGameTitleID; String titleID = selectedGameTitleID;
String dlcPath; String dlcPath;
System.out.println("add DLC: "+selectedGameTitleID); LOGGER.info("add DLC: "+selectedGameTitleID);
if(selectedGameTitleID == null){ if(selectedGameTitleID == null){
System.out.println("trying to add a dlc to null! null is not valid!"); System.out.println("trying to add a dlc to null! null is not valid!");
Alert alert = new Alert(AlertType.WARNING); Alert alert = new Alert(AlertType.WARNING);
@@ -490,21 +489,21 @@ public class MainWindowController {
File srcDir = new File(dlcPath); File srcDir = new File(dlcPath);
File destDir = new File(cemuPath+"\\mlc01\\usr\\title\\"+parts[0]+"\\"+parts[1]+"\\aoc"); File destDir = new File(cemuPath+"\\mlc01\\usr\\title\\"+parts[0]+"\\"+parts[1]+"\\aoc");
System.out.println(dlcPath); LOGGER.info(dlcPath);
System.out.println(destDir.toString()); LOGGER.info(destDir.toString());
if(destDir.exists() != true){ if(destDir.exists() != true){
destDir.mkdir(); destDir.mkdir();
} }
try { try {
System.out.println("copying files..."); LOGGER.info("copying files...");
playBtn.setText("copying files..."); playBtn.setText("copying files...");
playBtn.setDisable(true); playBtn.setDisable(true);
FileUtils.copyDirectory(srcDir, destDir); //TODO progress indicator FileUtils.copyDirectory(srcDir, destDir); //TODO progress indicator
playBtn.setText("play"); playBtn.setText("play");
playBtn.setDisable(false); playBtn.setDisable(false);
System.out.println("done!"); LOGGER.info("copying files done!");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -545,7 +544,6 @@ public class MainWindowController {
for (int i = 0; i < courses.size(); i++) { for (int i = 0; i < courses.size(); i++) {
if (courses.get(i).getId() == id) { if (courses.get(i).getId() == id) {
try { try {
// System.out.println("http://smmdb.ddns.net/courseimg/" + id + "_full.jpg?v=3");
URL url = new URL("http://smmdb.ddns.net/courseimg/" + id + "_full.jpg?v=3"); URL url = new URL("http://smmdb.ddns.net/courseimg/" + id + "_full.jpg?v=3");
Image image = new Image(url.toURI().toString()); Image image = new Image(url.toURI().toString());
smmdbImageView.setImage(image); smmdbImageView.setImage(image);
@@ -573,7 +571,6 @@ public class MainWindowController {
} }
}); });
LOGGER.info("initializing Actions done!"); LOGGER.info("initializing Actions done!");
// System.out.println("initializing Actions done!");
} }
@FXML @FXML
@@ -677,7 +674,7 @@ public class MainWindowController {
void cemuTFBtnAction(ActionEvent event) { void cemuTFBtnAction(ActionEvent event) {
File cemuDirectory = directoryChooser.showDialog(main.primaryStage); File cemuDirectory = directoryChooser.showDialog(main.primaryStage);
if(cemuDirectory == null){ if(cemuDirectory == null){
System.out.println("No Directory selected"); LOGGER.info("No Directory selected");
}else{ }else{
setCemuPath(cemuDirectory.getAbsolutePath()); setCemuPath(cemuDirectory.getAbsolutePath());
saveSettings(); saveSettings();
@@ -696,7 +693,7 @@ public class MainWindowController {
void romTFBtnAction(ActionEvent event) { void romTFBtnAction(ActionEvent event) {
File romDirectory = directoryChooser.showDialog(main.primaryStage); File romDirectory = directoryChooser.showDialog(main.primaryStage);
if(romDirectory == null){ if(romDirectory == null){
System.out.println("No Directory selected"); LOGGER.info("No Directory selected");
}else{ }else{
setRomPath(romDirectory.getAbsolutePath()); setRomPath(romDirectory.getAbsolutePath());
saveSettings(); saveSettings();
@@ -727,7 +724,7 @@ public class MainWindowController {
pm.setMaximum(conn.getContentLength()); // tell the progress bar the total number of bytes we are going to read. pm.setMaximum(conn.getContentLength()); // tell the progress bar the total number of bytes we are going to read.
FileUtils.copyInputStreamToFile(pmis, new File(downloadFileURL)); //download file + "/mlc01/emulatorSave" FileUtils.copyInputStreamToFile(pmis, new File(downloadFileURL)); //download file + "/mlc01/emulatorSave"
pmis.close(); pmis.close();
System.out.println("downloaded successfull"); LOGGER.info("downloaded successfull");
File downloadFile = new File(downloadFileURL); File downloadFile = new File(downloadFileURL);
@@ -765,16 +762,14 @@ public class MainWindowController {
//rename zipfile //rename zipfile
File course = new File(destination + "/course000"); File course = new File(destination + "/course000");
course.renameTo( new File(destination + "/" + courseName)); course.renameTo( new File(destination + "/" + courseName));
System.out.println("Added new course: " + courseName + ", full path is: " + destination + "/" + courseName); LOGGER.info("Added new course: " + courseName + ", full path is: " + destination + "/" + courseName);
} catch (ZipException e) { } catch (ZipException e) {
e.printStackTrace(); LOGGER.error("an error occurred during unziping the file!", e);
System.err.println("an error occurred during unziping the file!");
} }
downloadFile.delete(); downloadFile.delete();
} catch (IOException e) { } catch (IOException e) {
System.err.println("something went wrong during downloading the course"); LOGGER.error("something went wrong during downloading the course", e);
e.printStackTrace();
} }
} }
@@ -934,7 +929,7 @@ public class MainWindowController {
* then add the rom to the local_roms database * then add the rom to the local_roms database
*/ */
if(exit){ if(exit){
System.out.println("No parameter set!"); LOGGER.info("No parameter set!");
}else{ }else{
coverName = new File(coverPath).getName(); coverName = new File(coverPath).getName();
try { try {
@@ -950,16 +945,14 @@ public class MainWindowController {
ImageIO.write(resizeImagePNG, "png", new File(pictureCache+"\\"+coverName)); //save image to pictureCache ImageIO.write(resizeImagePNG, "png", new File(pictureCache+"\\"+coverName)); //save image to pictureCache
coverPath = pictureCache+"\\"+coverName; coverPath = pictureCache+"\\"+coverName;
} catch (IOException e) { } catch (IOException e) {
System.out.println("Ops something went wrong!"); LOGGER.error("Ops something went wrong!", e);
} }
try { try {
dbController.addRom(title, coverPath, romPath, titleID, "", "", "", "0"); dbController.addRom(title, coverPath, romPath, titleID, "", "", "", "0");
dbController.loadSingleRom(titleID); dbController.loadSingleRom(titleID);
} catch (SQLException e) { } catch (SQLException e) {
// Auto-generated catch block LOGGER.error("Oops, something went wrong! Error during adding a game.", e);
System.out.println("Oops, something went wrong! Error during adding a game.");
e.printStackTrace();
} }
} }
} }
@@ -980,7 +973,7 @@ public class MainWindowController {
Image coverImage = new Image(coverFile.toURI().toString()); Image coverImage = new Image(coverFile.toURI().toString());
generatePosition(); generatePosition();
System.out.println("add " + getxPos()); //TODO debug LOGGER.info("add " + getxPos()); //TODO debug
VBox.setLayoutX(getxPos()); VBox.setLayoutX(getxPos());
VBox.setLayoutY(getyPos()); VBox.setLayoutY(getyPos());
VBox.getChildren().addAll(gameTitleLabel,gameBtn); VBox.getChildren().addAll(gameTitleLabel,gameBtn);
@@ -996,7 +989,7 @@ public class MainWindowController {
gameBtn.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { gameBtn.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override @Override
public void handle(MouseEvent event) { public void handle(MouseEvent event) {
System.out.println("selected: "+title+"; ID: "+titleID); LOGGER.info("selected: "+title+"; ID: "+titleID);
//getting the selected game index by comparing event.getSource() with games.get(i).getButton() //getting the selected game index by comparing event.getSource() with games.get(i).getButton()
for(int i=0; i<games.size(); i++){ for(int i=0; i<games.size(); i++){
@@ -1269,59 +1262,100 @@ public class MainWindowController {
void saveSettings(){ void saveSettings(){
LOGGER.info("saving Settings..."); LOGGER.info("saving Settings...");
// System.out.print("saving Settings... "); OutputStream outputStream; //new output-stream
OutputStream outputStream; //new output-stream try {
try { props.setProperty("cemuPath", getCemuPath());
props.setProperty("cemuPath", getCemuPath()); props.setProperty("romPath", getRomPath());
props.setProperty("romPath", getRomPath()); props.setProperty("color", getColor());
props.setProperty("color", getColor()); props.setProperty("fullscreen", String.valueOf(isFullscreen()));
props.setProperty("fullscreen", String.valueOf(isFullscreen())); props.setProperty("cloudSync", String.valueOf(cloudSync));
props.setProperty("cloudSync", String.valueOf(cloudSync)); if (getCloudService() == null) {
if (getCloudService() == null) { props.setProperty("cloudService", "");
props.setProperty("cloudService", ""); } else {
} else { props.setProperty("cloudService", getCloudService());
props.setProperty("cloudService", getCloudService()); }
} props.setProperty("folderID", main.cloudController.getFolderID(getCloudService()));
props.setProperty("folderID", main.cloudController.getFolderID(getCloudService())); if(System.getProperty("os.name").equals("Linux")){
if(System.getProperty("os.name").equals("Linux")){ outputStream = new FileOutputStream(configFileLinux);
outputStream = new FileOutputStream(fileLinux); }else{
}else{ outputStream = new FileOutputStream(configFileWin);
outputStream = new FileOutputStream(fileWin);
}
props.storeToXML(outputStream, "cemu_UI settings"); //write new .xml
outputStream.close();
LOGGER.info("saving Settings done!");
// System.out.println("done!");
} catch (IOException e) {
LOGGER.error("an error occured", e);
// e.printStackTrace();
} }
props.storeToXML(outputStream, "cemu_UI settings"); //write new .xml
outputStream.close();
LOGGER.info("saving Settings done!");
} catch (IOException e) {
LOGGER.error("an error occured", e);
}
} }
/**
* loading saved settings from the config.xml file
* if a value is not present, default is used instead
*/
void loadSettings(){ void loadSettings(){
LOGGER.info("loading settings..."); LOGGER.info("loading settings...");
// System.out.print("loading settings... ");
InputStream inputStream; InputStream inputStream;
try { try {
if(System.getProperty("os.name").equals("Linux")){ if(System.getProperty("os.name").equals("Linux")){
inputStream = new FileInputStream(fileLinux); inputStream = new FileInputStream(configFileLinux);
}else{ }else{
inputStream = new FileInputStream(fileWin); inputStream = new FileInputStream(configFileWin);
} }
props.loadFromXML(inputStream); //new input-stream from .xml props.loadFromXML(inputStream); //new input-stream from .xml
setCemuPath(props.getProperty("cemuPath"));
setRomPath(props.getProperty("romPath")); try {
setColor(props.getProperty("color")); setCemuPath(props.getProperty("cemuPath"));
setFullscreen(Boolean.parseBoolean(props.getProperty("fullscreen"))); } catch (Exception e) {
setCloudSync(Boolean.parseBoolean(props.getProperty("cloudSync"))); LOGGER.error("cloud not load cemuPath", e);
setCloudService(props.getProperty("cloudService")); setCemuPath("");
main.cloudController.setFolderID(props.getProperty("folderID"), getCloudService()); }
try {
setRomPath(props.getProperty("romPath"));
} catch (Exception e) {
LOGGER.error("could not load romPath", e);
setRomPath("");
}
try {
setColor(props.getProperty("color"));
} catch (Exception e) {
LOGGER.error("could not load color value, setting default instead", e);
setColor("00a8cc");
}
try {
setFullscreen(Boolean.parseBoolean(props.getProperty("fullscreen")));
} catch (Exception e) {
LOGGER.error("could not load fullscreen, setting default instead", e);
setFullscreen(false);
}
try {
setCloudSync(Boolean.parseBoolean(props.getProperty("cloudSync")));
} catch (Exception e) {
LOGGER.error("could not load cloudSync, setting default instead", e);
setCloudSync(false);
}
try {
setCloudService(props.getProperty("cloudService"));
} catch (Exception e) {
LOGGER.error("could not load cloudSync", e);
setCloudService("");
}
try {
main.cloudController.setFolderID(props.getProperty("folderID"), getCloudService());
} catch (Exception e) {
LOGGER.error("could not load folderID, disable cloud sync. Please contact an developer", e);
setCloudSync(false);
}
inputStream.close(); inputStream.close();
LOGGER.info("loading settings done!"); LOGGER.info("loading settings done!");
// System.out.println("done!");
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("an error occured", e); LOGGER.error("an error occured", e);
// e.printStackTrace();
} }
} }
+9 -4
View File
@@ -9,6 +9,10 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.eclipsesource.json.Json; import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray; import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonValue; import com.eclipsesource.json.JsonValue;
@@ -18,6 +22,7 @@ import datatypes.SmmdbApiDataType;
public class SmmdbApiQuery { public class SmmdbApiQuery {
private String URL = "http://smmdb.ddns.net/api/getcourses?"; private String URL = "http://smmdb.ddns.net/api/getcourses?";
private static final Logger LOGGER = LogManager.getLogger(SmmdbApiQuery.class.getName());
public SmmdbApiQuery() { public SmmdbApiQuery() {
//Auto-generated constructor stub //Auto-generated constructor stub
@@ -37,11 +42,10 @@ public class SmmdbApiQuery {
BufferedReader ina = new BufferedReader(new InputStreamReader(apiUrl.openStream())); BufferedReader ina = new BufferedReader(new InputStreamReader(apiUrl.openStream()));
output = ina.readLine(); output = ina.readLine();
ina.close(); ina.close();
System.out.println("response from " + URL + " was valid"); LOGGER.info("response from " + URL + " was valid");
} catch (IOException e) { } catch (IOException e) {
System.out.println("error while making api request or reading response"); LOGGER.error("error while making api request or reading response");
System.out.println("response from " + URL + " was: " + output); LOGGER.error("response from " + URL + " was: " + output, e);
e.printStackTrace();
} }
String apiOutput = "{ \"courses\": " + output + "}"; String apiOutput = "{ \"courses\": " + output + "}";
@@ -116,6 +120,7 @@ public class SmmdbApiQuery {
} catch (Exception e) { } catch (Exception e) {
nintendoid = "notset"; nintendoid = "notset";
} }
try { try {
title = item.asObject().getString("title", "");; title = item.asObject().getString("title", "");;
} catch (Exception e) { } catch (Exception e) {
+1
View File
@@ -28,6 +28,7 @@ public class playGame extends Thread{
dbController = db; dbController = db;
} }
@Override
public void run(){ public void run(){
String selectedGameTitleID = mainWindowController.getSelectedGameTitleID(); String selectedGameTitleID = mainWindowController.getSelectedGameTitleID();
String executeComand; String executeComand;