public static bool Sync() { if (!System.Threading.Monitor.TryEnter(_lock)) { //Already syncing, return when on-going sync is done lock (_lock) { return(true); } } else { try { InteropEmu.DisplayMessage("GoogleDrive", "SynchronizationStarted"); using (_accessor = new GoogleDriveAccessor()) { if (!CloudSyncHelper.DownloadData()) { InteropEmu.DisplayMessage("GoogleDrive", "SynchronizationFailed"); return(false); } CloudSyncHelper.UploadData(); InteropEmu.DisplayMessage("GoogleDrive", "SynchronizationCompleted"); ConfigManager.Config.PreferenceInfo.CloudLastSync = DateTime.Now; ConfigManager.ApplyChanges(); return(true); } } finally { System.Threading.Monitor.Exit(_lock); } } }
public static bool Sync() { if (!System.Threading.Monitor.TryEnter(_lock)) { //Already syncing, return when on-going sync is done lock (_lock) { return(true); } } else { try { string googleDriveFolder = Path.Combine(ConfigManager.HomeFolder, "GoogleDrive"); if (!Directory.Exists(googleDriveFolder) || Directory.EnumerateFiles(googleDriveFolder).Where((string filename) => filename.Contains("TokenResponse")).Count() == 0) { //Sync token has been deleted, disable sync ConfigManager.Config.PreferenceInfo.CloudSaveIntegration = false; ConfigManager.ApplyChanges(); return(false); } InteropEmu.DisplayMessage("GoogleDrive", "SynchronizationStarted"); using (_accessor = new GoogleDriveAccessor()) { FileDownloadResult result = CloudSyncHelper.DownloadData(); if (result == FileDownloadResult.Error) { InteropEmu.DisplayMessage("GoogleDrive", "SynchronizationFailed"); return(false); } CloudSyncHelper.UploadData(); InteropEmu.DisplayMessage("GoogleDrive", "SynchronizationCompleted"); ConfigManager.Config.PreferenceInfo.CloudLastSync = DateTime.Now; ConfigManager.ApplyChanges(); return(true); } } finally { System.Threading.Monitor.Exit(_lock); } } }