public override void Load() { if (!PlatformAPISettings.Running) { return; } try { this.manifest = SaveFileManifest.Deserialize((IStorageMethod)this); } catch (NullReferenceException ex) { } catch (FormatException ex) { } if (this.manifest == null) { this.manifest = new SaveFileManifest(); this.manifest.Save((IStorageMethod)this, false); } else { this.deserialized = true; } }
public static SaveFileManifest DeserializeSafe(string data) { SaveFileManifest saveFileManifest = new SaveFileManifest(); string[] strArray = data.Split(new string[1] { "\r\n%------%" }, StringSplitOptions.RemoveEmptyEntries); if (strArray.Length <= 1) { return((SaveFileManifest)null); } string str = strArray[0]; saveFileManifest.Accounts.Clear(); for (int index = 1; index < strArray.Length; ++index) { try { SaveAccountData fromString = SaveAccountData.ParseFromString(strArray[index]); saveFileManifest.Accounts.Add(fromString); if (fromString.Username == str) { saveFileManifest.LastLoggedInUser = fromString; } } catch (FormatException ex) { } catch (NullReferenceException ex) { } } return(saveFileManifest); }
public override void Load() { FolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/My Games/Hacknet/Accounts/"; if (!Directory.Exists(FolderPath)) Directory.CreateDirectory(FolderPath); try { manifest = SaveFileManifest.Deserialize(this); } catch (FormatException ex) { manifest = null; } catch (NullReferenceException ex) { manifest = null; } if (manifest == null) { manifest = new SaveFileManifest(); manifest.Save(this); } else deserialized = true; }
public override void Load() { FolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/My Games/Hacknet/Accounts/"; if (!Directory.Exists(FolderPath)) { Directory.CreateDirectory(FolderPath); } try { manifest = SaveFileManifest.Deserialize(this); } catch (FormatException ex) { manifest = null; } catch (NullReferenceException ex) { manifest = null; } if (manifest == null) { manifest = new SaveFileManifest(); manifest.Save(this); } else { deserialized = true; } }
public static SaveFileManifest Deserialize(string data) { var saveFileManifest = new SaveFileManifest(); var strArray = data.Split(new string[1] { "\r\n%------%" }, StringSplitOptions.RemoveEmptyEntries); if (strArray.Length <= 1) { return(null); } var str = strArray[0]; saveFileManifest.Accounts.Clear(); for (var index = 1; index < strArray.Length; ++index) { var saveAccountData = SaveAccountData.ParseFromString(strArray[index]); saveFileManifest.Accounts.Add(saveAccountData); if (saveAccountData.Username == str) { saveFileManifest.LastLoggedInUser = saveAccountData; } } return(saveFileManifest); }
public virtual void UpdateDataFromOtherManager(IStorageMethod otherMethod) { string username = this.manifest.LastLoggedInUser.Username; SaveFileManifest saveManifest = otherMethod.GetSaveManifest(); for (int index1 = 0; index1 < saveManifest.Accounts.Count; ++index1) { SaveAccountData account1 = saveManifest.Accounts[index1]; bool flag = false; for (int index2 = 0; index2 < this.manifest.Accounts.Count; ++index2) { SaveAccountData account2 = this.manifest.Accounts[index2]; if (account2.Username == account1.Username) { flag = true; TimeSpan timeSpan = account1.LastWriteTime - account2.LastWriteTime; if (account1.LastWriteTime > account2.LastWriteTime && timeSpan.TotalSeconds > 5.0) { Stream fileReadStream = otherMethod.GetFileReadStream(account1.FileUsername); if (fileReadStream != null) { string data = Utils.ReadEntireContentsOfStream(fileReadStream); if (data.Length > 100) { this.WriteFileData(account2.FileUsername, data); } } break; } break; } } if (!flag) { Stream fileReadStream = otherMethod.GetFileReadStream(account1.FileUsername); if (fileReadStream != null) { string fileNameForUsername = SaveFileManager.GetSaveFileNameForUsername(account1.Username); this.manifest.AddUser(account1.Username, account1.Password, DateTime.UtcNow, fileNameForUsername); string data = Utils.ReadEntireContentsOfStream(fileReadStream); this.WriteFileData(fileNameForUsername, data); } } } for (int index = 0; index < this.manifest.Accounts.Count; ++index) { if (this.manifest.Accounts[index].Username == username) { this.manifest.LastLoggedInUser = this.manifest.Accounts[index]; } } if (this.manifest.LastLoggedInUser.Username == null && this.manifest.Accounts.Count > 0) { this.manifest.LastLoggedInUser = this.manifest.Accounts[0]; } this.manifest.Save((IStorageMethod)this, false); }
public override void Load() { if (!PlatformAPISettings.Running) return; manifest = SaveFileManifest.Deserialize(this); if (manifest == null) { manifest = new SaveFileManifest(); manifest.Save(this); } else deserialized = true; }
private static SaveFileManifest ReadOldSysemLocalSaveManifest() { var saveReadStream = RemoteSaveStorage.GetSaveReadStream("_accountsMeta", true); if (saveReadStream == null) { return(null); } var data = new StreamReader(saveReadStream).ReadToEnd(); saveReadStream.Close(); saveReadStream.Dispose(); return(SaveFileManifest.Deserialize(data)); }
private static SaveFileManifest ReadOldSysemLocalSaveManifest() { Stream saveReadStream = RemoteSaveStorage.GetSaveReadStream("_accountsMeta", true); if (saveReadStream == null) { return((SaveFileManifest)null); } string end = new StreamReader(saveReadStream).ReadToEnd(); saveReadStream.Close(); saveReadStream.Dispose(); return(SaveFileManifest.DeserializeSafe(end)); }
public override void Load() { if (!PlatformAPISettings.Running) { return; } manifest = SaveFileManifest.Deserialize(this); if (manifest == null) { manifest = new SaveFileManifest(); manifest.Save(this); } else { deserialized = true; } }
public static SaveFileManifest Deserialize(IStorageMethod storage) { if (!storage.FileExists("Accounts.txt")) { return((SaveFileManifest)null); } SaveFileManifest saveFileManifest = (SaveFileManifest)null; using (Stream fileReadStream = storage.GetFileReadStream("Accounts.txt")) { string end = new StreamReader(fileReadStream).ReadToEnd(); if (!string.IsNullOrEmpty(end.Trim())) { saveFileManifest = SaveFileManifest.Deserialize(end); } } return(saveFileManifest); }
public static SaveFileManifest Deserialize(string data) { var saveFileManifest = new SaveFileManifest(); var strArray = data.Split(new string[1] { "\r\n%------%" }, StringSplitOptions.RemoveEmptyEntries); if (strArray.Length <= 1) return null; var str = strArray[0]; saveFileManifest.Accounts.Clear(); for (var index = 1; index < strArray.Length; ++index) { var saveAccountData = SaveAccountData.ParseFromString(strArray[index]); saveFileManifest.Accounts.Add(saveAccountData); if (saveAccountData.Username == str) saveFileManifest.LastLoggedInUser = saveAccountData; } return saveFileManifest; }
public static void DeleteUser(string username) { for (int index1 = 0; index1 < SaveFileManager.StorageMethods.Count; ++index1) { SaveFileManifest saveManifest = SaveFileManager.StorageMethods[index1].GetSaveManifest(); for (int index2 = 0; index2 < saveManifest.Accounts.Count; ++index2) { if (saveManifest.Accounts[index2].Username == username) { saveManifest.Accounts.RemoveAt(index2); --index2; } } if (saveManifest.LastLoggedInUser.Username == username) { saveManifest.LastLoggedInUser = saveManifest.Accounts.Count <= 0 ? new SaveAccountData() : saveManifest.Accounts[0]; } saveManifest.Save(SaveFileManager.StorageMethods[index1], true); } }
public OldSystemStorageMethod(SaveFileManifest manifest) { this.manifest = manifest; }
public override void Load() { string platform = SDL.SDL_GetPlatform(); if (platform.Equals("Linux")) { this.FolderPath = Environment.GetEnvironmentVariable("XDG_DATA_HOME"); if (string.IsNullOrEmpty(this.FolderPath)) { this.FolderPath = Environment.GetEnvironmentVariable("HOME"); if (string.IsNullOrEmpty(this.FolderPath)) { this.FolderPath = "./"; } else { this.FolderPath += "/.local/share/Hacknet/Accounts/"; } } else { this.FolderPath += "/Hacknet/Accounts/"; } } else if (platform.Equals("Mac OS X")) { this.FolderPath = Environment.GetEnvironmentVariable("HOME"); if (string.IsNullOrEmpty(this.FolderPath)) { this.FolderPath = "./"; } else { this.FolderPath += "/Library/Application Support/Hacknet/Accounts/"; } } else { if (!platform.Equals("Windows")) { throw new NotSupportedException("Unhandled SDL2 platform!"); } this.FolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/My Games/Hacknet/Accounts/"; } try { if (!Directory.Exists(this.FullFolderPath)) { Directory.CreateDirectory(this.FullFolderPath); } } catch (UnauthorizedAccessException ex) { Utils.AppendToErrorFile("Local Documents Storage load error : Insufficient permissions for folder access.\r\n" + Utils.GenerateReportFromException((Exception)ex)); this.FolderPath = "Accounts/"; MainMenu.AccumErrors = MainMenu.AccumErrors + "\r\nERROR: Local Documents Storage Folder is refusing access. Saving accounts to:\r\n" + Path.GetFullPath(this.FolderPath); } try { this.manifest = SaveFileManifest.Deserialize((IStorageMethod)this); } catch (FormatException ex) { this.manifest = (SaveFileManifest)null; Console.WriteLine("Local Save Manifest Corruption: " + Utils.GenerateReportFromException((Exception)ex)); } catch (NullReferenceException ex) { this.manifest = (SaveFileManifest)null; Console.WriteLine("Local Save Manifest Corruption: " + Utils.GenerateReportFromException((Exception)ex)); } if (this.manifest == null) { this.manifest = new SaveFileManifest(); this.manifest.Save((IStorageMethod)this, true); } else { this.deserialized = true; } }
public static void UpdateStorageMethodsFromSourcesToLatest() { var num = -1; for (var index = 0; index < StorageMethods.Count; ++index) { if (StorageMethods[index].DidDeserialize) { num = index; break; } } if (num == -1) { var saveFileManifest1 = ReadOldSysemSteamCloudSaveManifest(); var saveFileManifest2 = ReadOldSysemLocalSaveManifest(); if (saveFileManifest1 == null && saveFileManifest2 == null) { Console.WriteLine("New Game Detected!"); } else { var manifest = new SaveFileManifest(); var utcNow = DateTime.UtcNow; var flag = false; if (saveFileManifest2 != null) { for (var index = 0; index < saveFileManifest2.Accounts.Count; ++index) { var str = RemoteSaveStorage.Standalone_FolderPath + RemoteSaveStorage.BASE_SAVE_FILE_NAME + saveFileManifest2.Accounts[index].FileUsername + RemoteSaveStorage.SAVE_FILE_EXT; if (File.Exists(str)) { var fileInfo = new FileInfo(str); if (fileInfo.Length > 100L) { manifest.AddUser(saveFileManifest2.Accounts[index].Username, saveFileManifest2.Accounts[index].Password, fileInfo.LastWriteTimeUtc, str); } } } for (var index = 0; index < manifest.Accounts.Count; ++index) { if (saveFileManifest2.LastLoggedInUser.Username == manifest.Accounts[index].Username) { manifest.LastLoggedInUser = manifest.Accounts[index]; } } if (manifest.LastLoggedInUser.Username == null) { var index = manifest.Accounts.Count - 1; if (index >= 0) { manifest.LastLoggedInUser = manifest.Accounts[index]; flag = true; } } } if (saveFileManifest1 != null) { for (var index1 = 0; index1 < saveFileManifest1.Accounts.Count; ++index1) { try { var str = RemoteSaveStorage.BASE_SAVE_FILE_NAME + saveFileManifest1.Accounts[index1].FileUsername + RemoteSaveStorage.SAVE_FILE_EXT; if (SteamRemoteStorage.FileExists(str)) { if (SteamRemoteStorage.GetFileSize(str) > 100) { var index2 = -1; for (var index3 = 0; index3 < manifest.Accounts.Count; ++index3) { if (manifest.Accounts[index3].Username == saveFileManifest1.Accounts[index1].Username) { index2 = index3; break; } } if (index2 >= 0) { if (new DateTime(1970, 1, 1, 0, 0, 0) + TimeSpan.FromSeconds(SteamRemoteStorage.GetFileTimestamp(str)) > manifest.Accounts[index2].LastWriteTime) { var saveReadStream = RemoteSaveStorage.GetSaveReadStream(str, false); if (saveReadStream != null) { var saveData = new StreamReader(saveReadStream).ReadToEnd(); saveReadStream.Close(); saveReadStream.Dispose(); RemoteSaveStorage.WriteSaveData(saveData, str, true); } else { MainMenu.AccumErrors = MainMenu.AccumErrors + "WARNING: Cloud account " + saveFileManifest1.Accounts[index1].Username + " failed to convert over to new secure account system.\nRestarting your computer and Hacknet may resolve this issue."; } } } else { var filepath = RemoteSaveStorage.Standalone_FolderPath + RemoteSaveStorage.BASE_SAVE_FILE_NAME + saveFileManifest1.Accounts[index1].Username + RemoteSaveStorage.SAVE_FILE_EXT; var saveReadStream = RemoteSaveStorage.GetSaveReadStream( saveFileManifest1.Accounts[index1].Username, false); if (saveReadStream != null) { RemoteSaveStorage.WriteSaveData( Utils.ReadEntireContentsOfStream(saveReadStream), saveFileManifest1.Accounts[index1].Username, true); manifest.AddUser(saveFileManifest1.Accounts[index1].Username, saveFileManifest1.Accounts[index1].Password, utcNow, filepath); } else { MainMenu.AccumErrors = MainMenu.AccumErrors + "WARNING: Cloud account " + saveFileManifest1.Accounts[index1].Username + " failed to convert over to new secure account system.\nRestarting your computer and Hacknet may resolve this issue."; } } } } } catch (Exception ex) { MainMenu.AccumErrors = MainMenu.AccumErrors + "WARNING: Error upgrading account #" + (index1 + 1) + ":\r\n" + Utils.GenerateReportFromException(ex); if (!HasSentErrorReport) { var extraData = "cloudAccounts: " + (saveFileManifest1 == null ? "NULL" : string.Concat(saveFileManifest1.Accounts.Count)) + " vs localAccounts " + (saveFileManifest2 == null ? "NULL" : string.Concat(saveFileManifest2.Accounts.Count)); Utils.SendThreadedErrorReport(ex, "AccountUpgrade_Error", extraData); HasSentErrorReport = true; } } } if (flag) { for (var index = 0; index < manifest.Accounts.Count; ++index) { if (saveFileManifest2.LastLoggedInUser.Username == manifest.Accounts[index].Username) { manifest.LastLoggedInUser = manifest.Accounts[index]; } } } } var systemStorageMethod = new OldSystemStorageMethod(manifest); for (var index = 0; index < StorageMethods.Count; ++index) { StorageMethods[index].UpdateDataFromOtherManager(systemStorageMethod); } } } else { for (var index = 1; index < StorageMethods.Count; ++index) { StorageMethods[0].UpdateDataFromOtherManager(StorageMethods[index]); } } }
public static void UpdateStorageMethodsFromSourcesToLatest() { var num = -1; for (var index = 0; index < StorageMethods.Count; ++index) { if (StorageMethods[index].DidDeserialize) { num = index; break; } } if (num == -1) { var saveFileManifest1 = ReadOldSysemSteamCloudSaveManifest(); var saveFileManifest2 = ReadOldSysemLocalSaveManifest(); if (saveFileManifest1 == null && saveFileManifest2 == null) { Console.WriteLine("New Game Detected!"); } else { var manifest = new SaveFileManifest(); var utcNow = DateTime.UtcNow; var flag = false; if (saveFileManifest2 != null) { for (var index = 0; index < saveFileManifest2.Accounts.Count; ++index) { var str = RemoteSaveStorage.Standalone_FolderPath + RemoteSaveStorage.BASE_SAVE_FILE_NAME + saveFileManifest2.Accounts[index].FileUsername + RemoteSaveStorage.SAVE_FILE_EXT; if (File.Exists(str)) { var fileInfo = new FileInfo(str); if (fileInfo.Length > 100L) manifest.AddUser(saveFileManifest2.Accounts[index].Username, saveFileManifest2.Accounts[index].Password, fileInfo.LastWriteTimeUtc, str); } } for (var index = 0; index < manifest.Accounts.Count; ++index) { if (saveFileManifest2.LastLoggedInUser.Username == manifest.Accounts[index].Username) manifest.LastLoggedInUser = manifest.Accounts[index]; } if (manifest.LastLoggedInUser.Username == null) { var index = manifest.Accounts.Count - 1; if (index >= 0) { manifest.LastLoggedInUser = manifest.Accounts[index]; flag = true; } } } if (saveFileManifest1 != null) { for (var index1 = 0; index1 < saveFileManifest1.Accounts.Count; ++index1) { try { var str = RemoteSaveStorage.BASE_SAVE_FILE_NAME + saveFileManifest1.Accounts[index1].FileUsername + RemoteSaveStorage.SAVE_FILE_EXT; if (SteamRemoteStorage.FileExists(str)) { if (SteamRemoteStorage.GetFileSize(str) > 100) { var index2 = -1; for (var index3 = 0; index3 < manifest.Accounts.Count; ++index3) { if (manifest.Accounts[index3].Username == saveFileManifest1.Accounts[index1].Username) { index2 = index3; break; } } if (index2 >= 0) { if (new DateTime(1970, 1, 1, 0, 0, 0) + TimeSpan.FromSeconds(SteamRemoteStorage.GetFileTimestamp(str)) > manifest.Accounts[index2].LastWriteTime) { var saveReadStream = RemoteSaveStorage.GetSaveReadStream(str, false); if (saveReadStream != null) { var saveData = new StreamReader(saveReadStream).ReadToEnd(); saveReadStream.Close(); saveReadStream.Dispose(); RemoteSaveStorage.WriteSaveData(saveData, str, true); } else MainMenu.AccumErrors = MainMenu.AccumErrors + "WARNING: Cloud account " + saveFileManifest1.Accounts[index1].Username + " failed to convert over to new secure account system.\nRestarting your computer and Hacknet may resolve this issue."; } } else { var filepath = RemoteSaveStorage.Standalone_FolderPath + RemoteSaveStorage.BASE_SAVE_FILE_NAME + saveFileManifest1.Accounts[index1].Username + RemoteSaveStorage.SAVE_FILE_EXT; var saveReadStream = RemoteSaveStorage.GetSaveReadStream( saveFileManifest1.Accounts[index1].Username, false); if (saveReadStream != null) { RemoteSaveStorage.WriteSaveData( Utils.ReadEntireContentsOfStream(saveReadStream), saveFileManifest1.Accounts[index1].Username, true); manifest.AddUser(saveFileManifest1.Accounts[index1].Username, saveFileManifest1.Accounts[index1].Password, utcNow, filepath); } else MainMenu.AccumErrors = MainMenu.AccumErrors + "WARNING: Cloud account " + saveFileManifest1.Accounts[index1].Username + " failed to convert over to new secure account system.\nRestarting your computer and Hacknet may resolve this issue."; } } } } catch (Exception ex) { MainMenu.AccumErrors = MainMenu.AccumErrors + "WARNING: Error upgrading account #" + (index1 + 1) + ":\r\n" + Utils.GenerateReportFromException(ex); if (!HasSentErrorReport) { var extraData = "cloudAccounts: " + (saveFileManifest1 == null ? "NULL" : string.Concat(saveFileManifest1.Accounts.Count)) + " vs localAccounts " + (saveFileManifest2 == null ? "NULL" : string.Concat(saveFileManifest2.Accounts.Count)); Utils.SendThreadedErrorReport(ex, "AccountUpgrade_Error", extraData); HasSentErrorReport = true; } } } if (flag) { for (var index = 0; index < manifest.Accounts.Count; ++index) { if (saveFileManifest2.LastLoggedInUser.Username == manifest.Accounts[index].Username) manifest.LastLoggedInUser = manifest.Accounts[index]; } } } var systemStorageMethod = new OldSystemStorageMethod(manifest); for (var index = 0; index < StorageMethods.Count; ++index) StorageMethods[index].UpdateDataFromOtherManager(systemStorageMethod); } } else { for (var index = 1; index < StorageMethods.Count; ++index) StorageMethods[0].UpdateDataFromOtherManager(StorageMethods[index]); } }