Пример #1
0
        /// <summary>
        /// Saves any data that we need to persist between app instances
        /// </summary>
        private void SavePersistentData()
        {
            if (this.Shared)
            {
                return;
            }

            var data = new PersistentData()
            {
                Character      = this.Character
                , RefreshToken = this.Token.RefreshToken
                , Cookie       = this.Cookie
            };

            data.Save();
        }
Пример #2
0
        /// <summary>
        /// Loads persistent data from storage.
        /// </summary>
        /// <returns></returns>
        public static PersistentData Load()
        {
            try
            {
                PersistentData data     = null;
                var            pathData = Path.Combine(Application.UserAppDataPath, Filename);

                if (!File.Exists(pathData))
                {
                    return(data);
                }

                var cipherData = File.ReadAllBytes(pathData);

                var entropy    = cipherData.Take(20).ToArray();
                var cipherText = cipherData.Skip(20).ToArray();

                var plainText = ProtectedData.Unprotect(cipherText, entropy, DataProtectionScope.CurrentUser);

                using (var stream = new MemoryStream(plainText))
                {
                    var formatter = new BinaryFormatter();
                    data = formatter.Deserialize(stream) as PersistentData;
                }

                return(data);
            }
            catch (CryptographicException)
            {
                // we should be able to continue
                return(null);
            }
            catch (Exception)
            {
                throw;
            }
        }