Exemple #1
0
        private async void OnRoamingDataChanged(ApplicationData sender, object args)
        {
            using (await f_lock.Acquire())
            {
                var roamingFiles = await Task.WhenAll((await sender.RoamingFolder.GetFilesAsync())
                                                      .Where(f => f.Name != Constants.IV_FILE_NAME)
                                                      .Select(async x => await BindableStorageFile.Create(x)));

                var newDictionary = (await sender.RoamingFolder.GetFilesAsync()).First(f => f.Name == Constants.IV_FILE_NAME);
                await newDictionary.CopyAsync(_roamingFolder, Constants.IV_FILE_NAME, NameCollisionOption.ReplaceExisting);

                //Remove no-longer-synced-files
                foreach (var file in RoamedFiles)
                {
                    if (!await ContainsBindableStorageFile(file, roamingFiles))
                    {
                        await DeleteFileAsync(file.BackingFile, FileLocation.Roamed);
                    }
                }

                foreach (var file in roamingFiles.Where(f => f.Name != Constants.IV_FILE_NAME))
                {
                    if (!(await ContainsBindableStorageFile(file, RoamedFiles)))
                    {
                        file.IsRoamed = true;
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                                                                      () => RoamedFiles.Add(file));
                    }
                }
            }
        }
Exemple #2
0
        private async Task CreateAsync()
        {
            if (_initialized)
            {
                return;
            }

            ApplicationData.Current.DataChanged += OnRoamingDataChanged;
            LocalFiles  = new ObservableCollection <IBindableStorageFile>();
            RoamedFiles = new ObservableCollection <IBindableStorageFile>();

            var allFiles = await GetFilesAsync();

            foreach (var local in allFiles.LocalFiles)
            {
                var bsf = await BindableStorageFile.Create(local);

                LocalFiles.Add(bsf);
            }
            foreach (var roamed in allFiles.RoamingFiles)
            {
                if (roamed.Name == Constants.IV_FILE_NAME)
                {
                    continue;
                }
                var bsf = await BindableStorageFile.Create(roamed);

                bsf.IsRoamed = true;
                RoamedFiles.Add(bsf);
            }

            _initialized = true;
            IsInitialized.SetResult(true);
        }
Exemple #3
0
        /// <summary>
        /// Saves and encrypts the contents into a StorageFile with the given name, and the given password.
        /// </summary>
        /// <param name="contents">The contents to encrypt.</param>
        /// <param name="fileName">The filename with which to save the file.</param>
        /// <param name="password">The password that will be used to generate the encryption key.</param>
        /// <returns>If successful, returns the created StorageFile.</returns>
        public async Task <BindableStorageFile> SaveAndEncryptFileAsync(string contents, string fileName, string password)
        {
            using (await f_lock.Acquire())
            {
                if (!_initialized)
                {
                    throw new ServiceNotInitializedException($"{nameof(FileService)} was not initialized before access was attempted.");
                }
                if (contents == null)
                {
                    throw new ArgumentException("File contents cannot be null.");
                }

                string iv = Guid.NewGuid().ToString("N"); // OLD IV code.

                string encryptedContents = LegacyEncryptionManager.Encrypt(contents, password, iv);
                var    savedFile         = await _localFolder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);

                await FileIO.WriteTextAsync(savedFile, encryptedContents);

                string savedFileName = savedFile.Name;

                BindableStorageFile bsf = await BindableStorageFile.Create(savedFile);

                LocalFiles.Add(bsf);

                await _ivService.Add(GetParentFolder(bsf.BackingFile), iv, FileLocation.Local);

                return(bsf);
            }
        }
Exemple #4
0
        private async void ChangeActiveFile(BindableStorageFile arg)
        {
            string password = await GetPassword();

            if (password != null)
            {
                ActiveFile      = arg;
                _codeDictionary = await GetCodes(password);
            }
        }
Exemple #5
0
        private async void DeleteFile(BindableStorageFile item)
        {
            FileService.FileLocation location = _fileService.GetFileLocation(item);
            await _fileService.DeleteFileAsync((StorageFile)item.BackingFile, location);

            if (item == ActiveFile)
            {
                ActiveFile = null;
            }

            ShouldShowPlaceholder = FileGroups.Any(x => x.Files.Any()) ? Visibility.Collapsed : Visibility.Visible;
        }
Exemple #6
0
        private async void RenameFile(BindableStorageFile item)
        {
            string newName = await GetNewName(item.Name);

            if (newName != null)
            {
                await _fileService.RenameFileAsync(item, newName);

                if (ActiveFile == item)
                {
                    OpenFileText = item.Name;
                }
            }
        }
Exemple #7
0
 public FileService.FileLocation GetFileLocation(BindableStorageFile file)
 {
     throw new NotImplementedException();
 }
Exemple #8
0
 public FileLocation GetFileLocation(BindableStorageFile file)
 {
     return(file.IsRoamed ? FileLocation.Roamed : FileLocation.Local);
 }
Exemple #9
0
        private async void RemoveFileFromSync(BindableStorageFile file)
        {
            await _fileService.StopRoamingFile(file);

            await UpdateAvailableRoamingSpace();
        }
Exemple #10
0
        private async void SyncFile(BindableStorageFile file)
        {
            await _fileService.RoamFile(file);

            await UpdateAvailableRoamingSpace();
        }