// Start is called before the first frame update void Awake() { handler = GameObject.FindGameObjectWithTag("GameManager").GetComponent <SaveFileHandler>(); text = GetComponent <TMPro.TextMeshProUGUI>(); BuildTextFromData(); }
private void ExecuteSyncAction(SaveFileHandler saveHandler, SyncAction action) { if (action != SyncAction.None) { Logger.Info($"Performing Sync Action: {action}, on {saveHandler.LocalSaveFile.GameTitle}"); } else { Logger.Debug($"Performing Sync Action: {action}, on {saveHandler.LocalSaveFile.GameTitle}"); } switch (action) { case SyncAction.Push: { saveHandler.RemoteSaveFile.PushSaves(); break; } case SyncAction.Pull: { saveHandler.RemoteSaveFile.PullSaves(); break; } case SyncAction.None: { break; } } }
private void InitSaveFiles() { Logger.Info($"Scanning for Touhou Games at: {ConfigManager.GetSetting("TouhouGamesDirectory")}"); Dictionary <string, string> oldGenGamesFound = FindTouhouSavePath.GetTouhouOldGenPath(ConfigManager.GetSetting("TouhouGamesDirectory")); // TODO: Detect and sync newer generation games that does not exist on the PC, but have save files on the drive Dictionary <string, string> newGenGamesFound = FindTouhouSavePath.GetTouhouNewGenPath(ConfigManager.GetSetting("TouhouGamesDirectory")); Logger.Info($"Scanning completed. Found a total of {oldGenGamesFound.Count + newGenGamesFound.Count} games"); Logger.Info("Processing Found Games"); Logger.Trace("Instantiating Object Representation for Local Touhou Save files"); TouhouLocalSaveFile[] newGenSaveFiles = TouhouLocalNewGenSaveFile.ToTouhouSaveFiles(newGenGamesFound); TouhouLocalSaveFile[] oldGenSaveFiles = TouhouLocalOldGenSaveFile.ToTouhouSaveFiles(oldGenGamesFound); Logger.Trace("Instantiation Completed for Local Touhou Save Object Representation"); Logger.Trace("Instantiating Object Representation for Remote Touhou Save files"); TouhouRemoteSaveFile[] remoteSaveFiles = TouhouRemoteSaveFile.ToTouhouRemoteSaveFiles(newGenSaveFiles, oldGenSaveFiles, m_googleDriveHandler, m_googleDriveSaveFolder); Logger.Trace("Instantiation Completed for Remote Touhou Save Object Representation"); Logger.Trace("Instantiating Touhou Save File Wrapper"); this.SaveFiles = SaveFileHandler.ToTouhouSaveFilesHandlers(remoteSaveFiles); Logger.Trace("Instantiation Completed for Touhou Save File Wrapper"); }
private static async ValueTask ProcessFile(FileInfo file, bool overwrite) { if (!file.Exists) { await Console.Error.WriteLineAsync($"[ ERROR ] File \"{file.FullName}\" could not be found and has been skipped."); return; } await using FileStream inputStream = file.OpenRead(); bool encrypted = SaveFileHandler.IsFileEncrypted(inputStream); Stream?processed; if (encrypted) { processed = await Decrypt(inputStream); } else { processed = await Encrypt(inputStream); } if (processed == null) { await Console.Out.WriteLineAsync($"[ ERROR ] Content of file \"{file.Name}\" could not be converted to a supported format."); return; } processed.Position = 0; string outputFile = GetOutputFilePath(file, encrypted, overwrite); await using FileStream outputStream = File.Open(outputFile, FileMode.Create, FileAccess.Write); await processed.CopyToAsync(outputStream); }
public static async ValueTask ProcessFile(FileInfo file, bool overwrite) { if (!file.Exists) { EventLogger.logError($"File \"{file.FullName}\" could not be found and has been skipped."); return; } using FileStream inputStream = file.OpenRead(); bool encrypted = SaveFileHandler.IsFileEncrypted(inputStream); Stream?processed = encrypted ? await Decrypt(inputStream) : await Encrypt(inputStream); if (processed == null) { EventLogger.logError($"Content of file \"{file.Name}\" could not be converted to a supported format."); return; } processed.Seek(0, SeekOrigin.Begin); string outputFile = GetOutputFilePath(file, encrypted, overwrite); using FileStream outputStream = File.Open(outputFile, FileMode.Create, FileAccess.Write); await processed.CopyToAsync(outputStream); }
/// <summary> /// Handles all errors that may occur during saving file. /// </summary> /// <param name="saveFileHandler">Method for saving file</param> private static void SaveFile(SaveFileHandler saveFileHandler) { try { SaveFileEvent = saveFileHandler; SaveFileEvent(); } catch (ArgumentException ex) { MessageLog.LogError(ResHelper.GetString("Error_ArgumentException"), ex); } catch (PathTooLongException ex) { MessageLog.LogError(ResHelper.GetString("Error_PathTooLongException"), ex); } catch (DirectoryNotFoundException ex) { MessageLog.LogError(ResHelper.GetString("Error_DirectoryNotFoundException"), ex); } catch (UnauthorizedAccessException ex) { MessageLog.LogError(ResHelper.GetString("Error_UnauthorizedAccessException"), ex); } catch (FileNotFoundException ex) { MessageLog.LogError(ResHelper.GetString("Error_FileNotFoundException"), ex); } catch (NotSupportedException ex) { MessageLog.LogError(ResHelper.GetString("Error_PathTooLongException"), ex); } }
/// <summary> /// Import selected file /// </summary> /// <param name="file">The save file that was selected</param> private void DoFileInteraction(string file) { SelectedFile = file; SaveFileHandler.ImportMods(file); Page_ModsConfig_Detours.SetStatus("Status_Message_Imported".Translate()); this.Close(true); }
private async ValueTask <EncryptionData> Decrypt(EncryptionData rawData) { await using Stream encStream = rawData.EncryptedStream !; await using Stream decStream = await _encryptionProvider.DecryptAsync(encStream); SaveFileHandler.RemoveTrailingZeroes(decStream); return(await EncryptionData.From(null, decStream)); }
/// <summary> /// Determines what to do with the local save file /// </summary> /// <param name="handler"></param> /// <returns></returns> private SyncAction DetermineSyncAction(SaveFileHandler handler) { SaveFileMetadata metadata; double localModifyTime = handler.LocalSaveFile.GetScoreDatModifyTime(); try { metadata = handler.RemoteSaveFile.GetRemoteSaveFileMetaData(); } catch (Exception e) { Logger.Error(e, "Failed to retrieve/load Metadata for file. Overwriting Remote File"); return(SyncAction.Push); } double remoteModifyTime = metadata.DatLastMod; double timeDifference = localModifyTime - remoteModifyTime; double localDatSize = handler.LocalSaveFile.GetScoreDatSize(); bool isSaveSizeSame = Math.Abs(localDatSize - metadata.DatSize) < 0.001; bool localSaveBigger = localDatSize > metadata.DatSize; // If the time difference with the google drive are not that different // and we have to account for upload time and other stuff // Thus, they might be the same save file if (Math.Abs(timeDifference) <= SyncThresholdTimeDifference) { Logger.Debug($"Not performing any Sync action for: {handler.LocalSaveFile.GameTitle}. Same modified time or modified time difference in acceptable range ({SyncThresholdTimeDifference} > {timeDifference})"); return(SyncAction.None); } // if the time difference is a positive number, // that means the current save file is x seconds ahead of google drive save // which then we need to push the current save to the cloud if (timeDifference > 0) { Logger.Trace($"Potential Sync action: Push. Remote Save is {timeDifference} seconds behind local save"); // The remote save is bigger but the local dat is more recently updated if (!isSaveSizeSame && !localSaveBigger) { Logger.Trace($"Potential Sync Action Discarded. The Remote File is {timeDifference} seconds behind, but save size is {metadata.DatSize - localDatSize} bytes larger. Requesting User Action"); return(HandleConflict(false, true)); } Logger.Debug($"Performing Sync Action: Push, on {handler.LocalSaveFile.GameTitle}"); return(SyncAction.Push); } else { Logger.Trace($"Potential Sync action: Push. Local Save is {Math.Abs(timeDifference)} seconds behind remote save"); if (!isSaveSizeSame && localSaveBigger) { Logger.Trace($"Potential Sync Action Discarded. The Local File is {Math.Abs(timeDifference)} seconds behind, but save size is {localDatSize - metadata.DatSize} bytes larger. Requesting User Action"); return(HandleConflict(true, false)); } Logger.Debug($"Performing Sync Action: Pull, on {handler.LocalSaveFile.GameTitle}"); return(SyncAction.Pull); } }
public static async ValueTask <Stream?> Encrypt(Stream data) { using Stream encrypted = await AesEncryptionProvider.EncryptAsync(data); Stream result = SaveFileHandler.PrependMagicToEncrypted(encrypted); result.Seek(0, SeekOrigin.Begin); return(result); }
void Start() { GameControllerInstance = this; InputText = InputTextPrefab.GetComponent <TMP_InputField>(); Words = SaveFileHandler.ReturnWordsList(); StartGame(); }
public static async ValueTask <Stream?> Decrypt(Stream data) { Stream decrypted = await AesEncryptionProvider.DecryptAsync(data); Stream result = SaveFileHandler.RemoveTrailingZeroes(decrypted); result.Seek(0, SeekOrigin.Begin); return(result); }
private async ValueTask <ApiEncryptionModel> Decrypt(string base64Data) { await using MemoryStream encStream = new MemoryStream(Convert.FromBase64String(base64Data)); await using Stream decStream = await _encryptionProvider.DecryptAsync(encStream); SaveFileHandler.RemoveTrailingZeroes(decStream); return(new ApiEncryptionModel { Decrypted = await GetBase64Data(decStream) }); }
// Start is called before the first frame update void Start() { // Grab all of our components generator = GameObject.FindGameObjectWithTag("IngredientGenerator").GetComponent <IngredientGenerator>(); handler = GetComponent <SaveFileHandler>(); player = GetComponent <PlayerDataManager>(); if (tooltip = GameObject.Find("Tooltip")) { tooltip.GetComponent <Tooltip>().HideTooltip(); } }
void Awake() { if (handler == null) { handler = this; SaveFileHandler.Load(); DontDestroyOnLoad(this); } else { Destroy(this); } }
public void Create(ApplicationDbContext dataSource, string serverPath, IEnumerable <HttpPostedFileBase> files, string[] filesToIgnore, string createdById, SaveFileHandler saveFile) { NotificationDate = DateTime.Now; ByUserId = createdById; DateTimeEntered = DateTime.Now; TimeStamp = DateTime.Now; DateTimeModified = DateTime.Now; foreach (var file in files) { if (file == null) { continue; } var singleOrDefault = filesToIgnore.SingleOrDefault(f => f.EndsWith(file.FileName) == true); if (!string.IsNullOrEmpty(singleOrDefault)) { continue; } if (Attachments == null) { Attachments = new List <Attachment>(); } byte[] binData = saveFile(file, serverPath); Attachment attachment = new Attachment { Name = file.FileName, DateTimeEntered = DateTime.Now, EnteredBy = this.EnteredBy, TimeStamp = DateTime.Now, AttachmentContent = binData, DateTimeModified = DateTime.Now, ModifiedBy = this.EnteredBy }; this.Attachments.Add(attachment); } dataSource.Notifications.Add(this); dataSource.SaveChanges(); }
/// <summary> /// Reload the list of save files /// </summary> private void ReloadFiles() { this.files.Clear(); foreach (FileInfo saveFile in GenFilePaths.AllSavedGameFiles) { try { this.files.Add(new SaveFileInfo(saveFile)); this.filesModCount.Add(SaveFileHandler.GetModCount(Path.GetFileNameWithoutExtension(saveFile.Name))); } catch (Exception ex) { Log.Error("Exception loading " + saveFile.Name + ": " + ex.ToString()); } } }
private void OnLevelWasLoaded(int level) { if (PersistenceScript.instance == transform.parent.GetComponent <PersistenceScript>()) { // Grab all of our components generator = GameObject.FindGameObjectWithTag("IngredientGenerator").GetComponent <IngredientGenerator>(); handler = GetComponent <SaveFileHandler>(); player = GetComponent <PlayerDataManager>(); if (tooltip = GameObject.Find("Tooltip")) { tooltip.GetComponent <Tooltip>().HideTooltip(); } player.RefreshInventory(); } }
static void Main(string[] args) { SaveFileHandler saveFileHandler = new SaveFileHandler(new AssetManager()); Inventory inventory = new Inventory(); Item item = new Item("Test item", 5); Item item2 = new Item("Testst", 1); inventory.addItem(item); inventory.addItem(item2); saveFileHandler.saveInventory(inventory); Inventory loadedInv = saveFileHandler.loadInventory(); Console.ReadLine(); ItemDropManager idm = new ItemDropManager(new SaveFileHandler()); }
private async Task <Stream?> decryptFileIntoStream(string filePath) { var file = new FileInfo(filePath); using FileStream inputStream = file.OpenRead(); bool encrypted = SaveFileHandler.IsFileEncrypted(inputStream); if (!encrypted) { Assert.Fail($"The file \"{file.Name}\" was in an unexpected format."); return(null); } Stream?stream = await FileProcessHelper.Decrypt(inputStream); if (stream == null) { Assert.Fail($"Content of file \"{file.Name}\" could not be converted to a supported format."); return(null); } return(stream); }
private async Task <ProfileSaveFile?> handleDatFileOpen(string filePath) { var file = new FileInfo(filePath); using FileStream inputStream = file.OpenRead(); bool encrypted = SaveFileHandler.IsFileEncrypted(inputStream); if (!encrypted) { EventLogger.logError($"The file \"{file.Name}\" was in an unexpected format."); showError?.Invoke(R.formatFILE_IN_UNEXPECTED_FORMAT_ERROR_MESSAGE(file.Name)); return(null); } using Stream? processed = await FileProcessHelper.Decrypt(inputStream); if (processed == null) { EventLogger.logError($"Content of file \"{file.Name}\" could not be converted to a supported format."); showError?.Invoke(R.formatFILE_DECRYPT_ERROR_MESSAGE(file.Name)); return(null); } return(await tryParseFileStreamAsync(processed !)); }
void OnApplicationQuit() { SaveFileHandler.Save(); }
private static async ValueTask <Stream?> Encrypt(Stream data) { await using Stream encrypted = await EncryptionProviders.Current.EncryptAsync(data); return(SaveFileHandler.PrependMagicToEncrypted(encrypted)); }
private static async ValueTask <Stream?> Decrypt(Stream data) { Stream decrypted = await EncryptionProviders.Current.DecryptAsync(data); return(SaveFileHandler.RemoveTrailingZeroes(decrypted)); }
private void OnSaveFileChanged(SaveFileHandler handler) { this.m_syncQueue.Add(handler); }
public ItemDropManager(SaveFileHandler saveFileHandler) : this(saveFileHandler.loadAllIngameItems()) { }
public void constructor02() { SaveFileHandler sfh = new SaveFileHandler(); ItemDropManager idm = new ItemDropManager(sfh); }
public void unlockLevel() { SaveFileHandler.SaveGame(levelNumber + 1); }