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