google drive controller clean up
This commit is contained in:
parent
51875e3b72
commit
32e474b6be
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.
Binary file not shown.
Binary file not shown.
|
@ -189,6 +189,7 @@ public class MainWindowController {
|
|||
romTextField.setText(romPath);
|
||||
colorPicker.setValue(Color.valueOf(getColor()));
|
||||
fullscreenToggleBtn.setSelected(isFullscreen());
|
||||
cloudSyncToggleBtn.setSelected(isCloudSync());
|
||||
edit.setDisable(true);
|
||||
applyColor();
|
||||
}
|
||||
|
|
|
@ -40,24 +40,21 @@ public class GoogleDriveController {
|
|||
private ArrayList<String> localSavegamesName = new ArrayList<>();
|
||||
private ArrayList<String> cloudSavegamesName = new ArrayList<>();
|
||||
|
||||
/** Application name. */
|
||||
private final String APPLICATION_NAME ="cemu_Ui Drive API Controller";
|
||||
|
||||
/** Directory to store user credentials for this application. */
|
||||
//Directory to store user credentials for this application
|
||||
private final java.io.File DATA_STORE_DIR = new java.io.File(System.getProperty("user.home"), ".credentials/cemu_UI_credential");
|
||||
|
||||
/** Global instance of the {@link FileDataStoreFactory}. */
|
||||
//Global instance of the {@link FileDataStoreFactory}
|
||||
private FileDataStoreFactory DATA_STORE_FACTORY;
|
||||
|
||||
/** Global instance of the JSON factory. */
|
||||
//Global instance of the JSON factory
|
||||
private final JsonFactory JSON_FACTORY =JacksonFactory.getDefaultInstance();
|
||||
|
||||
/** Global instance of the HTTP transport. */
|
||||
//Global instance of the HTTP transport
|
||||
private HttpTransport HTTP_TRANSPORT;
|
||||
|
||||
/** Global instance of the scopes required by this quickstart.
|
||||
*
|
||||
* If modifying these scopes, delete your previously saved credentials
|
||||
/**If modifying these scopes, delete your previously saved credentials
|
||||
* at ~/.credentials/cemu_UI_credential
|
||||
*/
|
||||
private final java.util.Collection<String> SCOPES = DriveScopes.all();
|
||||
|
@ -110,15 +107,11 @@ public class GoogleDriveController {
|
|||
public void main(String cemuDirectory) throws IOException {
|
||||
service = getDriveService();
|
||||
this.cemuDirectory = cemuDirectory;
|
||||
// sync();
|
||||
|
||||
// upload();
|
||||
// download();
|
||||
}
|
||||
|
||||
public void sync(String cemuDirectory) throws IOException {
|
||||
getLocalSavegames();
|
||||
// upload();
|
||||
|
||||
if (!checkFolder()) {
|
||||
creatFolder();
|
||||
|
||||
|
@ -136,7 +129,7 @@ public class GoogleDriveController {
|
|||
// 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())) {
|
||||
|
||||
int localSavegamesNumber = localSavegamesName.indexOf(cloudSavegames.get(i).getName());
|
||||
|
@ -169,27 +162,23 @@ public class GoogleDriveController {
|
|||
uploadFile(localSavegames.get(j));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//check if there are new local files to upload or download, if so upload/download them and [check if there are files in the cloud were last edit is newer than local, and other way round]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//create a folder in google drive
|
||||
private void creatFolder() throws IOException {
|
||||
System.out.println("creating new folder");
|
||||
File fileMetadata = new File();
|
||||
fileMetadata.setName("cemu_savegames");
|
||||
fileMetadata.setMimeType("application/vnd.google-apps.folder");
|
||||
|
||||
File file = service.files().create(fileMetadata)
|
||||
.setFields("id")
|
||||
.execute();
|
||||
File file = service.files().create(fileMetadata).setFields("id").execute();
|
||||
System.out.println("Folder ID: " + file.getId());
|
||||
folderID = file.getId();
|
||||
}
|
||||
|
||||
//check if folder already exist
|
||||
private boolean checkFolder() {
|
||||
try {
|
||||
Files.List request = service.files().list().setQ("mimeType = 'application/vnd.google-apps.folder' and name = 'cemu_savegames'");
|
||||
|
@ -205,6 +194,7 @@ public class GoogleDriveController {
|
|||
}
|
||||
}
|
||||
|
||||
//reading all local savegames
|
||||
private void getLocalSavegames() throws IOException {
|
||||
java.io.File dir = new java.io.File(cemuDirectory+"/mlc01/emulatorSave");
|
||||
String[] extensions = new String[] { "dat" };
|
||||
|
@ -221,6 +211,7 @@ public class GoogleDriveController {
|
|||
}
|
||||
}
|
||||
|
||||
//reading all cloud savegames
|
||||
private void getCloudSavegames() throws IOException {
|
||||
Files.List request = service.files().list().setQ("fileExtension = 'dat' and '"+folderID+"' in parents").setFields("nextPageToken, files(id, name, size, modifiedTime, createdTime)");
|
||||
FileList files = request.execute();
|
||||
|
@ -231,9 +222,9 @@ public class GoogleDriveController {
|
|||
// System.out.println(file.getName());
|
||||
// System.out.println(file.getModifiedTime()+"\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//upload a file to the cloud from the local savegames folder
|
||||
public void uploadFile(java.io.File uploadFile) throws IOException{
|
||||
System.out.println("uploading ...");
|
||||
File fileMetadata = new File();
|
||||
|
@ -245,19 +236,17 @@ public class GoogleDriveController {
|
|||
|
||||
FileContent mediaContent = new FileContent("", uploadFile);
|
||||
File file = service.files().create(fileMetadata, mediaContent).setFields("id, parents").execute();
|
||||
// uploadedFile = file;
|
||||
System.out.println("File ID: " + file.getId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//download a file from the cloud to the local savegames folder
|
||||
private void downloadFile(File downloadFile) throws IOException{
|
||||
System.out.println("downloading "+downloadFile.getName()+" ...");
|
||||
// String directory = downloadFile.getName().substring(0,8);
|
||||
java.io.File directoryFile = new java.io.File("/mlc01/emulatorSave/"+ downloadFile.getName().substring(0,8));
|
||||
String file = downloadFile.getName().substring(9,downloadFile.getName().length());
|
||||
// System.out.println(cemuDirectory+"/mlc01/emulatorSave/"+ directory +"/"+ file);
|
||||
// System.out.println(downloadFile.getId());
|
||||
// System.out.println("DownloadfileID: " + downloadFile.getId());
|
||||
if(!directoryFile.exists()) {
|
||||
directoryFile.mkdir();
|
||||
}
|
||||
|
@ -267,6 +256,7 @@ public class GoogleDriveController {
|
|||
System.out.println("done");
|
||||
}
|
||||
|
||||
//update a file in the cloud, by deleting the old one and uploading an new with the same id
|
||||
private void updateFile(File oldFile, java.io.File newFile) throws IOException {
|
||||
//deleting old file
|
||||
service.files().delete(oldFile.getId()).execute();
|
||||
|
@ -279,7 +269,6 @@ public class GoogleDriveController {
|
|||
|
||||
FileContent mediaContent = new FileContent("", newFile);
|
||||
File file = service.files().create(fileMetadata, mediaContent).setFields("id, parents").execute();
|
||||
// uploadedFile = file;
|
||||
System.out.println("File ID: " + file.getId());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue