2017-03-28 17:40:01 +02:00
package application ;
import java.io.IOException ;
import javafx.application.Platform ;
public class playGame extends Thread {
MainWindowController mainWindowController ;
dbController dbController ;
public playGame ( MainWindowController m , dbController db ) {
mainWindowController = m ;
dbController = db ;
}
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-04-08 10:52:01 +02:00
System . out . println ( 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 ) ) ;
timePlayed = Integer . parseInt ( dbController . getTimePlayed ( selectedGameTitleID ) ) + timePlayedNow ;
dbController . setTimePlayed ( Integer . toString ( timePlayed ) , selectedGameTitleID ) ;
Platform . runLater ( ( ) - > {
2017-04-06 12:00:36 +02:00
if ( Integer . parseInt ( dbController . getTimePlayed ( selectedGameTitleID ) ) > 60 ) {
int hoursPlayed = ( int ) Math . floor ( Integer . parseInt ( dbController . getTimePlayed ( selectedGameTitleID ) ) / 60 ) ;
int minutesPlayed = Integer . parseInt ( dbController . getTimePlayed ( selectedGameTitleID ) ) - 60 * hoursPlayed ;
mainWindowController . timePlayedBtn . setText ( hoursPlayed + " h " + minutesPlayed + " min " ) ;
} else {
mainWindowController . timePlayedBtn . setText ( dbController . getTimePlayed ( selectedGameTitleID ) + " min " ) ;
}
2017-03-28 17:40:01 +02:00
mainWindowController . main . primaryStage . setIconified ( false ) ;
} ) ;
} catch ( IOException | InterruptedException e ) {
e . printStackTrace ( ) ;
}
}
}