major code clean up
This commit is contained in:
parent
7434d0be25
commit
db8fcd4bdc
|
@ -34,6 +34,7 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import com.cemu_UI.controller.CloudController;
|
import com.cemu_UI.controller.CloudController;
|
||||||
|
import com.cemu_UI.controller.XMLController;
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
|
@ -53,30 +54,18 @@ public class Main extends Application {
|
||||||
private Stage primaryStage;
|
private Stage primaryStage;
|
||||||
private MainWindowController mainWindowController;
|
private MainWindowController mainWindowController;
|
||||||
private CloudController cloudController;
|
private CloudController cloudController;
|
||||||
|
private static XMLController xmlController;
|
||||||
private AnchorPane pane;
|
private AnchorPane pane;
|
||||||
private Scene scene;
|
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 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;
|
private static Logger LOGGER;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
try {
|
try {
|
||||||
LOGGER.info("OS: " + osName + " " + osVers + " " + osArch);
|
LOGGER.info("OS: " + XMLController.getOsName() + " " + XMLController.getOsVers() + " " + XMLController.getOsVers());
|
||||||
LOGGER.info("Java: " + javaVend + " " + javaVers);
|
LOGGER.info("Java: " + XMLController.getJavaVend() + " " + XMLController.getJavaVers());
|
||||||
LOGGER.info("User: " + userName + " " + userHome);
|
LOGGER.info("User: " + XMLController.getUserName() + " " + XMLController.getUserHome());
|
||||||
|
|
||||||
this.primaryStage = primaryStage;
|
this.primaryStage = primaryStage;
|
||||||
mainWindowController = new MainWindowController(this);
|
mainWindowController = new MainWindowController(this);
|
||||||
|
@ -122,37 +111,32 @@ public class Main extends Application {
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!directory.exists()) {
|
if (!XMLController.getDirCemuUI().exists()) {
|
||||||
LOGGER.info("creating cemu_UI directory");
|
LOGGER.info("creating cemu_UI directory");
|
||||||
directory.mkdir();
|
XMLController.getDirCemuUI().mkdir();
|
||||||
pictureCache.mkdir();
|
XMLController.getPictureCache().mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!configFile.exists()) {
|
if (!XMLController.getConfigFile().exists()) {
|
||||||
LOGGER.info("firststart, setting default values");
|
LOGGER.info("firststart, setting default values");
|
||||||
firstStart();
|
firstStart();
|
||||||
mainWindowController.setColor("00a8cc");
|
xmlController.saveSettings();
|
||||||
mainWindowController.setAutoUpdate(false);
|
|
||||||
mainWindowController.setLanguage("en_US");
|
|
||||||
mainWindowController.setLastLocalSync(0);
|
|
||||||
mainWindowController.setxPosHelper(0);
|
|
||||||
mainWindowController.saveSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pictureCache.exists()) {
|
if (!XMLController.getPictureCache().exists()) {
|
||||||
pictureCache.mkdir();
|
XMLController.getPictureCache().mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!reference_gamesFile.exists()) {
|
if (!XMLController.getRference_gamesFile().exists()) {
|
||||||
if (gamesDBFile.exists()) {
|
if (XMLController.getGamesDBFile().exists()) {
|
||||||
gamesDBFile.delete();
|
XMLController.getGamesDBFile().delete();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
LOGGER.info("downloading ReferenceGameList.db... ");
|
LOGGER.info("downloading ReferenceGameList.db... ");
|
||||||
URL website = new URL(gamesDBdownloadURL);
|
URL website = new URL(gamesDBdownloadURL);
|
||||||
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
|
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
|
||||||
FileOutputStream fos = new FileOutputStream(reference_gamesFile);
|
FileOutputStream fos = new FileOutputStream(XMLController.getRference_gamesFile());
|
||||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
fos.close();
|
fos.close();
|
||||||
LOGGER.info("finished downloading games.db");
|
LOGGER.info("finished downloading games.db");
|
||||||
|
@ -166,9 +150,11 @@ public class Main extends Application {
|
||||||
mainWindowController.getDbController().init();
|
mainWindowController.getDbController().init();
|
||||||
|
|
||||||
// if cloud sync is activated start sync
|
// if cloud sync is activated start sync
|
||||||
if(mainWindowController.isCloudSync()) {
|
if (XMLController.isCloudSync()) {
|
||||||
cloudController.initializeConnection(mainWindowController.getCloudService(), mainWindowController.getCemuPath());
|
cloudController.initializeConnection(XMLController.getCloudService(),
|
||||||
cloudController.sync(mainWindowController.getCloudService(), mainWindowController.getCemuPath(), directory.getPath());
|
XMLController.getCemuPath());
|
||||||
|
cloudController.sync(XMLController.getCloudService(), XMLController.getCemuPath(),
|
||||||
|
XMLController.getDirCemuUIPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -177,24 +163,20 @@ public class Main extends Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
String logPath = "";
|
||||||
|
|
||||||
if (osName.contains("Windows")) {
|
if (System.getProperty("os.name").contains("Windows")) {
|
||||||
dirCemuUI = userHome + "/Documents/cemu_UI";
|
logPath = System.getProperty("user.home") + "/Documents/cemu_UI/app.log";
|
||||||
} else {
|
} else {
|
||||||
dirCemuUI = userHome + "/cemu_UI";
|
logPath = System.getProperty("user.home") + "/cemu_UI/app.log";
|
||||||
}
|
}
|
||||||
|
|
||||||
directory = new File(dirCemuUI);
|
System.setProperty("logFilename", logPath);
|
||||||
configFile = new File(dirCemuUI + "/config.xml");
|
File logFile = new File(logPath);
|
||||||
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");
|
|
||||||
logFile.delete();
|
logFile.delete();
|
||||||
LOGGER = LogManager.getLogger(Main.class.getName());
|
LOGGER = LogManager.getLogger(Main.class.getName());
|
||||||
|
|
||||||
|
xmlController = new XMLController();
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,10 +190,10 @@ public class Main extends Application {
|
||||||
if (result.get() == ButtonType.OK) {
|
if (result.get() == ButtonType.OK) {
|
||||||
DirectoryChooser directoryChooser = new DirectoryChooser();
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
File selectedDirectory = directoryChooser.showDialog(primaryStage);
|
File selectedDirectory = directoryChooser.showDialog(primaryStage);
|
||||||
mainWindowController.setCemuPath(selectedDirectory.getAbsolutePath());
|
XMLController.setCemuPath(selectedDirectory.getAbsolutePath());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mainWindowController.setCemuPath(null);
|
XMLController.setCemuPath(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Alert alert2 = new Alert(AlertType.CONFIRMATION); // new alert with file-chooser
|
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) {
|
if (result2.get() == ButtonType.OK) {
|
||||||
DirectoryChooser directoryChooser = new DirectoryChooser();
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
File selectedDirectory = directoryChooser.showDialog(primaryStage);
|
File selectedDirectory = directoryChooser.showDialog(primaryStage);
|
||||||
mainWindowController.setRomDirectoryPath(selectedDirectory.getAbsolutePath());
|
XMLController.setRomDirectoryPath(selectedDirectory.getAbsolutePath());
|
||||||
} else {
|
} else {
|
||||||
mainWindowController.setRomDirectoryPath(null);
|
XMLController.setRomDirectoryPath(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +233,8 @@ public class Main extends Application {
|
||||||
saveTask = new TimerTask() {
|
saveTask = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mainWindowController.saveSettings();
|
XMLController.setWindowWidth(mainWindowController.getMainAnchorPane().getWidth());
|
||||||
|
xmlController.saveSettings();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
timer.schedule(saveTask, delayTime);
|
timer.schedule(saveTask, delayTime);
|
||||||
|
@ -272,7 +255,8 @@ public class Main extends Application {
|
||||||
saveTask = new TimerTask() {
|
saveTask = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mainWindowController.saveSettings();
|
XMLController.setWindowHeight(mainWindowController.getMainAnchorPane().getHeight());
|
||||||
|
xmlController.saveSettings();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
timer.schedule(saveTask, delayTime);
|
timer.schedule(saveTask, delayTime);
|
||||||
|
@ -306,47 +290,11 @@ public class Main extends Application {
|
||||||
return main;
|
return main;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stage getPrimaryStage() {
|
|
||||||
return primaryStage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrimaryStage(Stage primaryStage) {
|
|
||||||
this.primaryStage = primaryStage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CloudController getCloudController() {
|
public CloudController getCloudController() {
|
||||||
return cloudController;
|
return cloudController;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCloudController(CloudController cloudController) {
|
|
||||||
this.cloudController = cloudController;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnchorPane getPane() {
|
public AnchorPane getPane() {
|
||||||
return pane;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,8 @@ import java.awt.Graphics2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
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.DBController;
|
||||||
import com.cemu_UI.controller.SmmdbAPIController;
|
import com.cemu_UI.controller.SmmdbAPIController;
|
||||||
import com.cemu_UI.controller.UpdateController;
|
import com.cemu_UI.controller.UpdateController;
|
||||||
|
import com.cemu_UI.controller.XMLController;
|
||||||
import com.cemu_UI.datatypes.CourseTableDataType;
|
import com.cemu_UI.datatypes.CourseTableDataType;
|
||||||
import com.cemu_UI.datatypes.GlobalDataTypes.CloudService;
|
import com.cemu_UI.datatypes.GlobalDataTypes.CloudService;
|
||||||
import com.cemu_UI.datatypes.SmmdbApiDataType;
|
import com.cemu_UI.datatypes.SmmdbApiDataType;
|
||||||
|
@ -102,6 +99,7 @@ import javafx.scene.text.FontWeight;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import javafx.scene.text.TextFlow;
|
import javafx.scene.text.TextFlow;
|
||||||
import javafx.stage.DirectoryChooser;
|
import javafx.stage.DirectoryChooser;
|
||||||
|
import javafx.stage.Stage;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
import net.lingala.zip4j.core.ZipFile;
|
import net.lingala.zip4j.core.ZipFile;
|
||||||
import net.lingala.zip4j.exception.ZipException;
|
import net.lingala.zip4j.exception.ZipException;
|
||||||
|
@ -182,19 +180,13 @@ public class MainWindowController {
|
||||||
private playGame playGame;
|
private playGame playGame;
|
||||||
private static MainWindowController MWC;
|
private static MainWindowController MWC;
|
||||||
private UpdateController updateController;
|
private UpdateController updateController;
|
||||||
|
private XMLController xmlController;
|
||||||
|
private Stage primaryStage;
|
||||||
private boolean menuTrue = false;
|
private boolean menuTrue = false;
|
||||||
private boolean settingsTrue = false;
|
private boolean settingsTrue = false;
|
||||||
private boolean playTrue = false;
|
private boolean playTrue = false;
|
||||||
private boolean smmdbTrue = 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 gameExecutePath;
|
||||||
private String color;
|
|
||||||
private String dialogBtnStyle;
|
private String dialogBtnStyle;
|
||||||
private String selectedGameTitleID;
|
private String selectedGameTitleID;
|
||||||
private String selectedGameTitle;
|
private String selectedGameTitle;
|
||||||
|
@ -204,13 +196,10 @@ public class MainWindowController {
|
||||||
private String versionName = "Purple Comet";
|
private String versionName = "Purple Comet";
|
||||||
private int xPos = -200;
|
private int xPos = -200;
|
||||||
private int yPos = 17;
|
private int yPos = 17;
|
||||||
private int xPosHelper;
|
private int xPosHelper = 0;
|
||||||
private int oldXPosHelper;
|
private int oldXPosHelper;
|
||||||
private int selectedUIDataIndex;
|
private int selectedUIDataIndex;
|
||||||
private int selected;
|
private int selected;
|
||||||
private long lastLocalSync;
|
|
||||||
private double windowWidth;
|
|
||||||
private double windowHeight;
|
|
||||||
private DirectoryChooser directoryChooser = new DirectoryChooser();
|
private DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta");
|
private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta");
|
||||||
private ObservableList<String> languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)");
|
private ObservableList<String> languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)");
|
||||||
|
@ -279,8 +268,9 @@ public class MainWindowController {
|
||||||
private String smmdbDownloadBtnDownload;
|
private String smmdbDownloadBtnDownload;
|
||||||
|
|
||||||
public MainWindowController(Main main) {
|
public MainWindowController(Main main) {
|
||||||
|
xmlController = new XMLController();
|
||||||
this.main = main;
|
this.main = main;
|
||||||
dbController = new DBController(main, this);
|
dbController = new DBController(this);
|
||||||
smmdbAPIController = new SmmdbAPIController();
|
smmdbAPIController = new SmmdbAPIController();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +279,7 @@ public class MainWindowController {
|
||||||
* loadSettings, checkAutoUpdate, initUI and initActions
|
* loadSettings, checkAutoUpdate, initUI and initActions
|
||||||
*/
|
*/
|
||||||
public void init() {
|
public void init() {
|
||||||
loadSettings();
|
xmlController.loadSettings(); // load settings
|
||||||
checkAutoUpdate();
|
checkAutoUpdate();
|
||||||
initUI();
|
initUI();
|
||||||
initActions();
|
initActions();
|
||||||
|
@ -301,21 +291,24 @@ public class MainWindowController {
|
||||||
private void initUI() {
|
private void initUI() {
|
||||||
LOGGER.info("initializing UI ...");
|
LOGGER.info("initializing UI ...");
|
||||||
|
|
||||||
if (getWindowWidth() > 100 && getWindowHeight() > 100) {
|
primaryStage = (Stage) mainAnchorPane.getScene().getWindow(); // set primary stage for dialogs
|
||||||
mainAnchorPane.setPrefSize(getWindowWidth(), getWindowHeight());
|
|
||||||
|
// TODO this is broken
|
||||||
|
if (XMLController.getWindowWidth() > 100 && XMLController.getWindowHeight() > 100) {
|
||||||
|
mainAnchorPane.setPrefSize(XMLController.getWindowWidth(), XMLController.getWindowHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
cemuTextField.setText(cemuPath);
|
cemuTextField.setText(XMLController.getCemuPath());
|
||||||
romTextField.setText(romDirectoryPath);
|
romTextField.setText(XMLController.getRomDirectoryPath());
|
||||||
colorPicker.setValue(Color.valueOf(getColor()));
|
colorPicker.setValue(Color.valueOf(XMLController.getColor()));
|
||||||
fullscreenToggleBtn.setSelected(isFullscreen());
|
fullscreenToggleBtn.setSelected(XMLController.isFullscreen());
|
||||||
cloudSyncToggleBtn.setSelected(isCloudSync());
|
cloudSyncToggleBtn.setSelected(XMLController.isCloudSync());
|
||||||
autoUpdateToggleBtn.setSelected(isAutoUpdate());
|
autoUpdateToggleBtn.setSelected(XMLController.isAutoUpdate());
|
||||||
branchChoisBox.setItems(branches);
|
branchChoisBox.setItems(branches);
|
||||||
languageChoisBox.setItems(languages);
|
languageChoisBox.setItems(languages);
|
||||||
bottomHBox.setPickOnBounds(false);
|
bottomHBox.setPickOnBounds(false);
|
||||||
|
|
||||||
if (isUseBeta()) {
|
if (XMLController.isUseBeta()) {
|
||||||
branchChoisBox.getSelectionModel().select(1);
|
branchChoisBox.getSelectionModel().select(1);
|
||||||
} else {
|
} else {
|
||||||
branchChoisBox.getSelectionModel().select(0);
|
branchChoisBox.getSelectionModel().select(0);
|
||||||
|
@ -373,7 +366,7 @@ public class MainWindowController {
|
||||||
}
|
}
|
||||||
if (settingsTrue) {
|
if (settingsTrue) {
|
||||||
settingsScrollPane.setVisible(false);
|
settingsScrollPane.setVisible(false);
|
||||||
saveSettings();
|
xmlController.saveSettings();
|
||||||
settingsTrue = false;
|
settingsTrue = false;
|
||||||
}
|
}
|
||||||
if (smmdbTrue) {
|
if (smmdbTrue) {
|
||||||
|
@ -393,7 +386,7 @@ public class MainWindowController {
|
||||||
// new edit dialog
|
// new edit dialog
|
||||||
String headingText = editHeadingText + " \"" + selectedGameTitle + "\"";
|
String headingText = editHeadingText + " \"" + selectedGameTitle + "\"";
|
||||||
JFXEditGameDialog editGameDialog = new JFXEditGameDialog(headingText, editBodyText, dialogBtnStyle, 450,
|
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.setTitle(gameInfo[0]);
|
||||||
editGameDialog.setCoverPath(gameInfo[1]);
|
editGameDialog.setCoverPath(gameInfo[1]);
|
||||||
editGameDialog.setRomPath(gameInfo[2]);
|
editGameDialog.setRomPath(gameInfo[2]);
|
||||||
|
@ -451,11 +444,11 @@ public class MainWindowController {
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
DirectoryChooser directoryChooser = new DirectoryChooser();
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
File selectedDirecroty = directoryChooser.showDialog(main.getPrimaryStage());
|
File selectedDirecroty = directoryChooser.showDialog(primaryStage);
|
||||||
String updatePath = selectedDirecroty.getAbsolutePath();
|
String updatePath = selectedDirecroty.getAbsolutePath();
|
||||||
String[] parts = selectedGameTitleID.split("-"); // split string into 2 parts at "-"
|
String[] parts = selectedGameTitleID.split("-"); // split string into 2 parts at "-"
|
||||||
File srcDir = new File(updatePath);
|
File srcDir = new File(updatePath);
|
||||||
File destDir = new File(cemuPath + "/mlc01/usr/title/" + parts[0] + "/" + parts[1]);
|
File destDir = new File(XMLController.getCemuPath() + "/mlc01/usr/title/" + parts[0] + "/" + parts[1]);
|
||||||
|
|
||||||
// if directory doesn't exist create it
|
// if directory doesn't exist create it
|
||||||
if (destDir.exists() != true) {
|
if (destDir.exists() != true) {
|
||||||
|
@ -502,11 +495,11 @@ public class MainWindowController {
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
DirectoryChooser directoryChooser = new DirectoryChooser();
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
File selectedDirecroty = directoryChooser.showDialog(main.getPrimaryStage());
|
File selectedDirecroty = directoryChooser.showDialog(primaryStage);
|
||||||
String dlcPath = selectedDirecroty.getAbsolutePath();
|
String dlcPath = selectedDirecroty.getAbsolutePath();
|
||||||
String[] parts = selectedGameTitleID.split("-"); // split string into 2 parts at "-"
|
String[] parts = selectedGameTitleID.split("-"); // split string into 2 parts at "-"
|
||||||
File srcDir = new File(dlcPath);
|
File srcDir = new File(dlcPath);
|
||||||
File destDir = new File(cemuPath + "/mlc01/usr/title/" + parts[0] + "/" + parts[1] + "/aoc");
|
File destDir = new File(XMLController.getCemuPath() + "/mlc01/usr/title/" + parts[0] + "/" + parts[1] + "/aoc");
|
||||||
|
|
||||||
// if directory doesn't exist create it
|
// if directory doesn't exist create it
|
||||||
if (destDir.exists() != true) {
|
if (destDir.exists() != true) {
|
||||||
|
@ -628,26 +621,27 @@ public class MainWindowController {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
languageChoisBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
|
languageChoisBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) {
|
public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) {
|
||||||
String language = languageChoisBox.getItems().get((int) new_value).toString();
|
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)
|
language = language.substring(language.length() - 6, language.length() - 1); // reading only en_US from
|
||||||
setLanguage(language);
|
// English (en_US)
|
||||||
setUILanguage();
|
XMLController.setUsrLocal(language);
|
||||||
saveSettings();
|
setUILanguage();
|
||||||
}
|
xmlController.saveSettings();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
branchChoisBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
|
branchChoisBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) {
|
public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) {
|
||||||
if (branchChoisBox.getItems().get((int) new_value).toString() == "beta") {
|
if (branchChoisBox.getItems().get((int) new_value).toString() == "beta") {
|
||||||
setUseBeta(true);
|
XMLController.setUseBeta(true);
|
||||||
} else {
|
} else {
|
||||||
setUseBeta(false);
|
XMLController.setUseBeta(false);
|
||||||
}
|
}
|
||||||
saveSettings();
|
xmlController.saveSettings();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -702,11 +696,11 @@ public class MainWindowController {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
||||||
if (new File(newValue).exists()) {
|
if (new File(newValue).exists()) {
|
||||||
setCemuPath(newValue);
|
XMLController.setCemuPath(newValue);
|
||||||
saveSettings();
|
xmlController.saveSettings();
|
||||||
} else {
|
} else {
|
||||||
String bodyText = newValue + ": No such file or directory";
|
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();
|
fileErrorDialog.showAndWait();
|
||||||
LOGGER.warn(newValue + ": No such file or directory");
|
LOGGER.warn(newValue + ": No such file or directory");
|
||||||
}
|
}
|
||||||
|
@ -717,12 +711,12 @@ public class MainWindowController {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
||||||
if (new File(newValue).exists()) {
|
if (new File(newValue).exists()) {
|
||||||
setRomDirectoryPath(newValue);
|
XMLController.setRomDirectoryPath(newValue);
|
||||||
saveSettings();
|
xmlController.saveSettings();
|
||||||
reloadRoms();
|
reloadRoms();
|
||||||
} else {
|
} else {
|
||||||
String bodyText = newValue + ": No such file or directory";
|
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();
|
fileErrorDialog.showAndWait();
|
||||||
LOGGER.warn(newValue + ": No such file or directory");
|
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"
|
String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (" + buildNumber + ") \"" + versionName + "\" \n"
|
||||||
+ aboutBtnBodyText;
|
+ aboutBtnBodyText;
|
||||||
|
|
||||||
JFXInfoAlert infoAlert = new JFXInfoAlert(aboutBtnHeadingText, bodyText, dialogBtnStyle, main.getPrimaryStage());
|
JFXInfoAlert infoAlert = new JFXInfoAlert(aboutBtnHeadingText, bodyText, dialogBtnStyle, primaryStage);
|
||||||
infoAlert.showAndWait();
|
infoAlert.showAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,7 +749,7 @@ public class MainWindowController {
|
||||||
if (settingsTrue) {
|
if (settingsTrue) {
|
||||||
settingsScrollPane.setVisible(false);
|
settingsScrollPane.setVisible(false);
|
||||||
settingsTrue = false;
|
settingsTrue = false;
|
||||||
saveSettings();
|
xmlController.saveSettings();
|
||||||
} else {
|
} else {
|
||||||
settingsScrollPane.setVisible(true);
|
settingsScrollPane.setVisible(true);
|
||||||
settingsTrue = true;
|
settingsTrue = true;
|
||||||
|
@ -826,7 +820,7 @@ public class MainWindowController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void cemuTFBtnAction() {
|
private void cemuTFBtnAction() {
|
||||||
File cemuDirectory = directoryChooser.showDialog(main.getPrimaryStage());
|
File cemuDirectory = directoryChooser.showDialog(primaryStage);
|
||||||
if (cemuDirectory != null) {
|
if (cemuDirectory != null) {
|
||||||
cemuTextField.setText(cemuDirectory.getAbsolutePath());
|
cemuTextField.setText(cemuDirectory.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
@ -834,7 +828,7 @@ public class MainWindowController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void romTFBtnAction() {
|
private void romTFBtnAction() {
|
||||||
File romDirectory = directoryChooser.showDialog(main.getPrimaryStage());
|
File romDirectory = directoryChooser.showDialog(primaryStage);
|
||||||
if (romDirectory != null) {
|
if (romDirectory != null) {
|
||||||
romTextField.setText(romDirectory.getAbsolutePath());
|
romTextField.setText(romDirectory.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
@ -842,7 +836,7 @@ public class MainWindowController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void updateBtnAction() {
|
private void updateBtnAction() {
|
||||||
updateController = new UpdateController(this, buildNumber, useBeta);
|
updateController = new UpdateController(this, buildNumber, XMLController.isUseBeta());
|
||||||
Thread updateThread = new Thread(updateController);
|
Thread updateThread = new Thread(updateController);
|
||||||
updateThread.setName("Updater");
|
updateThread.setName("Updater");
|
||||||
updateThread.start();
|
updateThread.start();
|
||||||
|
@ -850,12 +844,8 @@ public class MainWindowController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void autoUpdateToggleBtnAction() {
|
private void autoUpdateToggleBtnAction() {
|
||||||
if (isAutoUpdate()) {
|
XMLController.setAutoUpdate(!XMLController.isAutoUpdate());
|
||||||
setAutoUpdate(false);
|
xmlController.saveSettings();
|
||||||
} else {
|
|
||||||
setAutoUpdate(true);
|
|
||||||
}
|
|
||||||
saveSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -866,8 +856,8 @@ public class MainWindowController {
|
||||||
@FXML
|
@FXML
|
||||||
private void smmdbDownloadBtnAction() {
|
private void smmdbDownloadBtnAction() {
|
||||||
String downloadUrl = "http://smmdb.ddns.net/api/downloadcourse?id=" + id + "&type=zip";
|
String downloadUrl = "http://smmdb.ddns.net/api/downloadcourse?id=" + id + "&type=zip";
|
||||||
String downloadFileURL = getCemuPath() + "/" + id + ".zip"; // getCemuPath() + "/" + smmID + "/" + id + ".rar"
|
String downloadFileURL = XMLController.getCemuPath() + "/" + id + ".zip"; // getCemuPath() + "/" + smmID + "/" + id + ".rar"
|
||||||
String outputFile = getCemuPath() + "/";
|
String outputFile = XMLController.getCemuPath() + "/";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LOGGER.info("beginning download ...");
|
LOGGER.info("beginning download ...");
|
||||||
|
@ -933,41 +923,36 @@ public class MainWindowController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void fullscreenToggleBtnAction() {
|
private void fullscreenToggleBtnAction() {
|
||||||
if (fullscreen) {
|
XMLController.setFullscreen(!XMLController.isFullscreen());
|
||||||
fullscreen = false;
|
xmlController.saveSettings();
|
||||||
} else {
|
|
||||||
fullscreen = true;
|
|
||||||
}
|
|
||||||
saveSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void cloudSyncToggleBtnAction() {
|
private void cloudSyncToggleBtnAction() {
|
||||||
if(cloudSync) {
|
XMLController.setCloudSync(!XMLController.isCloudSync());
|
||||||
cloudSync = false;
|
|
||||||
} else {
|
if(XMLController.isCloudSync()) {
|
||||||
EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>(){
|
EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>(){
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event){
|
public void handle(ActionEvent event){
|
||||||
cloudSync = true;
|
|
||||||
//TODO rework for other cloud services
|
//TODO rework for other cloud services
|
||||||
// CloudService service = CloudService.GoogleDrive;
|
// CloudService service = CloudService.GoogleDrive;
|
||||||
cloudService = CloudService.GoogleDrive;
|
XMLController.setCloudService(CloudService.GoogleDrive);
|
||||||
|
|
||||||
// start cloud sync in new thread
|
// start cloud sync in new thread
|
||||||
Thread thread = new Thread(new Runnable() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
if (main.getCloudController().initializeConnection(getCloudService(), getCemuPath())) {
|
if (main.getCloudController().initializeConnection(XMLController.getCloudService(), XMLController.getCemuPath())) {
|
||||||
main.getCloudController().sync(getCloudService(), getCemuPath(), main.getDirectory().getPath());
|
main.getCloudController().sync(XMLController.getCloudService(), XMLController.getCemuPath(), XMLController.getDirCemuUIPath());
|
||||||
saveSettings();
|
xmlController.saveSettings();
|
||||||
} else {
|
} else {
|
||||||
cloudSyncToggleBtn.setSelected(false);
|
cloudSyncToggleBtn.setSelected(false);
|
||||||
|
|
||||||
// cloud sync init error dialog
|
// cloud sync init error dialog
|
||||||
JFXInfoAlert cloudSyncErrorDialog = new JFXInfoAlert(cloudSyncErrorHeadingText,
|
JFXInfoAlert cloudSyncErrorDialog = new JFXInfoAlert(cloudSyncErrorHeadingText,
|
||||||
cloudSyncErrorBodyText, dialogBtnStyle, main.getPrimaryStage());
|
cloudSyncErrorBodyText, dialogBtnStyle, primaryStage);
|
||||||
cloudSyncErrorDialog.showAndWait();
|
cloudSyncErrorDialog.showAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1002,7 +987,7 @@ public class MainWindowController {
|
||||||
String headingText = addGameBtnHeadingText;
|
String headingText = addGameBtnHeadingText;
|
||||||
String bodyText = addGameBtnBodyText;
|
String bodyText = addGameBtnBodyText;
|
||||||
JFXEditGameDialog addGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450, 300, 0,
|
JFXEditGameDialog addGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450, 300, 0,
|
||||||
this, main.getPrimaryStage(), main.getPane());
|
this, primaryStage, main.getPane());
|
||||||
addGameDialog.show();
|
addGameDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1021,11 +1006,11 @@ public class MainWindowController {
|
||||||
|
|
||||||
//addGame error dialog
|
//addGame error dialog
|
||||||
JFXInfoAlert errorDialog = new JFXInfoAlert(addBtnReturnErrorHeadingText, addBtnReturnErrorBodyText,
|
JFXInfoAlert errorDialog = new JFXInfoAlert(addBtnReturnErrorHeadingText, addBtnReturnErrorBodyText,
|
||||||
dialogBtnStyle, main.getPrimaryStage());
|
dialogBtnStyle, primaryStage);
|
||||||
errorDialog.showAndWait();
|
errorDialog.showAndWait();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
File pictureCache = main.getPictureCache();
|
File pictureCache = XMLController.getPictureCache();
|
||||||
String coverName = new File(coverPath).getName();
|
String coverName = new File(coverPath).getName();
|
||||||
try {
|
try {
|
||||||
BufferedImage originalImage = ImageIO.read(new File(coverPath)); //load cover
|
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
|
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
|
games.removeAll(games); // remove all games from the mwc game list
|
||||||
dbController.loadAllGames(); // load all games from the database to the mwc
|
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
|
// set the selected local strings to all needed elements
|
||||||
void setUILanguage(){
|
void setUILanguage(){
|
||||||
switch(getLanguage()){
|
switch(XMLController.getUsrLocal()){
|
||||||
case "en_US":
|
case "en_US":
|
||||||
bundle = ResourceBundle.getBundle("locals.cemu_UI-Local", Locale.US); //us_English
|
bundle = ResourceBundle.getBundle("locals.cemu_UI-Local", Locale.US); //us_English
|
||||||
languageChoisBox.getSelectionModel().select(0);
|
languageChoisBox.getSelectionModel().select(0);
|
||||||
|
@ -1302,10 +1287,10 @@ public class MainWindowController {
|
||||||
// if AutoUpdate, then check for updates
|
// if AutoUpdate, then check for updates
|
||||||
private void checkAutoUpdate() {
|
private void checkAutoUpdate() {
|
||||||
|
|
||||||
if (isAutoUpdate()) {
|
if (XMLController.isAutoUpdate()) {
|
||||||
try {
|
try {
|
||||||
LOGGER.info("AutoUpdate: looking for updates on startup ...");
|
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);
|
Thread updateThread = new Thread(updateController);
|
||||||
updateThread.setName("Updater");
|
updateThread.setName("Updater");
|
||||||
updateThread.start();
|
updateThread.start();
|
||||||
|
@ -1456,16 +1441,16 @@ public class MainWindowController {
|
||||||
|
|
||||||
// change the color of all needed GUI elements
|
// change the color of all needed GUI elements
|
||||||
private void applyColor() {
|
private void applyColor() {
|
||||||
String boxStyle = "-fx-background-color: #"+getColor()+";";
|
String boxStyle = "-fx-background-color: #" + XMLController.getColor() + ";";
|
||||||
String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #"+getColor()+"; -fx-text-fill: BLACK;";
|
String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #" + XMLController.getColor() + "; -fx-text-fill: BLACK;";
|
||||||
String btnStyleWhite = "-fx-button-type: RAISED; -fx-background-color: #"+getColor()+"; -fx-text-fill: WHITE;";
|
String btnStyleWhite = "-fx-button-type: RAISED; -fx-background-color: #" + XMLController.getColor() + "; -fx-text-fill: WHITE;";
|
||||||
BigInteger icolor = new BigInteger(getColor(),16);
|
BigInteger icolor = new BigInteger(XMLController.getColor(),16);
|
||||||
BigInteger ccolor = new BigInteger("78909cff",16);
|
BigInteger ccolor = new BigInteger("78909cff",16);
|
||||||
|
|
||||||
sideMenuVBox.setStyle(boxStyle);
|
sideMenuVBox.setStyle(boxStyle);
|
||||||
topHBox.setStyle(boxStyle);
|
topHBox.setStyle(boxStyle);
|
||||||
cemuTextField.setFocusColor(Color.valueOf(getColor()));
|
cemuTextField.setFocusColor(Color.valueOf(XMLController.getColor()));
|
||||||
romTextField.setFocusColor(Color.valueOf(getColor()));
|
romTextField.setFocusColor(Color.valueOf(XMLController.getColor()));
|
||||||
|
|
||||||
if (icolor.compareTo(ccolor) == -1) {
|
if (icolor.compareTo(ccolor) == -1) {
|
||||||
dialogBtnStyle = btnStyleWhite;
|
dialogBtnStyle = btnStyleWhite;
|
||||||
|
@ -1516,158 +1501,7 @@ public class MainWindowController {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < games.size(); i++) {
|
for (int i = 0; i < games.size(); i++) {
|
||||||
games.get(i).getButton().setRipplerFill(Paint.valueOf(getColor()));
|
games.get(i).getButton().setRipplerFill(Paint.valueOf(XMLController.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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1709,8 +1543,8 @@ public class MainWindowController {
|
||||||
private void editColor(String input){
|
private void editColor(String input){
|
||||||
StringBuilder sb = new StringBuilder(input);
|
StringBuilder sb = new StringBuilder(input);
|
||||||
sb.delete(0, 2);
|
sb.delete(0, 2);
|
||||||
this.color = sb.toString();
|
XMLController.setColor(sb.toString());
|
||||||
saveSettings();
|
xmlController.saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
@ -1718,8 +1552,8 @@ public class MainWindowController {
|
||||||
* @return the main color in hexadecimal format
|
* @return the main color in hexadecimal format
|
||||||
*/
|
*/
|
||||||
private String hexToRgb() {
|
private String hexToRgb() {
|
||||||
LOGGER.info(getColor());
|
LOGGER.info(XMLController.getColor());
|
||||||
int hex = Integer.parseInt(getColor().substring(0, 5), 16);
|
int hex = Integer.parseInt(XMLController.getColor().substring(0, 5), 16);
|
||||||
|
|
||||||
int r = (hex & 0xFF0000) >> 16;
|
int r = (hex & 0xFF0000) >> 16;
|
||||||
int g = (hex & 0xFF00) >> 8;
|
int g = (hex & 0xFF00) >> 8;
|
||||||
|
@ -1752,33 +1586,9 @@ public class MainWindowController {
|
||||||
public DBController getDbController() {
|
public DBController getDbController() {
|
||||||
return dbController;
|
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() {
|
public Stage getPrimaryStage() {
|
||||||
return romDirectoryPath;
|
return primaryStage;
|
||||||
}
|
|
||||||
|
|
||||||
public void setRomDirectoryPath(String romDirectoryPath) {
|
|
||||||
this.romDirectoryPath = romDirectoryPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getColor() {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColor(String color) {
|
|
||||||
this.color = color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getxPos() {
|
public int getxPos() {
|
||||||
|
@ -1805,46 +1615,6 @@ public class MainWindowController {
|
||||||
this.xPosHelper = xPosHelper;
|
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() {
|
public String getGameExecutePath() {
|
||||||
return gameExecutePath;
|
return gameExecutePath;
|
||||||
}
|
}
|
||||||
|
@ -1861,14 +1631,6 @@ public class MainWindowController {
|
||||||
this.selectedGameTitleID = selectedGameTitleID;
|
this.selectedGameTitleID = selectedGameTitleID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CloudService getCloudService() {
|
|
||||||
return cloudService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCloudService(CloudService cloudService) {
|
|
||||||
this.cloudService = cloudService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JFXButton getPlayBtn() {
|
public JFXButton getPlayBtn() {
|
||||||
return playBtn;
|
return playBtn;
|
||||||
}
|
}
|
||||||
|
@ -1876,31 +1638,11 @@ public class MainWindowController {
|
||||||
public void setPlayBtn(JFXButton playBtn) {
|
public void setPlayBtn(JFXButton playBtn) {
|
||||||
this.playBtn = 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() {
|
public int getOldXPosHelper() {
|
||||||
return oldXPosHelper;
|
return oldXPosHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOldXPosHelper(int oldXPosHelper) {
|
|
||||||
this.oldXPosHelper = oldXPosHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLanguage() {
|
public String getLanguage() {
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
@ -1913,10 +1655,6 @@ public class MainWindowController {
|
||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBundle(ResourceBundle bundle) {
|
|
||||||
this.bundle = bundle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnchorPane getMainAnchorPane() {
|
public AnchorPane getMainAnchorPane() {
|
||||||
return mainAnchorPane;
|
return mainAnchorPane;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import com.cemu_UI.controller.DBController;
|
import com.cemu_UI.controller.DBController;
|
||||||
|
import com.cemu_UI.controller.XMLController;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ public class playGame extends Thread{
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String selectedGameTitleID = mainWindowController.getSelectedGameTitleID();
|
String selectedGameTitleID = mainWindowController.getSelectedGameTitleID();
|
||||||
String cemuBin = mainWindowController.getCemuPath() + "/Cemu.exe";
|
String cemuBin = XMLController.getCemuPath() + "/Cemu.exe";
|
||||||
String gameExec = "\"" + mainWindowController.getGameExecutePath() + "\"";
|
String gameExec = "\"" + mainWindowController.getGameExecutePath() + "\"";
|
||||||
long startTime;
|
long startTime;
|
||||||
long endTime;
|
long endTime;
|
||||||
|
@ -53,18 +54,18 @@ public class playGame extends Thread{
|
||||||
Process p;
|
Process p;
|
||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
mainWindowController.getMain().getPrimaryStage().setIconified(true); // minimize cemu_UI
|
mainWindowController.getPrimaryStage().setIconified(true); // minimize cemu_UI
|
||||||
});
|
});
|
||||||
startTime = System.currentTimeMillis();
|
startTime = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
if (System.getProperty("os.name").equals("Linux")) {
|
if (System.getProperty("os.name").equals("Linux")) {
|
||||||
if(mainWindowController.isFullscreen()){
|
if(XMLController.isFullscreen()){
|
||||||
p = new ProcessBuilder("wine", cemuBin, "-f", "-g", gameExec).start();
|
p = new ProcessBuilder("wine", cemuBin, "-f", "-g", gameExec).start();
|
||||||
} else {
|
} else {
|
||||||
p = new ProcessBuilder("wine", cemuBin, "-g", gameExec).start();
|
p = new ProcessBuilder("wine", cemuBin, "-g", gameExec).start();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(mainWindowController.isFullscreen()){
|
if(XMLController.isFullscreen()){
|
||||||
p = new ProcessBuilder(cemuBin, "-f", "-g", gameExec).start();
|
p = new ProcessBuilder(cemuBin, "-f", "-g", gameExec).start();
|
||||||
} else {
|
} else {
|
||||||
p = new ProcessBuilder(cemuBin, "-g", gameExec).start();
|
p = new ProcessBuilder(cemuBin, "-g", gameExec).start();
|
||||||
|
@ -85,14 +86,14 @@ public class playGame extends Thread{
|
||||||
} else {
|
} else {
|
||||||
mainWindowController.totalPlaytimeBtn.setText(dbController.getTotalPlaytime(selectedGameTitleID) + " min");
|
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
|
//sync savegame with cloud service
|
||||||
if (mainWindowController.isCloudSync()) {
|
if (XMLController.isCloudSync()) {
|
||||||
mainWindowController.setLastLocalSync(Instant.now().getEpochSecond());
|
XMLController.setLastLocalSync(Instant.now().getEpochSecond());
|
||||||
mainWindowController.getMain().getCloudController().sync(mainWindowController.getCloudService(),
|
mainWindowController.getMain().getCloudController().sync(XMLController.getCloudService(),
|
||||||
mainWindowController.getCemuPath(), mainWindowController.getMain().getDirectory().getPath());
|
XMLController.getCemuPath(), XMLController.getDirCemuUIPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class CloudController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MainWindowController mwc;
|
private MainWindowController mwc;
|
||||||
|
private XMLController xmlController = new XMLController();
|
||||||
private GoogleDriveController googleDriveController = new GoogleDriveController();
|
private GoogleDriveController googleDriveController = new GoogleDriveController();
|
||||||
private static final Logger LOGGER = LogManager.getLogger(CloudController.class.getName());
|
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!");
|
LOGGER.info("cloud sync folder dosen't exist, creating one!");
|
||||||
googleDriveController.creatFolder();
|
googleDriveController.creatFolder();
|
||||||
googleDriveController.uploadZipFile(zipFile);
|
googleDriveController.uploadZipFile(zipFile);
|
||||||
} else if (mwc.getLastLocalSync() > lastCloudSync) {
|
} else if (XMLController.getLastLocalSync() > lastCloudSync) {
|
||||||
LOGGER.info("local is new, going to upload zip");
|
LOGGER.info("local is new, going to upload zip");
|
||||||
googleDriveController.uploadZipFile(zipFile);
|
googleDriveController.uploadZipFile(zipFile);
|
||||||
} else if (mwc.getLastLocalSync() < lastCloudSync) {
|
} else if (XMLController.getLastLocalSync() < lastCloudSync) {
|
||||||
LOGGER.info("cloud is new, going to download zip");
|
LOGGER.info("cloud is new, going to download zip");
|
||||||
unzipSavegames(cemuDirectory, googleDriveController.downloadZipFile(cemu_UIDirectory));
|
unzipSavegames(cemuDirectory, googleDriveController.downloadZipFile(cemu_UIDirectory));
|
||||||
mwc.setLastLocalSync(lastCloudSync);
|
XMLController.setLastLocalSync(lastCloudSync);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("nothing to do");
|
LOGGER.info("nothing to do");
|
||||||
break;
|
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;
|
break;
|
||||||
|
|
||||||
case Dropbox:
|
case Dropbox:
|
||||||
|
@ -134,7 +135,7 @@ public class CloudController {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
mwc.getPlayBtn().setText("play");
|
mwc.getPlayBtn().setText("play");
|
||||||
mwc.getPlayBtn().setDisable(false);
|
mwc.getPlayBtn().setDisable(false);
|
||||||
mwc.saveSettings();
|
xmlController.saveSettings();
|
||||||
});
|
});
|
||||||
|
|
||||||
LOGGER.info("synchronization successful!");
|
LOGGER.info("synchronization successful!");
|
||||||
|
@ -210,16 +211,5 @@ public class CloudController {
|
||||||
}
|
}
|
||||||
return folderID;
|
return folderID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFolderID(String folderID, CloudService cloudService) {
|
|
||||||
if (cloudService != null) {
|
|
||||||
if (cloudService == CloudService.GoogleDrive) {
|
|
||||||
googleDriveController.setFolderID(folderID);
|
|
||||||
}
|
|
||||||
if (cloudService == CloudService.Dropbox) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,17 +44,14 @@ import org.apache.logging.log4j.Logger;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import com.cemu_UI.application.Main;
|
|
||||||
import com.cemu_UI.application.MainWindowController;
|
import com.cemu_UI.application.MainWindowController;
|
||||||
|
|
||||||
public class DBController {
|
public class DBController {
|
||||||
|
|
||||||
public DBController(Main main, MainWindowController mainWindowController) {
|
public DBController(MainWindowController mainWindowController) {
|
||||||
this.main = main;
|
|
||||||
this.mainWindowController = mainWindowController;
|
this.mainWindowController = mainWindowController;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Main main;
|
|
||||||
private MainWindowController mainWindowController;
|
private MainWindowController mainWindowController;
|
||||||
private ArrayList<String> entries = new ArrayList<>();
|
private ArrayList<String> entries = new ArrayList<>();
|
||||||
private String DB_PATH_localRoms;
|
private String DB_PATH_localRoms;
|
||||||
|
@ -103,7 +100,7 @@ public class DBController {
|
||||||
* games.db contains a reverence list to for the automatic detection mode
|
* games.db contains a reverence list to for the automatic detection mode
|
||||||
*/
|
*/
|
||||||
private void loadGamesDatabase() {
|
private void loadGamesDatabase() {
|
||||||
DB_PATH_games = main.getReference_gamesFile().getAbsolutePath();
|
DB_PATH_games = XMLController.getRference_gamesFile().getAbsolutePath();
|
||||||
try {
|
try {
|
||||||
// create a database connection
|
// create a database connection
|
||||||
connectionGames = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH_games);
|
connectionGames = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH_games);
|
||||||
|
@ -209,7 +206,7 @@ public class DBController {
|
||||||
File dir = new File(directory);
|
File dir = new File(directory);
|
||||||
File appFile;
|
File appFile;
|
||||||
String[] extensions = new String[] { "rpx", "jsp" };
|
String[] extensions = new String[] { "rpx", "jsp" };
|
||||||
File pictureCache = main.getPictureCache();
|
File pictureCache = XMLController.getPictureCache();
|
||||||
String coverPath;
|
String coverPath;
|
||||||
try {
|
try {
|
||||||
Statement stmt = connectionGames.createStatement();
|
Statement stmt = connectionGames.createStatement();
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(XMLController.class.getName());
|
||||||
|
private Properties props = new Properties();
|
||||||
|
|
||||||
|
public XMLController() {
|
||||||
|
|
||||||
|
if (osName.contains("Windows")) {
|
||||||
|
dirCemuUIPath = userHome + "/Documents/cemu_UI";
|
||||||
|
} else {
|
||||||
|
dirCemuUIPath = userHome + "/cemu_UI";
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the concrete files
|
||||||
|
dirCemuUI = new File(dirCemuUIPath);
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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", getUsrLocal());
|
||||||
|
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", getFolderID());
|
||||||
|
props.setProperty("lastLocalSync", Long.toString(getLastLocalSync()));
|
||||||
|
props.setProperty("windowWidth", Double.toString(getWindowWidth()));
|
||||||
|
props.setProperty("windowHeight", Double.toString(getWindowHeight()));
|
||||||
|
|
||||||
|
OutputStream outputStream = new FileOutputStream(XMLController.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
|
||||||
|
*/
|
||||||
|
public void loadSettings() {
|
||||||
|
LOGGER.info("loading settings ...");
|
||||||
|
try {
|
||||||
|
InputStream inputStream = new FileInputStream(XMLController.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");
|
||||||
|
setUsrLocal("en_US");
|
||||||
|
} else {
|
||||||
|
setUsrLocal(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 {
|
||||||
|
setFolderID(props.getProperty("folderID"));
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getters for application variables
|
||||||
|
|
||||||
|
public static String getUserHome() {
|
||||||
|
return userHome;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getOsName() {
|
||||||
|
return osName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getOsArch() {
|
||||||
|
return osArch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getOsVers() {
|
||||||
|
return osVers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getJavaVers() {
|
||||||
|
return javaVers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getJavaVend() {
|
||||||
|
return javaVend;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSysLocal() {
|
||||||
|
return sysLocal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDirCemuUIPath() {
|
||||||
|
return dirCemuUIPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getDirCemuUI() {
|
||||||
|
return dirCemuUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getConfigFile() {
|
||||||
|
return configFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getGamesDBFile() {
|
||||||
|
return gamesDBFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getRference_gamesFile() {
|
||||||
|
return reference_gamesFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getPictureCache() {
|
||||||
|
return pictureCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
// getters & setters for user settings
|
||||||
|
|
||||||
|
public static String getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setColor(String color) {
|
||||||
|
XMLController.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getUsrLocal() {
|
||||||
|
return usrLocal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setUsrLocal(String usrLocal) {
|
||||||
|
XMLController.usrLocal = usrLocal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isAutoUpdate() {
|
||||||
|
return autoUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setAutoUpdate(boolean autoUpdate) {
|
||||||
|
XMLController.autoUpdate = autoUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isUseBeta() {
|
||||||
|
return useBeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setUseBeta(boolean useBeta) {
|
||||||
|
XMLController.useBeta = useBeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFullscreen() {
|
||||||
|
return fullscreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setFullscreen(boolean fullscreen) {
|
||||||
|
XMLController.fullscreen = fullscreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCloudSync() {
|
||||||
|
return cloudSync;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCloudSync(boolean cloudSync) {
|
||||||
|
XMLController.cloudSync = cloudSync;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getCemuPath() {
|
||||||
|
return cemuPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCemuPath(String cemuPath) {
|
||||||
|
XMLController.cemuPath = cemuPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getRomDirectoryPath() {
|
||||||
|
return romDirectoryPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setRomDirectoryPath(String romDirectoryPath) {
|
||||||
|
XMLController.romDirectoryPath = romDirectoryPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getFolderID() {
|
||||||
|
return folderID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setFolderID(String folderID) {
|
||||||
|
XMLController.folderID = folderID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CloudService getCloudService() {
|
||||||
|
return cloudService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCloudService(CloudService cloudService) {
|
||||||
|
XMLController.cloudService = cloudService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getLastLocalSync() {
|
||||||
|
return lastLocalSync;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLastLocalSync(long lastLocalSync) {
|
||||||
|
XMLController.lastLocalSync = lastLocalSync;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getWindowWidth() {
|
||||||
|
return windowWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setWindowWidth(double windowWidth) {
|
||||||
|
XMLController.windowWidth = windowWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getWindowHeight() {
|
||||||
|
return windowHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setWindowHeight(double windowHeight) {
|
||||||
|
XMLController.windowHeight = windowHeight;
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ import java.util.Collections;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cemu_UI.controller.XMLController;
|
||||||
import com.google.api.client.auth.oauth2.Credential;
|
import com.google.api.client.auth.oauth2.Credential;
|
||||||
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
|
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
|
||||||
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
|
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
|
||||||
|
@ -50,7 +51,7 @@ import com.google.api.services.drive.model.FileList;
|
||||||
public class GoogleDriveController {
|
public class GoogleDriveController {
|
||||||
|
|
||||||
Drive service;
|
Drive service;
|
||||||
private String folderID;
|
private String folderID = XMLController.getFolderID();
|
||||||
private File downloadFile;
|
private File downloadFile;
|
||||||
private static final Logger LOGGER = LogManager.getLogger(GoogleDriveController.class.getName());
|
private static final Logger LOGGER = LogManager.getLogger(GoogleDriveController.class.getName());
|
||||||
|
|
||||||
|
@ -77,43 +78,41 @@ public class GoogleDriveController {
|
||||||
try {
|
try {
|
||||||
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
|
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
|
||||||
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
|
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
|
||||||
folderID = "";
|
folderID = ""; // TODO why do we do this?
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
LOGGER.error("error", t);
|
LOGGER.error("error", t);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an authorized Credential object.
|
* Creates an authorized Credential object.
|
||||||
* @return an authorized Credential object.
|
*
|
||||||
* @throws IOException
|
* @return an authorized Credential object.
|
||||||
*/
|
* @throws IOException
|
||||||
public Credential authorize() throws IOException {
|
*/
|
||||||
// Load client secrets.
|
public Credential authorize() throws IOException {
|
||||||
InputStream in = getClass().getClassLoader().getResourceAsStream("client_secret.json");
|
// Load client secrets.
|
||||||
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
|
InputStream in = getClass().getClassLoader().getResourceAsStream("client_secret.json");
|
||||||
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
|
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
|
||||||
.setDataStoreFactory(DATA_STORE_FACTORY)
|
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
|
||||||
.setAccessType("offline")
|
clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY).setAccessType("offline").build();
|
||||||
.build();
|
|
||||||
|
Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
|
||||||
Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
|
LOGGER.info("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
|
||||||
LOGGER.info("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
|
return credential;
|
||||||
return credential;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build and return an authorized Drive client service.
|
* Build and return an authorized Drive client service.
|
||||||
|
*
|
||||||
* @return an authorized Drive client service
|
* @return an authorized Drive client service
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public Drive getDriveService() throws IOException {
|
public Drive getDriveService() throws IOException {
|
||||||
Credential credential = authorize();
|
Credential credential = authorize();
|
||||||
return new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
|
return new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
|
||||||
.setApplicationName(APPLICATION_NAME)
|
}
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void main(String cemuDirectory) throws IOException {
|
public void main(String cemuDirectory) throws IOException {
|
||||||
service = getDriveService();
|
service = getDriveService();
|
||||||
|
@ -211,7 +210,7 @@ public class GoogleDriveController {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LOGGER.info("FolderID: " + files.getFiles().get(0).getId());
|
LOGGER.info("FolderID: " + files.getFiles().get(0).getId());
|
||||||
setFolderID(files.getFiles().get(0).getId());
|
folderID = files.getFiles().get(0).getId();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Oops, something went wrong! It seems that you have more than one folder called 'cemu_savegames'!", e);
|
LOGGER.error("Oops, something went wrong! It seems that you have more than one folder called 'cemu_savegames'!", e);
|
||||||
}
|
}
|
||||||
|
@ -220,9 +219,5 @@ public class GoogleDriveController {
|
||||||
public String getFolderID() {
|
public String getFolderID() {
|
||||||
return folderID;
|
return folderID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFolderID(String folderID) {
|
|
||||||
this.folderID = folderID;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue