code clean up
This commit is contained in:
parent
ed5eef8a49
commit
28a3723a76
|
@ -1,177 +1,178 @@
|
||||||
/**
|
/**
|
||||||
* cemu_UI
|
* cemu_UI
|
||||||
*
|
*
|
||||||
* Copyright 2017 <@Seil0>
|
* Copyright 2017 <@Seil0>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
* MA 02110-1301, USA.
|
* MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package application;
|
package application;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.stage.DirectoryChooser;
|
import javafx.stage.DirectoryChooser;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.ButtonType;
|
import javafx.scene.control.ButtonType;
|
||||||
import javafx.scene.control.Alert.AlertType;
|
import javafx.scene.control.Alert.AlertType;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
|
||||||
|
|
||||||
public class Main extends Application {
|
public class Main extends Application {
|
||||||
|
|
||||||
Stage primaryStage;
|
Stage primaryStage;
|
||||||
private MainWindowController mainWindowController;
|
private MainWindowController mainWindowController;
|
||||||
private String dirWin = System.getProperty("user.home") + "/Documents/cemu_UI"; //Windows: C:/Users/"User"/Documents/HomeFlix
|
private String dirWin = System.getProperty("user.home") + "/Documents/cemu_UI"; //Windows: C:/Users/"User"/Documents/HomeFlix
|
||||||
private String dirLinux = System.getProperty("user.home") + "/cemu_UI"; //Linux: /home/"User"/HomeFlix
|
private String dirLinux = System.getProperty("user.home") + "/cemu_UI"; //Linux: /home/"User"/HomeFlix
|
||||||
private String gamesDBdownloadURL = "https://github.com/Seil0/cemu_UI/raw/master/downloadContent/games.db";
|
private String gamesDBdownloadURL = "https://github.com/Seil0/cemu_UI/raw/master/downloadContent/games.db";
|
||||||
private File directory;
|
private File directory;
|
||||||
private File configFile;
|
private File configFile;
|
||||||
private File gamesDBFile;
|
private File gamesDBFile;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private File localDB;
|
private File localDB;
|
||||||
private File pictureCache;
|
private File pictureCache;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
this.primaryStage = primaryStage;
|
this.primaryStage = primaryStage;
|
||||||
mainWindow();
|
mainWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mainWindow(){
|
private void mainWindow(){
|
||||||
try {
|
try {
|
||||||
FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindow.fxml"));
|
FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindow.fxml"));
|
||||||
AnchorPane pane = loader.load();
|
AnchorPane pane = loader.load();
|
||||||
primaryStage.setResizable(false);
|
primaryStage.setResizable(false);
|
||||||
primaryStage.setTitle("cemu_UI");
|
primaryStage.setTitle("cemu_UI");
|
||||||
// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/recources/Homeflix_Icon_64x64.png"))); //adds application icon
|
// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/recources/Homeflix_Icon_64x64.png"))); //adds application icon
|
||||||
|
|
||||||
mainWindowController = loader.getController(); //Link of FXMLController and controller class
|
mainWindowController = loader.getController(); //Link of FXMLController and controller class
|
||||||
mainWindowController.setMain(this); //call setMain
|
mainWindowController.setMain(this); //call setMain
|
||||||
|
|
||||||
//get os and the right paths
|
- //get os and the right paths
|
||||||
if(System.getProperty("os.name").equals("Linux")){
|
+ //get OS and the right paths
|
||||||
directory = new File(dirLinux);
|
if(System.getProperty("os.name").equals("Linux")){
|
||||||
configFile = new File(dirLinux + "/config.xml");
|
directory = new File(dirLinux);
|
||||||
gamesDBFile = new File(dirLinux + "/games.db");
|
configFile = new File(dirLinux + "/config.xml");
|
||||||
localDB = new File(dirLinux+"/localRoms.db");
|
gamesDBFile = new File(dirLinux + "/games.db");
|
||||||
pictureCache= new File(dirLinux+"/picture_cache");
|
localDB = new File(dirLinux+"/localRoms.db");
|
||||||
}else{
|
pictureCache= new File(dirLinux+"/picture_cache");
|
||||||
directory = new File(dirWin);
|
}else{
|
||||||
configFile = new File(dirWin + "/config.xml");
|
directory = new File(dirWin);
|
||||||
gamesDBFile = new File(dirWin + "/games.db");
|
configFile = new File(dirWin + "/config.xml");
|
||||||
localDB = new File(dirWin+"/localRoms.db");
|
gamesDBFile = new File(dirWin + "/games.db");
|
||||||
pictureCache= new File(dirWin+"/picture_cache");
|
localDB = new File(dirWin+"/localRoms.db");
|
||||||
}
|
pictureCache= new File(dirWin+"/picture_cache");
|
||||||
|
}
|
||||||
|
|
||||||
//startup checks
|
//startup checks
|
||||||
System.out.println(directory.exists());
|
System.out.println(directory.exists());
|
||||||
System.out.println(configFile.exists());
|
System.out.println(configFile.exists());
|
||||||
if(directory.exists() != true){
|
if(directory.exists() != true){
|
||||||
System.out.println("mkdir all");
|
System.out.println("mkdir all");
|
||||||
directory.mkdir();
|
directory.mkdir();
|
||||||
pictureCache.mkdir();
|
pictureCache.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(configFile.exists() != true){
|
if(configFile.exists() != true){
|
||||||
System.out.println("firststart");
|
System.out.println("firststart");
|
||||||
firstStart();
|
firstStart();
|
||||||
mainWindowController.setColor("00a8cc");
|
mainWindowController.setColor("00a8cc");
|
||||||
mainWindowController.setxPosHelper(0);
|
mainWindowController.setxPosHelper(0);
|
||||||
mainWindowController.saveSettings();
|
mainWindowController.saveSettings();
|
||||||
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs)
|
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs)
|
||||||
System.exit(0); //finishes itself
|
System.exit(0); //finishes itself
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pictureCache.exists() != true){
|
if(pictureCache.exists() != true){
|
||||||
pictureCache.mkdir();
|
pictureCache.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gamesDBFile.exists() != true){
|
if(gamesDBFile.exists() != true){
|
||||||
try {
|
try {
|
||||||
System.out.print("downloading games.db... ");
|
System.out.print("downloading games.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(gamesDBFile);
|
FileOutputStream fos = new FileOutputStream(gamesDBFile);
|
||||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
fos.close();
|
fos.close();
|
||||||
System.out.println("done!");
|
System.out.println("done!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//loading settings and initialize UI
|
//loading settings and initialize UI
|
||||||
mainWindowController.loadSettings();
|
mainWindowController.loadSettings();
|
||||||
mainWindowController.dbController.main();
|
mainWindowController.dbController.main();
|
||||||
mainWindowController.addUIData();
|
mainWindowController.addUIData();
|
||||||
mainWindowController.initActions();
|
mainWindowController.initActions();
|
||||||
mainWindowController.initUI();
|
mainWindowController.initUI();
|
||||||
|
|
||||||
Scene scene = new Scene(pane); //create new scene, append pane to scene
|
Scene scene = new Scene(pane); //create new scene, append pane to scene
|
||||||
scene.getStylesheets().add(Main.class.getResource("MainWindows.css").toExternalForm());
|
scene.getStylesheets().add(Main.class.getResource("MainWindows.css").toExternalForm());
|
||||||
primaryStage.setScene(scene); //append scene to stage
|
primaryStage.setScene(scene); //append scene to stage
|
||||||
primaryStage.show(); //show stage
|
primaryStage.show(); //show stage
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void firstStart(){
|
private void firstStart(){
|
||||||
Alert alert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
|
Alert alert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
|
||||||
alert.setTitle("cemu_UI");
|
alert.setTitle("cemu_UI");
|
||||||
alert.setHeaderText("cemu installation");
|
alert.setHeaderText("cemu installation");
|
||||||
alert.setContentText("please select your cemu installation");
|
alert.setContentText("please select your cemu installation");
|
||||||
|
|
||||||
Optional<ButtonType> result = alert.showAndWait();
|
Optional<ButtonType> result = alert.showAndWait();
|
||||||
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());
|
mainWindowController.setCemuPath(selectedDirectory.getAbsolutePath());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mainWindowController.setCemuPath(null);
|
mainWindowController.setCemuPath(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Alert alert2 = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
|
Alert alert2 = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
|
||||||
alert2.setTitle("cemu_UI");
|
alert2.setTitle("cemu_UI");
|
||||||
alert2.setHeaderText("rom directory");
|
alert2.setHeaderText("rom directory");
|
||||||
alert2.setContentText("please select your rom directory");
|
alert2.setContentText("please select your rom directory");
|
||||||
|
|
||||||
Optional<ButtonType> result2 = alert2.showAndWait();
|
Optional<ButtonType> result2 = alert2.showAndWait();
|
||||||
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.setRomPath(selectedDirectory.getAbsolutePath());
|
mainWindowController.setRomPath(selectedDirectory.getAbsolutePath());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mainWindowController.setRomPath(null);
|
mainWindowController.setRomPath(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue