/// <summary> /// Delete old files files if the config says so. /// </summary> private static void CleanUpOldFiles() { if (!LogFileExists) { return; } if (config.MaxNumberOfLogFiles == 0) { return; // 0 = infinity } List <string> files = Directory.GetFiles(LogsPath).OrderBy(x => x).ToList(); if (files.Count < config.MaxNumberOfLogFiles) { return; } int filesToDelete = files.Count - config.MaxNumberOfLogFiles; for (int i = 0; i < filesToDelete; ++i) { File.Delete(files[i]); } #if UNITY_WEBGL && !UNITY_EDITOR WebGlUtils.SyncFiles(); #endif deletedFilesOnceThisSession = true; }
/// <summary> /// Saves the game. /// </summary> /// <param name="path">Save game path.</param> private void SaveGame(string path) { Utils.DeleteDirectory(path); Directory.CreateDirectory(path); for (int i = 0; i < Library.SavableObjects.Count; i++) { File.WriteAllText(path + "/" + i + ".savo", Library.SavableObjects[i].Save()); } CleanUpOldSaves(); #if UNITY_WEBGL && !UNITY_EDITOR Logger.LogInfo("WebGL file sync in progress.", this); WebGlUtils.SyncFiles(); #endif }
/// <summary> /// Saved the data edited in the scriptable to the configuration file. /// </summary> public override void Save() { Logger.LogInfo("Trying to save configuration file to " + FullPath + ".", LoggingName); if (!Directory.Exists(Path)) { Directory.CreateDirectory(Path); } string data = JsonUtility.ToJson(ConfigData, true); if (Encrypted) { data = data.ToBase64(); } File.WriteAllText(FullPath, data); Logger.LogInfo("Saved configuration file to " + FullPath + ".", LoggingName); #if UNITY_WEBGL && !UNITY_EDITOR WebGlUtils.SyncFiles(); #endif }
/// <summary> /// Saves a log line to file. /// </summary> /// <param name="line">The line to save.</param> private static void SaveLineToFile(string line) { // Prevent saving editor logs. if (!Application.isPlaying) { return; } if (!Directory.Exists(LogsPath)) { Directory.CreateDirectory(LogsPath); } using (StreamWriter writer = File.AppendText(FilePath)) writer.WriteLine(line); #if UNITY_WEBGL && !UNITY_EDITOR WebGlUtils.SyncFiles(); #endif if (!deletedFilesOnceThisSession) { CleanUpOldFiles(); } }