more logger work and lib updates
* jfoenix 1.7.0 -> 1.8.0 * sqlite 3.19.1 -> 3.20.0 * replaced all remaining syso/syse with logger output * fixed a bug in smmdb api integration by only requesting the first 70 courses (this is a temporary workaround) * code clean up * typo fixes
This commit is contained in:
@ -16,6 +16,9 @@ package application;
|
||||
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 class CloudController {
|
||||
|
||||
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 class CloudController {
|
||||
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 class CloudController {
|
||||
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 class CloudController {
|
||||
main.mainWindowController.getPlayBtn().setText("play");
|
||||
});
|
||||
main.mainWindowController.saveSettings();
|
||||
System.out.println("sync finished!");
|
||||
LOGGER.info("synchronization successful!");
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
@ -117,13 +121,13 @@ public class CloudController {
|
||||
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")) {
|
||||
|
@ -110,8 +110,8 @@
|
||||
<Font name="System Bold" size="14.0" />
|
||||
</font>
|
||||
</JFXButton>
|
||||
<JFXButton fx:id="timePlayedBtn" buttonType="RAISED" maxHeight="32.0" minWidth="100.0" onAction="#timePlayedBtnAction" prefHeight="32.0" style="-fx-background-color: #ffffff; -fx-button-type: RAISED; -fx-text-fill: BLACK;" visible="false" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="516.5" AnchorPane.topAnchor="558.0">
|
||||
<JFXButton fx:id="totalPlaytimeBtn" buttonType="RAISED" maxHeight="32.0" minWidth="100.0" onAction="#totalPlaytimeBtnAction" prefHeight="32.0" style="-fx-background-color: #ffffff; -fx-button-type: RAISED; -fx-text-fill: BLACK;" visible="false" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="516.5" AnchorPane.topAnchor="558.0">
|
||||
</JFXButton>
|
||||
<JFXButton fx:id="lastTimePlayedBtn" buttonType="RAISED" maxHeight="32.0" minWidth="100.0" onAction="#lastTimePlayedBtnAction" prefHeight="32.0" style="-fx-background-color: #ffffff; -fx-button-type: RAISED; -fx-text-fill: BLACK;" visible="false" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="516.5" AnchorPane.topAnchor="558.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</AnchorPane>
|
||||
|
@ -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 @@ public class MainWindowController {
|
||||
}
|
||||
|
||||
@FXML
|
||||
void timePlayedBtnAction(ActionEvent event){
|
||||
void totalPlaytimeBtnAction(ActionEvent event){
|
||||
|
||||
}
|
||||
|
||||
@ -1010,7 +1010,7 @@ public class MainWindowController {
|
||||
//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 class MainWindowController {
|
||||
}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 @@ public class MainWindowController {
|
||||
}
|
||||
|
||||
void saveSettings(){
|
||||
LOGGER.info("saving Settings...");
|
||||
LOGGER.info("saving Settings ...");
|
||||
OutputStream outputStream; //new output-stream
|
||||
try {
|
||||
props.setProperty("cemuPath", getCemuPath());
|
||||
@ -1293,7 +1293,7 @@ public class MainWindowController {
|
||||
* 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 @@ public class MainWindowController {
|
||||
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 @@ public class MainWindowController {
|
||||
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 @@ public class MainWindowController {
|
||||
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();
|
||||
|
@ -21,7 +21,8 @@ import datatypes.SmmdbApiDataType;
|
||||
|
||||
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 class SmmdbApiQuery {
|
||||
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) {
|
||||
|
@ -32,6 +32,8 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||
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 class dbController {
|
||||
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 @@ public class dbController {
|
||||
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 @@ public class dbController {
|
||||
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 @@ public class dbController {
|
||||
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 @@ public class dbController {
|
||||
}
|
||||
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 @@ public class dbController {
|
||||
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 @@ public class dbController {
|
||||
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 @@ public class dbController {
|
||||
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 @@ public class dbController {
|
||||
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 @@ public class dbController {
|
||||
|
||||
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<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true);
|
||||
for (File file : files) {
|
||||
if(System.getProperty("os.name").equals("Linux")){
|
||||
@ -201,16 +203,13 @@ public class dbController {
|
||||
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 @@ public class dbController {
|
||||
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 @@ public class dbController {
|
||||
}
|
||||
|
||||
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 @@ public class dbController {
|
||||
connection.commit();
|
||||
stmt.close();
|
||||
}catch(SQLException e){
|
||||
e.printStackTrace();
|
||||
LOGGER.error("failed to set the last played", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,23 +278,24 @@ public class dbController {
|
||||
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 @@ public class dbController {
|
||||
stmt.close();
|
||||
rs.close();
|
||||
}catch(SQLException e){
|
||||
e.printStackTrace();
|
||||
LOGGER.error("failed to get total play time", e);
|
||||
}
|
||||
return timePlayed;
|
||||
}
|
||||
|
@ -16,12 +16,16 @@ package application;
|
||||
|
||||
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 class playGame extends Thread{
|
||||
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);
|
||||
});
|
||||
|
@ -11,6 +11,8 @@ import java.util.Collections;
|
||||
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<File> cloudSavegames = new ArrayList<>();
|
||||
private ArrayList<String> localSavegamesName = new ArrayList<>();
|
||||
private ArrayList<String> 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 class 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 class GoogleDriveController {
|
||||
.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 class GoogleDriveController {
|
||||
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 class GoogleDriveController {
|
||||
// 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 class GoogleDriveController {
|
||||
|
||||
//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 @@ public class GoogleDriveController {
|
||||
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<java.io.File> files = (List<java.io.File>) FileUtils.listFiles(dir, extensions, true);
|
||||
for (java.io.File file : files) {
|
||||
localSavegamesName.add(file.getParentFile().getName()+"_"+file.getName());
|
||||
@ -199,7 +202,7 @@ public class GoogleDriveController {
|
||||
|
||||
//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 @@ public class GoogleDriveController {
|
||||
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 @@ public class GoogleDriveController {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
BIN
src/libraries/sqlite-jdbc-3.20.0.jar
Normal file
BIN
src/libraries/sqlite-jdbc-3.20.0.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user