diff --git a/.classpath b/.classpath index 4959c4e..63d30d8 100644 --- a/.classpath +++ b/.classpath @@ -20,10 +20,10 @@ - - + + diff --git a/bin/.gitignore b/bin/.gitignore index 7885cd5..18eab41 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,4 +1,3 @@ /application/ /resources/ -/log4j2.xml -/snippet/ +/cloudControllerInstances/ diff --git a/bin/application/CloudController$1.class b/bin/application/CloudController$1.class index b7c69cc..4935c64 100644 Binary files a/bin/application/CloudController$1.class and b/bin/application/CloudController$1.class differ diff --git a/bin/application/CloudController$2.class b/bin/application/CloudController$2.class index 4862738..39f3eb2 100644 Binary files a/bin/application/CloudController$2.class and b/bin/application/CloudController$2.class differ diff --git a/bin/application/CloudController$3.class b/bin/application/CloudController$3.class index d0b0686..3058cdf 100644 Binary files a/bin/application/CloudController$3.class and b/bin/application/CloudController$3.class differ diff --git a/bin/application/CloudController.class b/bin/application/CloudController.class index 1121c7a..dde3943 100644 Binary files a/bin/application/CloudController.class and b/bin/application/CloudController.class differ diff --git a/bin/application/MainWindow.fxml b/bin/application/MainWindow.fxml index d61b2d2..c745c9e 100644 --- a/bin/application/MainWindow.fxml +++ b/bin/application/MainWindow.fxml @@ -110,8 +110,8 @@ - + - \ No newline at end of file + diff --git a/bin/application/MainWindowController$12.class b/bin/application/MainWindowController$12.class index cc7b003..48751b4 100644 Binary files a/bin/application/MainWindowController$12.class and b/bin/application/MainWindowController$12.class differ diff --git a/bin/application/MainWindowController.class b/bin/application/MainWindowController.class index 767fc97..51479fd 100644 Binary files a/bin/application/MainWindowController.class and b/bin/application/MainWindowController.class differ diff --git a/bin/application/SmmdbApiQuery.class b/bin/application/SmmdbApiQuery.class index 4610d27..a1097a2 100644 Binary files a/bin/application/SmmdbApiQuery.class and b/bin/application/SmmdbApiQuery.class differ diff --git a/bin/application/dbController.class b/bin/application/dbController.class index d116fcf..ba561da 100644 Binary files a/bin/application/dbController.class and b/bin/application/dbController.class differ diff --git a/bin/application/playGame.class b/bin/application/playGame.class index c6e8af5..5e89f50 100644 Binary files a/bin/application/playGame.class and b/bin/application/playGame.class differ diff --git a/bin/cloudControllerInstances/GoogleDriveController.class b/bin/cloudControllerInstances/GoogleDriveController.class index 35d9ff8..7b3469e 100644 Binary files a/bin/cloudControllerInstances/GoogleDriveController.class and b/bin/cloudControllerInstances/GoogleDriveController.class differ diff --git a/bin/libraries/jfoenix-1.7.0.jar b/bin/libraries/jfoenix-1.8.0.jar similarity index 91% rename from bin/libraries/jfoenix-1.7.0.jar rename to bin/libraries/jfoenix-1.8.0.jar index 33f545f..1f58fd6 100644 Binary files a/bin/libraries/jfoenix-1.7.0.jar and b/bin/libraries/jfoenix-1.8.0.jar differ diff --git a/bin/libraries/sqlite-jdbc-3.19.3.jar b/bin/libraries/sqlite-jdbc-3.19.3.jar deleted file mode 100644 index c29a09f..0000000 Binary files a/bin/libraries/sqlite-jdbc-3.19.3.jar and /dev/null differ diff --git a/bin/libraries/sqlite-jdbc-3.20.0.jar b/bin/libraries/sqlite-jdbc-3.20.0.jar new file mode 100644 index 0000000..f6aa562 Binary files /dev/null and b/bin/libraries/sqlite-jdbc-3.20.0.jar differ diff --git a/bin/log4j2.xml b/bin/log4j2.xml new file mode 100644 index 0000000..b3ad7b2 --- /dev/null +++ b/bin/log4j2.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/application/CloudController.java b/src/application/CloudController.java index 7f1d1a0..74d72f2 100644 --- a/src/application/CloudController.java +++ b/src/application/CloudController.java @@ -16,6 +16,9 @@ import java.io.File; import java.io.IOException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import cloudControllerInstances.GoogleDriveController; import javafx.application.Platform; @@ -27,26 +30,27 @@ public CloudController(Main ma) { private Main main; private GoogleDriveController googleDriveController = new GoogleDriveController(); + private static final Logger LOGGER = LogManager.getLogger(CloudController.class.getName()); void initializeConnection(String cloudService, String cemuDirectory) { - System.out.println("sartting cloud initialisation... "); + LOGGER.info("sartting cloud initialisation ..."); if(cloudService.equals("GoogleDrive")) { - System.out.println("selected service is Google Drive"); + LOGGER.info("selected service is Google Drive"); try { googleDriveController.main(cemuDirectory); } catch (IOException e) { - e.printStackTrace(); + LOGGER.error("error while initialize connection", e); } } if(cloudService.equals("Dropbox")) { - System.out.println("selected service is Dropbox"); + LOGGER.info("selected service is Dropbox"); } - System.out.println("cloud initialisation done!"); + LOGGER.info("cloud initialisation done!"); } void stratupCheck(String cloudService, String cemuDirectory) { if(cloudService.equals("GoogleDrive")) { - System.out.println("starting startup check google drive..."); + LOGGER.info("starting startup check google drive ..."); try { if (!googleDriveController.checkFolder()) { googleDriveController.creatFolder(); @@ -69,7 +73,7 @@ public void run() { sync(cloudService, cemuDirectory); } } catch (IOException e) { - e.printStackTrace(); + LOGGER.error("google drive startup check failed", e); } } if(cloudService.equals("Dropbox")) { @@ -88,13 +92,13 @@ public void run() { Platform.runLater(() -> { main.mainWindowController.getPlayBtn().setText("syncing..."); }); - System.out.println("starting sync in new thread..."); + LOGGER.info("starting synchronization in new thread ..."); if(cloudService.equals("GoogleDrive")) { try { googleDriveController.sync(cemuDirectory); } catch (IOException e) { - e.printStackTrace(); + LOGGER.error("google drive synchronization failed", e); } } if(cloudService.equals("Dropbox")) { @@ -104,7 +108,7 @@ public void run() { main.mainWindowController.getPlayBtn().setText("play"); }); main.mainWindowController.saveSettings(); - System.out.println("sync finished!"); + LOGGER.info("synchronization successful!"); } }); thread.start(); @@ -117,13 +121,13 @@ void uploadFile(String cloudService, File file) { new Thread() { @Override public void run() { - System.out.println("starting uploadFile in new thread..."); + LOGGER.info("starting uploadFile in new thread ..."); if(cloudService.equals("GoogleDrive")) { try { googleDriveController.uploadFile(file); } catch (IOException e) { - e.printStackTrace(); + LOGGER.error("google drive uploadFile failed" ,e); } } if(cloudService.equals("Dropbox")) { diff --git a/src/application/MainWindow.fxml b/src/application/MainWindow.fxml index d61b2d2..c745c9e 100644 --- a/src/application/MainWindow.fxml +++ b/src/application/MainWindow.fxml @@ -110,8 +110,8 @@ - + - \ No newline at end of file + diff --git a/src/application/MainWindowController.java b/src/application/MainWindowController.java index 64741bd..55d9677 100644 --- a/src/application/MainWindowController.java +++ b/src/application/MainWindowController.java @@ -130,7 +130,7 @@ public class MainWindowController { private JFXButton lastTimePlayedBtn; @FXML - JFXButton timePlayedBtn; + JFXButton totalPlaytimeBtn; @FXML private JFXHamburger menuHam; @@ -218,9 +218,9 @@ public class MainWindowController { private String selectedGameTitleID; private String selectedGameTitle; private String id; - private String version = "0.1.6"; - private String buildNumber = "037"; - private String versionName = "Throwback Galaxy"; + private String version = "0.1.7"; + private String buildNumber = "039"; + private String versionName = "Throwback Galaxy"; private int xPos = -200; private int yPos = 17; private int xPosHelper; @@ -661,7 +661,7 @@ void playBtnAction(ActionEvent event) throws InterruptedException, IOException{ } @FXML - void timePlayedBtnAction(ActionEvent event){ + void totalPlaytimeBtnAction(ActionEvent event){ } @@ -1010,7 +1010,7 @@ public void handle(MouseEvent event) { //setting last played if(dbController.getLastPlayed(titleID).equals("") || dbController.getLastPlayed(titleID).equals(null)){ lastTimePlayedBtn.setText("Last played, never"); - timePlayedBtn.setText(dbController.getTimePlayed(titleID)+ " min"); + totalPlaytimeBtn.setText(dbController.getTotalPlaytime(titleID)+ " min"); }else{ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); @@ -1025,12 +1025,12 @@ public void handle(MouseEvent event) { }else{ lastTimePlayedBtn.setText("Last played, "+dbController.getLastPlayed(titleID)); } - if(Integer.parseInt(dbController.getTimePlayed(titleID)) > 60){ - int hoursPlayed = (int) Math.floor(Integer.parseInt(dbController.getTimePlayed(titleID))/60); - int minutesPlayed = Integer.parseInt(dbController.getTimePlayed(titleID))-60*hoursPlayed; - timePlayedBtn.setText(hoursPlayed+"h "+minutesPlayed+"min"); + if(Integer.parseInt(dbController.getTotalPlaytime(titleID)) > 60){ + int hoursPlayed = (int) Math.floor(Integer.parseInt(dbController.getTotalPlaytime(titleID))/60); + int minutesPlayed = Integer.parseInt(dbController.getTotalPlaytime(titleID))-60*hoursPlayed; + totalPlaytimeBtn.setText(hoursPlayed+"h "+minutesPlayed+"min"); }else{ - timePlayedBtn.setText(dbController.getTimePlayed(titleID)+ " min"); + totalPlaytimeBtn.setText(dbController.getTotalPlaytime(titleID)+ " min"); } } @@ -1261,7 +1261,7 @@ private void applyColor() { } void saveSettings(){ - LOGGER.info("saving Settings..."); + LOGGER.info("saving Settings ..."); OutputStream outputStream; //new output-stream try { props.setProperty("cemuPath", getCemuPath()); @@ -1293,7 +1293,7 @@ void saveSettings(){ * if a value is not present, default is used instead */ void loadSettings(){ - LOGGER.info("loading settings..."); + LOGGER.info("loading settings ..."); InputStream inputStream; try { if(System.getProperty("os.name").equals("Linux")){ @@ -1394,7 +1394,7 @@ private void sideMenuSlideOut(){ private void playBtnSlideIn(){ playBtn.setVisible(true); lastTimePlayedBtn.setVisible(true); - timePlayedBtn.setVisible(true); + totalPlaytimeBtn.setVisible(true); playTrue = true; TranslateTransition playBtnTransition = new TranslateTransition(Duration.millis(300), playBtn); @@ -1407,7 +1407,7 @@ private void playBtnSlideIn(){ lastTimePlayedBtnTransition.setToY(0); lastTimePlayedBtnTransition.play(); - TranslateTransition timePlayedBtnTransition = new TranslateTransition(Duration.millis(300), timePlayedBtn); + TranslateTransition timePlayedBtnTransition = new TranslateTransition(Duration.millis(300), totalPlaytimeBtn); timePlayedBtnTransition.setFromY(55); timePlayedBtnTransition.setToY(0); timePlayedBtnTransition.play(); @@ -1425,7 +1425,7 @@ void playBtnSlideOut(){ lastTimePlayedBtnTransition.setToY(56); lastTimePlayedBtnTransition.play(); - TranslateTransition timePlayedBtnTransition = new TranslateTransition(Duration.millis(300), timePlayedBtn); + TranslateTransition timePlayedBtnTransition = new TranslateTransition(Duration.millis(300), totalPlaytimeBtn); timePlayedBtnTransition.setFromY(0); timePlayedBtnTransition.setToY(56); timePlayedBtnTransition.play(); diff --git a/src/application/SmmdbApiQuery.java b/src/application/SmmdbApiQuery.java index b920a2b..a64c105 100644 --- a/src/application/SmmdbApiQuery.java +++ b/src/application/SmmdbApiQuery.java @@ -21,7 +21,8 @@ public class SmmdbApiQuery { - private String URL = "http://smmdb.ddns.net/api/getcourses?"; + //FIXME limit=70 as workaround for to long response, courseDataGz is to long + private String URL = "http://smmdb.ddns.net/api/getcourses?format=json&limit=70"; private static final Logger LOGGER = LogManager.getLogger(SmmdbApiQuery.class.getName()); public SmmdbApiQuery() { @@ -42,13 +43,14 @@ public ArrayList startQuery() { BufferedReader ina = new BufferedReader(new InputStreamReader(apiUrl.openStream())); output = ina.readLine(); ina.close(); + System.out.println(output); LOGGER.info("response from " + URL + " was valid"); } catch (IOException e) { LOGGER.error("error while making api request or reading response"); LOGGER.error("response from " + URL + " was: " + output, e); } - String apiOutput = "{ \"courses\": " + output + "}"; + String apiOutput = "{ \"courses\": " + output + "}"; JsonArray items = Json.parse(apiOutput).asObject().get("courses").asArray(); for (JsonValue item : items) { diff --git a/src/application/dbController.java b/src/application/dbController.java index d3e3677..c421d77 100644 --- a/src/application/dbController.java +++ b/src/application/dbController.java @@ -32,6 +32,8 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -47,15 +49,16 @@ public dbController(MainWindowController m) { private String DB_PATH_games; private Connection connection = null; private Connection connectionGames = null; + private static final Logger LOGGER = LogManager.getLogger(dbController.class.getName()); public void main(){ - System.out.println("<==========starting loading sql==========>"); + LOGGER.info("<==========starting loading sql==========>"); loadRomDatabase(); loadGamesDatabase(); createRomDatabase(); loadAllRoms(); checkRemoveEntry(); - System.out.println("<==========finished loading sql==========>"); + LOGGER.info("<==========finished loading sql==========>"); } private void loadRomDatabase(){ @@ -70,9 +73,9 @@ private void loadRomDatabase(){ connection.setAutoCommit(false); //AutoCommit to false -> manual commit is active } catch (SQLException e) { // if the error message is "out of memory", it probably means no database file is found - System.err.println(e.getMessage()); + LOGGER.error("error while loading the ROM database", e); } - System.out.println("rom database loaded successfull"); + LOGGER.info("ROM database loaded successfull"); } /** @@ -91,9 +94,9 @@ private void loadGamesDatabase(){ connectionGames.setAutoCommit(false); //AutoCommit to false -> manual commit is active } catch (SQLException e) { // if the error message is "out of memory", it probably means no database file is found - System.err.println(e.getMessage()); + LOGGER.error("error while loading the games database", e); } - System.out.println("games database loaded successfull"); + LOGGER.info("games database loaded successfull"); } //creating database, if database has 0 entries search for all .rpx files in the roms directory and add them @@ -103,8 +106,8 @@ void createRomDatabase() { stmt.executeUpdate("create table if not exists local_roms (title, coverPath, romPath, titleID, productCode, region, lastPlayed, timePlayed)"); stmt.close(); connection.commit(); - } catch (SQLException e1) { - e1.printStackTrace(); + } catch (SQLException e) { + LOGGER.error("error while creating ROM database", e); } try { @@ -115,9 +118,8 @@ void createRomDatabase() { } stmt.close(); rs.close(); - }catch (SQLException ea){ - System.err.println("Ups! an error occured!"); - ea.printStackTrace(); + }catch (SQLException e){ + LOGGER.error("error while loading ROMs from ROM database, local_roms table", e); } if(entries.size() == 0){ loadRomDirectory(mainWindowController.getRomPath()); @@ -129,7 +131,7 @@ void addRom(String title, String coverPath, String romPath, String titleID, Stri stmt.executeUpdate("insert into local_roms values ('"+title+"','"+coverPath+"','"+romPath+"','"+titleID+"','"+productCode+"','"+region+"','"+lastPlayed+"','"+timePlayed+"')"); connection.commit(); stmt.close(); - System.out.println("added \""+title+"\" to databsae"); + LOGGER.info("added \""+title+"\" to ROM database"); } void removeRom(String titleID) throws SQLException{ @@ -137,12 +139,12 @@ void removeRom(String titleID) throws SQLException{ stmt.executeUpdate("delete from local_roms where titleID = '"+titleID+"'"); connection.commit(); stmt.close(); - System.out.println("removed \""+titleID+"\" from databsae"); + LOGGER.info("removed \""+titleID+"\" from ROM database"); } - //load all rom's on startup to the UI + //load all ROMs on startup to the mainWindowController void loadAllRoms(){ - System.out.println("loading all rom's on startup to mwc ..."); + LOGGER.info("loading all rom's on startup into the mainWindowController ..."); try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms"); @@ -152,13 +154,13 @@ void loadAllRoms(){ stmt.close(); rs.close(); }catch (Exception e){ - e.printStackTrace(); + LOGGER.error("error while loading all ROMs into the mainWindowController", e); } } - //load one single rom after manual adding one + //load one single ROM after manual adding into the mainWindowController void loadSingleRom(String titleID){ - System.out.println("loading a single rom (ID: "+titleID+") to mwc ..."); + LOGGER.info("loading a single ROM (ID: "+titleID+") into the mainWindowController ..."); try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms where titleID = '"+titleID+"'"); @@ -168,7 +170,7 @@ void loadSingleRom(String titleID){ stmt.close(); rs.close(); }catch (Exception e){ - e.printStackTrace(); + LOGGER.error("error while loading a single ROM into the mainWindowController", e); } } @@ -188,7 +190,7 @@ void loadRomDirectory(String directory){ try { Statement stmt = connectionGames.createStatement(); - System.out.println("Getting all .rpx files in " + dir.getCanonicalPath()+" including those in subdirectories \n"); + LOGGER.info("Getting all .rpx files in " + dir.getCanonicalPath()+" including those in subdirectories"); List files = (List) FileUtils.listFiles(dir, extensions, true); for (File file : files) { if(System.getProperty("os.name").equals("Linux")){ @@ -201,16 +203,13 @@ void loadRomDirectory(String directory){ Document document = documentBuilder.parse(appFile); String title_ID = document.getElementsByTagName("title_id").item(0).getTextContent(); title_ID = title_ID.substring(0, 8) + "-" + title_ID.substring(8, title_ID.length()); - System.out.println("Name: "+file.getName()+"; Title ID: "+title_ID); + LOGGER.info("Name: "+file.getName()+"; Title ID: "+title_ID); ResultSet rs = stmt.executeQuery("SELECT * FROM games WHERE TitleID = '"+title_ID+"';"); while (rs.next()) { - System.out.print(rs.getString(2)); if (checkEntry(rs.getString(2))) { - System.out.println(": game already in database"); + LOGGER.info(rs.getString(2) + ": game already in database"); }else{ - System.out.println(": add game"); - System.out.println("adding cover to cache ..."); - + LOGGER.info("adding cover to cache ..."); BufferedImage originalImage = ImageIO.read(new URL(rs.getString(6)));//change path to where file is located int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType(); BufferedImage resizeImagePNG = resizeImage(originalImage, type, 400, 600); @@ -221,15 +220,14 @@ void loadRomDirectory(String directory){ ImageIO.write(resizeImagePNG, "png", new File(pictureCache+"\\"+rs.getString(3)+".png")); //change path where you want it saved coverPath = pictureCache+"\\"+rs.getString(3)+".png"; } - + + LOGGER.info(rs.getString(2) + ": adding ROM"); addRom(rs.getString(2), coverPath, file.getCanonicalPath(), rs.getString(1), rs.getString(3), rs.getString(5),"","0"); } } - System.out.println(""); } } catch (IOException | SQLException | ParserConfigurationException | SAXException e) { - System.out.println("Ups something went wrong!"); - e.printStackTrace(); + LOGGER.error("error while loading ROMs from directory", e); } } @@ -244,8 +242,11 @@ private boolean checkEntry(String title) throws SQLException{ } private void checkRemoveEntry() { - // TODO needs to be implemented! - System.out.println("check if entry removed not done yet!"); + /** + * TODO needs to be implemented! + * don't show ROM on the UI, but keep all parameter in case it's showing up again ask if old data should be used + */ + //LOGGER.info("check if entry removed not done yet!"); } private static BufferedImage resizeImage(BufferedImage originalImage, int type, int IMG_WIDTH, int IMG_HEIGHT) { @@ -264,7 +265,7 @@ void setLastPlayed(String titleID){ connection.commit(); stmt.close(); }catch(SQLException e){ - e.printStackTrace(); + LOGGER.error("failed to set the last played", e); } } @@ -277,23 +278,24 @@ String getLastPlayed(String titleID){ stmt.close(); rs.close(); }catch(SQLException e){ - e.printStackTrace(); + LOGGER.error("failed to get the last played", e); } return lastPlayed; } - void setTimePlayed(String timePlayed, String titleID){ + void setTotalPlaytime(String timePlayed, String titleID){ try{ Statement stmt = connection.createStatement(); stmt.executeUpdate("UPDATE local_roms SET timePlayed='"+timePlayed+"' WHERE titleID = '"+titleID+"';"); connection.commit(); stmt.close(); }catch(SQLException e){ + LOGGER.error("failed to set total play time", e); e.printStackTrace(); } } - String getTimePlayed(String titleID){ + String getTotalPlaytime(String titleID){ String timePlayed = null; try{ Statement stmt = connection.createStatement(); @@ -302,7 +304,7 @@ String getTimePlayed(String titleID){ stmt.close(); rs.close(); }catch(SQLException e){ - e.printStackTrace(); + LOGGER.error("failed to get total play time", e); } return timePlayed; } diff --git a/src/application/playGame.java b/src/application/playGame.java index 256896b..6f8305d 100644 --- a/src/application/playGame.java +++ b/src/application/playGame.java @@ -16,12 +16,16 @@ import java.io.IOException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import javafx.application.Platform; public class playGame extends Thread{ MainWindowController mainWindowController; dbController dbController; + private static final Logger LOGGER = LogManager.getLogger(playGame.class.getName()); public playGame(MainWindowController m, dbController db){ mainWindowController = m; @@ -56,22 +60,22 @@ public void run(){ executeComand = mainWindowController.getCemuPath()+"\\Cemu.exe -g \""+mainWindowController.getGameExecutePath()+"\""; } } - System.out.println(executeComand); + LOGGER.info(executeComand); p = Runtime.getRuntime().exec(executeComand); p.waitFor(); endTime = System.currentTimeMillis(); timePlayedNow = (int) Math.floor(((endTime - startTime)/1000/60)); - timePlayed = Integer.parseInt(dbController.getTimePlayed(selectedGameTitleID))+timePlayedNow; + timePlayed = Integer.parseInt(dbController.getTotalPlaytime(selectedGameTitleID))+timePlayedNow; - dbController.setTimePlayed(Integer.toString(timePlayed), selectedGameTitleID); + dbController.setTotalPlaytime(Integer.toString(timePlayed), selectedGameTitleID); Platform.runLater(() -> { - if(Integer.parseInt(dbController.getTimePlayed(selectedGameTitleID)) > 60){ - int hoursPlayed = (int) Math.floor(Integer.parseInt(dbController.getTimePlayed(selectedGameTitleID))/60); - int minutesPlayed = Integer.parseInt(dbController.getTimePlayed(selectedGameTitleID))-60*hoursPlayed; - mainWindowController.timePlayedBtn.setText(hoursPlayed+"h "+minutesPlayed+"min"); + if(Integer.parseInt(dbController.getTotalPlaytime(selectedGameTitleID)) > 60){ + int hoursPlayed = (int) Math.floor(Integer.parseInt(dbController.getTotalPlaytime(selectedGameTitleID))/60); + int minutesPlayed = Integer.parseInt(dbController.getTotalPlaytime(selectedGameTitleID))-60*hoursPlayed; + mainWindowController.totalPlaytimeBtn.setText(hoursPlayed+"h "+minutesPlayed+"min"); }else{ - mainWindowController.timePlayedBtn.setText(dbController.getTimePlayed(selectedGameTitleID)+ " min"); + mainWindowController.totalPlaytimeBtn.setText(dbController.getTotalPlaytime(selectedGameTitleID)+ " min"); } mainWindowController.main.primaryStage.setIconified(false); }); diff --git a/src/cloudControllerInstances/GoogleDriveController.java b/src/cloudControllerInstances/GoogleDriveController.java index 5c0058c..e5f92e3 100644 --- a/src/cloudControllerInstances/GoogleDriveController.java +++ b/src/cloudControllerInstances/GoogleDriveController.java @@ -11,6 +11,8 @@ import java.util.List; import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp; @@ -39,6 +41,7 @@ public class GoogleDriveController { private ArrayList cloudSavegames = new ArrayList<>(); private ArrayList localSavegamesName = new ArrayList<>(); private ArrayList cloudSavegamesName = new ArrayList<>(); + private static final Logger LOGGER = LogManager.getLogger(GoogleDriveController.class.getName()); private final String APPLICATION_NAME ="cemu_Ui Drive API Controller"; @@ -65,7 +68,7 @@ public GoogleDriveController() { DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); folderID = ""; } catch (Throwable t) { - t.printStackTrace(); + LOGGER.error("error", t); System.exit(1); } } @@ -87,7 +90,7 @@ public Credential authorize() throws IOException { .setAccessType("offline") .build(); Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); - System.out.println("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath()); + LOGGER.info("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath()); return credential; } @@ -129,19 +132,19 @@ public void sync(String cemuDirectory) throws IOException { FileInputStream fis = new FileInputStream(localSavegames.get(localSavegamesNumber)); if (cloudSavegames.get(i).getMd5Checksum().equals(org.apache.commons.codec.digest.DigestUtils.md5Hex(fis))) { - System.out.println("both files are the same, nothing to do"); + LOGGER.info("both files are the same, nothing to do"); } else { if (localModified >= cloudModified) { - System.out.print("local is newer, "); + LOGGER.info("local is newer"); updateFile(cloudSavegames.get(i), localSavegames.get(localSavegamesNumber)); } else { - System.out.print("cloud is newer, "); + LOGGER.info("cloud is newer"); downloadFile(cloudSavegames.get(i)); } } } else { - System.out.print("file doesn't exist locally, "); + LOGGER.info("file doesn't exist locally"); downloadFile(cloudSavegames.get(i)); } } @@ -149,7 +152,7 @@ public void sync(String cemuDirectory) throws IOException { // upload file to cloud which don't exist in the cloud for (int j = 0; j < localSavegames.size(); j++) { if (!cloudSavegamesName.contains(localSavegamesName.get(j))) { - System.out.print("file doesn't exist in the cloud, "); + LOGGER.info("file doesn't exist in the cloud"); uploadFile(localSavegames.get(j)); } } @@ -157,13 +160,13 @@ public void sync(String cemuDirectory) throws IOException { //create a folder in google drive public void creatFolder() throws IOException { - System.out.println("creating new folder"); + LOGGER.info("creating new folder"); File fileMetadata = new File(); fileMetadata.setName("cemu_savegames"); fileMetadata.setMimeType("application/vnd.google-apps.folder"); File file = service.files().create(fileMetadata).setFields("id").execute(); - System.out.println("Folder ID: " + file.getId()); + LOGGER.info("Folder ID: " + file.getId()); folderID = file.getId(); } @@ -189,7 +192,7 @@ private void getLocalSavegames() throws IOException { String[] extensions = new String[] { "dat","sav","bin" }; localSavegames.removeAll(localSavegames); localSavegamesName.removeAll(localSavegamesName); - System.out.println("Getting all dat,sav,bin files in " + dir.getCanonicalPath()+" including those in subdirectories"); + LOGGER.info("Getting all dat,sav,bin files in " + dir.getCanonicalPath()+" including those in subdirectories"); List files = (List) FileUtils.listFiles(dir, extensions, true); for (java.io.File file : files) { localSavegamesName.add(file.getParentFile().getName()+"_"+file.getName()); @@ -199,7 +202,7 @@ private void getLocalSavegames() throws IOException { //reading all cloud savegames private void getCloudSavegames() throws IOException { - System.out.println("getting all cloud savegames"); + LOGGER.info("getting all cloud savegames"); cloudSavegames.removeAll(cloudSavegames); cloudSavegamesName.removeAll(cloudSavegamesName); Files.List request = service.files().list().setQ("'"+folderID+"' in parents").setFields("nextPageToken, files(id, name, size, modifiedTime, createdTime, md5Checksum)"); @@ -216,46 +219,45 @@ private void getSavegamesFolderID() throws IOException { FileList files = request.execute(); try { - System.out.println("FolderID: " + files.getFiles().get(0).getId()); + LOGGER.info("FolderID: " + files.getFiles().get(0).getId()); setFolderID(files.getFiles().get(0).getId()); } catch (Exception e) { - System.out.println("Oops, something went wrong! It seems that you have more than one folder called 'cemu_savegames'!"); - e.printStackTrace(); + LOGGER.error("Oops, something went wrong! It seems that you have more than one folder called 'cemu_savegames'!", e); } } //upload a file to the cloud from the local savegames folder public void uploadFile(java.io.File uploadFile) throws IOException{ - System.out.println("uploading " + uploadFile.getName() + "..."); + LOGGER.info("uploading " + uploadFile.getName() + " ..."); File fileMetadata = new File(); fileMetadata.setName(uploadFile.getParentFile().getName()+"_"+uploadFile.getName()); fileMetadata.setParents(Collections.singletonList(folderID)); fileMetadata.setModifiedTime(new DateTime(uploadFile.lastModified())); FileContent mediaContent = new FileContent("", uploadFile); File file = service.files().create(fileMetadata, mediaContent).setFields("id, parents").execute(); - System.out.println("upload successfull, File ID: " + file.getId()); + LOGGER.info("upload successfull, File ID: " + file.getId()); } //download a file from the cloud to the local savegames folder - private void downloadFile(File downloadFile) throws IOException{ - System.out.print("downloading "+downloadFile.getName()+"... "); + private void downloadFile(File downloadFile) throws IOException{ + LOGGER.info("downloading "+downloadFile.getName()+" ..."); java.io.File directory = new java.io.File(cemuDirectory+"/mlc01/emulatorSave/"+ downloadFile.getName().substring(0,8)); String file = downloadFile.getName().substring(9,downloadFile.getName().length()); if(!directory.exists()) { - System.out.print("dir dosent exist... "); + LOGGER.info("dir dosent exist"); directory.mkdir(); } OutputStream outputStream = new FileOutputStream(directory +"/"+ file); service.files().get(downloadFile.getId()).executeMediaAndDownloadTo(outputStream); outputStream.close(); - System.out.println("done"); + LOGGER.info("download successfull, File ID: " + file); //TODO add FileID } //update a file in the cloud, by deleting the old one and uploading an new with the same id private void updateFile(File oldFile, java.io.File newFile) throws IOException { - System.out.println("updating " +oldFile.getName()+"... "); + LOGGER.info("updating " +oldFile.getName()+" ..."); service.files().delete(oldFile.getId()).execute(); //deleting old file //uploading new file @@ -266,21 +268,19 @@ private void updateFile(File oldFile, java.io.File newFile) throws IOException { FileContent mediaContent = new FileContent("", newFile); File file = service.files().create(fileMetadata, mediaContent).setFields("id, parents").execute(); - System.out.println("File ID: " + file.getId()); + LOGGER.info("update successfull, File ID: " + file.getId()); } public void uploadAllFiles() { try { getLocalSavegames(); - System.out.println("uploading " + localSavegames.size() + " files..."); + LOGGER.info("uploading " + localSavegames.size() + " files ..."); for (int i = 0; i < localSavegames.size(); i++) { uploadFile(localSavegames.get(i)); } - System.out.println("finished uploading all files!"); + LOGGER.info("finished uploading all files"); } catch (IOException e) { - //Auto-generated catch block - System.out.println("Oops, there went something wrong! Error during uploading all files."); - e.printStackTrace(); + LOGGER.error("error while uploading all files", e); } } diff --git a/src/libraries/jfoenix-1.7.0.jar b/src/libraries/jfoenix-1.8.0.jar similarity index 91% rename from src/libraries/jfoenix-1.7.0.jar rename to src/libraries/jfoenix-1.8.0.jar index 33f545f..1f58fd6 100644 Binary files a/src/libraries/jfoenix-1.7.0.jar and b/src/libraries/jfoenix-1.8.0.jar differ diff --git a/src/libraries/sqlite-jdbc-3.19.3.jar b/src/libraries/sqlite-jdbc-3.19.3.jar deleted file mode 100644 index c29a09f..0000000 Binary files a/src/libraries/sqlite-jdbc-3.19.3.jar and /dev/null differ diff --git a/src/libraries/sqlite-jdbc-3.20.0.jar b/src/libraries/sqlite-jdbc-3.20.0.jar new file mode 100644 index 0000000..f6aa562 Binary files /dev/null and b/src/libraries/sqlite-jdbc-3.20.0.jar differ