code clean up

This commit is contained in:
Jannik 2018-06-12 16:24:12 +02:00
parent cc4e73c45d
commit 9b7a85cabe
3 changed files with 72 additions and 120 deletions

View File

@ -47,7 +47,6 @@ import javafx.scene.control.ButtonType;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.AnchorPane;
public class Main extends Application {
private Stage primaryStage;
@ -63,13 +62,12 @@ public class Main extends Application {
private static String javaVers = System.getProperty("java.version");
private static String javaVend= System.getProperty("java.vendor");
private String gamesDBdownloadURL = "https://github.com/Seil0/cemu_UI/raw/master/downloadContent/games.db";
public String dirWin = userHome + "/Documents/cemu_UI"; // Windows: C:/Users/"User"/Documents/cemu_UI
public String dirLinux = userHome + "/cemu_UI"; // Linux: /home/"User"/cemu_UI
private File directory;
private File configFile;
private File gamesDBFile;
private File reference_gamesFile;
private File pictureCache;
private static String dirCemuUI;
private static File directory;
private static File configFile;
private static File gamesDBFile;
private static File reference_gamesFile;
private static File pictureCache;
private static Logger LOGGER;
@Override
@ -78,7 +76,10 @@ public class Main extends Application {
LOGGER.info("OS: " + osName + " " + osVers + " " + osArch);
LOGGER.info("Java: " + javaVend + " " + javaVers);
LOGGER.info("User: " + userName + " " + userHome);
this.primaryStage = primaryStage;
mainWindowController = new MainWindowController(this);
mainWindow();
initActions();
} catch (Exception e) {
@ -91,28 +92,21 @@ public class Main extends Application {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(ClassLoader.getSystemResource("fxml/MainWindow.fxml"));
loader.setController(mainWindowController);
pane = (AnchorPane) loader.load();
primaryStage.setMinWidth(265.00);
primaryStage.setMinHeight(425.00);
primaryStage.setTitle("cemu_UI");
// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/resources/Homeflix_Icon_64x64.png"))); //adds application icon
mainWindowController = loader.getController(); // Link of FXMLController and controller class
mainWindowController.setMain(this); // call setMain
cloudController = new CloudController(mainWindowController); // call cloudController constructor
// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream(""))); //adds application icon
primaryStage.setOnCloseRequest(event -> System.exit(1));
// get OS and the specific paths
if (osName.equals("Linux")) {
directory = new File(dirLinux);
configFile = new File(dirLinux + "/config.xml");
gamesDBFile = new File(dirLinux + "/games.db");
reference_gamesFile = new File(dirLinux + "/reference_games.db");
pictureCache= new File(dirLinux+"/picture_cache");
} else {
directory = new File(dirWin);
configFile = new File(dirWin + "/config.xml");
gamesDBFile = new File(dirWin + "/games.db");
reference_gamesFile = new File(dirWin + "/reference_games.db");
pictureCache= new File(dirWin+"/picture_cache");
}
// generate window
scene = new Scene(pane); // create new scene, append pane to scene
scene.getStylesheets().add(Main.class.getResource("/css/MainWindows.css").toExternalForm());
primaryStage.setScene(scene); // append scene to stage
primaryStage.show(); // show stage
cloudController = new CloudController(mainWindowController); // call cloudController constructor
// startup checks
// check if client_secret.json is present
@ -165,14 +159,6 @@ public class Main extends Application {
}
}
// generate window
scene = new Scene(pane); // create new scene, append pane to scene
scene.getStylesheets().add(Main.class.getResource("/css/MainWindows.css").toExternalForm());
primaryStage.setMinWidth(265.00);
primaryStage.setMinHeight(425.00);
primaryStage.setScene(scene); // append scene to stage
primaryStage.show(); // show stage
// init here as it loads the games to the mwc and the gui, therefore the window must exist
mainWindowController.init();
mainWindowController.getDbController().init();
@ -183,9 +169,31 @@ public class Main extends Application {
cloudController.sync(mainWindowController.getCloudService(), mainWindowController.getCemuPath(), directory.getPath());
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
if (osName.contains("Windows")) {
dirCemuUI = userHome + "/Documents/cemu_UI";
} else {
dirCemuUI = userHome + "/cemu_UI";
}
directory = new File(dirCemuUI);
configFile = new File(dirCemuUI + "/config.xml");
gamesDBFile = new File(dirCemuUI + "/games.db");
reference_gamesFile = new File(dirCemuUI + "/reference_games.db");
pictureCache= new File(dirCemuUI+"/picture_cache");
// delete old log file and create new
System.setProperty("logFilename", dirCemuUI + "/app.log");
File logFile = new File(dirCemuUI + "/app.log");
logFile.delete();
LOGGER = LogManager.getLogger(Main.class.getName());
launch(args);
}
private void firstStart() {
@ -291,26 +299,6 @@ public class Main extends Application {
primaryStage.heightProperty().addListener(heightListener);
primaryStage.maximizedProperty().addListener(maximizeListener);
}
public static void main(String[] args) {
// delete old log file and create new
if (osName.equals("Linux")) {
System.setProperty("logFilename", userHome + "/cemu_UI/app.log");
File logFile = new File(userHome + "/cemu_UI/app.log");
logFile.delete();
} else {
System.setProperty("logFilename", userHome + "/Documents/cemu_UI/app.log");
File logFile = new File(userHome + "/Documents/cemu_UI/app.log");
logFile.delete();
}
LOGGER = LogManager.getLogger(Main.class.getName());
launch(args);
}
@Override
public void stop() {
System.exit(0);
}
public Stage getPrimaryStage() {
return primaryStage;

View File

@ -111,37 +111,26 @@ public class MainWindowController {
@FXML
private JFXButton aboutBtn;
@FXML
private JFXButton settingsBtn;
@FXML
private JFXButton addBtn;
@FXML
private JFXButton reloadRomsBtn;
@FXML
private JFXButton smmdbBtn;
@FXML
private JFXButton cemuTFBtn;
@FXML
private JFXButton romTFBtn;
@FXML
private JFXButton updateBtn;
@FXML
private JFXButton smmdbDownloadBtn;
@FXML
private JFXButton playBtn;
@FXML
private JFXButton lastTimePlayedBtn;
@FXML
JFXButton totalPlaytimeBtn;
@ -150,58 +139,46 @@ public class MainWindowController {
@FXML
private JFXTextField cemuTextField;
@FXML
private JFXTextField romTextField;
@FXML
private JFXTextField courseSearchTextFiled;
@FXML
private JFXTextField executeCommandTextFiled;
@FXML
private TextFlow smmdbTextFlow;
@FXML
private JFXColorPicker colorPicker;
@FXML
private JFXToggleButton cloudSyncToggleBtn;
@FXML
private JFXToggleButton autoUpdateToggleBtn;
@FXML
private JFXToggleButton fullscreenToggleBtn;
@FXML
private ChoiceBox<String> languageChoisBox;
@FXML
private ChoiceBox<String> branchChoisBox;
@FXML
private AnchorPane mainAnchorPane;
@FXML
private AnchorPane gamesAnchorPane;
@FXML
private AnchorPane settingsAnchorPane;
@FXML
private AnchorPane smmdbAnchorPane;
@FXML
private ScrollPane mainScrollPane;
@FXML
private ScrollPane settingsScrollPane;
@FXML
private ScrollPane smmdbScrollPane;
@FXML
private ScrollPane smmdbImageViewScrollPane;
@ -210,7 +187,6 @@ public class MainWindowController {
@FXML
private HBox topHBox;
@FXML
private HBox bottomHBox;
@ -219,31 +195,22 @@ public class MainWindowController {
@FXML
private Label helpLbl;
@FXML
private Label cemu_UISettingsLbl;
@FXML
private Label cemuDirectoryLbl;
@FXML
private Label romDirectoryLbl;
@FXML
private Label mainColorLbl;
@FXML
private Label languageLbl;
@FXML
private Label updateLbl;
@FXML
private Label branchLbl;
@FXML
private Label cemuSettingsLbl;
@FXML
private Label licensesLbl;
@ -251,17 +218,14 @@ public class MainWindowController {
private JFXTreeTableView<CourseTableDataType> courseTreeTable = new JFXTreeTableView<CourseTableDataType>();
@FXML
TreeItem<CourseTableDataType> root = new TreeItem<>(new CourseTableDataType("", "", 0, 0));
private TreeItem<CourseTableDataType> root = new TreeItem<>(new CourseTableDataType("", "", 0, 0));
@FXML
private JFXTreeTableColumn<CourseTableDataType, String> titleColumn = new JFXTreeTableColumn<>("title");
@FXML
private JFXTreeTableColumn<CourseTableDataType, String> idColumn = new JFXTreeTableColumn<>("id");
@FXML
private JFXTreeTableColumn<CourseTableDataType, Integer> starsColumn = new JFXTreeTableColumn<>("stars");
@FXML
private JFXTreeTableColumn<CourseTableDataType, Integer> timeColumn = new JFXTreeTableColumn<>("time");
@ -294,7 +258,7 @@ public class MainWindowController {
private String selectedGameTitle;
private String id;
private String version = "0.3.0";
private String buildNumber = "077";
private String buildNumber = "079";
private String versionName = "Purple Comet";
private int xPos = -200;
private int yPos = 17;
@ -372,8 +336,8 @@ public class MainWindowController {
private String smmdbDownloadBtnLoading;
private String smmdbDownloadBtnDownload;
public void setMain(Main m) {
this.main = m;
public MainWindowController(Main main) {
this.main = main;
dbController = new DBController(main, this);
smmdbAPIController = new SmmdbAPIController();
}
@ -382,7 +346,7 @@ public class MainWindowController {
* initialize the MainWindowController
* loadSettings, checkAutoUpdate, initUI and initActions
*/
void init() {
public void init() {
loadSettings();
checkAutoUpdate();
initUI();
@ -837,7 +801,7 @@ public class MainWindowController {
}
@FXML
void detailsSlideoutBtnAction() {
private void detailsSlideoutBtnAction() {
playBtnSlideOut();
}
@ -851,7 +815,7 @@ public class MainWindowController {
}
@FXML
void settingsBtnAction() {
private void settingsBtnAction() {
if (smmdbTrue) {
smmdbAnchorPane.setVisible(false);
smmdbTrue = false;
@ -867,12 +831,12 @@ public class MainWindowController {
}
@FXML
void reloadRomsBtnAction() throws IOException {
private void reloadRomsBtnAction() throws IOException {
reloadRoms();
}
@FXML
void smmdbBtnAction() {
private void smmdbBtnAction() {
// show smmdbAnchorPane
if (smmdbTrue) {
smmdbAnchorPane.setVisible(false);
@ -911,7 +875,7 @@ public class MainWindowController {
}
@FXML
void playBtnAction() throws InterruptedException, IOException {
private void playBtnAction() throws InterruptedException, IOException {
dbController.setLastPlayed(selectedGameTitleID);
playGame = new playGame(this, dbController);
@ -919,17 +883,17 @@ public class MainWindowController {
}
@FXML
void totalPlaytimeBtnAction() {
private void totalPlaytimeBtnAction() {
}
@FXML
void lastTimePlayedBtnAction() {
private void lastTimePlayedBtnAction() {
}
@FXML
void cemuTFBtnAction() {
private void cemuTFBtnAction() {
File cemuDirectory = directoryChooser.showDialog(main.getPrimaryStage());
if (cemuDirectory != null) {
cemuTextField.setText(cemuDirectory.getAbsolutePath());
@ -937,7 +901,7 @@ public class MainWindowController {
}
@FXML
void romTFBtnAction() {
private void romTFBtnAction() {
File romDirectory = directoryChooser.showDialog(main.getPrimaryStage());
if (romDirectory != null) {
romTextField.setText(romDirectory.getAbsolutePath());
@ -945,7 +909,7 @@ public class MainWindowController {
}
@FXML
void updateBtnAction() {
private void updateBtnAction() {
updateController = new UpdateController(this, buildNumber, useBeta);
Thread updateThread = new Thread(updateController);
updateThread.setName("Updater");
@ -953,7 +917,7 @@ public class MainWindowController {
}
@FXML
void autoUpdateToggleBtnAction() {
private void autoUpdateToggleBtnAction() {
if (isAutoUpdate()) {
setAutoUpdate(false);
} else {
@ -963,12 +927,12 @@ public class MainWindowController {
}
@FXML
void courseSearchTextFiledAction() {
private void courseSearchTextFiledAction() {
// not in use
}
@FXML
void smmdbDownloadBtnAction() {
private void smmdbDownloadBtnAction() {
String downloadUrl = "http://smmdb.ddns.net/api/downloadcourse?id=" + id + "&type=zip";
String downloadFileURL = getCemuPath() + "/" + id + ".zip"; // getCemuPath() + "/" + smmID + "/" + id + ".rar"
String outputFile = getCemuPath() + "/";
@ -1036,7 +1000,7 @@ public class MainWindowController {
}
@FXML
void fullscreenToggleBtnAction() {
private void fullscreenToggleBtnAction() {
if (fullscreen) {
fullscreen = false;
} else {
@ -1046,7 +1010,7 @@ public class MainWindowController {
}
@FXML
void cloudSyncToggleBtnAction() {
private void cloudSyncToggleBtnAction() {
if(cloudSync) {
cloudSync = false;
} else {
@ -1096,13 +1060,13 @@ public class MainWindowController {
}
@FXML
void colorPickerAction() {
private void colorPickerAction() {
editColor(colorPicker.getValue().toString());
applyColor();
}
@FXML
void addBtnAction() {
private void addBtnAction() {
String headingText = addGameBtnHeadingText;
String bodyText = addGameBtnBodyText;
JFXEditGameDialog addGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450, 300, 0,

View File

@ -18,7 +18,7 @@
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.TextFlow?>
<AnchorPane fx:id="mainAnchorPane" minHeight="405.0" minWidth="260.0" prefHeight="600.0" prefWidth="904.0" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.cemu_UI.application.MainWindowController">
<AnchorPane fx:id="mainAnchorPane" minHeight="405.0" minWidth="260.0" prefHeight="600.0" prefWidth="904.0" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ScrollPane fx:id="mainScrollPane" fitToWidth="true" layoutY="38.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<content>