Browse Source

major code clean up

pull/7/head
Jannik 3 years ago
parent
commit
db8fcd4bdc
  1. 126
      src/main/java/com/cemu_UI/application/Main.java
  2. 432
      src/main/java/com/cemu_UI/application/MainWindowController.java
  3. 19
      src/main/java/com/cemu_UI/application/playGame.java
  4. 22
      src/main/java/com/cemu_UI/controller/CloudController.java
  5. 11
      src/main/java/com/cemu_UI/controller/DBController.java
  6. 404
      src/main/java/com/cemu_UI/controller/XMLController.java
  7. 57
      src/main/java/com/cemu_UI/vendorCloudController/GoogleDriveController.java

126
src/main/java/com/cemu_UI/application/Main.java

@ -34,6 +34,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.cemu_UI.controller.CloudController;
import com.cemu_UI.controller.XMLController;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
@ -53,30 +54,18 @@ public class Main extends Application {
private Stage primaryStage;
private MainWindowController mainWindowController;
private CloudController cloudController;
private static XMLController xmlController;
private AnchorPane pane;
private Scene scene;
private static String userHome = System.getProperty("user.home");
private static String userName = System.getProperty("user.name");
private static String osName = System.getProperty("os.name");
private static String osArch = System.getProperty("os.arch");
private static String osVers = System.getProperty("os.version");
private static String javaVers = System.getProperty("java.version");
private static String javaVend= System.getProperty("java.vendor");
private String gamesDBdownloadURL = "https://git.mosad.xyz/Seil0/cemu_UI/raw/branch/master/downloadContent/games.db";
private static String dirCemuUI;
private static File directory;
private static File configFile;
private static File gamesDBFile;
private static File reference_gamesFile;
private static File pictureCache;
private static Logger LOGGER;
@Override
public void start(Stage primaryStage) {
try {
LOGGER.info("OS: " + osName + " " + osVers + " " + osArch);
LOGGER.info("Java: " + javaVend + " " + javaVers);
LOGGER.info("User: " + userName + " " + userHome);
LOGGER.info("OS: " + XMLController.getOsName() + " " + XMLController.getOsVers() + " " + XMLController.getOsVers());
LOGGER.info("Java: " + XMLController.getJavaVend() + " " + XMLController.getJavaVers());
LOGGER.info("User: " + XMLController.getUserName() + " " + XMLController.getUserHome());
this.primaryStage = primaryStage;
mainWindowController = new MainWindowController(this);
@ -122,37 +111,32 @@ public class Main extends Application {
alert.showAndWait();
}
if (!directory.exists()) {
if (!XMLController.getDirCemuUI().exists()) {
LOGGER.info("creating cemu_UI directory");
directory.mkdir();
pictureCache.mkdir();
XMLController.getDirCemuUI().mkdir();
XMLController.getPictureCache().mkdir();
}
if (!configFile.exists()) {
if (!XMLController.getConfigFile().exists()) {
LOGGER.info("firststart, setting default values");
firstStart();
mainWindowController.setColor("00a8cc");
mainWindowController.setAutoUpdate(false);
mainWindowController.setLanguage("en_US");
mainWindowController.setLastLocalSync(0);
mainWindowController.setxPosHelper(0);
mainWindowController.saveSettings();
xmlController.saveSettings();
}
if (!pictureCache.exists()) {
pictureCache.mkdir();
if (!XMLController.getPictureCache().exists()) {
XMLController.getPictureCache().mkdir();
}
if (!reference_gamesFile.exists()) {
if (gamesDBFile.exists()) {
gamesDBFile.delete();
if (!XMLController.getRference_gamesFile().exists()) {
if (XMLController.getGamesDBFile().exists()) {
XMLController.getGamesDBFile().delete();
}
try {
LOGGER.info("downloading ReferenceGameList.db... ");
URL website = new URL(gamesDBdownloadURL);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(reference_gamesFile);
FileOutputStream fos = new FileOutputStream(XMLController.getRference_gamesFile());
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
LOGGER.info("finished downloading games.db");
@ -166,9 +150,11 @@ public class Main extends Application {
mainWindowController.getDbController().init();
// if cloud sync is activated start sync
if(mainWindowController.isCloudSync()) {
cloudController.initializeConnection(mainWindowController.getCloudService(), mainWindowController.getCemuPath());
cloudController.sync(mainWindowController.getCloudService(), mainWindowController.getCemuPath(), directory.getPath());
if (XMLController.isCloudSync()) {
cloudController.initializeConnection(XMLController.getCloudService(),
XMLController.getCemuPath());
cloudController.sync(XMLController.getCloudService(), XMLController.getCemuPath(),
XMLController.getDirCemuUIPath());
}
} catch (IOException e) {
@ -177,24 +163,20 @@ public class Main extends Application {
}
public static void main(String[] args) {
String logPath = "";
if (osName.contains("Windows")) {
dirCemuUI = userHome + "/Documents/cemu_UI";
if (System.getProperty("os.name").contains("Windows")) {
logPath = System.getProperty("user.home") + "/Documents/cemu_UI/app.log";
} else {
dirCemuUI = userHome + "/cemu_UI";
logPath = System.getProperty("user.home") + "/cemu_UI/app.log";
}
directory = new File(dirCemuUI);
configFile = new File(dirCemuUI + "/config.xml");
gamesDBFile = new File(dirCemuUI + "/games.db");
reference_gamesFile = new File(dirCemuUI + "/reference_games.db");
pictureCache= new File(dirCemuUI+"/picture_cache");
// delete old log file and create new
System.setProperty("logFilename", dirCemuUI + "/app.log");
File logFile = new File(dirCemuUI + "/app.log");
System.setProperty("logFilename", logPath);
File logFile = new File(logPath);
logFile.delete();
LOGGER = LogManager.getLogger(Main.class.getName());
xmlController = new XMLController();
launch(args);
}
@ -208,10 +190,10 @@ public class Main extends Application {
if (result.get() == ButtonType.OK) {
DirectoryChooser directoryChooser = new DirectoryChooser();
File selectedDirectory = directoryChooser.showDialog(primaryStage);
mainWindowController.setCemuPath(selectedDirectory.getAbsolutePath());
XMLController.setCemuPath(selectedDirectory.getAbsolutePath());
} else {
mainWindowController.setCemuPath(null);
XMLController.setCemuPath(null);
}
Alert alert2 = new Alert(AlertType.CONFIRMATION); // new alert with file-chooser
@ -223,9 +205,9 @@ public class Main extends Application {
if (result2.get() == ButtonType.OK) {
DirectoryChooser directoryChooser = new DirectoryChooser();
File selectedDirectory = directoryChooser.showDialog(primaryStage);
mainWindowController.setRomDirectoryPath(selectedDirectory.getAbsolutePath());
XMLController.setRomDirectoryPath(selectedDirectory.getAbsolutePath());
} else {
mainWindowController.setRomDirectoryPath(null);
XMLController.setRomDirectoryPath(null);
}
}
@ -251,7 +233,8 @@ public class Main extends Application {
saveTask = new TimerTask() {
@Override
public void run() {
mainWindowController.saveSettings();
XMLController.setWindowWidth(mainWindowController.getMainAnchorPane().getWidth());
xmlController.saveSettings();
}
};
timer.schedule(saveTask, delayTime);
@ -272,7 +255,8 @@ public class Main extends Application {
saveTask = new TimerTask() {
@Override
public void run() {
mainWindowController.saveSettings();
XMLController.setWindowHeight(mainWindowController.getMainAnchorPane().getHeight());
xmlController.saveSettings();
}
};
timer.schedule(saveTask, delayTime);
@ -306,47 +290,11 @@ public class Main extends Application {
return main;
}
public Stage getPrimaryStage() {
return primaryStage;
}
public void setPrimaryStage(Stage primaryStage) {
this.primaryStage = primaryStage;
}
public CloudController getCloudController() {
return cloudController;
}
public void setCloudController(CloudController cloudController) {
this.cloudController = cloudController;
}
public AnchorPane getPane() {
return pane;
}
public void setPane(AnchorPane pane) {
this.pane = pane;
}
public File getDirectory() {
return directory;
}
public File getConfigFile() {
return configFile;
}
public File getGamesDBFile() {
return gamesDBFile;
}
public File getReference_gamesFile() {
return reference_gamesFile;
}
public File getPictureCache() {
return pictureCache;
}
}

432
src/main/java/com/cemu_UI/application/MainWindowController.java

@ -24,12 +24,8 @@ import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
@ -54,6 +50,7 @@ import org.apache.logging.log4j.Logger;
import com.cemu_UI.controller.DBController;
import com.cemu_UI.controller.SmmdbAPIController;
import com.cemu_UI.controller.UpdateController;
import com.cemu_UI.controller.XMLController;
import com.cemu_UI.datatypes.CourseTableDataType;
import com.cemu_UI.datatypes.GlobalDataTypes.CloudService;
import com.cemu_UI.datatypes.SmmdbApiDataType;
@ -102,6 +99,7 @@ import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import javafx.util.Duration;
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
@ -182,19 +180,13 @@ public class MainWindowController {
private playGame playGame;
private static MainWindowController MWC;
private UpdateController updateController;
private XMLController xmlController;
private Stage primaryStage;
private boolean menuTrue = false;
private boolean settingsTrue = false;
private boolean playTrue = false;
private boolean smmdbTrue = false;
private boolean autoUpdate = false;
private boolean useBeta = false;
private boolean fullscreen;
private boolean cloudSync;
private CloudService cloudService;
private String cemuPath;
private String romDirectoryPath;
private String gameExecutePath;
private String color;
private String dialogBtnStyle;
private String selectedGameTitleID;
private String selectedGameTitle;
@ -204,13 +196,10 @@ public class MainWindowController {
private String versionName = "Purple Comet";
private int xPos = -200;
private int yPos = 17;
private int xPosHelper;
private int xPosHelper = 0;
private int oldXPosHelper;
private int selectedUIDataIndex;
private int selected;
private long lastLocalSync;
private double windowWidth;
private double windowHeight;
private DirectoryChooser directoryChooser = new DirectoryChooser();
private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta");
private ObservableList<String> languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)");
@ -279,8 +268,9 @@ public class MainWindowController {
private String smmdbDownloadBtnDownload;
public MainWindowController(Main main) {
xmlController = new XMLController();
this.main = main;
dbController = new DBController(main, this);
dbController = new DBController(this);
smmdbAPIController = new SmmdbAPIController();
}
@ -289,7 +279,7 @@ public class MainWindowController {
* loadSettings, checkAutoUpdate, initUI and initActions
*/
public void init() {
loadSettings();
xmlController.loadSettings(); // load settings
checkAutoUpdate();
initUI();
initActions();
@ -301,21 +291,24 @@ public class MainWindowController {
private void initUI() {
LOGGER.info("initializing UI ...");
if (getWindowWidth() > 100 && getWindowHeight() > 100) {
mainAnchorPane.setPrefSize(getWindowWidth(), getWindowHeight());
primaryStage = (Stage) mainAnchorPane.getScene().getWindow(); // set primary stage for dialogs
// TODO this is broken
if (XMLController.getWindowWidth() > 100 && XMLController.getWindowHeight() > 100) {
mainAnchorPane.setPrefSize(XMLController.getWindowWidth(), XMLController.getWindowHeight());
}
cemuTextField.setText(cemuPath);
romTextField.setText(romDirectoryPath);
colorPicker.setValue(Color.valueOf(getColor()));
fullscreenToggleBtn.setSelected(isFullscreen());
cloudSyncToggleBtn.setSelected(isCloudSync());
autoUpdateToggleBtn.setSelected(isAutoUpdate());
cemuTextField.setText(XMLController.getCemuPath());
romTextField.setText(XMLController.getRomDirectoryPath());
colorPicker.setValue(Color.valueOf(XMLController.getColor()));
fullscreenToggleBtn.setSelected(XMLController.isFullscreen());
cloudSyncToggleBtn.setSelected(XMLController.isCloudSync());
autoUpdateToggleBtn.setSelected(XMLController.isAutoUpdate());
branchChoisBox.setItems(branches);
languageChoisBox.setItems(languages);
bottomHBox.setPickOnBounds(false);
if (isUseBeta()) {
if (XMLController.isUseBeta()) {
branchChoisBox.getSelectionModel().select(1);
} else {
branchChoisBox.getSelectionModel().select(0);
@ -373,7 +366,7 @@ public class MainWindowController {
}
if (settingsTrue) {
settingsScrollPane.setVisible(false);
saveSettings();
xmlController.saveSettings();
settingsTrue = false;
}
if (smmdbTrue) {
@ -393,7 +386,7 @@ public class MainWindowController {
// new edit dialog
String headingText = editHeadingText + " \"" + selectedGameTitle + "\"";
JFXEditGameDialog editGameDialog = new JFXEditGameDialog(headingText, editBodyText, dialogBtnStyle, 450,
300, 1, MWC, main.getPrimaryStage(), main.getPane());
300, 1, MWC, primaryStage, main.getPane());
editGameDialog.setTitle(gameInfo[0]);
editGameDialog.setCoverPath(gameInfo[1]);
editGameDialog.setRomPath(gameInfo[2]);
@ -451,11 +444,11 @@ public class MainWindowController {
@Override
public void handle(ActionEvent event) {
DirectoryChooser directoryChooser = new DirectoryChooser();
File selectedDirecroty = directoryChooser.showDialog(main.getPrimaryStage());
File selectedDirecroty = directoryChooser.showDialog(primaryStage);
String updatePath = selectedDirecroty.getAbsolutePath();
String[] parts = selectedGameTitleID.split("-"); // split string into 2 parts at "-"
File srcDir = new File(updatePath);
File destDir = new File(cemuPath + "/mlc01/usr/title/" + parts[0] + "/" + parts[1]);
File destDir = new File(XMLController.getCemuPath() + "/mlc01/usr/title/" + parts[0] + "/" + parts[1]);
// if directory doesn't exist create it
if (destDir.exists() != true) {
@ -502,11 +495,11 @@ public class MainWindowController {
@Override
public void handle(ActionEvent event) {
DirectoryChooser directoryChooser = new DirectoryChooser();
File selectedDirecroty = directoryChooser.showDialog(main.getPrimaryStage());
File selectedDirecroty = directoryChooser.showDialog(primaryStage);
String dlcPath = selectedDirecroty.getAbsolutePath();
String[] parts = selectedGameTitleID.split("-"); // split string into 2 parts at "-"
File srcDir = new File(dlcPath);
File destDir = new File(cemuPath + "/mlc01/usr/title/" + parts[0] + "/" + parts[1] + "/aoc");
File destDir = new File(XMLController.getCemuPath() + "/mlc01/usr/title/" + parts[0] + "/" + parts[1] + "/aoc");
// if directory doesn't exist create it
if (destDir.exists() != true) {
@ -628,26 +621,27 @@ public class MainWindowController {
}
});
languageChoisBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) {
String language = languageChoisBox.getItems().get((int) new_value).toString();
language = language.substring(language.length()-6,language.length()-1); //reading only en_US from English (en_US)
setLanguage(language);
setUILanguage();
saveSettings();
}
});
languageChoisBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) {
String language = languageChoisBox.getItems().get((int) new_value).toString();
language = language.substring(language.length() - 6, language.length() - 1); // reading only en_US from
// English (en_US)
XMLController.setUsrLocal(language);
setUILanguage();
xmlController.saveSettings();
}
});
branchChoisBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) {
if (branchChoisBox.getItems().get((int) new_value).toString() == "beta") {
setUseBeta(true);
XMLController.setUseBeta(true);
} else {
setUseBeta(false);
XMLController.setUseBeta(false);
}
saveSettings();
xmlController.saveSettings();
}
});
@ -702,11 +696,11 @@ public class MainWindowController {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (new File(newValue).exists()) {
setCemuPath(newValue);
saveSettings();
XMLController.setCemuPath(newValue);
xmlController.saveSettings();
} else {
String bodyText = newValue + ": No such file or directory";
JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, dialogBtnStyle, main.getPrimaryStage());
JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, dialogBtnStyle, primaryStage);
fileErrorDialog.showAndWait();
LOGGER.warn(newValue + ": No such file or directory");
}
@ -717,12 +711,12 @@ public class MainWindowController {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (new File(newValue).exists()) {
setRomDirectoryPath(newValue);
saveSettings();
XMLController.setRomDirectoryPath(newValue);
xmlController.saveSettings();
reloadRoms();
} else {
String bodyText = newValue + ": No such file or directory";
JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, dialogBtnStyle, main.getPrimaryStage());
JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, dialogBtnStyle, primaryStage);
fileErrorDialog.showAndWait();
LOGGER.warn(newValue + ": No such file or directory");
}
@ -742,7 +736,7 @@ public class MainWindowController {
String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (" + buildNumber + ") \"" + versionName + "\" \n"
+ aboutBtnBodyText;
JFXInfoAlert infoAlert = new JFXInfoAlert(aboutBtnHeadingText, bodyText, dialogBtnStyle, main.getPrimaryStage());
JFXInfoAlert infoAlert = new JFXInfoAlert(aboutBtnHeadingText, bodyText, dialogBtnStyle, primaryStage);
infoAlert.showAndWait();
}
@ -755,7 +749,7 @@ public class MainWindowController {
if (settingsTrue) {
settingsScrollPane.setVisible(false);
settingsTrue = false;
saveSettings();
xmlController.saveSettings();
} else {
settingsScrollPane.setVisible(true);
settingsTrue = true;
@ -826,7 +820,7 @@ public class MainWindowController {
@FXML
private void cemuTFBtnAction() {
File cemuDirectory = directoryChooser.showDialog(main.getPrimaryStage());
File cemuDirectory = directoryChooser.showDialog(primaryStage);
if (cemuDirectory != null) {
cemuTextField.setText(cemuDirectory.getAbsolutePath());
}
@ -834,7 +828,7 @@ public class MainWindowController {
@FXML
private void romTFBtnAction() {
File romDirectory = directoryChooser.showDialog(main.getPrimaryStage());
File romDirectory = directoryChooser.showDialog(primaryStage);
if (romDirectory != null) {
romTextField.setText(romDirectory.getAbsolutePath());
}
@ -842,7 +836,7 @@ public class MainWindowController {
@FXML
private void updateBtnAction() {
updateController = new UpdateController(this, buildNumber, useBeta);
updateController = new UpdateController(this, buildNumber, XMLController.isUseBeta());
Thread updateThread = new Thread(updateController);
updateThread.setName("Updater");
updateThread.start();
@ -850,12 +844,8 @@ public class MainWindowController {
@FXML
private void autoUpdateToggleBtnAction() {
if (isAutoUpdate()) {
setAutoUpdate(false);
} else {
setAutoUpdate(true);
}
saveSettings();
XMLController.setAutoUpdate(!XMLController.isAutoUpdate());
xmlController.saveSettings();
}
@FXML
@ -866,8 +856,8 @@ public class MainWindowController {
@FXML
private void smmdbDownloadBtnAction() {
String downloadUrl = "http://smmdb.ddns.net/api/downloadcourse?id=" + id + "&type=zip";
String downloadFileURL = getCemuPath() + "/" + id + ".zip"; // getCemuPath() + "/" + smmID + "/" + id + ".rar"
String outputFile = getCemuPath() + "/";
String downloadFileURL = XMLController.getCemuPath() + "/" + id + ".zip"; // getCemuPath() + "/" + smmID + "/" + id + ".rar"
String outputFile = XMLController.getCemuPath() + "/";
try {
LOGGER.info("beginning download ...");
@ -933,41 +923,36 @@ public class MainWindowController {
@FXML
private void fullscreenToggleBtnAction() {
if (fullscreen) {
fullscreen = false;
} else {
fullscreen = true;
}
saveSettings();
XMLController.setFullscreen(!XMLController.isFullscreen());
xmlController.saveSettings();
}
@FXML
private void cloudSyncToggleBtnAction() {
if(cloudSync) {
cloudSync = false;
} else {
XMLController.setCloudSync(!XMLController.isCloudSync());
if(XMLController.isCloudSync()) {
EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
cloudSync = true;
//TODO rework for other cloud services
// CloudService service = CloudService.GoogleDrive;
cloudService = CloudService.GoogleDrive;
XMLController.setCloudService(CloudService.GoogleDrive);
// start cloud sync in new thread
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
if (main.getCloudController().initializeConnection(getCloudService(), getCemuPath())) {
main.getCloudController().sync(getCloudService(), getCemuPath(), main.getDirectory().getPath());
saveSettings();
if (main.getCloudController().initializeConnection(XMLController.getCloudService(), XMLController.getCemuPath())) {
main.getCloudController().sync(XMLController.getCloudService(), XMLController.getCemuPath(), XMLController.getDirCemuUIPath());
xmlController.saveSettings();
} else {
cloudSyncToggleBtn.setSelected(false);
// cloud sync init error dialog
JFXInfoAlert cloudSyncErrorDialog = new JFXInfoAlert(cloudSyncErrorHeadingText,
cloudSyncErrorBodyText, dialogBtnStyle, main.getPrimaryStage());
cloudSyncErrorBodyText, dialogBtnStyle, primaryStage);
cloudSyncErrorDialog.showAndWait();
}
@ -1002,7 +987,7 @@ public class MainWindowController {
String headingText = addGameBtnHeadingText;
String bodyText = addGameBtnBodyText;
JFXEditGameDialog addGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450, 300, 0,
this, main.getPrimaryStage(), main.getPane());
this, primaryStage, main.getPane());
addGameDialog.show();
}
@ -1021,11 +1006,11 @@ public class MainWindowController {
//addGame error dialog
JFXInfoAlert errorDialog = new JFXInfoAlert(addBtnReturnErrorHeadingText, addBtnReturnErrorBodyText,
dialogBtnStyle, main.getPrimaryStage());
dialogBtnStyle, primaryStage);
errorDialog.showAndWait();
} else {
File pictureCache = main.getPictureCache();
File pictureCache = XMLController.getPictureCache();
String coverName = new File(coverPath).getName();
try {
BufferedImage originalImage = ImageIO.read(new File(coverPath)); //load cover
@ -1184,7 +1169,7 @@ public class MainWindowController {
main.getPane().getChildren().add(spinner); // add spinner to pane
});
dbController.loadRomDirectory(getRomDirectoryPath()); // reload the ROM directory
dbController.loadRomDirectory(XMLController.getRomDirectoryPath()); // reload the ROM directory
games.removeAll(games); // remove all games from the mwc game list
dbController.loadAllGames(); // load all games from the database to the mwc
@ -1218,7 +1203,7 @@ public class MainWindowController {
// set the selected local strings to all needed elements
void setUILanguage(){
switch(getLanguage()){
switch(XMLController.getUsrLocal()){
case "en_US":
bundle = ResourceBundle.getBundle("locals.cemu_UI-Local", Locale.US); //us_English
languageChoisBox.getSelectionModel().select(0);
@ -1302,10 +1287,10 @@ public class MainWindowController {
// if AutoUpdate, then check for updates
private void checkAutoUpdate() {
if (isAutoUpdate()) {
if (XMLController.isAutoUpdate()) {
try {
LOGGER.info("AutoUpdate: looking for updates on startup ...");
updateController = new UpdateController(this, buildNumber, useBeta);
updateController = new UpdateController(this, buildNumber, XMLController.isUseBeta());
Thread updateThread = new Thread(updateController);
updateThread.setName("Updater");
updateThread.start();
@ -1456,16 +1441,16 @@ public class MainWindowController {
// change the color of all needed GUI elements
private void applyColor() {
String boxStyle = "-fx-background-color: #"+getColor()+";";
String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #"+getColor()+"; -fx-text-fill: BLACK;";
String btnStyleWhite = "-fx-button-type: RAISED; -fx-background-color: #"+getColor()+"; -fx-text-fill: WHITE;";
BigInteger icolor = new BigInteger(getColor(),16);
String boxStyle = "-fx-background-color: #" + XMLController.getColor() + ";";
String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #" + XMLController.getColor() + "; -fx-text-fill: BLACK;";
String btnStyleWhite = "-fx-button-type: RAISED; -fx-background-color: #" + XMLController.getColor() + "; -fx-text-fill: WHITE;";
BigInteger icolor = new BigInteger(XMLController.getColor(),16);
BigInteger ccolor = new BigInteger("78909cff",16);
sideMenuVBox.setStyle(boxStyle);
topHBox.setStyle(boxStyle);
cemuTextField.setFocusColor(Color.valueOf(getColor()));
romTextField.setFocusColor(Color.valueOf(getColor()));
cemuTextField.setFocusColor(Color.valueOf(XMLController.getColor()));
romTextField.setFocusColor(Color.valueOf(XMLController.getColor()));
if (icolor.compareTo(ccolor) == -1) {
dialogBtnStyle = btnStyleWhite;
@ -1516,158 +1501,7 @@ public class MainWindowController {
}
for (int i = 0; i < games.size(); i++) {
games.get(i).getButton().setRipplerFill(Paint.valueOf(getColor()));
}
}
/**
* save settings to the config.xml file
*/
public void saveSettings() {
LOGGER.info("saving Settings ...");
try {
props.setProperty("cemuPath", getCemuPath());
props.setProperty("romPath", getRomDirectoryPath());
props.setProperty("color", getColor());
props.setProperty("language", getLanguage());
props.setProperty("fullscreen", String.valueOf(isFullscreen()));
props.setProperty("cloudSync", String.valueOf(isCloudSync()));
props.setProperty("autoUpdate", String.valueOf(isAutoUpdate()));
props.setProperty("useBeta", String.valueOf(isUseBeta()));
if (getCloudService() == null) {
props.setProperty("cloudService", "");
} else {
props.setProperty("cloudService", getCloudService().toString());
}
props.setProperty("folderID", main.getCloudController().getFolderID(getCloudService()));
props.setProperty("lastLocalSync", String.valueOf(getLastLocalSync()));
props.setProperty("windowWidth", String.valueOf(mainAnchorPane.getWidth()));
props.setProperty("windowHeight", String.valueOf(mainAnchorPane.getHeight()));
OutputStream outputStream = new FileOutputStream(main.getConfigFile()); // new output-stream
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
*/
private void loadSettings() {
LOGGER.info("loading settings ...");
try {
InputStream inputStream = new FileInputStream(main.getConfigFile());
props.loadFromXML(inputStream); // new input-stream from .xml
try {
setCemuPath(props.getProperty("cemuPath"));
} catch (Exception e) {
LOGGER.error("cloud not load cemuPath", e);
setCemuPath("");
}
try {
setRomDirectoryPath(props.getProperty("romPath"));
} catch (Exception e) {
LOGGER.error("could not load romPath", e);
setRomDirectoryPath("");
}
try {
setColor(props.getProperty("color"));
} catch (Exception e) {
LOGGER.error("could not load color value, setting default instead", e);
setColor("00a8cc");
}
if (props.getProperty("language") == null) {
LOGGER.error("cloud not load language, setting default instead");
setLanguage("en_US");
} else {
setLanguage(props.getProperty("language"));
}
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 {
setAutoUpdate(Boolean.parseBoolean(props.getProperty("autoUpdate")));
} catch (Exception e) {
LOGGER.error("cloud not load autoUpdate", e);
setAutoUpdate(false);
}
try {
setUseBeta(Boolean.parseBoolean(props.getProperty("useBeta")));
} catch (Exception e) {
LOGGER.error("cloud not load autoUpdate", e);
setUseBeta(false);
}
try {
switch (props.getProperty("cloudService")) {
case "GoogleDrive":
setCloudService(CloudService.GoogleDrive);
break;
case "Dropbox":
setCloudService(CloudService.Dropbox);
break;
default:
break;
}
} catch (Exception e) {
LOGGER.error("could not load cloudSync", e);
setCloudService(null);
}
try {
main.getCloudController().setFolderID(props.getProperty("folderID"), getCloudService());
} catch (Exception e) {
LOGGER.error("could not load folderID, disable cloud sync. Please contact an developer", e);
setCloudSync(false);
}
try {
setLastLocalSync(Long.parseLong(props.getProperty("lastLocalSync")));
} catch (Exception e) {
LOGGER.error("could not load lastSuccessSync, setting default instead", e);
setLastLocalSync(0);
}
try {
setWindowWidth(Double.parseDouble(props.getProperty("windowWidth")));
} catch (Exception e) {
LOGGER.error("could not load windowWidth, setting default instead", e);
setWindowWidth(904);
}
try {
setWindowHeight(Double.parseDouble(props.getProperty("windowHeight")));
} catch (Exception e) {
LOGGER.error("could not load windowHeight, setting default instead", e);
setWindowHeight(600);
}
inputStream.close();
LOGGER.info("loading settings done!");
} catch (IOException e) {
LOGGER.error("an error occured", e);
games.get(i).getButton().setRipplerFill(Paint.valueOf(XMLController.getColor()));
}
}
@ -1709,8 +1543,8 @@ public class MainWindowController {
private void editColor(String input){
StringBuilder sb = new StringBuilder(input);
sb.delete(0, 2);
this.color = sb.toString();
saveSettings();
XMLController.setColor(sb.toString());
xmlController.saveSettings();
}
@SuppressWarnings("unused")
@ -1718,8 +1552,8 @@ public class MainWindowController {
* @return the main color in hexadecimal format
*/
private String hexToRgb() {
LOGGER.info(getColor());
int hex = Integer.parseInt(getColor().substring(0, 5), 16);
LOGGER.info(XMLController.getColor());
int hex = Integer.parseInt(XMLController.getColor().substring(0, 5), 16);
int r = (hex & 0xFF0000) >> 16;
int g = (hex & 0xFF00) >> 8;
@ -1752,33 +1586,9 @@ public class MainWindowController {
public DBController getDbController() {
return dbController;
}
public void setMainAnchorPane(AnchorPane mainAnchorPane) {
this.mainAnchorPane = mainAnchorPane;
}
public String getCemuPath() {
return cemuPath;
}
public void setCemuPath(String cemuPath) {
this.cemuPath = cemuPath;
}
public String getRomDirectoryPath() {
return romDirectoryPath;
}
public void setRomDirectoryPath(String romDirectoryPath) {
this.romDirectoryPath = romDirectoryPath;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
public Stage getPrimaryStage() {
return primaryStage;
}
public int getxPos() {
@ -1805,46 +1615,6 @@ public class MainWindowController {
this.xPosHelper = xPosHelper;
}
public long getLastLocalSync() {
return lastLocalSync;
}
public void setLastLocalSync(long lastLocalSync) {
this.lastLocalSync = lastLocalSync;
}
public boolean isFullscreen() {
return fullscreen;
}
public void setFullscreen(boolean fullscreen) {
this.fullscreen = fullscreen;
}
public boolean isCloudSync() {
return cloudSync;
}
public void setCloudSync(boolean cloudSync) {
this.cloudSync = cloudSync;
}
public boolean isAutoUpdate() {
return autoUpdate;
}
public void setAutoUpdate(boolean autoUpdate) {
this.autoUpdate = autoUpdate;
}
public boolean isUseBeta() {
return useBeta;
}
public void setUseBeta(boolean useBeta) {
this.useBeta = useBeta;
}
public String getGameExecutePath() {
return gameExecutePath;
}
@ -1861,14 +1631,6 @@ public class MainWindowController {
this.selectedGameTitleID = selectedGameTitleID;
}
public CloudService getCloudService() {
return cloudService;
}
public void setCloudService(CloudService cloudService) {
this.cloudService = cloudService;
}
public JFXButton getPlayBtn() {
return playBtn;
}
@ -1876,31 +1638,11 @@ public class MainWindowController {
public void setPlayBtn(JFXButton playBtn) {
this.playBtn = playBtn;
}
public double getWindowWidth() {
return windowWidth;
}
public void setWindowWidth(double windowWidth) {
this.windowWidth = windowWidth;
}
public double getWindowHeight() {
return windowHeight;
}
public void setWindowHeight(double windowHeight) {
this.windowHeight = windowHeight;
}
public int getOldXPosHelper() {
return oldXPosHelper;
}
public void setOldXPosHelper(int oldXPosHelper) {
this.oldXPosHelper = oldXPosHelper;
}
public String getLanguage() {
return language;
}
@ -1913,10 +1655,6 @@ public class MainWindowController {
return bundle;
}
public void setBundle(ResourceBundle bundle) {
this.bundle = bundle;
}
public AnchorPane getMainAnchorPane() {
return mainAnchorPane;
}

19
src/main/java/com/cemu_UI/application/playGame.java

@ -27,6 +27,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.cemu_UI.controller.DBController;
import com.cemu_UI.controller.XMLController;
import javafx.application.Platform;
@ -44,7 +45,7 @@ public class playGame extends Thread{
@Override
public void run() {
String selectedGameTitleID = mainWindowController.getSelectedGameTitleID();
String cemuBin = mainWindowController.getCemuPath() + "/Cemu.exe";
String cemuBin = XMLController.getCemuPath() + "/Cemu.exe";
String gameExec = "\"" + mainWindowController.getGameExecutePath() + "\"";
long startTime;
long endTime;
@ -53,18 +54,18 @@ public class playGame extends Thread{
Process p;
Platform.runLater(() -> {
mainWindowController.getMain().getPrimaryStage().setIconified(true); // minimize cemu_UI
mainWindowController.getPrimaryStage().setIconified(true); // minimize cemu_UI
});
startTime = System.currentTimeMillis();
try {
if (System.getProperty("os.name").equals("Linux")) {
if(mainWindowController.isFullscreen()){
if(XMLController.isFullscreen()){
p = new ProcessBuilder("wine", cemuBin, "-f", "-g", gameExec).start();
} else {
p = new ProcessBuilder("wine", cemuBin, "-g", gameExec).start();
}
} else {
if(mainWindowController.isFullscreen()){
if(XMLController.isFullscreen()){
p = new ProcessBuilder(cemuBin, "-f", "-g", gameExec).start();
} else {
p = new ProcessBuilder(cemuBin, "-g", gameExec).start();
@ -85,14 +86,14 @@ public class playGame extends Thread{
} else {
mainWindowController.totalPlaytimeBtn.setText(dbController.getTotalPlaytime(selectedGameTitleID) + " min");
}
mainWindowController.getMain().getPrimaryStage().setIconified(false); // maximize cemu_UI
mainWindowController.getPrimaryStage().setIconified(false); // maximize cemu_UI
});
//sync savegame with cloud service
if (mainWindowController.isCloudSync()) {
mainWindowController.setLastLocalSync(Instant.now().getEpochSecond());
mainWindowController.getMain().getCloudController().sync(mainWindowController.getCloudService(),
mainWindowController.getCemuPath(), mainWindowController.getMain().getDirectory().getPath());
if (XMLController.isCloudSync()) {
XMLController.setLastLocalSync(Instant.now().getEpochSecond());
mainWindowController.getMain().getCloudController().sync(XMLController.getCloudService(),
XMLController.getCemuPath(), XMLController.getDirCemuUIPath());
}
} catch (IOException | InterruptedException e) {

22
src/main/java/com/cemu_UI/controller/CloudController.java

@ -46,6 +46,7 @@ public class CloudController {
}
private MainWindowController mwc;
private XMLController xmlController = new XMLController();
private GoogleDriveController googleDriveController = new GoogleDriveController();
private static final Logger LOGGER = LogManager.getLogger(CloudController.class.getName());
@ -105,19 +106,19 @@ public class CloudController {
LOGGER.info("cloud sync folder dosen't exist, creating one!");
googleDriveController.creatFolder();
googleDriveController.uploadZipFile(zipFile);
} else if (mwc.getLastLocalSync() > lastCloudSync) {
} else if (XMLController.getLastLocalSync() > lastCloudSync) {
LOGGER.info("local is new, going to upload zip");
googleDriveController.uploadZipFile(zipFile);
} else if (mwc.getLastLocalSync() < lastCloudSync) {
} else if (XMLController.getLastLocalSync() < lastCloudSync) {
LOGGER.info("cloud is new, going to download zip");
unzipSavegames(cemuDirectory, googleDriveController.downloadZipFile(cemu_UIDirectory));
mwc.setLastLocalSync(lastCloudSync);
XMLController.setLastLocalSync(lastCloudSync);
break;
} else {
LOGGER.info("nothing to do");
break;
}
mwc.setLastLocalSync(Long.parseLong(zipFile.getName().substring(0, zipFile.getName().length() - 4))); // set time of last sucessfull sync
XMLController.setLastLocalSync(Long.parseLong(zipFile.getName().substring(0, zipFile.getName().length() - 4))); // set time of last sucessfull sync
break;
case Dropbox:
@ -134,7 +135,7 @@ public class CloudController {
Platform.runLater(() -> {
mwc.getPlayBtn().setText("play");
mwc.getPlayBtn().setDisable(false);
mwc.saveSettings();
xmlController.saveSettings();
});
LOGGER.info("synchronization successful!");
@ -210,16 +211,5 @@ public class CloudController {
}
return folderID;
}
public void setFolderID(String folderID, CloudService cloudService) {
if (cloudService != null) {
if (cloudService == CloudService.GoogleDrive) {
googleDriveController.setFolderID(folderID);
}
if (cloudService == CloudService.Dropbox) {
}
}
}
}

11
src/main/java/com/cemu_UI/controller/DBController.java

@ -44,17 +44,14 @@ import org.apache.logging.log4j.Logger;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import com.cemu_UI.application.Main;
import com.cemu_UI.application.MainWindowController;
public class DBController {
public DBController(Main main, MainWindowController mainWindowController) {
this.main = main;
public DBController(MainWindowController mainWindowController) {
this.mainWindowController = mainWindowController;
}
private Main main;
private MainWindowController mainWindowController;
private ArrayList<String> entries = new ArrayList<>();
private String DB_PATH_localRoms;
@ -103,7 +100,7 @@ public class DBController {
* games.db contains a reverence list to for the automatic detection mode
*/
private void loadGamesDatabase() {
DB_PATH_games = main.getReference_gamesFile().getAbsolutePath();
DB_PATH_games = XMLController.getRference_gamesFile().getAbsolutePath();
try {
// create a database connection
connectionGames = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH_games);
@ -209,7 +206,7 @@ public class DBController {
File dir = new File(directory);
File appFile;
String[] extensions = new String[] { "rpx", "jsp" };
File pictureCache = main.getPictureCache();
File pictureCache = XMLController.getPictureCache();
String coverPath;
try {
Statement stmt = connectionGames.createStatement();

404
src/main/java/com/cemu_UI/controller/XMLController.java

@ -0,0 +1,404 @@
/**
* cemu_UI
*
* Copyright 2019 <@Seil0>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package com.cemu_UI.controller;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.cemu_UI.datatypes.GlobalDataTypes.CloudService;
public class XMLController {
private static final String userHome = System.getProperty("user.home");
private static final String userName = System.getProperty("user.name");
private static final String osName = System.getProperty("os.name");
private static final String osArch = System.getProperty("os.arch");
private static final String osVers = System.getProperty("os.version");
private static final String javaVers = System.getProperty("java.version");
private static final String javaVend = System.getProperty("java.vendor");
private static final String sysLocal = System.getProperty("user.language") + "_" + System.getProperty("user.country");
private static String dirCemuUIPath;
private static File dirCemuUI;
private static File configFile;
private static File gamesDBFile;
private static File reference_gamesFile;
private static File pictureCache;
// user settings
private static String color = "00a8cc";
private static String usrLocal = sysLocal;
private static boolean autoUpdate = false;
private static boolean useBeta = false;
private static boolean fullscreen = false;
private static boolean cloudSync = false;
private static String cemuPath;
private static String romDirectoryPath;
private static String folderID;
private static CloudService cloudService;
private static long lastLocalSync;
private static double windowWidth;
private static double windowHeight;