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-11-13 16:44:39 +01:00
package com.cemu_UI.application ;
2017-03-28 17:40:01 +02:00
import java.io.IOException ;
2017-12-12 23:52:54 +01:00
import java.time.Instant ;
2017-03-28 17:40:01 +02:00
2017-09-12 15:04:21 +02:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
2017-12-12 11:19:33 +01:00
import com.cemu_UI.controller.DBController ;
2017-11-13 16:44:39 +01:00
2017-03-28 17:40:01 +02:00
import javafx.application.Platform ;
public class playGame extends Thread {
MainWindowController mainWindowController ;
2017-12-12 11:19:33 +01:00
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
2017-12-12 11:19:33 +01:00
public playGame ( MainWindowController m , com . cemu_UI . controller . DBController db ) {
2017-03-28 17:40:01 +02:00
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 ( ) ;
2018-02-03 15:39:35 +01:00
String cemuBin = mainWindowController . getCemuPath ( ) + " /Cemu.exe " ;
String gameExec = " \" " + mainWindowController . getGameExecutePath ( ) + " \" " ;
2017-03-28 17:40:01 +02:00
long startTime ;
long endTime ;
int timePlayedNow ;
int timePlayed ;
Process p ;
Platform . runLater ( ( ) - > {
2017-12-12 11:19:33 +01:00
mainWindowController . main . getPrimaryStage ( ) . setIconified ( true ) ; // minimize cemu_UI
2017-03-28 17:40:01 +02:00
} ) ;
startTime = System . currentTimeMillis ( ) ;
try {
2018-02-03 15:39:35 +01:00
if ( System . getProperty ( " os.name " ) . equals ( " Linux " ) ) {
if ( mainWindowController . isFullscreen ( ) ) {
p = new ProcessBuilder ( " wine " , cemuBin , " -f " , " -g " , gameExec ) . start ( ) ;
2018-02-03 14:22:41 +01:00
} else {
2018-02-03 15:39:35 +01:00
p = new ProcessBuilder ( " wine " , cemuBin , " -g " , gameExec ) . start ( ) ;
2018-02-03 14:22:41 +01:00
}
2018-02-03 15:39:35 +01:00
} else {
if ( mainWindowController . isFullscreen ( ) ) {
p = new ProcessBuilder ( cemuBin , " -f " , " -g " , gameExec ) . start ( ) ;
2018-02-03 14:22:41 +01:00
} else {
2018-02-03 15:39:35 +01:00
p = new ProcessBuilder ( cemuBin , " -g " , gameExec ) . start ( ) ;
2018-02-03 14:22:41 +01:00
}
2018-02-03 15:39:35 +01:00
}
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-12-12 11:19:33 +01:00
mainWindowController . main . getPrimaryStage ( ) . setIconified ( false ) ; // maximize cemu_UI
2017-03-28 17:40:01 +02:00
} ) ;
2017-04-17 00:58:49 +02:00
//sync savegame with cloud service
2017-12-12 23:52:54 +01:00
if ( mainWindowController . isCloudSync ( ) ) {
mainWindowController . setLastLocalSync ( Instant . now ( ) . getEpochSecond ( ) ) ;
mainWindowController . main . getCloudController ( ) . sync ( mainWindowController . getCloudService ( ) ,
mainWindowController . getCemuPath ( ) , mainWindowController . main . getDirectory ( ) . getPath ( ) ) ;
}
2017-04-17 00:58:49 +02:00
2017-03-28 17:40:01 +02:00
} catch ( IOException | InterruptedException e ) {
e . printStackTrace ( ) ;
}
}
}