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);
        }
Beispiel #2
0
        public async Task ReadFromStream(Stream stream)
        {
            stream.Position = 0;
            StreamReader streamReader = new StreamReader(stream);

            while (!streamReader.EndOfStream)
            {
                string line = await streamReader.ReadLineAsync();

                string[] lineSplit = line.Split('\t');
                string   gameName  = lineSplit[0];
                gameEntries[gameName] = new List <SavegameEntry>();
                for (int i = 1; i < lineSplit.Length; i++)
                {
                    SavegameEntry entry = SavegameEntry.Deserialize(lineSplit[i]);
                    gameEntries[gameName].Add(entry);
                }
            }
            streamReader.Close();
        }
        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();
        }
        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);
        }