2017-04-19 02:15:44 +02:00
/ * *
* cemu_UI
*
2019-05-17 00:22:51 +02:00
* Copyright 2017 - 2019 < @Seil0 >
2017-04-19 02:15:44 +02:00
*
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
* /
2019-05-17 00:22:51 +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 ;
2019-05-18 13:19:34 +02:00
import com.cemu_UI.controller.CloudController ;
2017-12-12 11:19:33 +01:00
import com.cemu_UI.controller.DBController ;
2019-01-22 19:21:38 +01:00
import com.cemu_UI.controller.XMLController ;
2017-11-13 16:44:39 +01:00
2017-03-28 17:40:01 +02:00
import javafx.application.Platform ;
2019-04-09 00:42:39 +02:00
public class playGame extends Thread {
2017-03-28 17:40:01 +02:00
2018-02-04 15:19:36 +01:00
private MainWindowController mainWindowController ;
private 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
2018-02-04 15:19:36 +01:00
public playGame ( MainWindowController m , com . cemu_UI . controller . DBController db ) {
2017-03-28 17:40:01 +02:00
mainWindowController = m ;
dbController = db ;
}
2018-02-04 15:19:36 +01:00
2017-08-30 11:29:58 +02:00
@Override
2018-02-04 15:19:36 +01:00
public void run ( ) {
2017-03-28 17:40:01 +02:00
String selectedGameTitleID = mainWindowController . getSelectedGameTitleID ( ) ;
2019-01-22 19:21:38 +01:00
String cemuBin = XMLController . getCemuPath ( ) + " /Cemu.exe " ;
2018-02-03 15:39:35 +01:00
String gameExec = " \" " + mainWindowController . getGameExecutePath ( ) + " \" " ;
2017-03-28 17:40:01 +02:00
long startTime ;
long endTime ;
int timePlayedNow ;
int timePlayed ;
Process p ;
Platform . runLater ( ( ) - > {
2019-01-22 19:21:38 +01:00
mainWindowController . getPrimaryStage ( ) . setIconified ( true ) ; // minimize cemu_UI
2017-03-28 17:40:01 +02:00
} ) ;
startTime = System . currentTimeMillis ( ) ;
2018-02-18 18:27:36 +01:00
try {
2018-02-03 15:39:35 +01:00
if ( System . getProperty ( " os.name " ) . equals ( " Linux " ) ) {
2019-01-22 19:21:38 +01:00
if ( XMLController . isFullscreen ( ) ) {
2018-02-03 15:39:35 +01:00
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 {
2019-01-22 19:21:38 +01:00
if ( XMLController . isFullscreen ( ) ) {
2018-02-03 15:39:35 +01:00
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
2018-02-04 15:19:36 +01:00
p . waitFor ( ) ; // wait until cemu is closed so we can calculate the played time
2017-03-28 17:40:01 +02:00
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
2018-02-04 15:19:36 +01:00
dbController . setTotalPlaytime ( Integer . toString ( timePlayed ) , selectedGameTitleID ) ;
Platform . runLater ( ( ) - > {
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 " ) ;
} else {
mainWindowController . totalPlaytimeBtn . setText ( dbController . getTotalPlaytime ( selectedGameTitleID ) + " min " ) ;
}
2019-01-22 19:21:38 +01:00
mainWindowController . getPrimaryStage ( ) . setIconified ( false ) ; // maximize cemu_UI
2018-02-04 15:19:36 +01:00
} ) ;
2017-04-17 00:58:49 +02:00
//sync savegame with cloud service
2019-01-22 19:21:38 +01:00
if ( XMLController . isCloudSync ( ) ) {
XMLController . setLastLocalSync ( Instant . now ( ) . getEpochSecond ( ) ) ;
2019-05-18 13:19:34 +02:00
CloudController . getInstance ( mainWindowController ) . sync ( XMLController . getCloudService ( ) ,
2019-01-22 19:21:38 +01:00
XMLController . getCemuPath ( ) , XMLController . getDirCemuUIPath ( ) ) ;
2017-12-12 23:52:54 +01:00
}
2017-04-17 00:58:49 +02:00
2018-02-04 15:19:36 +01:00
} catch ( IOException | InterruptedException e ) {
LOGGER . error ( e ) ;
2017-03-28 17:40:01 +02:00
}
}
}