/// <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(); } }
/// <summary> /// Process the commands. /// </summary> /// <param name="command">Command given.</param> /// <param name="parameters">Parameters.</param> // ReSharper disable once CyclomaticComplexity protected override bool ProcessCommand(string command, params string[] parameters) { switch (command) { case "Exit": if (parameters.Length != 0) { WrongParamNumber(command, parameters.Length, 0); return(false); } Utils.CloseGame(); break; case "Log": if (parameters.Length != 1) { WrongParamNumber(command, parameters.Length, 1); return(false); } Logger.LogInfo(parameters[0], ModuleName); break; case "Save": { if (parameters.Length != 0) { WrongParamNumber(command, parameters.Length, 0); return(false); } SavegameManager.Instance.SaveGame(); break; } case "Load": { if (parameters.Length != 0) { WrongParamNumber(command, parameters.Length, 0); return(false); } SavegameManager.Instance.LoadGame(); break; } case "GetVersion": { if (parameters.Length != 0) { WrongParamNumber(command, parameters.Length, 0); return(false); } Logger.LogInfo("Game version: " + Version.FullVersion, this); break; } case "GetLanguage": { if (parameters.Length != 0) { WrongParamNumber(command, parameters.Length, 0); return(false); } Logger.LogInfo("Current language: " + LocalizationManager.Instance.CurrentLanguageName, this); break; } case "SetLanguage": { if (parameters.Length != 1) { WrongParamNumber(command, parameters.Length, 1); return(false); } if (uint.TryParse(parameters[0], out uint newLanguage)) { LocalizationManager.Instance.CurrentLanguage = newLanguage; } else { WrongParams(command); } break; } #region WebGlCommands #pragma warning disable 162 // ReSharper disable HeuristicUnreachableCode case "DownloadLogFile": { #if !UNITY_WEBGL || UNITY_EDITOR Logger.LogError("Run this command only on web.", ModuleName); return(false); #endif if (parameters.Length != 0) { WrongParamNumber(command, parameters.Length, 0); return(false); } #if UNITY_WEBGL WebGlUtils.DownloadFile(Logger.FilePath); #endif break; } case "SaveAndDownload": { #if !UNITY_WEBGL || UNITY_EDITOR Logger.LogError("Run this command only on web.", ModuleName); return(false); #endif if (parameters.Length != 0) { WrongParamNumber(command, parameters.Length, 0); return(false); } #if UNITY_WEBGL WebGlUtils.SaveAndDownloadSaveGame(); #endif break; } case "UploadSave": { #if !UNITY_WEBGL || UNITY_EDITOR Logger.LogError("Run this command only on web.", ModuleName); return(false); #endif if (parameters.Length != 0) { WrongParamNumber(command, parameters.Length, 0); return(false); } #if UNITY_WEBGL WebGlUtils.UploadAndLoadSavegame(); #endif break; } // ReSharper enable HeuristicUnreachableCode #pragma warning restore 162 #endregion default: return(false); } return(true); }