Beispiel #1
0
 private async void SavePositionButton_Click(object sender, RoutedEventArgs e)
 {
     if (await Picker.PickSaveFileAsync() is StorageFile SaveFile)
     {
         TargetFile = await FileSystemStorageItemBase.CreatedByStorageItemAsync(SaveFile);
     }
 }
Beispiel #2
0
        private async void LibraryProperties_Click(object sender, RoutedEventArgs e)
        {
            if (LibraryGrid.SelectedItem is LibraryFolder Library)
            {
                FileSystemStorageFolder Folder = await FileSystemStorageItemBase.CreatedByStorageItemAsync(Library.Folder);

                if (Folder != null)
                {
                    await Folder.LoadAsync();

                    AppWindow NewWindow = await AppWindow.TryCreateAsync();

                    NewWindow.RequestSize(new Size(420, 600));
                    NewWindow.RequestMoveRelativeToCurrentViewContent(new Point(Window.Current.Bounds.Width / 2 - 200, Window.Current.Bounds.Height / 2 - 300));
                    NewWindow.PersistedStateId = "Properties";
                    NewWindow.Title            = Globalization.GetString("Properties_Window_Title");
                    NewWindow.TitleBar.ExtendsContentIntoTitleBar    = true;
                    NewWindow.TitleBar.ButtonForegroundColor         = AppThemeController.Current.Theme == ElementTheme.Dark ? Colors.White : Colors.Black;
                    NewWindow.TitleBar.ButtonBackgroundColor         = Colors.Transparent;
                    NewWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

                    ElementCompositionPreview.SetAppWindowContent(NewWindow, new PropertyBase(NewWindow, Folder));
                    WindowManagementPreview.SetPreferredMinSize(NewWindow, new Size(420, 600));

                    await NewWindow.TryShowAsync();
                }
            }
        }
        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);
                }
            }
        }