private void UpdateLocalGameInfoDisplays(string selectedGameName) { if (selectedGameName == null) { localSaveTimestampTextBlock.Text = ""; installDirTextBlock.Text = ""; return; } string timestampMessage = null; string installDir = null; try { installDir = savegameSync.GetLocalInstallDir(selectedGameName); SaveSpec saveSpec = SaveSpecRepository.GetRepository().GetSaveSpec(selectedGameName); if (!Directory.Exists(installDir)) { timestampMessage = "Error: install dir does not exist"; } else { DateTime timestamp = savegameSync.GetLocalSaveTimestamp(saveSpec, installDir); timestampMessage = timestamp.ToString(); } } catch (SavegameSyncException e) { timestampMessage = "Error: " + e.Message; } localSaveTimestampTextBlock.Text = timestampMessage; installDirTextBlock.Text = installDir; }
public AddGameDialog() { InitializeComponent(); foreach (SaveSpec spec in SaveSpecRepository.GetRepository().GetAllSaveSpecs()) { listBox.Items.Add(spec.GameName); } }
public static SaveSpecRepository GetRepository() { if (singleton == null) { singleton = new SaveSpecRepository(); } return(singleton); }
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(); }
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(); }