Ejemplo n.º 1
0
 private static bool UploadData()
 {
     using (MemoryStream stream = CloudSyncHelper.GetDataStream()) {
         var gdAccessor = new GoogleDriveAccessor();
         return(_accessor.UploadFile(stream, "MesenData.zip"));
     }
 }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        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);
                }
            }
        }
Ejemplo n.º 4
0
 private static bool UploadData()
 {
     using (MemoryStream stream = CloudSyncHelper.GetDataStream()) {
         return(_accessor.UploadFile(stream, "MesenData.zip"));
     }
 }