2017-04-17 01:02:43 +02:00
/ * *
* cemu_UI
*
* Copyright 2017 < @Seil0 >
*
2017-04-19 02:15:44 +02:00
* " THE CHOCOLATE-WARE LICENSE " ( Revision 1 ) :
* As long as you retain this notice this software is licensed under the GNU GENERAL PUBLIC LICENSE Version 3 ,
* with the following additions :
* If we meet some day , and you think this stuff is worth it ,
* you can buy me a chocolate in return . - @Seil0
* ( license based in Beer - ware , see https : //fedoraproject.org/wiki/Licensing/Beerware )
2017-04-17 01:02:43 +02:00
*
* /
package application ;
import java.io.File ;
import java.io.FileOutputStream ;
import java.io.IOException ;
import java.net.URL ;
import java.nio.channels.Channels ;
import java.nio.channels.ReadableByteChannel ;
import java.util.Optional ;
2017-05-01 16:46:00 +02:00
2017-08-27 20:44:08 +02:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
2017-04-17 01:02:43 +02:00
import javafx.application.Application ;
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 ;
public class Main extends Application {
Stage primaryStage ;
2017-05-07 19:57:55 +02:00
public MainWindowController mainWindowController ; //TODO find a better way
2017-04-17 01:02:43 +02:00
CloudController cloudController ;
2017-08-01 20:11:17 +02:00
AnchorPane pane ;
private Scene scene ;
2017-04-17 01:02:43 +02:00
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 gamesDBdownloadURL = " https://github.com/Seil0/cemu_UI/raw/master/downloadContent/games.db " ;
private File directory ;
private File configFile ;
private File gamesDBFile ;
@SuppressWarnings ( " unused " )
private File localDB ;
private File pictureCache ;
2017-08-27 20:44:08 +02:00
private static final Logger LOGGER = LogManager . getLogger ( Main . class . getName ( ) ) ;
2017-04-17 01:02:43 +02:00
@Override
public void start ( Stage primaryStage ) {
this . primaryStage = primaryStage ;
cloudController = new CloudController ( this ) ;
mainWindow ( ) ;
}
private void mainWindow ( ) {
try {
FXMLLoader loader = new FXMLLoader ( Main . class . getResource ( " MainWindow.fxml " ) ) ;
2017-08-01 20:11:17 +02:00
pane = loader . load ( ) ;
2017-04-17 01:02:43 +02:00
primaryStage . setResizable ( false ) ;
primaryStage . setTitle ( " cemu_UI " ) ;
2017-06-01 16:21:24 +02:00
// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/resources/Homeflix_Icon_64x64.png"))); //adds application icon
2017-04-17 01:02:43 +02:00
mainWindowController = loader . getController ( ) ; //Link of FXMLController and controller class
mainWindowController . setMain ( this ) ; //call setMain
//get os and the right paths
if ( System . getProperty ( " os.name " ) . equals ( " Linux " ) ) {
directory = new File ( dirLinux ) ;
configFile = new File ( dirLinux + " /config.xml " ) ;
gamesDBFile = new File ( dirLinux + " /games.db " ) ;
localDB = new File ( dirLinux + " /localRoms.db " ) ;
pictureCache = new File ( dirLinux + " /picture_cache " ) ;
2017-08-11 20:01:43 +02:00
pane . setPrefWidth ( 904 ) ; //this could be a kde plasma specific issue
2017-04-17 01:02:43 +02:00
} else {
directory = new File ( dirWin ) ;
configFile = new File ( dirWin + " /config.xml " ) ;
gamesDBFile = new File ( dirWin + " /games.db " ) ;
localDB = new File ( dirWin + " /localRoms.db " ) ;
pictureCache = new File ( dirWin + " /picture_cache " ) ;
2017-08-11 20:01:43 +02:00
pane . setPrefWidth ( 892 ) ;
2017-04-17 01:02:43 +02:00
}
//startup checks
2017-08-26 00:13:09 +02:00
//check if client_secret.jason is present
if ( Main . class . getResourceAsStream ( " /resources/client_secret.json " ) = = null ) {
2017-08-27 20:44:08 +02:00
LOGGER . error ( " client_secret is missing!!!!! " ) ;
2017-08-26 00:13:09 +02:00
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 ( ) ;
}
2017-08-27 20:44:08 +02:00
LOGGER . info ( " Directory: " + directory . exists ( ) ) ;
LOGGER . info ( " Configfile: " + configFile . exists ( ) ) ;
if ( ! directory . exists ( ) ) {
LOGGER . info ( " creating cemu_UI directory " ) ;
2017-04-17 01:02:43 +02:00
directory . mkdir ( ) ;
pictureCache . mkdir ( ) ;
}
2017-08-27 20:44:08 +02:00
if ( ! configFile . exists ( ) ) {
LOGGER . info ( " firststart, setting default values " ) ;
2017-04-17 01:02:43 +02:00
firstStart ( ) ;
mainWindowController . setColor ( " 00a8cc " ) ;
mainWindowController . setxPosHelper ( 0 ) ;
mainWindowController . saveSettings ( ) ;
Runtime . getRuntime ( ) . exec ( " java -jar cemu_UI.jar " ) ; //start again (preventing Bugs)
2017-08-27 20:44:08 +02:00
System . exit ( 0 ) ; //finishes itselfdownloading games.db...
2017-04-17 01:02:43 +02:00
}
if ( pictureCache . exists ( ) ! = true ) {
pictureCache . mkdir ( ) ;
}
if ( gamesDBFile . exists ( ) ! = true ) {
try {
2017-08-27 20:44:08 +02:00
LOGGER . info ( " downloading games.db... " ) ;
2017-04-17 01:02:43 +02:00
URL website = new URL ( gamesDBdownloadURL ) ;
ReadableByteChannel rbc = Channels . newChannel ( website . openStream ( ) ) ;
FileOutputStream fos = new FileOutputStream ( gamesDBFile ) ;
fos . getChannel ( ) . transferFrom ( rbc , 0 , Long . MAX_VALUE ) ;
fos . close ( ) ;
2017-08-27 20:44:08 +02:00
LOGGER . info ( " finished downloading games.db " ) ;
2017-04-17 01:02:43 +02:00
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
//loading settings and initialize UI, dbController.main() loads all databases
mainWindowController . loadSettings ( ) ;
2017-05-07 19:57:55 +02:00
mainWindowController . dbController . main ( ) ;
2017-04-17 01:02:43 +02:00
if ( mainWindowController . isCloudSync ( ) ) {
cloudController . initializeConnection ( mainWindowController . getCloudService ( ) , mainWindowController . getCemuPath ( ) ) ;
2017-05-04 22:07:50 +02:00
cloudController . stratupCheck ( mainWindowController . getCloudService ( ) , mainWindowController . getCemuPath ( ) ) ;
2017-04-17 01:02:43 +02:00
}
mainWindowController . addUIData ( ) ;
mainWindowController . initActions ( ) ;
mainWindowController . initUI ( ) ;
2017-08-01 20:11:17 +02:00
scene = new Scene ( pane ) ; //create new scene, append pane to scene
2017-04-17 01:02:43 +02:00
scene . getStylesheets ( ) . add ( Main . class . getResource ( " MainWindows.css " ) . toExternalForm ( ) ) ;
primaryStage . setScene ( scene ) ; //append scene to stage
primaryStage . show ( ) ; //show stage
} 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 ( ) ) ;
} else {
mainWindowController . setCemuPath ( null ) ;
}
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 ) {
DirectoryChooser directoryChooser = new DirectoryChooser ( ) ;
File selectedDirectory = directoryChooser . showDialog ( primaryStage ) ;
mainWindowController . setRomPath ( selectedDirectory . getAbsolutePath ( ) ) ;
} else {
mainWindowController . setRomPath ( null ) ;
}
}
public static void main ( String [ ] args ) {
launch ( args ) ;
}
}