2017-04-19 02:15:44 +02:00
/ * *
* cemu_UI
*
* Copyright 2017 < @Seil0 >
*
2017-10-15 13:37:45 +02:00
* 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
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
2017-04-19 02:15:44 +02:00
*
2017-10-15 13:37:45 +02:00
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston ,
* MA 02110 - 1301 , USA .
2017-04-19 02:15:44 +02:00
* /
2017-03-28 17:40:01 +02:00
package application ;
import java.io.IOException ;
2017-09-12 15:04:21 +02:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
2017-03-28 17:40:01 +02:00
import javafx.application.Platform ;
public class playGame extends Thread {
MainWindowController mainWindowController ;
dbController dbController ;
2017-09-12 15:04:21 +02:00
private static final Logger LOGGER = LogManager . getLogger ( playGame . class . getName ( ) ) ;
2017-03-28 17:40:01 +02:00
public playGame ( MainWindowController m , dbController db ) {
mainWindowController = m ;
dbController = db ;
}
2017-08-30 11:29:58 +02:00
@Override
2017-03-28 17:40:01 +02:00
public void run ( ) {
String selectedGameTitleID = mainWindowController . getSelectedGameTitleID ( ) ;
2017-04-08 10:52:01 +02:00
String executeComand ;
2017-03-28 17:40:01 +02:00
long startTime ;
long endTime ;
int timePlayedNow ;
int timePlayed ;
Process p ;
Platform . runLater ( ( ) - > {
mainWindowController . main . primaryStage . setIconified ( true ) ;
} ) ;
startTime = System . currentTimeMillis ( ) ;
try {
if ( mainWindowController . isFullscreen ( ) ) {
2017-04-08 10:52:01 +02:00
if ( System . getProperty ( " os.name " ) . equals ( " Linux " ) ) {
executeComand = " wine " + mainWindowController . getCemuPath ( ) + " /Cemu.exe -f -g \" " + mainWindowController . getGameExecutePath ( ) + " \" " ;
} else {
executeComand = mainWindowController . getCemuPath ( ) + " \\ Cemu.exe -f -g \" " + mainWindowController . getGameExecutePath ( ) + " \" " ;
}
2017-03-28 17:40:01 +02:00
} else {
2017-04-08 10:52:01 +02:00
if ( System . getProperty ( " os.name " ) . equals ( " Linux " ) ) {
executeComand = " wine " + mainWindowController . getCemuPath ( ) + " /Cemu.exe -g \" " + mainWindowController . getGameExecutePath ( ) + " \" " ;
} else {
executeComand = mainWindowController . getCemuPath ( ) + " \\ Cemu.exe -g \" " + mainWindowController . getGameExecutePath ( ) + " \" " ;
}
2017-03-28 17:40:01 +02:00
}
2017-09-12 15:04:21 +02:00
LOGGER . info ( executeComand ) ;
2017-03-28 17:40:01 +02:00
2017-04-08 10:52:01 +02:00
p = Runtime . getRuntime ( ) . exec ( executeComand ) ;
2017-03-28 17:40:01 +02:00
p . waitFor ( ) ;
endTime = System . currentTimeMillis ( ) ;
timePlayedNow = ( int ) Math . floor ( ( ( endTime - startTime ) / 1000 / 60 ) ) ;
2017-09-12 15:04:21 +02:00
timePlayed = Integer . parseInt ( dbController . getTotalPlaytime ( selectedGameTitleID ) ) + timePlayedNow ;
2017-03-28 17:40:01 +02:00
2017-09-12 15:04:21 +02:00
dbController . setTotalPlaytime ( Integer . toString ( timePlayed ) , selectedGameTitleID ) ;
2017-03-28 17:40:01 +02:00
Platform . runLater ( ( ) - > {
2017-09-12 15:04:21 +02:00
if ( Integer . parseInt ( dbController . getTotalPlaytime ( selectedGameTitleID ) ) > 60 ) {
int hoursPlayed = ( int ) Math . floor ( Integer . parseInt ( dbController . getTotalPlaytime ( selectedGameTitleID ) ) / 60 ) ;
int minutesPlayed = Integer . parseInt ( dbController . getTotalPlaytime ( selectedGameTitleID ) ) - 60 * hoursPlayed ;
mainWindowController . totalPlaytimeBtn . setText ( hoursPlayed + " h " + minutesPlayed + " min " ) ;
2017-04-06 12:00:36 +02:00
} else {
2017-09-12 15:04:21 +02:00
mainWindowController . totalPlaytimeBtn . setText ( dbController . getTotalPlaytime ( selectedGameTitleID ) + " min " ) ;
2017-04-06 12:00:36 +02:00
}
2017-03-28 17:40:01 +02:00
mainWindowController . main . primaryStage . setIconified ( false ) ;
} ) ;
2017-04-17 00:58:49 +02:00
// System.out.println(mainWindowController.getCemuPath()+"/mlc01/emulatorSave/"+);
//sync savegame with cloud service
if ( mainWindowController . isCloudSync ( ) ) {
mainWindowController . main . cloudController . sync ( mainWindowController . getCloudService ( ) , mainWindowController . getCemuPath ( ) ) ;
}
2017-03-28 17:40:01 +02:00
} catch ( IOException | InterruptedException e ) {
e . printStackTrace ( ) ;
}
}
}