Esempio n. 1
0
        private async void Save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (await FileSystemStorageItemBase.CreateAsync(TextFile.Path, StorageItemTypes.File, CreateOption.ReplaceExisting) is FileSystemStorageFile File)
                {
                    using (FileStream Stream = await File.GetFileStreamFromFileAsync(AccessMode.Write))
                        using (StreamWriter Writer = new StreamWriter(Stream, SaveEncoding))
                        {
                            await Writer.WriteAsync(EditText.Text);
                        }
                }
                else
                {
                    throw new FileNotFoundException();
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, "Could not save the content to file");

                QueueContentDialog Dialog = new QueueContentDialog
                {
                    Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                    Content         = Globalization.GetString("QueueDialog_CouldReadWriteFile_Content"),
                    CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                };

                await Dialog.ShowAsync();
            }
            finally
            {
                Frame.GoBack();
            }
        }
Esempio n. 2
0
        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var Deferral = args.GetDeferral();

            try
            {
                if (CurrentEncoding == null)
                {
                    args.Cancel       = true;
                    InvalidTip.IsOpen = true;
                }
                else if (await FileSystemStorageItemBase.OpenAsync(ExtractLocation) is not FileSystemStorageFolder)
                {
                    if (await FileSystemStorageItemBase.CheckExistAsync(ExtractLocation) == false)
                    {
                        await FileSystemStorageItemBase.CreateAsync(ExtractLocation, StorageItemTypes.Folder, CreateOption.OpenIfExist).ConfigureAwait(false);
                    }
                    else
                    {
                        args.Cancel = true;
                    }
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex);
            }
            finally
            {
                Deferral.Complete();
            }
        }
Esempio n. 3
0
        private async Task LoadSecureFile()
        {
            IsNewStart = false;

            SecureCollection.Clear();

Retry:
            string SecureAreaFolderPath;

            if (ApplicationData.Current.LocalSettings.Values.TryGetValue("SecureAreaStorageLocation", out object SPath))
            {
                SecureAreaFolderPath = Convert.ToString(SPath);
            }
            else
            {
                SecureAreaFolderPath = DefaultSecureAreaFolderPath;
                ApplicationData.Current.LocalSettings.Values["SecureAreaStorageLocation"] = DefaultSecureAreaFolderPath;
            }

            FileSystemStorageItemBase SItem;

            if (SecureAreaFolderPath.Equals(DefaultSecureAreaFolderPath, StringComparison.OrdinalIgnoreCase))
            {
                SItem = await FileSystemStorageItemBase.CreateAsync(SecureAreaFolderPath, StorageItemTypes.Folder, CreateOption.OpenIfExist);
            }
            else
            {
                SItem = await FileSystemStorageItemBase.OpenAsync(SecureAreaFolderPath);
            }

            if (SItem is FileSystemStorageFolder SFolder)
            {
                SecureFolder = SFolder;
                SecureCollection.AddRange((await SecureFolder.GetChildItemsAsync(false, false, Filter: ItemFilters.File, AdvanceFilter: (Name) => Path.GetExtension(Name).Equals(".sle", StringComparison.OrdinalIgnoreCase))).Cast <FileSystemStorageFile>());

                if (SecureCollection.Count == 0)
                {
                    EmptyTips.Visibility = Visibility.Visible;
                }
            }
            else
            {
                SecureAreaChangeLocationDialog Dialog = new SecureAreaChangeLocationDialog();

                if (await Dialog.ShowAsync() == ContentDialogResult.Primary)
                {
                    goto Retry;
                }
                else
                {
                    Frame.GoBack();
                }
            }
        }
Esempio n. 4
0
        private async Task LoadSecureFile()
        {
            IsNewStart = false;

            SecureFolder = await FileSystemStorageItemBase.CreateAsync(Path.Combine(ApplicationData.Current.LocalCacheFolder.Path, "SecureFolder"), StorageItemTypes.Folder, CreateOption.OpenIfExist) as FileSystemStorageFolder;

            SecureCollection.AddRange((await SecureFolder.GetChildItemsAsync(false, false, Filter: ItemFilters.File)).Cast <FileSystemStorageFile>());

            if (SecureCollection.Count == 0)
            {
                EmptyTips.Visibility = Visibility.Visible;
            }
        }
Esempio n. 5
0
        private async Task LoadSecureFile()
        {
            IsNewStart = false;

            SecureFolder = await FileSystemStorageItemBase.CreateAsync(Path.Combine(ApplicationData.Current.LocalCacheFolder.Path, "SecureFolder"), StorageItemTypes.Folder, CreateOption.OpenIfExist).ConfigureAwait(true);

            foreach (SecureAreaStorageItem Item in SecureFolder.GetChildrenItems(false, ItemFilters.File))
            {
                SecureCollection.Add(Item);
            }

            if (SecureCollection.Count == 0)
            {
                EmptyTips.Visibility = Visibility.Visible;
            }
        }
        private async void Save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (CurrentEncoding != null)
                {
                    try
                    {
                        if (await FileSystemStorageItemBase.CreateAsync(TextFile.Path, StorageItemTypes.File, CreateOption.ReplaceExisting).ConfigureAwait(true) is FileSystemStorageItemBase Item)
                        {
                            using (FileStream Stream = Item.GetFileStreamFromFile(AccessMode.Write))
                                using (StreamWriter Writer = new StreamWriter(Stream, CurrentEncoding))
                                {
                                    await Writer.WriteAsync(Text.Text).ConfigureAwait(true);
                                }
                        }
                        else
                        {
                            throw new FileNotFoundException();
                        }
                    }
                    catch
                    {
                        QueueContentDialog Dialog = new QueueContentDialog
                        {
                            Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                            Content         = Globalization.GetString("QueueDialog_CouldReadWriteFile_Content"),
                            CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                        };

                        await Dialog.ShowAsync().ConfigureAwait(true);
                    }

                    Frame.GoBack();
                }
                else
                {
                    InvalidTip.IsOpen = true;
                }
            }
            catch
            {
                InvalidTip.IsOpen = true;
            }
        }
Esempio n. 7
0
        private async Task ImportFilesAsync(IEnumerable <StorageFile> FileList)
        {
            if (FileList.Any())
            {
                await ActivateLoading(true, DisplayString : Globalization.GetString("Progress_Tip_Importing"));

                Cancellation = new CancellationTokenSource();

                try
                {
                    ulong TotalSize       = 0;
                    ulong CurrentPosition = 0;

                    List <FileSystemStorageFile> NewFileList = new List <FileSystemStorageFile>();

                    foreach (StorageFile ImportFile in FileList)
                    {
                        FileSystemStorageFile File = await FileSystemStorageItemBase.CreatedByStorageItemAsync(ImportFile);

                        if (File != null)
                        {
                            NewFileList.Add(File);
                            TotalSize += File.SizeRaw;
                        }
                    }

                    foreach (FileSystemStorageFile OriginFile in NewFileList)
                    {
                        string EncryptedFilePath = Path.Combine(SecureFolder.Path, $"{Path.GetFileNameWithoutExtension(OriginFile.Name)}.sle");

                        if (await FileSystemStorageItemBase.CreateAsync(EncryptedFilePath, StorageItemTypes.File, CreateOption.GenerateUniqueName) is FileSystemStorageFile EncryptedFile)
                        {
                            using (FileStream OriginFStream = await OriginFile.GetFileStreamFromFileAsync(AccessMode.Read))
                                using (FileStream EncryptFStream = await EncryptedFile.GetFileStreamFromFileAsync(AccessMode.Write))
                                    using (SLEOutputStream SLEStream = new SLEOutputStream(EncryptFStream, OriginFile.Name, AESKey, AESKeySize))
                                    {
                                        await OriginFStream.CopyToAsync(SLEStream, OriginFStream.Length, async (s, e) =>
                                        {
                                            await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                            {
                                                ProBar.IsIndeterminate = false;
                                                ProBar.Value           = Convert.ToInt32((CurrentPosition + Convert.ToUInt64(e.ProgressPercentage / 100d * OriginFile.SizeRaw)) * 100d / TotalSize);
                                            });
                                        }, Cancellation.Token);

                                        CurrentPosition += OriginFile.SizeRaw;

                                        await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                                        {
                                            ProBar.Value = Convert.ToInt32(CurrentPosition * 100d / TotalSize);
                                        });
                                    }

                            await EncryptedFile.RefreshAsync();

                            SecureCollection.Add(EncryptedFile);

                            await OriginFile.DeleteAsync(false);
                        }
                    }
                }
                catch (OperationCanceledException cancelException)
                {
                    LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled");
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, "An exception was threw when importing file");

                    QueueContentDialog Dialog = new QueueContentDialog
                    {
                        Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                        Content         = Globalization.GetString("QueueDialog_EncryptError_Content"),
                        CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                    };

                    _ = await Dialog.ShowAsync();
                }
                finally
                {
                    Cancellation.Dispose();
                    Cancellation = null;

                    await ActivateLoading(false);
                }
            }
        }