google drive integration v2/cloud integration clean up
* Clean up the cloud part * Added an alert to verify activation of cloud sync
This commit is contained in:
parent
e796b582fa
commit
ef2d913ace
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -17,6 +17,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import cloudControllerInstances.GoogleDriveController;
|
import cloudControllerInstances.GoogleDriveController;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
|
||||||
public class CloudController {
|
public class CloudController {
|
||||||
|
|
||||||
@ -24,12 +25,11 @@ public class CloudController {
|
|||||||
main = ma;
|
main = ma;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")//TODO
|
Main main;
|
||||||
private Main main;
|
|
||||||
private GoogleDriveController googleDriveController = new GoogleDriveController();
|
private GoogleDriveController googleDriveController = new GoogleDriveController();
|
||||||
|
|
||||||
void initializeConnection(String cloudService, String cemuDirectory) {
|
void initializeConnection(String cloudService, String cemuDirectory) {
|
||||||
System.out.println("sartting initialisation... ");
|
System.out.println("sartting cloud initialisation... ");
|
||||||
if(cloudService == "GoogleDrive") {
|
if(cloudService == "GoogleDrive") {
|
||||||
try {
|
try {
|
||||||
googleDriveController.main(cemuDirectory);
|
googleDriveController.main(cemuDirectory);
|
||||||
@ -40,7 +40,7 @@ public class CloudController {
|
|||||||
if(cloudService == "Dropbox") {
|
if(cloudService == "Dropbox") {
|
||||||
|
|
||||||
}
|
}
|
||||||
System.out.println("done!");
|
System.out.println("cloud initialisation done!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void stratupCheck(String cloudService, String cemuDirectory) {
|
void stratupCheck(String cloudService, String cemuDirectory) {
|
||||||
@ -50,7 +50,19 @@ public class CloudController {
|
|||||||
if (!googleDriveController.checkFolder()) {
|
if (!googleDriveController.checkFolder()) {
|
||||||
googleDriveController.creatFolder();
|
googleDriveController.creatFolder();
|
||||||
main.mainWindowController.saveSettings();
|
main.mainWindowController.saveSettings();
|
||||||
|
|
||||||
|
Thread thread = new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
main.mainWindowController.getPlayBtn().setText("syncing...");
|
||||||
|
});
|
||||||
googleDriveController.uploadAllFiles();
|
googleDriveController.uploadAllFiles();
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
main.mainWindowController.getPlayBtn().setText("play");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
thread.start();
|
||||||
} else {
|
} else {
|
||||||
sync(cloudService, cemuDirectory);
|
sync(cloudService, cemuDirectory);
|
||||||
}
|
}
|
||||||
@ -68,8 +80,11 @@ public class CloudController {
|
|||||||
void sync(String cloudService, String cemuDirectory) {
|
void sync(String cloudService, String cemuDirectory) {
|
||||||
|
|
||||||
//running sync in a new thread, instead of blocking the main thread
|
//running sync in a new thread, instead of blocking the main thread
|
||||||
new Thread() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
main.mainWindowController.getPlayBtn().setText("syncing...");
|
||||||
|
});
|
||||||
System.out.println("starting sync in new thread...");
|
System.out.println("starting sync in new thread...");
|
||||||
|
|
||||||
if(cloudService == "GoogleDrive") {
|
if(cloudService == "GoogleDrive") {
|
||||||
@ -82,8 +97,13 @@ public class CloudController {
|
|||||||
if(cloudService == "Dropbox") {
|
if(cloudService == "Dropbox") {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
main.mainWindowController.getPlayBtn().setText("play");
|
||||||
|
});
|
||||||
|
System.out.println("sync finished!");
|
||||||
}
|
}
|
||||||
}.start();
|
});
|
||||||
|
thread.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ import javafx.scene.layout.AnchorPane;
|
|||||||
public class Main extends Application {
|
public class Main extends Application {
|
||||||
|
|
||||||
Stage primaryStage;
|
Stage primaryStage;
|
||||||
MainWindowController mainWindowController;
|
public MainWindowController mainWindowController; //TODO find a better way
|
||||||
CloudController cloudController;
|
CloudController cloudController;
|
||||||
private String dirWin = System.getProperty("user.home") + "/Documents/cemu_UI"; //Windows: C:/Users/"User"/Documents/HomeFlix
|
private String dirWin = System.getProperty("user.home") + "/Documents/cemu_UI"; //Windows: C:/Users/"User"/Documents/HomeFlix
|
||||||
private String dirLinux = System.getProperty("user.home") + "/cemu_UI"; //Linux: /home/"User"/HomeFlix
|
private String dirLinux = System.getProperty("user.home") + "/cemu_UI"; //Linux: /home/"User"/HomeFlix
|
||||||
@ -120,12 +120,11 @@ public class Main extends Application {
|
|||||||
|
|
||||||
//loading settings and initialize UI, dbController.main() loads all databases
|
//loading settings and initialize UI, dbController.main() loads all databases
|
||||||
mainWindowController.loadSettings();
|
mainWindowController.loadSettings();
|
||||||
|
mainWindowController.dbController.main();
|
||||||
if(mainWindowController.isCloudSync()) {
|
if(mainWindowController.isCloudSync()) {
|
||||||
cloudController.initializeConnection(mainWindowController.getCloudService(), mainWindowController.getCemuPath());
|
cloudController.initializeConnection(mainWindowController.getCloudService(), mainWindowController.getCemuPath());
|
||||||
cloudController.stratupCheck(mainWindowController.getCloudService(), mainWindowController.getCemuPath());
|
cloudController.stratupCheck(mainWindowController.getCloudService(), mainWindowController.getCemuPath());
|
||||||
// mainWindowController.saveSettings();//TODO find a better way
|
|
||||||
}
|
}
|
||||||
mainWindowController.dbController.main();
|
|
||||||
mainWindowController.addUIData();
|
mainWindowController.addUIData();
|
||||||
mainWindowController.initActions();
|
mainWindowController.initActions();
|
||||||
mainWindowController.initUI();
|
mainWindowController.initUI();
|
||||||
|
@ -146,7 +146,7 @@ public class MainWindowController {
|
|||||||
private String selectedGameTitle;
|
private String selectedGameTitle;
|
||||||
private String color;
|
private String color;
|
||||||
private String version = "0.1.5";
|
private String version = "0.1.5";
|
||||||
private String buildNumber = "010";
|
private String buildNumber = "011";
|
||||||
private String versionName = "Gusty Garden";
|
private String versionName = "Gusty Garden";
|
||||||
private int xPos = -200;
|
private int xPos = -200;
|
||||||
private int yPos = 17;
|
private int yPos = 17;
|
||||||
@ -194,7 +194,7 @@ public class MainWindowController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initActions() {
|
void initActions() {
|
||||||
System.out.print("initializing Actions... ");
|
System.out.println("initializing Actions... ");
|
||||||
|
|
||||||
HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam);
|
HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam);
|
||||||
menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{
|
menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{
|
||||||
@ -419,7 +419,7 @@ public class MainWindowController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
System.out.println("done!");
|
System.out.println("initializing Actions done!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@ -540,9 +540,20 @@ public class MainWindowController {
|
|||||||
if(cloudSync) {
|
if(cloudSync) {
|
||||||
cloudSync = false;
|
cloudSync = false;
|
||||||
} else {
|
} else {
|
||||||
|
Alert cloudWarningAlert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
|
||||||
|
cloudWarningAlert.setTitle("cemu_UI");
|
||||||
|
cloudWarningAlert.setHeaderText("activate cloud savegame sync (beta)");
|
||||||
|
cloudWarningAlert.setContentText("You just activate the cloud savegame sync function of cemu_UI which is currently in beta. Are you sure you want to do this?");
|
||||||
|
cloudWarningAlert.initOwner(main.primaryStage);
|
||||||
|
Optional<ButtonType> coverResult = cloudWarningAlert.showAndWait();
|
||||||
|
if (coverResult.get() == ButtonType.OK){
|
||||||
cloudSync = true;
|
cloudSync = true;
|
||||||
main.cloudController.initializeConnection(getCloudService(), getCemuPath());
|
main.cloudController.initializeConnection(getCloudService(), getCemuPath());
|
||||||
main.cloudController.sync(getCloudService(), getCemuPath());
|
main.cloudController.sync(getCloudService(), getCemuPath());
|
||||||
|
} else {
|
||||||
|
cloudSyncToggleBtn.setSelected(false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
saveSettings();//TODO remove (only save on exit settings)
|
saveSettings();//TODO remove (only save on exit settings)
|
||||||
}
|
}
|
||||||
@ -1029,4 +1040,12 @@ public class MainWindowController {
|
|||||||
this.cloudService = cloudService;
|
this.cloudService = cloudService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JFXButton getPlayBtn() {
|
||||||
|
return playBtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayBtn(JFXButton playBtn) {
|
||||||
|
this.playBtn = playBtn;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
@ -112,24 +111,11 @@ public class GoogleDriveController {
|
|||||||
|
|
||||||
public void sync(String cemuDirectory) throws IOException {
|
public void sync(String cemuDirectory) throws IOException {
|
||||||
getLocalSavegames();
|
getLocalSavegames();
|
||||||
//
|
|
||||||
// if (!checkFolder()) {
|
|
||||||
// creatFolder();
|
|
||||||
//
|
|
||||||
// for (int i = 0; i < localSavegames.size(); i++) {
|
|
||||||
// uploadFile(localSavegames.get(i));
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
|
|
||||||
getCloudSavegames();
|
getCloudSavegames();
|
||||||
// System.out.println(cloudSavegames.size() + "; " + localSavegames.size() + "; " + localSavegamesName.size());
|
|
||||||
|
|
||||||
// download files from cloud which don't exist locally
|
// download files from cloud which don't exist locally
|
||||||
for (int i = 0; i < cloudSavegames.size(); i++) {
|
for (int i = 0; i < cloudSavegames.size(); i++) {
|
||||||
|
|
||||||
// System.out.println(localSavegamesName.get(i)+";"+cloudSavegames.get(i).getName());
|
|
||||||
// System.out.println(localSavegames.get(a).getName()+";"+cloudSavegames.get(i).getName().substring(9,cloudSavegames.get(i).getName().length()));
|
|
||||||
|
|
||||||
// if the file exists locally, check which one is newer
|
// if the file exists locally, check which one is newer
|
||||||
if (localSavegamesName.contains(cloudSavegames.get(i).getName())) {
|
if (localSavegamesName.contains(cloudSavegames.get(i).getName())) {
|
||||||
|
|
||||||
@ -138,24 +124,6 @@ public class GoogleDriveController {
|
|||||||
long cloudModified = cloudSavegames.get(i).getModifiedTime().getValue();
|
long cloudModified = cloudSavegames.get(i).getModifiedTime().getValue();
|
||||||
FileInputStream fis = new FileInputStream(localSavegames.get(localSavegamesNumber));
|
FileInputStream fis = new FileInputStream(localSavegames.get(localSavegamesNumber));
|
||||||
|
|
||||||
// // System.out.println(localSavegamesNumber);
|
|
||||||
//// System.out.println(localSavegames.get(localSavegamesNumber).getName() + "; " + cloudSavegames.get(i).getName());
|
|
||||||
// System.out.println(localModified + "; " + cloudModified);
|
|
||||||
//// System.out.println(new Date(localModified) + "; " + new Date(cloudModified));
|
|
||||||
// if (localModified == cloudModified) {
|
|
||||||
// System.out.println("both files are the same, nothing to do \n");
|
|
||||||
// } else if (localModified >= cloudModified) {
|
|
||||||
// System.out.println("\nlocal is newer, going to upload local file");
|
|
||||||
// System.out.println("uploading "+ localSavegames.get(localSavegamesNumber).getName()+"("+new Date(localModified)+")");
|
|
||||||
//// updateFile(cloudSavegames.get(i), localSavegames.get(localSavegamesNumber));
|
|
||||||
// } else {
|
|
||||||
// System.out.println("\ncloud is newer, going to download cloud file");
|
|
||||||
// System.out.println("downloading "+ cloudSavegames.get(i).getName() + "(" + new Date(cloudModified) + ")");
|
|
||||||
//// downloadFile(cloudSavegames.get(i));
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (cloudSavegames.get(i).getMd5Checksum().equals(org.apache.commons.codec.digest.DigestUtils.md5Hex(fis))) {
|
if (cloudSavegames.get(i).getMd5Checksum().equals(org.apache.commons.codec.digest.DigestUtils.md5Hex(fis))) {
|
||||||
System.out.println("both files are the same, nothing to do");
|
System.out.println("both files are the same, nothing to do");
|
||||||
} else {
|
} else {
|
||||||
@ -181,8 +149,6 @@ public class GoogleDriveController {
|
|||||||
uploadFile(localSavegames.get(j));
|
uploadFile(localSavegames.get(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//create a folder in google drive
|
//create a folder in google drive
|
||||||
@ -217,16 +183,11 @@ public class GoogleDriveController {
|
|||||||
private void getLocalSavegames() throws IOException {
|
private void getLocalSavegames() throws IOException {
|
||||||
java.io.File dir = new java.io.File(cemuDirectory+"/mlc01/emulatorSave");
|
java.io.File dir = new java.io.File(cemuDirectory+"/mlc01/emulatorSave");
|
||||||
String[] extensions = new String[] { "dat" };
|
String[] extensions = new String[] { "dat" };
|
||||||
|
System.out.println("Getting all .dat files in " + dir.getCanonicalPath()+" including those in subdirectories");
|
||||||
System.out.println("Getting all .dat files in " + dir.getCanonicalPath()+" including those in subdirectories \n");
|
|
||||||
List<java.io.File> files = (List<java.io.File>) FileUtils.listFiles(dir, extensions, true);
|
List<java.io.File> files = (List<java.io.File>) FileUtils.listFiles(dir, extensions, true);
|
||||||
for (java.io.File file : files) {
|
for (java.io.File file : files) {
|
||||||
localSavegamesName.add(file.getParentFile().getName()+"_"+file.getName());
|
localSavegamesName.add(file.getParentFile().getName()+"_"+file.getName());
|
||||||
localSavegames.add(file);
|
localSavegames.add(file);
|
||||||
// System.out.println(file.getAbsolutePath());
|
|
||||||
// System.out.println(file.getParentFile().getName());
|
|
||||||
// System.out.println(file.lastModified());
|
|
||||||
// System.out.println(file.getName()+"\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,8 +200,6 @@ public class GoogleDriveController {
|
|||||||
for (File file : files.getFiles()) {
|
for (File file : files.getFiles()) {
|
||||||
cloudSavegamesName.add(file.getName());
|
cloudSavegamesName.add(file.getName());
|
||||||
cloudSavegames.add(file);
|
cloudSavegames.add(file);
|
||||||
// System.out.println(file.getName());
|
|
||||||
// System.out.println(file.getModifiedTime()+"\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,29 +209,23 @@ public class GoogleDriveController {
|
|||||||
File fileMetadata = new File();
|
File fileMetadata = new File();
|
||||||
fileMetadata.setName(uploadFile.getParentFile().getName()+"_"+uploadFile.getName());
|
fileMetadata.setName(uploadFile.getParentFile().getName()+"_"+uploadFile.getName());
|
||||||
fileMetadata.setParents(Collections.singletonList(folderID));
|
fileMetadata.setParents(Collections.singletonList(folderID));
|
||||||
// System.out.println(new DateTime(uploadFile.lastModified())+"; "+ new DateTime(uploadFile.lastModified()).getTimeZoneShift());
|
|
||||||
fileMetadata.setModifiedTime(new DateTime(uploadFile.lastModified()));
|
fileMetadata.setModifiedTime(new DateTime(uploadFile.lastModified()));
|
||||||
// System.out.println(fileMetadata.getModifiedTime()+"; "+fileMetadata.getModifiedTime().getTimeZoneShift());
|
|
||||||
|
|
||||||
FileContent mediaContent = new FileContent("", uploadFile);
|
FileContent mediaContent = new FileContent("", uploadFile);
|
||||||
File file = service.files().create(fileMetadata, mediaContent).setFields("id, parents").execute();
|
File file = service.files().create(fileMetadata, mediaContent).setFields("id, parents").execute();
|
||||||
System.out.println("File ID: " + file.getId());
|
System.out.println("upload successfull, File ID: " + file.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
//download a file from the cloud to the local savegames folder
|
//download a file from the cloud to the local savegames folder
|
||||||
private void downloadFile(File downloadFile) throws IOException{
|
private void downloadFile(File downloadFile) throws IOException{
|
||||||
System.out.print("downloading "+downloadFile.getName()+"... ");
|
System.out.print("downloading "+downloadFile.getName()+"... ");
|
||||||
// String directory = downloadFile.getName().substring(0,8);
|
|
||||||
java.io.File directoryFile = new java.io.File(cemuDirectory+"/mlc01/emulatorSave/"+ downloadFile.getName().substring(0,8));
|
java.io.File directoryFile = new java.io.File(cemuDirectory+"/mlc01/emulatorSave/"+ downloadFile.getName().substring(0,8));
|
||||||
String file = downloadFile.getName().substring(9,downloadFile.getName().length());
|
String file = downloadFile.getName().substring(9,downloadFile.getName().length());
|
||||||
// System.out.println(cemuDirectory+"/mlc01/emulatorSave/"+ directory +"/"+ file);
|
|
||||||
// System.out.println("DownloadfileID: " + downloadFile.getId());
|
|
||||||
if(!directoryFile.exists()) {
|
if(!directoryFile.exists()) {
|
||||||
System.out.println("dir dosent exist");
|
System.out.println("dir dosent exist");
|
||||||
directoryFile.mkdir();
|
directoryFile.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputStream outputStream = new FileOutputStream(directoryFile +"/"+ file); //TODO needs to be tested
|
OutputStream outputStream = new FileOutputStream(directoryFile +"/"+ file);
|
||||||
service.files().get(downloadFile.getId()).executeMediaAndDownloadTo(outputStream);
|
service.files().get(downloadFile.getId()).executeMediaAndDownloadTo(outputStream);
|
||||||
|
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
@ -295,10 +248,9 @@ public class GoogleDriveController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void uploadAllFiles() {
|
public void uploadAllFiles() {
|
||||||
new Thread() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
getLocalSavegames();
|
getLocalSavegames();
|
||||||
|
System.out.println("uploading " + localSavegames.size() + " files...");
|
||||||
for (int i = 0; i < localSavegames.size(); i++) {
|
for (int i = 0; i < localSavegames.size(); i++) {
|
||||||
uploadFile(localSavegames.get(i));
|
uploadFile(localSavegames.get(i));
|
||||||
}
|
}
|
||||||
@ -307,8 +259,6 @@ public class GoogleDriveController {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getFolderID() {
|
public String getFolderID() {
|
||||||
|
Loading…
Reference in New Issue
Block a user