private async void SavePositionButton_Click(object sender, RoutedEventArgs e)
 {
     if (await Picker.PickSaveFileAsync() is StorageFile File)
     {
         TargetFile = FileSystemStorageItemBase.Open(File.Path, ItemFilters.File);
     }
 }
Exemple #2
0
 private async void LibraryProperties_Click(object sender, RoutedEventArgs e)
 {
     if (LibraryGrid.SelectedItem is LibraryFolder Library)
     {
         PropertyDialog Dialog = new PropertyDialog(FileSystemStorageItemBase.Open(Library.Folder.Path, ItemFilters.Folder));
         _ = await Dialog.ShowAsync().ConfigureAwait(true);
     }
 }
        private async Task Initialize()
        {
            try
            {
                ExitLocker   = new ManualResetEvent(false);
                Cancellation = new CancellationTokenSource();
                LoadQueue    = new Queue <int>();

                MainPage.ThisPage.IsAnyTaskRunning = true;

                Behavior.Attach(Flip);

                List <FileSystemStorageItemBase> FileList = FileSystemStorageItemBase.Open(Path.GetDirectoryName(SelectedPhotoPath), ItemFilters.Folder).GetChildrenItems(SettingControl.IsDisplayHiddenItem, ItemFilters.File).Where((Item) => Item.Type.Equals(".png", StringComparison.OrdinalIgnoreCase) || Item.Type.Equals(".jpg", StringComparison.OrdinalIgnoreCase) || Item.Type.Equals(".bmp", StringComparison.OrdinalIgnoreCase)).ToList();

                if (FileList.Count == 0)
                {
                    QueueContentDialog Dialog = new QueueContentDialog
                    {
                        Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                        Content         = Globalization.GetString("Queue_Dialog_ImageReadError_Content"),
                        CloseButtonText = Globalization.GetString("Common_Dialog_GoBack")
                    };
                    _ = await Dialog.ShowAsync().ConfigureAwait(true);

                    Frame.GoBack();
                }
                else
                {
                    int LastSelectIndex = FileList.FindIndex((Photo) => Photo.Path.Equals(SelectedPhotoPath, StringComparison.OrdinalIgnoreCase));
                    if (LastSelectIndex < 0 || LastSelectIndex >= FileList.Count)
                    {
                        LastSelectIndex = 0;
                    }

                    PhotoCollection  = new ObservableCollection <PhotoDisplaySupport>(FileList.Select((Item) => new PhotoDisplaySupport(Item)));
                    Flip.ItemsSource = PhotoCollection;

                    if (!await PhotoCollection[LastSelectIndex].ReplaceThumbnailBitmapAsync().ConfigureAwait(true))
                    {
                        CouldnotLoadTip.Visibility = Visibility.Visible;
                    }

                    for (int i = LastSelectIndex - 5 > 0 ? LastSelectIndex - 5 : 0; i <= (LastSelectIndex + 5 < PhotoCollection.Count - 1 ? LastSelectIndex + 5 : PhotoCollection.Count - 1) && !Cancellation.IsCancellationRequested; i++)
                    {
                        await PhotoCollection[i].GenerateThumbnailAsync().ConfigureAwait(true);
                    }

                    if (!Cancellation.IsCancellationRequested)
                    {
                        Flip.SelectedIndex     = LastSelectIndex;
                        Flip.SelectionChanged += Flip_SelectionChanged;
                        Flip.SelectionChanged += Flip_SelectionChanged1;

                        await EnterAnimation.BeginAsync().ConfigureAwait(true);
                    }
                }
            }
            catch (Exception ex)
            {
                CouldnotLoadTip.Visibility = Visibility.Visible;
                LogTracer.Log(ex, "An error was threw when initialize PhotoViewer");
            }
            finally
            {
                MainPage.ThisPage.IsAnyTaskRunning = false;
                ExitLocker.Set();
            }
        }
Exemple #4
0
        private async void Grid_Drop(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {
                IReadOnlyList <IStorageItem> Items = await e.DataView.GetStorageItemsAsync();

                if (Items.Any((Item) => Item.IsOfType(StorageItemTypes.Folder)))
                {
                    QueueContentDialog Dialog = new QueueContentDialog
                    {
                        Title           = Globalization.GetString("Common_Dialog_TipTitle"),
                        Content         = Globalization.GetString("QueueDialog_SecureAreaImportFiliter_Content"),
                        CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                    };

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

                if (Items.Any((Item) => Item.IsOfType(StorageItemTypes.File)))
                {
                    ActivateLoading(true, true);

                    Cancellation = new CancellationTokenSource();

                    try
                    {
                        foreach (string OriginFilePath in Items.Select((Item) => Item.Path))
                        {
                            if (FileSystemStorageItemBase.Open(OriginFilePath, ItemFilters.File) is FileSystemStorageItemBase Item)
                            {
                                if (await Item.EncryptAsync(SecureFolder.Path, EncryptionAESKey, AESKeySize, Cancellation.Token).ConfigureAwait(true) is SecureAreaStorageItem EncryptedFile)
                                {
                                    SecureCollection.Add(EncryptedFile);

                                    if (!Item.PermanentDelete())
                                    {
                                        LogTracer.Log(new Win32Exception(Marshal.GetLastWin32Error()), "Delete origin file failed after importing to SecureArea");
                                    }
                                }
                                else
                                {
                                    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().ConfigureAwait(true);
                                }
                            }
                        }
                    }
                    catch (TaskCanceledException cancelException)
                    {
                        LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled");
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "An error 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().ConfigureAwait(true);
                    }
                    finally
                    {
                        Cancellation.Dispose();
                        Cancellation = null;

                        await Task.Delay(1000).ConfigureAwait(true);

                        ActivateLoading(false);
                    }
                }
            }
        }
Exemple #5
0
        private async void AddFile_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker Picker = new FileOpenPicker
            {
                SuggestedStartLocation = PickerLocationId.ComputerFolder,
                ViewMode = PickerViewMode.Thumbnail
            };

            Picker.FileTypeFilter.Add("*");

            IReadOnlyList <StorageFile> FileList = await Picker.PickMultipleFilesAsync();

            if (FileList.Count > 0)
            {
                ActivateLoading(true, true);

                Cancellation = new CancellationTokenSource();

                try
                {
                    foreach (string OriginFilePath in FileList.Select((Item) => Item.Path))
                    {
                        if (FileSystemStorageItemBase.Open(OriginFilePath, ItemFilters.File) is FileSystemStorageItemBase Item)
                        {
                            if (await Item.EncryptAsync(SecureFolder.Path, EncryptionAESKey, AESKeySize, Cancellation.Token).ConfigureAwait(true) is SecureAreaStorageItem EncryptedFile)
                            {
                                SecureCollection.Add(EncryptedFile);

                                if (!Item.PermanentDelete())
                                {
                                    LogTracer.Log(new Win32Exception(Marshal.GetLastWin32Error()), "Delete origin file failed after importing to SecureArea");
                                }
                            }
                            else
                            {
                                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().ConfigureAwait(true);
                            }
                        }
                    }
                }
                catch (TaskCanceledException cancelException)
                {
                    LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled");
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, "An error 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().ConfigureAwait(true);
                }
                finally
                {
                    Cancellation.Dispose();
                    Cancellation = null;

                    await Task.Delay(1500).ConfigureAwait(true);

                    ActivateLoading(false);
                }
            }
        }