public virtual void UpdateDataFromOtherManager(IStorageMethod otherMethod)
        {
            var str          = manifest.LastLoggedInUser.Username;
            var saveManifest = otherMethod.GetSaveManifest();

            for (var index1 = 0; index1 < saveManifest.Accounts.Count; ++index1)
            {
                var saveAccountData1 = saveManifest.Accounts[index1];
                var flag             = false;
                for (var index2 = 0; index2 < manifest.Accounts.Count; ++index2)
                {
                    var saveAccountData2 = manifest.Accounts[index2];
                    if (saveAccountData2.Username == saveAccountData1.Username)
                    {
                        flag = true;
                        var timeSpan = saveAccountData1.LastWriteTime - saveAccountData2.LastWriteTime;
                        if (saveAccountData1.LastWriteTime > saveAccountData2.LastWriteTime &&
                            timeSpan.TotalSeconds > 5.0)
                        {
                            var fileReadStream = otherMethod.GetFileReadStream(saveAccountData1.FileUsername);
                            if (fileReadStream != null)
                            {
                                var data = Utils.ReadEntireContentsOfStream(fileReadStream);
                                if (data.Length > 100)
                                {
                                    WriteFileData(saveAccountData2.FileUsername, data);
                                }
                            }
                        }
                        break;
                    }
                }
                if (!flag)
                {
                    var fileReadStream = otherMethod.GetFileReadStream(saveAccountData1.FileUsername);
                    if (fileReadStream != null)
                    {
                        var fileNameForUsername = SaveFileManager.GetSaveFileNameForUsername(saveAccountData1.Username);
                        manifest.AddUser(saveAccountData1.Username, saveAccountData1.Password, DateTime.UtcNow,
                                         fileNameForUsername);
                        var data = Utils.ReadEntireContentsOfStream(fileReadStream);
                        WriteFileData(fileNameForUsername, data);
                    }
                }
            }
            for (var index = 0; index < manifest.Accounts.Count; ++index)
            {
                if (manifest.Accounts[index].Username == str)
                {
                    manifest.LastLoggedInUser = manifest.Accounts[index];
                }
            }
            if (manifest.LastLoggedInUser.Username == null && manifest.Accounts.Count > 0)
            {
                manifest.LastLoggedInUser = manifest.Accounts[0];
            }
            manifest.Save(this);
        }
Example #2
0
        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);
        }
Example #3
0
 public static void Init(bool needsOtherSourcesUpdate = true)
 {
     SaveFileManager.StorageMethods.Clear();
     SaveFileManager.StorageMethods.Add((IStorageMethod) new LocalDocumentsStorageMethod());
     if (PlatformAPISettings.Running && PlatformAPISettings.RemoteStorageRunning)
     {
         SaveFileManager.StorageMethods.Add((IStorageMethod) new SteamCloudStorageMethod());
     }
     for (int index = 0; index < SaveFileManager.StorageMethods.Count; ++index)
     {
         SaveFileManager.StorageMethods[index].Load();
     }
     if (!needsOtherSourcesUpdate)
     {
         return;
     }
     SaveFileManager.UpdateStorageMethodsFromSourcesToLatest();
 }
Example #4
0
        public static void WriteSaveData(string saveData, string playerID)
        {
            DateTime utcNow = DateTime.UtcNow;

            for (int index = 0; index < SaveFileManager.StorageMethods.Count; ++index)
            {
                try
                {
                    SaveFileManager.StorageMethods[index].WriteSaveFileData(SaveFileManager.GetSaveFileNameForUsername(playerID), playerID, saveData, utcNow);
                }
                catch (Exception ex)
                {
                    Utils.AppendToErrorFile("Error writing save data for user : "******"\r\n" + Utils.GenerateReportFromException(ex));
                }
            }
            if (SettingsLoader.hasEverSaved)
            {
                return;
            }
            SettingsLoader.hasEverSaved = true;
            SettingsLoader.writeStatusFile();
        }
Example #5
0
        public static void UpdateStorageMethodsFromSourcesToLatest()
        {
            int num = -1;

            for (int index = 0; index < SaveFileManager.StorageMethods.Count; ++index)
            {
                if (SaveFileManager.StorageMethods[index].DidDeserialize)
                {
                    num = index;
                    break;
                }
            }
            if (num == -1)
            {
                SaveFileManifest saveFileManifest1 = SaveFileManager.ReadOldSysemSteamCloudSaveManifest();
                SaveFileManifest saveFileManifest2 = SaveFileManager.ReadOldSysemLocalSaveManifest();
                if (saveFileManifest1 == null && saveFileManifest2 == null)
                {
                    Console.WriteLine("New Game Detected!");
                }
                else
                {
                    SaveFileManifest manifest = new SaveFileManifest();
                    DateTime         utcNow   = DateTime.UtcNow;
                    bool             flag     = false;
                    if (saveFileManifest2 != null)
                    {
                        for (int index = 0; index < saveFileManifest2.Accounts.Count; ++index)
                        {
                            string str = RemoteSaveStorage.Standalone_FolderPath + RemoteSaveStorage.BASE_SAVE_FILE_NAME + saveFileManifest2.Accounts[index].FileUsername + RemoteSaveStorage.SAVE_FILE_EXT;
                            if (File.Exists(str))
                            {
                                FileInfo fileInfo = new FileInfo(str);
                                if (fileInfo.Length > 100L)
                                {
                                    manifest.AddUser(saveFileManifest2.Accounts[index].Username, saveFileManifest2.Accounts[index].Password, fileInfo.LastWriteTimeUtc, str);
                                }
                            }
                        }
                        for (int 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)
                        {
                            int index = manifest.Accounts.Count - 1;
                            if (index >= 0)
                            {
                                manifest.LastLoggedInUser = manifest.Accounts[index];
                                flag = true;
                            }
                        }
                    }
                    if (saveFileManifest1 != null)
                    {
                        for (int index1 = 0; index1 < saveFileManifest1.Accounts.Count; ++index1)
                        {
                            try
                            {
                                string str = RemoteSaveStorage.BASE_SAVE_FILE_NAME + saveFileManifest1.Accounts[index1].FileUsername + RemoteSaveStorage.SAVE_FILE_EXT;
                                if (SteamRemoteStorage.FileExists(str))
                                {
                                    if (SteamRemoteStorage.GetFileSize(str) > 100)
                                    {
                                        int index2 = -1;
                                        for (int 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((double)SteamRemoteStorage.GetFileTimestamp(str)) > manifest.Accounts[index2].LastWriteTime)
                                            {
                                                Stream saveReadStream = RemoteSaveStorage.GetSaveReadStream(str, false);
                                                if (saveReadStream != null)
                                                {
                                                    string end = new StreamReader(saveReadStream).ReadToEnd();
                                                    saveReadStream.Close();
                                                    saveReadStream.Dispose();
                                                    RemoteSaveStorage.WriteSaveData(end, 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
                                        {
                                            string filepath       = RemoteSaveStorage.Standalone_FolderPath + RemoteSaveStorage.BASE_SAVE_FILE_NAME + saveFileManifest1.Accounts[index1].Username + RemoteSaveStorage.SAVE_FILE_EXT;
                                            Stream 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 #" + (object)(index1 + 1) + ":\r\n" + Utils.GenerateReportFromException(ex);
                                if (!SaveFileManager.HasSentErrorReport)
                                {
                                    string extraData = "cloudAccounts: " + (saveFileManifest1 == null ? "NULL" : string.Concat((object)saveFileManifest1.Accounts.Count)) + " vs localAccounts " + (saveFileManifest2 == null ? "NULL" : string.Concat((object)saveFileManifest2.Accounts.Count));
                                    Utils.SendThreadedErrorReport(ex, "AccountUpgrade_Error", extraData);
                                    SaveFileManager.HasSentErrorReport = true;
                                }
                            }
                        }
                        if (flag)
                        {
                            for (int index = 0; index < manifest.Accounts.Count; ++index)
                            {
                                if (saveFileManifest2.LastLoggedInUser.Username == manifest.Accounts[index].Username)
                                {
                                    manifest.LastLoggedInUser = manifest.Accounts[index];
                                }
                            }
                        }
                    }
                    OldSystemStorageMethod systemStorageMethod = new OldSystemStorageMethod(manifest);
                    for (int index = 0; index < SaveFileManager.StorageMethods.Count; ++index)
                    {
                        SaveFileManager.StorageMethods[index].UpdateDataFromOtherManager((IStorageMethod)systemStorageMethod);
                    }
                }
            }
            else
            {
                for (int index = 1; index < SaveFileManager.StorageMethods.Count; ++index)
                {
                    SaveFileManager.StorageMethods[0].UpdateDataFromOtherManager(SaveFileManager.StorageMethods[index]);
                }
            }
        }
Example #6
0
        public static bool AddUser(string username, string pass)
        {
            DateTime utcNow = DateTime.UtcNow;

            for (int index = 0; index < SaveFileManager.StorageMethods.Count; ++index)
            {
                try
                {
                    if (!SaveFileManager.StorageMethods[index].GetSaveManifest().AddUser(username, pass, utcNow, SaveFileManager.GetSaveFileNameForUsername(username)))
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    Utils.AppendToErrorFile("Error creating user : "******"\r\n" + Utils.GenerateReportFromException(ex));
                    return(false);
                }
            }
            return(true);
        }