Exemplo n.º 1
0
        /// <summary>
        /// Asynchronous save of ObservableCollection<AccountList>.
        /// </summary>
        public async void SaveAccountList()
        {
            if (AccountsList == null)
            {
                return;
            }

            //remove all empty rows.
            for (int i = AccountsList.Count - 1; i >= 0; i--)
            {
                if (AccountsList[i].IsEmpty)
                {
                    AccountsList.RemoveAt(i);
                }
            }
            KeyFile key;

            if (File.Exists(settings.keyLocation))
            {
                //load key from appdata.
                key = await CryptoTools.LoadStoredKeyFile(settings.keyLocation);
            }
            else
            {
                //create new keyfile if none created yet in appdata.
                key = await CryptoTools.CreateStoredKeyFile(settings.keyLocation);
            }
            //encrypt accountlist into byte array.
            byte[] listAsBytes = CryptoTools.EncryptData(key.key, key.IV, AccountsList);
            //save encrypted accountlist
            await FileManager.SaveFileAsync(settings.saveFileLocation, listAsBytes, false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load app settings.
        /// </summary>
        /// <returns></returns>
        public async Task <bool> LoadSettings()
        {
            byte[] o = await FileManager.OpenFile(Settings.SettingsFileURI);

            if (o == null || o.Length <= 0)
            {
                settings = new Settings();
                SaveSettings();
            }
            else
            {
                BinaryFormatter bf = new BinaryFormatter();
                settings = (Settings)bf.Deserialize(new MemoryStream(o));
                if (settings == null)
                {
                    settings = new Settings();
                    SaveSettings();
                }
            }

            o = await FileManager.OpenFile(settings.keyLocation);

            if (o == null || o.Length < 0)
            {
                await CryptoTools.CreateStoredKeyFile(settings.keyLocation); //new KeyFile();
            }

            /*   else
             * {
             *     keyFile = await CryptoTools.LoadStoredKeyFile(settings.keyLocation);
             *   //  BinaryFormatter bf = new BinaryFormatter();
             *  //   keyFile = (KeyFile)bf.Deserialize(new MemoryStream(o));
             *   //  if(keyFile == null)
             *    // {
             *    //     keyFile = new KeyFile();
             *    // }
             * }*/
            return(true);
        }