private async void deleteSaveButton_Click(object sender, RoutedEventArgs e)
        {
            object selection = orphanedSaveListBox.SelectedItem;

            if (selection == null)
            {
                return;
            }
            string saveFileName = selection.ToString();

            if (saveFileName == EMPTY_ORPHANED_LIST_MESSAGE)
            {
                return;
            }

            StartOperation();
            await SavegameSyncUtils.RunWithChecks(async() =>
            {
                await savegameSync.DeleteOrphanedSaveFile(saveFileName);
            });

            await UpdateOrphanedSaveList();

            FinishOperation();
        }
示例#2
0
        private async void copyFromCloudButton_Click(object sender, RoutedEventArgs e)
        {
            object selectedGame = localGameListBox.SelectedItem;

            if (selectedGame == null)
            {
                return;
            }
            string gameName = selectedGame.ToString();

            int saveIndex = savegameListControl.GetSelectedSaveIndex();

            if (saveIndex == -1)
            {
                return;
            }

            StartOperation("Downloading save for " + gameName + "...");
            await SavegameSyncUtils.RunWithChecks(async() =>
            {
                await savegameSync.DownloadAndUnzipSave(gameName, saveIndex);
            });

            UpdateLocalGameInfoDisplays(gameName);
            FinishOperation();
        }
        private async void deleteAllFilesButton_Click(object sender, RoutedEventArgs e)
        {
            string             message = "Delete all files stored in the cloud?";
            ConfirmationDialog dialog  = new ConfirmationDialog(message);
            bool?result = dialog.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                return;
            }

            string             message2 = "Are you sure you want to delete all files? (All your cloud saves will be lost!)";
            ConfirmationDialog dialog2  = new ConfirmationDialog(message2);
            bool?result2 = dialog2.ShowDialog();

            if (!result2.HasValue || !result2.Value)
            {
                return;
            }

            StartOperation();
            await SavegameSyncUtils.RunWithChecks(async() =>
            {
                await savegameSync.DeleteAllFilesAsync();
            });

            await UpdateOrphanedSaveList();
            await UpdateMissingEntriesListAsync();

            FinishOperation();
        }
        private async void deleteGameButton_Click(object sender, RoutedEventArgs e)
        {
            if (cloudGameListBox.SelectedItem == null)
            {
                return;
            }
            string gameName = cloudGameListBox.SelectedItem.ToString();

            string message = "Delete all save files stored in the cloud for "
                             + gameName + "?";
            ConfirmationDialog dialog = new ConfirmationDialog(message);
            bool?result = dialog.ShowDialog();

            if (result.HasValue && result.GetValueOrDefault())
            {
                StartOperation();
                await SavegameSyncUtils.RunWithChecks(async() =>
                {
                    await savegameSync.DeleteGameFromCloud(gameName);
                });
                await UpdateCloudGameList();

                await savegameListControl.SetGameAndUpdateAsync(null);

                FinishOperation();
            }
        }
        private async void downloadSaveButton_Click(object sender, RoutedEventArgs e)
        {
            object selection = orphanedSaveListBox.SelectedItem;

            if (selection == null)
            {
                return;
            }
            string saveFileName = selection.ToString();

            if (saveFileName == EMPTY_ORPHANED_LIST_MESSAGE)
            {
                return;
            }

            string message = "Download orphaned save file? (The zip file will be downloaded into"
                             + " the directory in which this app was launched.)";
            ConfirmationDialog dialog = new ConfirmationDialog(message);
            bool?result = dialog.ShowDialog();

            if (result.HasValue && result.GetValueOrDefault())
            {
                StartOperation();
                await SavegameSyncUtils.RunWithChecks(async() =>
                {
                    await savegameSync.DownloadOrphanedSaveFile(saveFileName);
                });

                FinishOperation();
            }
        }
        private async void downloadSaveButton_Click(object sender, RoutedEventArgs e)
        {
            object selection = cloudGameListBox.SelectedItem;

            if (selection == null)
            {
                return;
            }
            string gameName = selection.ToString();

            int saveIndex = savegameListControl.GetSelectedSaveIndex();

            if (saveIndex == -1)
            {
                return;
            }

            string downloadedFileName = savegameSync.GetSpecificSaveFileDownloadPath(gameName, saveIndex);
            string message            = "Download selected save? (The downloaded zip file will be downloaded"
                                        + " into the directory in which this app was launched and will be named \""
                                        + downloadedFileName + ".\")";
            ConfirmationDialog dialog = new ConfirmationDialog(message);
            bool?result = dialog.ShowDialog();

            if (result.HasValue && result.GetValueOrDefault())
            {
                StartOperation();
                await SavegameSyncUtils.RunWithChecks(async() =>
                {
                    await savegameSync.DownloadSpecificSaveFileAsync(gameName, saveIndex);
                });

                FinishOperation();
            }
        }
        public async Task <Dictionary <string, List <SavegameEntry> > > GetMissingSaveEntriesAsync()
        {
            Dictionary <string, List <SavegameEntry> > result = new Dictionary <string, List <SavegameEntry> >();

            await ReadSavegameList();

            foreach (string gameName in savegameList.GetGames())
            {
                List <SavegameEntry> saves = savegameList.ReadSaves(gameName);
                foreach (SavegameEntry save in saves)
                {
                    string saveFileName = SavegameSyncUtils.GetSavegameFileNameFromGuid(save.Guid);
                    List <Google.Apis.Drive.v3.Data.File> files = await googleDriveWrapper.SearchFileByNameAsync(saveFileName);

                    Debug.Assert(files.Count <= 1);
                    if (files.Count == 0)
                    {
                        if (!result.ContainsKey(gameName))
                        {
                            result.Add(gameName, new List <SavegameEntry>());
                        }
                        result[gameName].Add(save);
                    }
                }
            }

            return(result);
        }
示例#8
0
        public static SavegameEntry Deserialize(string str)
        {
            string[] stringSplit = str.Split(',');
            Guid     guid        = Guid.Parse(stringSplit[0]);
            DateTime timestamp   = SavegameSyncUtils.DeserializeDateTime(stringSplit[1]);

            return(new SavegameEntry(guid, timestamp));
        }
        private async void deleteMissingEntriesButton_Click(object sender, RoutedEventArgs e)
        {
            StartOperation();
            await SavegameSyncUtils.RunWithChecks(async() =>
            {
                await savegameSync.DeleteMissingSaveEntriesAsync();
            });

            await UpdateMissingEntriesListAsync();

            FinishOperation();
        }
示例#10
0
        public async Task DownloadSpecificSaveFileAsync(string gameName, int saveIndex)
        {
            await ReadSavegameList();

            List <SavegameEntry> saves = savegameList.ReadSaves(gameName);
            SavegameEntry        save  = saves[saveIndex];
            string saveFileName        = SavegameSyncUtils.GetSavegameFileNameFromGuid(save.Guid);

            string outputPath = GetSpecificSaveFileDownloadPath(gameName, saveIndex);

            FileUtils.DeleteIfExists(outputPath);
            await DownloadSaveFileToPathAsync(saveFileName, outputPath);
        }
示例#11
0
        public async Task ZipAndUploadSave(string gameName)
        {
            // Copy save files from the game's install directory into a temp directory according
            // to the spec
            string   installDir = localGameList.GetInstallDir(gameName);
            SaveSpec saveSpec   = SaveSpecRepository.GetRepository().GetSaveSpec(gameName);
            string   destDir    = Path.Combine(TempDir, "saveToUpload");

            FileUtils.DeleteIfExists(destDir);
            Directory.CreateDirectory(destDir);
            CopySaveFilesFromInstallDir(saveSpec, installDir, destDir);
            Debug.WriteLine("Dirs: " + installDir + " " + destDir);

            // Find the last write time of the save
            DateTime latestFileWriteTime = GetLocalSaveTimestamp(saveSpec, installDir);

            Debug.WriteLine("Latest write time: " + latestFileWriteTime);

            // Assign the save a guid and make it into a zip file
            Guid saveGuid = Guid.NewGuid();

            Debug.WriteLine("Guid: " + saveGuid);
            string zipFile = Path.Combine(TempDir, SavegameSyncUtils.GetSavegameFileNameFromGuid(saveGuid));

            FileUtils.DeleteIfExists(zipFile);
            ZipFile.CreateFromDirectory(destDir, zipFile);

            // Upload save
            string remoteFileName = SavegameSyncUtils.GetSavegameFileNameFromGuid(saveGuid);
            string fileId         = await googleDriveWrapper.CreateFileAsync(remoteFileName);

            using (FileStream fileStream = File.OpenRead(zipFile))
            {
                await googleDriveWrapper.UploadFileAsync(fileId, fileStream);
            }

            // Download latest version of SavegameList
            await ReadSavegameList();

            // Add save to SavegameList
            savegameList.AddSave(gameName, saveGuid, latestFileWriteTime);

            // Upload SavegameList
            await WriteSavegameList();

            CleanUpTempFiles();
        }
示例#12
0
        public async Task DeleteGameFromCloud(string gameName)
        {
            await ReadSavegameList();

            List <SavegameEntry> saves = savegameList.ReadSaves(gameName);

            savegameList.DeleteGame(gameName);
            await WriteSavegameList();

            foreach (SavegameEntry save in saves)
            {
                string saveFileName = SavegameSyncUtils.GetSavegameFileNameFromGuid(save.Guid);
                int    filesDeleted = await googleDriveWrapper.DeleteAllFilesWithNameAsync(saveFileName);

                Debug.Assert(filesDeleted == 1);
            }
        }
示例#13
0
        private async void copyToCloudButton_Click(object sender, RoutedEventArgs e)
        {
            object selectedGame = localGameListBox.SelectedItem;

            if (selectedGame == null)
            {
                return;
            }
            string gameName = selectedGame.ToString();

            StartOperation("Uploading save for " + gameName + "...");
            await SavegameSyncUtils.RunWithChecks(async() =>
            {
                await savegameSync.ZipAndUploadSave(gameName);
            });

            await savegameListControl.SetGameAndUpdateAsync(gameName);

            FinishOperation();
        }
示例#14
0
        public async Task DownloadAndUnzipSave(string gameName, int saveIndex)
        {
            // Download latest version of SavegameList
            await ReadSavegameList();

            // Read file name from SavegameList
            List <SavegameEntry> saves = savegameList.ReadSaves(gameName);
            SavegameEntry        save  = saves[saveIndex];
            Guid   saveGuid            = save.Guid;
            string saveFileName        = SavegameSyncUtils.GetSavegameFileNameFromGuid(saveGuid);

            Debug.WriteLine("Downloading save file " + saveFileName + " with index " + saveIndex + " and timestamp " + save.Timestamp);

            // Download zipped save from Google Drive
            var files = await googleDriveWrapper.SearchFileByNameAsync(saveFileName);

            Debug.Assert(files.Count == 1);
            string saveFileId  = files[0].Id;
            string zipFilePath = Path.Combine(TempDir, saveFileName);

            Directory.CreateDirectory(TempDir);
            using (FileStream fileStream = File.OpenWrite(zipFilePath))
            {
                await googleDriveWrapper.DownloadFileAsync(saveFileId, fileStream);
            }

            // Unzip zipped save
            string tempSaveDir = Path.Combine(TempDir, "downloadedSave");

            FileUtils.DeleteIfExists(tempSaveDir);
            ZipFile.ExtractToDirectory(zipFilePath, tempSaveDir);

            // Copy unzipped files/directories into game install directory
            string   installDir = localGameList.GetInstallDir(gameName);
            SaveSpec saveSpec   = SaveSpecRepository.GetRepository().GetSaveSpec(gameName);

            CopySaveFilesIntoInstallDir(saveSpec, tempSaveDir, installDir);

            CleanUpTempFiles();
        }
示例#15
0
        public async Task <List <string> > GetOrphanedSaveFileNames()
        {
            List <string> orphanedSaveFileNames = new List <string>();

            await ReadSavegameList();

            var files = await googleDriveWrapper.GetAllFilesAsync();

            foreach (var file in files)
            {
                bool foundFile = false;

                // Special case for the SavegameList file, which should be the only file that is
                // not a save file itself.
                if (file.Name == SavegameListFileName)
                {
                    foundFile = true;
                }

                foreach (string gameName in savegameList.GetGames())
                {
                    foreach (SavegameEntry entry in savegameList.ReadSaves(gameName))
                    {
                        string entryFileName = SavegameSyncUtils.GetSavegameFileNameFromGuid(entry.Guid);
                        if (entryFileName == file.Name)
                        {
                            foundFile = true;
                        }
                    }
                }

                if (!foundFile)
                {
                    orphanedSaveFileNames.Add(file.Name);
                }
            }
            return(orphanedSaveFileNames);
        }
        private async void downloadAllFilesButton_Click(object sender, RoutedEventArgs e)
        {
            string directoryName = $"SavegameSync-all-files-{DateTime.Now.Day}-{DateTime.Now.Month}-{DateTime.Now.Year}-{DateTime.Now.Hour}-{DateTime.Now.Minute}-{DateTime.Now.Second}";

            string message = "Download all files? The files will be downloaded into a directory"
                             + " named " + directoryName + " located in the directory in which this"
                             + " app was launched.";

            ConfirmationDialog dialog = new ConfirmationDialog(message);
            bool?result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                StartOperation();
                await SavegameSyncUtils.RunWithChecks(async() =>
                {
                    Directory.CreateDirectory(directoryName);
                    await savegameSync.DownloadAllFilesToDirectoryAsync(directoryName);
                });

                FinishOperation();
            }
        }
示例#17
0
        public async Task DeleteSave(string gameName, int saveIndex)
        {
            // Download latest version of SavegameList
            await ReadSavegameList();

            // Get guid of zipped save file to use later
            List <SavegameEntry> saves = savegameList.ReadSaves(gameName);
            SavegameEntry        save  = saves[saveIndex];
            Guid saveGuid = save.Guid;

            Debug.WriteLine("Deleting save file with guid " + saveGuid + ", index " + saveIndex + ", and timestamp " + save.Timestamp);

            // Delete save from SavegameList
            savegameList.DeleteSave(gameName, saveIndex);

            // Upload SavegameList
            await WriteSavegameList();

            // Delete zipped save file
            string saveFileName = SavegameSyncUtils.GetSavegameFileNameFromGuid(saveGuid);
            int    filesDeleted = await googleDriveWrapper.DeleteAllFilesWithNameAsync(saveFileName);

            Debug.Assert(filesDeleted == 1);
        }
示例#18
0
 public string Serialize()
 {
     return(String.Format("{0},{1}", Guid.ToString(), SavegameSyncUtils.SerializeDateTime(Timestamp)));
 }