Exemplo n.º 1
0
        private async Task SaveUserDataCoreAsync(string filePath)
        {
            string passwordBackup = UserPassword;

            UserPassword = HashString.SHA(UserPassword);
            await Task.Run(() => {
                lock (_userdataFileLocker) {
                    base.SaveToFile(filePath);
                }
            });

            UserPassword = passwordBackup;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建默认数据
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static void CreateEmptyUserData(string filePath)
        {
            APMCore.Model.UserData source = new APMCore.Model.UserData()
            {
                Avatar       = UserAvatarFileName,
                UserName     = "******",
                UserPassword = HashString.SHA("000000"),
                Description  = "CatCatHead",
                ColumnSize   = 3,
                IsEditMode   = false,
                Storage      = UserStorageFileName
            };

            UserData userData = new UserData(source);

            userData.SaveToFile(filePath);

            APMCore.ViewModel.StorageBase.CreateEmptyStorage(UserStorageFileName);
            File.Copy(UserStorageFileName, RuntimeStorageFileName);
            FileEncrypter encrypter = new FileEncrypter(new AESEncrypter("000000"));

            encrypter.Encrypt(RuntimeStorageFileName);
            File.Copy(RuntimeStorageFileName, UserStorageFileName, true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 打开储存库
        /// </summary>
        /// <param name="password">密码</param>
        public async Task OpenStorageAsync(string password)
        {
            if (HashString.SHA(password) != UserPassword)
            {
                throw new IncorrectUserPasswordException();
            }

            await DecryptDataBaseAsync(password);

            _dataBase = GetStorageConnection(RuntimeStorageFileName);
            lock (_storageFileLocker) {
                _dataBase.Open();
            }
            Storage = new Storage(_dataBase);

            try {
                await Storage.ReloadAsync();
            }
            catch {
                throw new UnableToLoadStorageException();
            }

            UserPassword = password;
        }