code clean up
* the mwc init process is now only one call in main * renamed a few methodes for better clearance * added a few TODOs
This commit is contained in:
parent
0f7d262bcb
commit
e0a73a1fbe
|
@ -17,6 +17,7 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src/test/main"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
|
|
@ -85,7 +85,6 @@ public class Main extends Application {
|
||||||
FXMLLoader loader = new FXMLLoader();
|
FXMLLoader loader = new FXMLLoader();
|
||||||
loader.setLocation(ClassLoader.getSystemResource("fxml/MainWindow.fxml"));
|
loader.setLocation(ClassLoader.getSystemResource("fxml/MainWindow.fxml"));
|
||||||
pane = (AnchorPane) loader.load();
|
pane = (AnchorPane) loader.load();
|
||||||
// primaryStage.setResizable(false);
|
|
||||||
primaryStage.setTitle("cemu_UI");
|
primaryStage.setTitle("cemu_UI");
|
||||||
// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/resources/Homeflix_Icon_64x64.png"))); //adds application icon
|
// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/resources/Homeflix_Icon_64x64.png"))); //adds application icon
|
||||||
|
|
||||||
|
@ -157,10 +156,11 @@ public class Main extends Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
// loading settings and initialize UI, dbController.main() loads all databases
|
// loading settings and initialize UI, dbController.main() loads all databases
|
||||||
mainWindowController.loadSettings();
|
mainWindowController.init();
|
||||||
mainWindowController.checkAutoUpdate();
|
// mainWindowController.loadSettings();
|
||||||
mainWindowController.initActions();
|
// mainWindowController.checkAutoUpdate();
|
||||||
mainWindowController.initUI();
|
// mainWindowController.initActions();
|
||||||
|
// mainWindowController.initUI();
|
||||||
mainWindowController.dbController.main();
|
mainWindowController.dbController.main();
|
||||||
if(mainWindowController.isCloudSync()) {
|
if(mainWindowController.isCloudSync()) {
|
||||||
cloudController.initializeConnection(mainWindowController.getCloudService(), mainWindowController.getCemuPath());
|
cloudController.initializeConnection(mainWindowController.getCloudService(), mainWindowController.getCemuPath());
|
||||||
|
|
|
@ -48,7 +48,6 @@ import javax.swing.ProgressMonitorInputStream;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
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.SmmdbAPIController;
|
import com.cemu_UI.controller.SmmdbAPIController;
|
||||||
import com.cemu_UI.controller.UpdateController;
|
import com.cemu_UI.controller.UpdateController;
|
||||||
import com.cemu_UI.controller.dbController;
|
import com.cemu_UI.controller.dbController;
|
||||||
|
@ -61,6 +60,7 @@ import com.cemu_UI.uiElements.JFXOkayCancelDialog;
|
||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.JFXButton;
|
||||||
import com.jfoenix.controls.JFXColorPicker;
|
import com.jfoenix.controls.JFXColorPicker;
|
||||||
import com.jfoenix.controls.JFXHamburger;
|
import com.jfoenix.controls.JFXHamburger;
|
||||||
|
import com.jfoenix.controls.JFXSpinner;
|
||||||
import com.jfoenix.controls.JFXTextField;
|
import com.jfoenix.controls.JFXTextField;
|
||||||
import com.jfoenix.controls.JFXToggleButton;
|
import com.jfoenix.controls.JFXToggleButton;
|
||||||
import com.jfoenix.controls.JFXTreeTableColumn;
|
import com.jfoenix.controls.JFXTreeTableColumn;
|
||||||
|
@ -70,6 +70,7 @@ import com.jfoenix.transitions.hamburger.HamburgerBackArrowBasicTransition;
|
||||||
import javafx.animation.FadeTransition;
|
import javafx.animation.FadeTransition;
|
||||||
import javafx.animation.ParallelTransition;
|
import javafx.animation.ParallelTransition;
|
||||||
import javafx.animation.TranslateTransition;
|
import javafx.animation.TranslateTransition;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
|
@ -318,7 +319,21 @@ public class MainWindowController {
|
||||||
smmdbAPIController = new SmmdbAPIController();
|
smmdbAPIController = new SmmdbAPIController();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initUI() {
|
/**
|
||||||
|
* initialize the MainWindowController
|
||||||
|
* loadSettings, checkAutoUpdate, initUI and initActions
|
||||||
|
*/
|
||||||
|
void init() {
|
||||||
|
loadSettings();
|
||||||
|
checkAutoUpdate();
|
||||||
|
initUI();
|
||||||
|
initActions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize all variable UI parameters and elements
|
||||||
|
*/
|
||||||
|
private void initUI() {
|
||||||
LOGGER.info("initializing UI ...");
|
LOGGER.info("initializing UI ...");
|
||||||
|
|
||||||
if (getWindowWidth() > 100 && getWindowHeight() > 100) {
|
if (getWindowWidth() > 100 && getWindowHeight() > 100) {
|
||||||
|
@ -368,7 +383,7 @@ public class MainWindowController {
|
||||||
/**
|
/**
|
||||||
* initialize all actions not initialized by a own method
|
* initialize all actions not initialized by a own method
|
||||||
*/
|
*/
|
||||||
void initActions() {
|
private void initActions() {
|
||||||
LOGGER.info("initializing Actions ...");
|
LOGGER.info("initializing Actions ...");
|
||||||
|
|
||||||
MWC = this;
|
MWC = this;
|
||||||
|
@ -435,7 +450,7 @@ public class MainWindowController {
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
try {
|
try {
|
||||||
games.remove(selectedUIDataIndex); // remove game form games-list
|
games.remove(selectedUIDataIndex); // remove game form games-list
|
||||||
dbController.removeRom(selectedGameTitleID); // remove game from database
|
dbController.removeGame(selectedGameTitleID); // remove game from database
|
||||||
refreshUIData(); // refresh all games at gamesAnchorPane (UI)
|
refreshUIData(); // refresh all games at gamesAnchorPane (UI)
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("error while removing ROM from database!", e);
|
LOGGER.error("error while removing ROM from database!", e);
|
||||||
|
@ -717,10 +732,31 @@ public class MainWindowController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void reloadRomsBtnAction() throws IOException {
|
void reloadRomsBtnAction() throws IOException {
|
||||||
reloadRomsBtn.setText("reloading...");
|
|
||||||
dbController.loadRomDirectory(getRomPath()); // TODO own thread
|
//TODO needs testing
|
||||||
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); // start again (preventing Bugs)
|
JFXSpinner spinner = new JFXSpinner();
|
||||||
System.exit(0); // finishes itself
|
spinner.setPrefSize(30, 30);
|
||||||
|
main.pane.getChildren().add(spinner);
|
||||||
|
AnchorPane.setTopAnchor(spinner, (main.pane.getHeight()-spinner.getPrefHeight())/2);
|
||||||
|
AnchorPane.setLeftAnchor(spinner, (main.pane.getWidth()-spinner.getPrefWidth())/2);
|
||||||
|
|
||||||
|
Thread thread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
dbController.loadRomDirectory(getRomPath()); // reload the rom directory
|
||||||
|
refreshUIData(); // refresh the list of games displayed on screen
|
||||||
|
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
main.pane.getChildren().remove(spinner);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
thread.start();
|
||||||
|
|
||||||
|
// reloadRomsBtn.setText("reloading...");
|
||||||
|
// dbController.loadRomDirectory(getRomPath());
|
||||||
|
// Runtime.getRuntime().exec("java -jar cemu_UI.jar"); // start again (preventing Bugs)
|
||||||
|
// System.exit(0); // finishes itself
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -1009,8 +1045,8 @@ public class MainWindowController {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dbController.addRom(title, coverPath, romPath, titleID, "", "", "", "0");
|
dbController.addGame(title, coverPath, romPath, titleID, "", "", "", "0");
|
||||||
dbController.loadSingleRom(titleID);
|
dbController.loadSingleGame(titleID);
|
||||||
if (menuTrue) {
|
if (menuTrue) {
|
||||||
sideMenuSlideOut();
|
sideMenuSlideOut();
|
||||||
burgerTask.setRate(-1.0);
|
burgerTask.setRate(-1.0);
|
||||||
|
@ -1027,7 +1063,7 @@ public class MainWindowController {
|
||||||
public void editBtnReturn(String title, String coverPath, String romPath, String titleID) {
|
public void editBtnReturn(String title, String coverPath, String romPath, String titleID) {
|
||||||
dbController.setGameInfo(title, coverPath, romPath, titleID);
|
dbController.setGameInfo(title, coverPath, romPath, titleID);
|
||||||
games.remove(selectedUIDataIndex);
|
games.remove(selectedUIDataIndex);
|
||||||
dbController.loadSingleRom(titleID);
|
dbController.loadSingleGame(titleID);
|
||||||
refreshUIData();
|
refreshUIData();
|
||||||
|
|
||||||
LOGGER.info("successfully edited " + titleID + ", new name is \"" + title + "\"");
|
LOGGER.info("successfully edited " + titleID + ", new name is \"" + title + "\"");
|
||||||
|
@ -1038,7 +1074,7 @@ public class MainWindowController {
|
||||||
* @param title : game title
|
* @param title : game title
|
||||||
* @param coverPath : path to cover (cache)
|
* @param coverPath : path to cover (cache)
|
||||||
* @param romPath : path to ROM file (.rpx)
|
* @param romPath : path to ROM file (.rpx)
|
||||||
* @param titleID : ROM ID
|
* @param titleID : game ID
|
||||||
*/
|
*/
|
||||||
public void addGame(String title, String coverPath, String romPath, String titleID){
|
public void addGame(String title, String coverPath, String romPath, String titleID){
|
||||||
VBox VBox = new VBox();
|
VBox VBox = new VBox();
|
||||||
|
@ -1176,7 +1212,7 @@ public class MainWindowController {
|
||||||
lastTimePlayedBtn.setLayoutX((width / 2) + 50 + 20.5);
|
lastTimePlayedBtn.setLayoutX((width / 2) + 50 + 20.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkAutoUpdate() {
|
private void checkAutoUpdate() {
|
||||||
|
|
||||||
if (isAutoUpdate()) {
|
if (isAutoUpdate()) {
|
||||||
try {
|
try {
|
||||||
|
@ -1444,7 +1480,7 @@ public class MainWindowController {
|
||||||
* loading saved settings from the config.xml file
|
* loading saved settings from the config.xml file
|
||||||
* if a value is not present, default is used instead
|
* if a value is not present, default is used instead
|
||||||
*/
|
*/
|
||||||
void loadSettings(){
|
private void loadSettings(){
|
||||||
LOGGER.info("loading settings ...");
|
LOGGER.info("loading settings ...");
|
||||||
InputStream inputStream;
|
InputStream inputStream;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class dbController {
|
||||||
|
|
||||||
private MainWindowController mainWindowController;
|
private MainWindowController mainWindowController;
|
||||||
private ArrayList<String> entries = new ArrayList<>();
|
private ArrayList<String> entries = new ArrayList<>();
|
||||||
private String DB_PATH;
|
private String DB_PATH_localRoms;
|
||||||
private String DB_PATH_games;
|
private String DB_PATH_games;
|
||||||
private Connection connection = null;
|
private Connection connection = null;
|
||||||
private Connection connectionGames = null;
|
private Connection connectionGames = null;
|
||||||
|
@ -66,20 +66,25 @@ public class dbController {
|
||||||
loadRomDatabase();
|
loadRomDatabase();
|
||||||
loadGamesDatabase();
|
loadGamesDatabase();
|
||||||
createRomDatabase();
|
createRomDatabase();
|
||||||
loadAllRoms();
|
loadAllGames();
|
||||||
checkRemoveEntry();
|
checkRemoveEntry();
|
||||||
LOGGER.info("<==========finished loading sql==========>");
|
LOGGER.info("<==========finished loading sql==========>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the path to the localRoms.db file and initialize the connection
|
||||||
|
*
|
||||||
|
* TODO this should be called LocalGames
|
||||||
|
*/
|
||||||
private void loadRomDatabase(){
|
private void loadRomDatabase(){
|
||||||
if (System.getProperty("os.name").equals("Linux")) {
|
if (System.getProperty("os.name").equals("Linux")) {
|
||||||
DB_PATH = System.getProperty("user.home") + "/cemu_UI/localRoms.db";
|
DB_PATH_localRoms = System.getProperty("user.home") + "/cemu_UI/localRoms.db";
|
||||||
}else{
|
}else{
|
||||||
DB_PATH = System.getProperty("user.home") + "\\Documents\\cemu_UI" + "\\" + "localRoms.db";
|
DB_PATH_localRoms = System.getProperty("user.home") + "\\Documents\\cemu_UI" + "\\" + "localRoms.db";
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// create a database connection
|
// create a database connection
|
||||||
connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH);
|
connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH_localRoms);
|
||||||
connection.setAutoCommit(false); //AutoCommit to false -> manual commit is active
|
connection.setAutoCommit(false); //AutoCommit to false -> manual commit is active
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
// if the error message is "out of memory", it probably means no database file is found
|
// if the error message is "out of memory", it probably means no database file is found
|
||||||
|
@ -89,28 +94,34 @@ public class dbController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method is used to load the games database with additional informations about a game
|
* set the path to the localRoms.db file and initialize the connection
|
||||||
* it is used if a new game is added (automatic or manual)
|
*
|
||||||
|
* games.dbcontains a reverence list to for the automatic detection mode
|
||||||
|
* TODO this should be called ReferenceGameList the games table should be called reference_games
|
||||||
*/
|
*/
|
||||||
private void loadGamesDatabase(){
|
private void loadGamesDatabase() {
|
||||||
if (System.getProperty("os.name").equals("Linux")) {
|
if (System.getProperty("os.name").equals("Linux")) {
|
||||||
DB_PATH_games = System.getProperty("user.home") + "/cemu_UI/games.db";
|
DB_PATH_games = System.getProperty("user.home") + "/cemu_UI/games.db";
|
||||||
}else{
|
} else {
|
||||||
DB_PATH_games = System.getProperty("user.home") + "\\Documents\\cemu_UI" + "\\" + "games.db";
|
DB_PATH_games = System.getProperty("user.home") + "\\Documents\\cemu_UI" + "\\" + "games.db";
|
||||||
}
|
}
|
||||||
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);
|
||||||
connectionGames.setAutoCommit(false); //AutoCommit to false -> manual commit is active
|
connectionGames.setAutoCommit(false); // AutoCommit to false -> manual commit is active
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
// if the error message is "out of memory", it probably means no database file is found
|
|
||||||
LOGGER.error("error while loading the games database", e);
|
LOGGER.error("error while loading the games database", e);
|
||||||
}
|
}
|
||||||
LOGGER.info("games database loaded successfull");
|
LOGGER.info("games database loaded successfull");
|
||||||
}
|
}
|
||||||
|
|
||||||
//creating database, if database has 0 entries search for all .rpx files in the roms directory and add them
|
/**
|
||||||
void createRomDatabase() {
|
* creating the local_roms table in localRoms.db
|
||||||
|
* if the table has no entries, call loadRomDirectory
|
||||||
|
*
|
||||||
|
* TODO the local_roms table should be called local_games
|
||||||
|
*/
|
||||||
|
void createRomDatabase() {
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("create table if not exists local_roms (title, coverPath, romPath, titleID, productCode, region, lastPlayed, timePlayed)");
|
stmt.executeUpdate("create table if not exists local_roms (title, coverPath, romPath, titleID, productCode, region, lastPlayed, timePlayed)");
|
||||||
|
@ -119,24 +130,25 @@ public class dbController {
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.error("error while creating ROM database", e);
|
LOGGER.error("error while creating ROM database", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms");
|
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms");
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
entries.add(rs.getString(2));
|
entries.add(rs.getString(2));
|
||||||
}
|
}
|
||||||
stmt.close();
|
stmt.close();
|
||||||
rs.close();
|
rs.close();
|
||||||
}catch (SQLException e){
|
} catch (SQLException e) {
|
||||||
LOGGER.error("error while loading ROMs from ROM database, local_roms table", e);
|
LOGGER.error("error while loading ROMs from ROM database, local_roms table", e);
|
||||||
}
|
}
|
||||||
if(entries.size() == 0){
|
if (entries.size() == 0) {
|
||||||
loadRomDirectory(mainWindowController.getRomPath());
|
loadRomDirectory(mainWindowController.getRomPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRom(String title, String coverPath, String romPath, String titleID, String productCode, String region, String lastPlayed, String timePlayed) throws SQLException{
|
// add a Ggame to the database
|
||||||
|
public void addGame(String title, String coverPath, String romPath, String titleID, String productCode, String region, String lastPlayed, String timePlayed) throws SQLException{
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("insert into local_roms values ('"+title+"','"+coverPath+"','"+romPath+"','"+titleID+"',"
|
stmt.executeUpdate("insert into local_roms values ('"+title+"','"+coverPath+"','"+romPath+"','"+titleID+"',"
|
||||||
+ "'"+productCode+"','"+region+"','"+lastPlayed+"','"+timePlayed+"')");
|
+ "'"+productCode+"','"+region+"','"+lastPlayed+"','"+timePlayed+"')");
|
||||||
|
@ -145,7 +157,7 @@ public class dbController {
|
||||||
LOGGER.info("added \""+title+"\" to ROM database");
|
LOGGER.info("added \""+title+"\" to ROM database");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRom(String titleID) throws SQLException{
|
public void removeGame(String titleID) throws SQLException{
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("delete from local_roms where titleID = '"+titleID+"'");
|
stmt.executeUpdate("delete from local_roms where titleID = '"+titleID+"'");
|
||||||
connection.commit();
|
connection.commit();
|
||||||
|
@ -154,8 +166,8 @@ public class dbController {
|
||||||
}
|
}
|
||||||
|
|
||||||
//load all ROMs on startup to the mainWindowController
|
//load all ROMs on startup to the mainWindowController
|
||||||
void loadAllRoms(){
|
void loadAllGames(){
|
||||||
LOGGER.info("loading all rom's on startup into the mainWindowController ...");
|
LOGGER.info("loading all games on startup into the mainWindowController ...");
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms");
|
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms");
|
||||||
|
@ -165,13 +177,13 @@ public class dbController {
|
||||||
stmt.close();
|
stmt.close();
|
||||||
rs.close();
|
rs.close();
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
LOGGER.error("error while loading all ROMs into the mainWindowController", e);
|
LOGGER.error("error while loading all games into the mainWindowController", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//load one single ROM after manual adding into the mainWindowController
|
//load one single ROM after manual adding into the mainWindowController
|
||||||
public void loadSingleRom(String titleID){
|
public void loadSingleGame(String titleID){
|
||||||
LOGGER.info("loading a single ROM (ID: "+titleID+") into the mainWindowController ...");
|
LOGGER.info("loading a single game (ID: "+titleID+") into the mainWindowController ...");
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms where titleID = '"+titleID+"'");
|
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms where titleID = '"+titleID+"'");
|
||||||
|
@ -181,11 +193,14 @@ public class dbController {
|
||||||
stmt.close();
|
stmt.close();
|
||||||
rs.close();
|
rs.close();
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
LOGGER.error("error while loading a single ROM into the mainWindowController", e);
|
LOGGER.error("error while loading a single game into the mainWindowController", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//get all files with .rpx TODO add other formats
|
/**
|
||||||
|
* get all .rpx files from a given directory and add them to the games database if they don't exist there
|
||||||
|
* @param directory where to search for the .rpx files
|
||||||
|
*/
|
||||||
public void loadRomDirectory(String directory){
|
public void loadRomDirectory(String directory){
|
||||||
File dir = new File(directory);
|
File dir = new File(directory);
|
||||||
File appFile;
|
File appFile;
|
||||||
|
@ -203,6 +218,7 @@ public class dbController {
|
||||||
Statement stmt = connectionGames.createStatement();
|
Statement stmt = connectionGames.createStatement();
|
||||||
List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true);
|
List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true);
|
||||||
LOGGER.info("Getting all .rpx files in " + dir.getCanonicalPath()+" including those in subdirectories");
|
LOGGER.info("Getting all .rpx files in " + dir.getCanonicalPath()+" including those in subdirectories");
|
||||||
|
// for all files in dir get the app.xml
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if(System.getProperty("os.name").equals("Linux")){
|
if(System.getProperty("os.name").equals("Linux")){
|
||||||
appFile = new File(file.getParent()+"/app.xml");
|
appFile = new File(file.getParent()+"/app.xml");
|
||||||
|
@ -212,10 +228,11 @@ public class dbController {
|
||||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||||
Document document = documentBuilder.parse(appFile);
|
Document document = documentBuilder.parse(appFile);
|
||||||
String title_ID = document.getElementsByTagName("title_id").item(0).getTextContent();
|
String title_ID = document.getElementsByTagName("title_id").item(0).getTextContent(); //get titile_ID from app.xml
|
||||||
title_ID = title_ID.substring(0, 8) + "-" + title_ID.substring(8, title_ID.length());
|
title_ID = title_ID.substring(0, 8) + "-" + title_ID.substring(8, title_ID.length());
|
||||||
LOGGER.info("Name: "+file.getName()+"; Title ID: "+title_ID);
|
LOGGER.info("Name: "+file.getName()+"; Title ID: "+title_ID);
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM games WHERE TitleID = '"+title_ID+"';");
|
ResultSet rs = stmt.executeQuery("SELECT * FROM games WHERE TitleID = '"+title_ID+"';");
|
||||||
|
// for all elements in the games table check if it's already present, else add it
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
if (checkEntry(rs.getString(2))) {
|
if (checkEntry(rs.getString(2))) {
|
||||||
LOGGER.info(rs.getString(2) + ": game already in database");
|
LOGGER.info(rs.getString(2) + ": game already in database");
|
||||||
|
@ -233,7 +250,7 @@ public class dbController {
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.info(rs.getString(2) + ": adding ROM");
|
LOGGER.info(rs.getString(2) + ": adding ROM");
|
||||||
addRom(rs.getString(2), coverPath, file.getCanonicalPath(), rs.getString(1), rs.getString(3), rs.getString(5),"","0");
|
addGame(rs.getString(2), coverPath, file.getCanonicalPath(), rs.getString(1), rs.getString(3), rs.getString(5),"","0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.cemu_UI.test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for simple App.
|
||||||
|
*/
|
||||||
|
public class AppTest extends TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the test case
|
||||||
|
*
|
||||||
|
* @param testName
|
||||||
|
* name of the test case
|
||||||
|
*/
|
||||||
|
public AppTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testClientsSecret() {
|
||||||
|
File client_secret = new File("/client_secret.json");
|
||||||
|
Assert.assertTrue(client_secret.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the suite of tests being tested
|
||||||
|
*/
|
||||||
|
public static Test suite() {
|
||||||
|
return new TestSuite(AppTest.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rigourous Test :-)
|
||||||
|
*/
|
||||||
|
public void testApp() {
|
||||||
|
assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue