2017-04-17 00:58:49 +02:00
/ * *
2017-04-19 02:15:44 +02:00
* cemu_UI
*
* Copyright 2017 < @Seil0 >
*
* " 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 00:58:49 +02:00
* /
package application ;
import java.io.File ;
import java.io.IOException ;
import cloudControllerInstances.GoogleDriveController ;
2017-05-07 19:57:55 +02:00
import javafx.application.Platform ;
2017-04-17 00:58:49 +02:00
public class CloudController {
public CloudController ( Main ma ) {
main = ma ;
}
2017-05-24 19:24:22 +02:00
private Main main ;
2017-04-17 00:58:49 +02:00
private GoogleDriveController googleDriveController = new GoogleDriveController ( ) ;
void initializeConnection ( String cloudService , String cemuDirectory ) {
2017-05-07 19:57:55 +02:00
System . out . println ( " sartting cloud initialisation... " ) ;
2017-05-25 19:07:16 +02:00
if ( cloudService . equals ( " GoogleDrive " ) ) {
System . out . println ( " selected service is Google Drive " ) ;
2017-04-17 00:58:49 +02:00
try {
googleDriveController . main ( cemuDirectory ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
2017-05-25 19:07:16 +02:00
if ( cloudService . equals ( " Dropbox " ) ) {
System . out . println ( " selected service is Dropbox " ) ;
2017-04-17 00:58:49 +02:00
}
2017-05-07 19:57:55 +02:00
System . out . println ( " cloud initialisation done! " ) ;
2017-04-17 00:58:49 +02:00
}
2017-05-04 22:07:50 +02:00
void stratupCheck ( String cloudService , String cemuDirectory ) {
2017-05-25 19:07:16 +02:00
if ( cloudService . equals ( " GoogleDrive " ) ) {
2017-05-04 22:32:25 +02:00
System . out . println ( " starting startup check google drive... " ) ;
2017-05-04 22:07:50 +02:00
try {
if ( ! googleDriveController . checkFolder ( ) ) {
googleDriveController . creatFolder ( ) ;
main . mainWindowController . saveSettings ( ) ;
2017-05-07 19:57:55 +02:00
Thread thread = new Thread ( new Runnable ( ) {
2017-08-30 11:29:58 +02:00
@Override
public void run ( ) {
2017-05-07 19:57:55 +02:00
Platform . runLater ( ( ) - > {
main . mainWindowController . getPlayBtn ( ) . setText ( " syncing... " ) ;
} ) ;
googleDriveController . uploadAllFiles ( ) ;
Platform . runLater ( ( ) - > {
main . mainWindowController . getPlayBtn ( ) . setText ( " play " ) ;
} ) ;
}
} ) ;
thread . start ( ) ;
2017-05-04 22:07:50 +02:00
} else {
sync ( cloudService , cemuDirectory ) ;
}
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
2017-05-25 19:07:16 +02:00
if ( cloudService . equals ( " Dropbox " ) ) {
2017-05-04 22:07:50 +02:00
}
}
2017-04-17 00:58:49 +02:00
void sync ( String cloudService , String cemuDirectory ) {
2017-05-01 16:46:00 +02:00
//running sync in a new thread, instead of blocking the main thread
2017-05-07 19:57:55 +02:00
Thread thread = new Thread ( new Runnable ( ) {
2017-08-30 11:29:58 +02:00
@Override
2017-05-07 19:57:55 +02:00
public void run ( ) {
Platform . runLater ( ( ) - > {
main . mainWindowController . getPlayBtn ( ) . setText ( " syncing... " ) ;
} ) ;
2017-05-01 16:46:00 +02:00
System . out . println ( " starting sync in new thread... " ) ;
2017-05-25 19:07:16 +02:00
if ( cloudService . equals ( " GoogleDrive " ) ) {
2017-05-01 16:46:00 +02:00
try {
googleDriveController . sync ( cemuDirectory ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
2017-05-25 19:07:16 +02:00
if ( cloudService . equals ( " Dropbox " ) ) {
2017-05-01 16:46:00 +02:00
}
2017-05-07 19:57:55 +02:00
Platform . runLater ( ( ) - > {
main . mainWindowController . getPlayBtn ( ) . setText ( " play " ) ;
} ) ;
2017-05-25 19:07:16 +02:00
main . mainWindowController . saveSettings ( ) ;
2017-05-07 19:57:55 +02:00
System . out . println ( " sync finished! " ) ;
2017-05-01 16:46:00 +02:00
}
2017-05-07 19:57:55 +02:00
} ) ;
thread . start ( ) ;
2017-05-01 16:46:00 +02:00
2017-04-17 00:58:49 +02:00
}
void uploadFile ( String cloudService , File file ) {
2017-05-01 16:46:00 +02:00
//running uploadFile in a new thread, instead of blocking the main thread
new Thread ( ) {
2017-08-30 11:29:58 +02:00
@Override
public void run ( ) {
2017-05-01 16:46:00 +02:00
System . out . println ( " starting uploadFile in new thread... " ) ;
2017-05-25 19:07:16 +02:00
if ( cloudService . equals ( " GoogleDrive " ) ) {
2017-05-01 16:46:00 +02:00
try {
googleDriveController . uploadFile ( file ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
2017-05-25 19:07:16 +02:00
if ( cloudService . equals ( " Dropbox " ) ) {
2017-04-17 00:58:49 +02:00
2017-05-01 16:46:00 +02:00
}
}
} . start ( ) ;
2017-04-17 00:58:49 +02:00
}
public String getFolderID ( String cloudService ) {
String folderID = " " ;
2017-08-11 20:01:43 +02:00
if ( cloudService ! = null ) {
if ( cloudService . equals ( " GoogleDrive " ) ) {
folderID = googleDriveController . getFolderID ( ) ;
}
if ( cloudService . equals ( " Dropbox " ) ) {
}
2017-04-17 00:58:49 +02:00
}
return folderID ;
}
public void setFolderID ( String folderID , String cloudService ) {
2017-08-11 20:01:43 +02:00
if ( cloudService ! = null ) {
if ( cloudService . equals ( " GoogleDrive " ) ) {
googleDriveController . setFolderID ( folderID ) ;
}
if ( cloudService . equals ( " Dropbox " ) ) {
}
2017-04-17 00:58:49 +02:00
}
}
}