コード例 #1
0
        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();
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
        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();
            }
        }
コード例 #7
0
        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
ファイル: SavegameList.cs プロジェクト: nlebeck/savegame-sync
        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));
        }
コード例 #9
0
        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);
        }
コード例 #16
0
        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
ファイル: SavegameList.cs プロジェクト: nlebeck/savegame-sync
 public string Serialize()
 {
     return(String.Format("{0},{1}", Guid.ToString(), SavegameSyncUtils.SerializeDateTime(Timestamp)));
 }