@ -1,7 +1,7 @@
/ * *
* cemu_UI
*
* Copyright 2017 < @Seil0 >
* Copyright 2017 - 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
@ -27,7 +27,6 @@ import java.io.IOException;
import java.net.URL ;
import java.nio.channels.Channels ;
import java.nio.channels.ReadableByteChannel ;
import java.util.Optional ;
import java.util.Timer ;
import java.util.TimerTask ;
@ -35,51 +34,45 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger ;
import com.cemu_UI.controller.CloudController ;
import com.cemu_UI.controller.XMLController ;
import com.cemu_UI.uiElements.JFXInfoAlert ;
import com.cemu_UI.uiElements.JFXOkayCancelAlert ;
import javafx.application.Application ;
import javafx.beans.value.ChangeListener ;
import javafx.beans.value.ObservableValue ;
import javafx.fxml.FXMLLoader ;
import javafx.stage.DirectoryChooser ;
import javafx.stage.Stage ;
import javafx.scene.Scene ;
import javafx.scene.control.Alert ;
import javafx.scene.control.ButtonType ;
import javafx.scene.control.Alert.AlertType ;
import javafx.scene.layout.AnchorPane ;
import javafx.stage.DirectoryChooser ;
import javafx.stage.Stage ;
public class Main extends Application {
private Stage primaryStage ;
private final String gamesDBdownloadURL = "https://git.mosad.xyz/Seil0/cemu_UI/raw/branch/master/downloadContent/games.db" ;
private static Main main ;
private static XMLController xmlController ;
private MainWindowController mainWindowController ;
private CloudController cloudController ;
private Stage primaryStage ;
private AnchorPane pane ;
private Scene scene ;
private static String userHome = System . getProperty ( "user.home" ) ;
private static String userName = System . getProperty ( "user.name" ) ;
private static String osName = System . getProperty ( "os.name" ) ;
private static String osArch = System . getProperty ( "os.arch" ) ;
private static String osVers = System . getProperty ( "os.version" ) ;
private static String javaVers = System . getProperty ( "java.version" ) ;
private static String javaVend = System . getProperty ( "java.vendor" ) ;
private String gamesDBdownloadURL = "https://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 Logger LOGGER ;
@Override
public void start ( Stage primaryStage ) {
try {
LOGGER . info ( "OS: " + osName + " " + osVers + " " + osArch ) ;
LOGGER . info ( "Java: " + javaVend + " " + javaVers ) ;
LOGGER . info ( "User: " + userName + " " + userHome ) ;
LOGGER . info ( "OS: " + XMLController . getOsName ( ) + " " + XMLController . getOsVers ( ) + " " + XMLController . getOsVers ( ) ) ;
LOGGER . info ( "Java: " + XMLController . getJavaVend ( ) + " " + XMLController . getJavaVers ( ) ) ;
LOGGER . info ( "User: " + XMLController . getUserName ( ) + " " + XMLController . getUserHome ( ) ) ;
this . primaryStage = primaryStage ;
mainWindowController = new MainWindowController ( ) ;
main = this ;
mainWindow ( ) ;
initActions ( ) ;
} catch ( Exception e ) {
@ -91,75 +84,61 @@ public class Main extends Application {
private void mainWindow ( ) {
try {
FXMLLoader loader = new FXMLLoader ( ) ;
loader . setLocation ( ClassLoader . getSystemResource ( "fxml/MainWindow.fxml" ) ) ;
loader . setLocation ( getClass ( ) . getResource ( "/fxml/MainWindow.fxml" ) ) ;
loader . setController ( mainWindowController ) ;
pane = ( AnchorPane ) loader . load ( ) ;
primaryStage . setMinWidth ( 1130 ) ;
primaryStage . setMinHeight ( 600 + 34 ) ;
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 ( 0 ) ) ;
// 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 = CloudController . getInstance ( mainWindowController ) ; // call cloudController constructor
// startup checks
// check if client_secret.ja son is present
// check if client_secret.json is present
if ( Main . class . getResourceAsStream ( "/client_secret.json" ) = = null ) {
LOGGER . error ( "client_secret is missing!!!!!" ) ;
Alert alert = new Alert ( AlertType . ERROR ) ;
alert . setTitle ( "cemu_UI" ) ;
alert . setHeaderText ( "Error" ) ;
alert . setContentText ( "client_secret is missing! Please contact the maintainer. \nIf you compiled cemu_UI by yourself see: \nhttps://github.com/Seil0/cemu_UI/wiki/Documantation" ) ;
alert . showAndWait ( ) ;
JFXInfoAlert noCSAlert = new JFXInfoAlert ( "Error" ,
"client_secret is missing! Please contact the maintainer. \n"
+ "If you compiled cemu_UI by yourself see: \n"
+ "https://git.mosad.xyz/Seil0/cemu_UI/wiki/Documantation" ,
"-fx-button-type: RAISED; -fx-background-color: #00a8cc; -fx-text-fill: BLACK;" , primaryStage ) ;
noCSAlert . showAndWait ( ) ;
}
if ( ! directory . exists ( ) ) {
if ( ! XMLController . getDirCemuUI ( ) . exists ( ) ) {
LOGGER . info ( "creating cemu_UI directory" ) ;
directory . mkdir ( ) ;
p ictureCache. mkdir ( ) ;
XMLController . getDirCemuUI ( ) . mkdir ( ) ;
XMLController . getP ictureCache( ) . mkdir ( ) ;
}
if ( ! c onfigFile. exists ( ) ) {
if ( ! XMLController . getC onfigFile( ) . exists ( ) ) {
LOGGER . info ( "firststart, setting default values" ) ;
firstStart ( ) ;
mainWindowController . setColor ( "00a8cc" ) ;
mainWindowController . setAutoUpdate ( false ) ;
mainWindowController . setLanguage ( "en_US" ) ;
mainWindowController . setLastLocalSync ( 0 ) ;
mainWindowController . setxPosHelper ( 0 ) ;
mainWindowController . saveSettings ( ) ;
Runtime . getRuntime ( ) . exec ( "java -jar cemu_UI.jar" ) ; //start again (preventing Bugs)
System . exit ( 0 ) ; //finishes itself
xmlController . saveSettings ( ) ;
}
if ( pictureCache . exists ( ) ! = true ) {
p ictureCache. mkdir ( ) ;
if ( ! XMLController . getPictureCache ( ) . exists ( ) ) {
XMLController . getPictureCache ( ) . mkdir ( ) ;
}
if ( ! reference_gamesFile . exists ( ) ) {
if ( gamesDBFile . exists ( ) ) {
gamesDBFile . delete ( ) ;
if ( ! XMLController . getRference_gamesFile ( ) . exists ( ) ) {
if ( XMLController . getGamesDBFile ( ) . exists ( ) ) {
XMLController . getGamesDBFile ( ) . delete ( ) ;
}
try {
LOGGER . info ( "downloading ReferenceGameList.db... " ) ;
URL website = new URL ( gamesDBdownloadURL ) ;
ReadableByteChannel rbc = Channels . newChannel ( website . openStream ( ) ) ;
FileOutputStream fos = new FileOutputStream ( reference_gamesFile ) ;
FileOutputStream fos = new FileOutputStream ( XMLCont roll er . getR ference_gamesFile( ) ) ;
fos . getChannel ( ) . transferFrom ( rbc , 0 , Long . MAX_VALUE ) ;
fos . close ( ) ;
LOGGER . info ( "finished downloading games.db" ) ;
@ -168,56 +147,68 @@ public class Main extends Application {
}
}
// loading settings and initialize UI, dbController.main() loads all databases
// init here as it loads the games to the mwc and the gui, therefore the window must exist
mainWindowController . init ( ) ;
mainWindowController . dbController . init ( ) ;
// if cloud sync is activated start sync
if ( mainWindowController . isCloudSync ( ) ) {
cloudController . initializeConnection ( mainWindowController . getCloudService ( ) , mainWindowController . getCemuPath ( ) ) ;
cloudController . sync ( mainWindowController . getCloudService ( ) , mainWindowController . getCemuPath ( ) , directory . getPath ( ) ) ;
}
mainWindowController . addUIData ( ) ;
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
} catch ( IOException e ) {
e . printStackTrace ( ) ;
if ( XMLController . isCloudSync ( ) ) {
cloudController . initializeConnection ( XMLController . getCloudService ( ) , XMLController . getCemuPath ( ) ) ;
cloudController . sync ( XMLController . getCloudService ( ) , XMLController . getCemuPath ( ) , XMLController . getDirCemuUIPath ( ) ) ;
}
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
private void firstStart ( ) {
Alert alert = new Alert ( AlertType . CONFIRMATION ) ; // new alert with file-chooser
alert . setTitle ( "cemu_UI" ) ;
alert . setHeaderText ( "cemu installation" ) ;
alert . setContentText ( "please select your cemu installation" ) ;
Optional < ButtonType > result = alert . showAndWait ( ) ;
if ( result . get ( ) = = ButtonType . OK ) {
DirectoryChooser directoryChooser = new DirectoryChooser ( ) ;
File selectedDirectory = directoryChooser . showDialog ( primaryStage ) ;
mainWindowController . setCemuPath ( selectedDirectory . getAbsolutePath ( ) ) ;
public static void main ( String [ ] args ) {
String logPath = "" ;
if ( System . getProperty ( "os.name" ) . contains ( "Windows" ) ) {
logPath = System . getProperty ( "user.home" ) + "/Documents/cemu_UI/app.log" ;
} else {
mainWindowController . setCemuPath ( null ) ;
logPath = System . getProperty ( "user.home" ) + "/cemu_UI/app.log" ;
}
Alert alert2 = new Alert ( AlertType . CONFIRMATION ) ; // new alert with file-chooser
alert2 . setTitle ( "cemu_UI" ) ;
alert2 . setHeaderText ( "rom directory" ) ;
alert2 . setContentText ( "please select your rom directory" ) ;
Optional < ButtonType > result2 = alert2 . showAndWait ( ) ;
if ( result2 . get ( ) = = ButtonType . OK ) {
System . setProperty ( "logFilename" , logPath ) ;
File logFile = new File ( logPath ) ;
logFile . delete ( ) ;
LOGGER = LogManager . getLogger ( Main . class . getName ( ) ) ;
xmlController = new XMLController ( ) ;
launch ( args ) ;
}
private void firstStart ( ) {
JFXOkayCancelAlert cemuInstallAlert = new JFXOkayCancelAlert ( "cemu installation" ,
"please select your cemu installation" ,
"-fx-button-type: RAISED; -fx-background-color: #00a8cc; -fx-text-fill: BLACK;" , primaryStage ) ;
cemuInstallAlert . setOkayAction ( e - > {
DirectoryChooser directoryChooser = new DirectoryChooser ( ) ;
File selectedDirectory = directoryChooser . showDialog ( primaryStage ) ;
mainWindowController . setRomPath ( selectedDirectory . getAbsolutePath ( ) ) ;
} else {
mainWindowController . setRomPath ( null ) ;
}
XMLController . setCemuPath ( selectedDirectory . getAbsolutePath ( ) ) ;
} ) ;
cemuInstallAlert . setCancelAction ( e - > {
XMLController . setCemuPath ( null ) ;
LOGGER . info ( "Action canceld by user!" ) ;
} ) ;
cemuInstallAlert . showAndWait ( ) ;
JFXOkayCancelAlert romDirectoryAlert = new JFXOkayCancelAlert ( "rom directory" ,
"please select your rom directory" ,
"-fx-button-type: RAISED; -fx-background-color: #00a8cc; -fx-text-fill: BLACK;" , primaryStage ) ;
romDirectoryAlert . setOkayAction ( e - > {
DirectoryChooser directoryChooser = new DirectoryChooser ( ) ;
File selectedDirectory = directoryChooser . showDialog ( primaryStage ) ;
XMLController . setRomDirectoryPath ( selectedDirectory . getAbsolutePath ( ) ) ;
} ) ;
romDirectoryAlert . setCancelAction ( e - > {
XMLController . setRomDirectoryPath ( null ) ;
LOGGER . info ( "Action canceld by user!" ) ;
} ) ;
romDirectoryAlert . showAndWait ( ) ;
}
private void initActions ( ) {
@ -229,20 +220,15 @@ public class Main extends Application {
@Override
public void changed ( ObservableValue < ? extends Number > observable , Number oldValue , final Number newValue ) {
int xPosHelperMax = ( int ) Math . floor ( ( mainWindowController . getMainAnchorPane ( ) . getWidth ( ) - 36 ) / 217 ) ;
// call only if there is enough space for a new row
if ( mainWindowController . getOldXPosHelper ( ) ! = xPosHelperMax ) {
mainWindowController . refreshUIData ( ) ;
}
// if saveTask is already running kill it
if ( saveTask ! = null ) saveTask . cancel ( ) ;
saveTask = new TimerTask ( ) {
@Override
public void run ( ) {
mainWindowController . saveSettings ( ) ;
public void run ( ) {
XMLController . setWindowWidth ( mainWindowController . getMainAnchorPane ( ) . getWidth ( ) ) ;
xmlController . saveSettings ( ) ;
}
} ;
timer . schedule ( saveTask , delayTime ) ;
@ -262,8 +248,9 @@ public class Main extends Application {
saveTask = new TimerTask ( ) {
@Override
public void run ( ) {
mainWindowController . saveSettings ( ) ;
public void run ( ) {
XMLController . setWindowHeight ( mainWindowController . getMainAnchorPane ( ) . getHeight ( ) ) ;
xmlController . saveSettings ( ) ;
}
} ;
timer . schedule ( saveTask , delayTime ) ;
@ -293,55 +280,15 @@ public class Main extends Application {
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 ;
}
public void setPrimaryStage ( Stage primaryStage ) {
this . primaryStage = primaryStage ;
public static Main getMain ( ) {
return main ;
}
public CloudController getCloudController ( ) {
return cloudController ;
}
public void setCloudController ( CloudController cloudController ) {
this . cloudController = cloudController ;
}
public AnchorPane getPane ( ) {
return pane ;
}
public void setPane ( AnchorPane pane ) {
this . pane = pane ;
}
public File getDirectory ( ) {
return directory ;
}
public void setDirectory ( File directory ) {
this . directory = directory ;
}
}