// Load single data public T TryLoad <T>(string key, T defaultValue = default(T), bool isLocal = false) { ES3File targetFile = null; if (!isLocal) { targetFile = file; } else { targetFile = localFile; } if (targetFile == null) { return(defaultValue); } if (!targetFile.KeyExists(key)) { return(defaultValue); } try { return(targetFile.Load <T>(key, defaultValue)); } catch (System.Exception e) { UnityEngine.Debug.LogException(e); return(defaultValue); } }
public void TrySave <T>(string key, T value, bool isLocal = false) { ES3File targetFile = null; if (!isLocal) { targetFile = file; } else { targetFile = localFile; } if (targetFile == null) { return; } try { targetFile.Save <T>(key, value); } catch (System.Exception e) { UnityEngine.Debug.LogException(e); } }
private void SaveDatum(ES3File saveFile, BaseVariable variable) { string saveKey = variable.Name; if (variable is IntVariable intVar) { saveFile.Save <int>(saveKey, intVar.Value); } else if (variable is FloatVariable floatVar) { saveFile.Save <float>(saveKey, floatVar.Value); } else if (variable is StringVariable stringVar) { saveFile.Save <string>(saveKey, stringVar.Value); } else if (variable is BoolVariable boolVar) { saveFile.Save <bool>(saveKey, boolVar.Value); } else { Debug.LogWarning("[ScriptableObjectSaveSystem]" + " Save Type not implemented. " + "Rich is just being lazy."); } }
private void LoadState(ES3File saveFile) { foreach (var datum in savedVariables) { LoadDatum(saveFile, datum); } }
private void SaveState(ES3File saveFile) { foreach (var datum in savedVariables) { SaveDatum(saveFile, datum); } }
private IEnumerator DownloadFile(ES3File es3File, string user, string password, long timestamp) { Reset(); var form = CreateWWWForm(); form.AddField("apiKey", apiKey); form.AddField("getFile", es3File.settings.path); form.AddField("user", GetUser(user, password)); if (timestamp > 0) { form.AddField("timestamp", timestamp.ToString()); } using (var webRequest = UnityWebRequest.Post(url, form)) { yield return(SendWebRequest(webRequest)); if (!HandleError(webRequest, false)) { if (webRequest.downloadedBytes > 0) { es3File.Clear(); es3File.SaveRaw(webRequest.downloadHandler.data); } else { error = string.Format("File {0} was not found on the server.", es3File.settings.path); errorCode = 3; } } } isDone = true; }
public UniTask Initialize() { _playerDataLoader = DIResolver.GetObject <PlayerDataLoader>(); file = new ES3File(true); _isInitialized = true; return(UniTask.CompletedTask); }
internal static ES3File GetOrCreateCachedFile(ES3Settings settings) { ES3File cachedFile; if (!cachedFiles.TryGetValue(settings.path, out cachedFile)) { cachedFile = new ES3File(settings, false); cachedFiles.Add(settings.path, cachedFile); } // Settings might refer to the same file, but might have changed. // To account for this, we update the settings of the ES3File each time we access it. cachedFile.settings = settings; return(cachedFile); }
private void SaveEncryptedContent(string path) { var saveValue = new ES3Settings().encoding.GetBytes(this.SaveDataContent); var _oldSettings = new ES3Settings(ES3.EncryptionType.None, string.Empty); _oldSettings.location = ES3.Location.File; var file = new ES3File(saveValue, _oldSettings); ES3Settings fileSetting = new ES3Settings(path, Default_ES3Settings); file.settings = fileSetting; file.Sync(); }
public int LoadLegacySavesAndReturnTheNumberOfLegacySaves(int NumberOfRegularSaves) { string[] FilesInSavesDirectory = ES3.GetFiles("saves"); // get only .tung files and parse out the extension List <string> saves = new List <string>(); foreach (string file in FilesInSavesDirectory) { if (file.Substring(file.Length - 5, 5) == ".tung") // if the extension is .tung { saves.Add(file.Substring(0, file.Length - 5)); } } // generate the actual menu for (int i = 0; i < saves.Count; i++) { GameObject penis = Instantiate(SavedGamePrefab, Parent); penis.name = saves[i]; // penis.transform.localPosition = new Vector3(0, -10 + i * -110, 0); // old method was to set position here, broken in 2017.3. Details on why in UISaveFile UISaveFile v****a = penis.GetComponent <UISaveFile>(); v****a.FileName = saves[i]; v****a.Title.text = saves[i]; v****a.LegacySave = true; v****a.LegacyWarning.SetActive(true); v****a.SetPosition(i + NumberOfRegularSaves); // new method of setting position // to find the size of the file, we have to load an ES3File instance ES3File file = new ES3File("saves/" + saves[i] + ".tung"); v****a.Info.text = (file.Size() / 1024).ToString() + " kb | " // get file size + ES3.GetTimestamp("saves/" + saves[i] + ".tung").ToLocalTime() // get the local time of the last time the save was modified .ToString(); UISaveFiles.Add(v****a); } Debug.Log(saves.Count.ToString() + " legacy saves"); return(saves.Count); }
private void Action_LoadFileFromSaveDataPath() { _isSaveDataPathValid = File.Exists(_saveDataPath); if (_isSaveDataPathValid.HasValue && _isSaveDataPathValid.Value) { ES3File file = new ES3File(_saveDataPath, Default_ES3Settings); var contentBytes = file.LoadRawBytes(); using (MemoryStream stream = new MemoryStream(contentBytes)) { StreamReader reader = new StreamReader(ES3Stream.CreateStream(stream, Default_ES3Settings, ES3FileMode.Read)); SaveDataContent = reader.ReadToEnd(); } } var obj = JsonConvert.DeserializeObject(SaveDataContent); SaveDataContent = JsonConvert.SerializeObject(obj, Formatting.Indented); }
public bool IsSaveKeyExist(string key, bool isLocal = false) { ES3File targetFile = null; if (!isLocal) { targetFile = file; } else { targetFile = localFile; } if (targetFile == null) { return(false); } bool result = targetFile.KeyExists(key); return(result); }
/// <summary>Uploads a local file to the server, overwriting any existing file.</summary> /// <param name="es3File">An ES3File containing the data we want to upload.</param> /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param> public IEnumerator UploadFile(ES3File es3File, string user) { return(UploadFile(es3File.GetBytes(), es3File.settings, user, "", DateTimeToUnixTimestamp(DateTime.Now))); }
/// <summary>Downloads a file from the server and saves it locally, overwriting any existing local file. An error is returned if the file does not exist.</summary> /// <param name="es3File">The ES3File we want to load our data into. The filename in the settings of the ES3File will be used when downloading.</param> /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param> /// <param name="password">The password of the user this file belongs to.</param> public IEnumerator DownloadFile(ES3File es3File, string user, string password) { return(DownloadFile(es3File, user, password, 0)); }
/// <summary>Downloads a file from the server and saves it locally, overwriting any existing local file. An error is returned if the file does not exist.</summary> /// <param name="es3File">The ES3File we want to load our data into. The filename in the settings of the ES3File will be used when downloading.</param> /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param> public IEnumerator DownloadFile(ES3File es3File, string user) { return(DownloadFile(es3File, user, "", 0)); }
/// <summary>Downloads a file from the server and saves it locally, overwriting any existing local file. An error is returned if the file does not exist.</summary> /// <param name="es3File">The ES3File we want to load our data into. The filename in the settings of the ES3File will be used when downloading.</param> public IEnumerator DownloadFile(ES3File es3File) { return(DownloadFile(es3File, "", "", 0)); }
/// <summary>Uploads a local file to the server, overwriting any existing file.</summary> /// <param name="es3File">An ES3File containing the data we want to upload.</param> /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param> /// <param name="password">The password of the user this file belongs to.</param> public IEnumerator UploadFile(ES3File es3File, string user, string password) { return(UploadFile(es3File.LoadRawBytes(), es3File.settings, user, password, DateTimeToUnixTimestamp(DateTime.Now))); }
/// <summary>Uploads a local file to the server, overwriting any existing file.</summary> /// <param name="es3File">An ES3File containing the data we want to upload.</param> public IEnumerator UploadFile(ES3File es3File) { return(UploadFile(es3File.LoadRawBytes(), es3File.settings, "", "", DateTimeToUnixTimestamp(DateTime.Now))); }
internal ES3CacheWriter(ES3Settings settings, bool writeHeaderAndFooter, bool mergeKeys) : base(settings, writeHeaderAndFooter, mergeKeys) { es3File = new ES3File(settings); }
/// <summary> /// Erases save data from file. /// </summary> public void DeleteState(ES3File saveFile) => saveFile.DeleteKey(SaveID);
/// <summary> /// Loads <see cref="AState"/> state from saveFile. /// </summary> public abstract void LoadState(ES3File saveFile);
/// <summary> /// Saves <see cref="AState"/> to saveFile. /// </summary> public abstract void SaveState(ES3File saveFile);
/// <summary>Uploads a local file to the server, overwriting any existing file.</summary> /// <param name="es3File">An ES3File containing the data we want to upload.</param> public IEnumerator UploadFile(ES3File es3File) { return(UploadFile(es3File.LoadRawBytes(), es3File.settings, "", "")); }
/// <summary>Uploads a local file to the server, overwriting any existing file.</summary> /// <param name="es3File">An ES3File containing the data we want to upload.</param> /// <param name="user">The unique name of the user this file belongs to, if the file isn't globally accessible.</param> /// <param name="password">The password of the user this file belongs to.</param> public IEnumerator UploadFile(ES3File es3File, string user, string password) { return(UploadFile(es3File.LoadRawBytes(), es3File.settings, user, password)); }