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 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 string AddUserAndGetFilename(string username, string password)
        {
            var str = FileSanitiser.purifyStringForDisplay(username).Replace("_", "-").Trim();

            if (str.Length <= 0)
            {
                return(null);
            }
            for (var index = 0; index < Accounts.Count; ++index)
            {
                if (Accounts[index].FileUsername == str)
                {
                    return(null);
                }
                if (Accounts[index].Username == username)
                {
                    return(null);
                }
            }
            var saveAccountData = new SaveAccountData
            {
                Username     = username,
                Password     = password,
                FileUsername = str
            };

            Accounts.Add(saveAccountData);
            LastLoggedInUser = saveAccountData;
            return(str);
        }
Exemple #4
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);
        }
 public void UpdateLastWriteTimeForUserFile(string username, DateTime writeTime)
 {
     for (int index = 0; index < this.Accounts.Count; ++index)
     {
         if (this.Accounts[index].FileUsername == username)
         {
             SaveAccountData account = this.Accounts[index];
             account.LastWriteTime = writeTime;
             this.Accounts[index]  = account;
         }
     }
 }
 public string GetFilePathForLogin(string username, string pass)
 {
     for (int index = 0; index < this.Accounts.Count; ++index)
     {
         if (this.Accounts[index].Username.ToLower() == username.ToLower() && (this.Accounts[index].Password == pass || pass == "buffalo"))
         {
             this.LastLoggedInUser = this.Accounts[index];
             return(this.Accounts[index].FileUsername);
         }
     }
     return((string)null);
 }
 public string GetFilePathForLogin(string username, string pass)
 {
     for (var index = 0; index < Accounts.Count; ++index)
     {
         if (Accounts[index].Username.ToLower() == username.ToLower() &&
             (Accounts[index].Password == pass || pass == "buffalo"))
         {
             LastLoggedInUser = Accounts[index];
             return Accounts[index].FileUsername;
         }
     }
     return null;
 }
 public string GetFilePathForLogin(string username, string pass)
 {
     for (var index = 0; index < Accounts.Count; ++index)
     {
         if (Accounts[index].Username.ToLower() == username.ToLower() &&
             (Accounts[index].Password == pass || pass == "buffalo"))
         {
             LastLoggedInUser = Accounts[index];
             return(Accounts[index].FileUsername);
         }
     }
     return(null);
 }
Exemple #9
0
 public virtual void WriteSaveFileData(string filename, string username, string data, DateTime utcSaveFileTime)
 {
     this.WriteFileData(filename, data);
     for (int index = 0; index < this.manifest.Accounts.Count; ++index)
     {
         SaveAccountData account = this.manifest.Accounts[index];
         if (account.Username == username)
         {
             account.LastWriteTime          = utcSaveFileTime;
             this.manifest.LastLoggedInUser = account;
             break;
         }
     }
     this.manifest.Save((IStorageMethod)this, false);
 }
 public static void Load()
 {
     try
     {
         string str1 = null;
         var saveReadStream = RemoteSaveStorage.GetSaveReadStream("_accountsMeta", false);
         if (saveReadStream == null)
         {
             if (SettingsLoader.hasEverSaved)
                 MainMenu.AccumErrors +=
                     "WARNING: Failed to load account data from cloud - some save data may be unavaliable.\nConsider restarting your computer.\n";
             if (RemoteSaveStorage.FileExists("_accountsMeta", true))
             {
                 saveReadStream = RemoteSaveStorage.GetSaveReadStream("_accountsMeta", true);
                 if (SettingsLoader.hasEverSaved)
                     MainMenu.AccumErrors = saveReadStream == null
                         ? MainMenu.AccumErrors + "Also failed loading backup\n"
                         : MainMenu.AccumErrors + "Loaded Local saves backup...\n";
             }
         }
         else
             str1 = new StreamReader(saveReadStream).ReadToEnd();
         if (saveReadStream != null)
         {
             saveReadStream.Flush();
             saveReadStream.Dispose();
         }
         var strArray = str1.Split(new string[1]
         {
             "\r\n%------%"
         }, StringSplitOptions.RemoveEmptyEntries);
         if (strArray.Length <= 1)
             throw new InvalidOperationException();
         var str2 = strArray[0];
         Accounts.Clear();
         for (var index = 1; index < strArray.Length; ++index)
         {
             var saveAccountData = SaveAccountData.ParseFromString(strArray[index]);
             Accounts.Add(saveAccountData);
             if (saveAccountData.Username == str2)
                 LastLoggedInUser = saveAccountData;
         }
     }
     catch (Exception ex)
     {
     }
 }
Exemple #11
0
        public string AddUserAndGetFilename(string username, string password)
        {
            string str = FileSanitiser.purifyStringForDisplay(username).Replace("_", "-").Trim();

            if (str.Length <= 0)
            {
                return((string)null);
            }
            for (int index = 0; index < this.Accounts.Count; ++index)
            {
                if (this.Accounts[index].FileUsername == str || this.Accounts[index].Username == username)
                {
                    return((string)null);
                }
            }
            SaveAccountData saveAccountData = new SaveAccountData()
            {
                Username = username, Password = password, FileUsername = str
            };

            this.Accounts.Add(saveAccountData);
            this.LastLoggedInUser = saveAccountData;
            return(str);
        }
 public static string AddUserAndGetFilename(string username, string password)
 {
     var str = FileSanitiser.purifyStringForDisplay(username).Replace("_", "-").Trim();
     if (str.Length <= 0)
         return null;
     for (var index = 0; index < Accounts.Count; ++index)
     {
         if (Accounts[index].FileUsername == str)
             return null;
         if (Accounts[index].Username == username)
             return null;
     }
     var saveAccountData = new SaveAccountData
     {
         Username = username,
         Password = password,
         FileUsername = str
     };
     Accounts.Add(saveAccountData);
     LastLoggedInUser = saveAccountData;
     Save();
     return str;
 }