private async void SavePositionButton_Click(object sender, RoutedEventArgs e)
 {
     if (await Picker.PickSaveFileAsync() is StorageFile File)
     {
         TargetFile = await FileSystemStorageItemBase.OpenAsync(File.Path, ItemFilters.File).ConfigureAwait(false);
     }
 }
        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)
                {
                    args.Cancel = true;
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex);
            }
            finally
            {
                Deferral.Complete();
            }
        }
示例#3
0
 private async void LibraryProperties_Click(object sender, RoutedEventArgs e)
 {
     if (LibraryGrid.SelectedItem is LibraryFolder Library && await FileSystemStorageItemBase.OpenAsync(Library.Folder.Path, ItemFilters.Folder).ConfigureAwait(true) is FileSystemStorageItemBase Item)
     {
         PropertyDialog Dialog = new PropertyDialog(Item);
         await Dialog.ShowAsync().ConfigureAwait(true);
     }
 }
示例#4
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();
                }
            }
        }
示例#5
0
        private async void QueueContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            ContentDialogButtonClickDeferral Deferral = args.GetDeferral();

            try
            {
                if (CurrentUseProgramList.SelectedItem is ProgramPickerItem CurrentItem)
                {
                    SelectedProgram = CurrentItem;
                }
                else if (OtherProgramList.SelectedItem is ProgramPickerItem OtherItem)
                {
                    SelectedProgram = OtherItem;
                }
                else
                {
                    args.Cancel = true;
                }

                if (SelectedProgram != null && UseAsAdmin.IsChecked.GetValueOrDefault() || OpenFromPropertiesWindow)
                {
                    string ExecutablePath = SelectedProgram.Path;

                    if (Path.IsPathRooted(ExecutablePath) && Path.GetExtension(ExecutablePath).Equals(".lnk", StringComparison.OrdinalIgnoreCase))
                    {
                        if (await FileSystemStorageItemBase.OpenAsync(ExecutablePath) is LinkStorageFile LinkFile)
                        {
                            if (await LinkFile.GetRawDataAsync() is LinkDataPackage Package && !string.IsNullOrEmpty(Package.LinkTargetPath))
                            {
                                ExecutablePath = Package.LinkTargetPath;
                            }
                        }
                    }

                    SQLite.Current.SetDefaultProgramPickerRecord(OpenFile.Type, ExecutablePath);
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex);
            }
            finally
            {
                Deferral.Complete();
            }
        }
示例#6
0
        private async Task <bool> CheckAccessAuthority()
        {
            string UserProfilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

            if (!string.IsNullOrEmpty(UserProfilePath))
            {
                if (await FileSystemStorageItemBase.OpenAsync(UserProfilePath) is not null)
                {
                    return(true);
                }
            }

            string DesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            if (!string.IsNullOrEmpty(DesktopPath))
            {
                if (await FileSystemStorageItemBase.OpenAsync(DesktopPath) is not null)
                {
                    return(true);
                }
            }

            return(await FileSystemStorageItemBase.OpenAsync(Environment.GetLogicalDrives().FirstOrDefault()) is not null);
        }
示例#7
0
        private async void ProgramPickerDialog_Loading(FrameworkElement sender, object args)
        {
            LoadingText.Visibility = Visibility.Visible;
            WholeArea.Visibility   = Visibility.Collapsed;

            Dictionary <string, Task <ProgramPickerItem> > RecommandLoadTaskList = new Dictionary <string, Task <ProgramPickerItem> >();

            try
            {
                string AdminExecutablePath = SQLite.Current.GetDefaultProgramPickerRecord(OpenFile.Type);

                using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController())
                {
                    if (string.IsNullOrEmpty(AdminExecutablePath))
                    {
                        AdminExecutablePath = await Exclusive.Controller.GetDefaultAssociationFromPathAsync(OpenFile.Path);
                    }

                    IReadOnlyList <AssociationPackage> SystemAssocAppList = await Exclusive.Controller.GetAssociationFromPathAsync(OpenFile.Path);

                    IReadOnlyList <AppInfo> UWPAssocAppList = await Launcher.FindFileHandlersAsync(OpenFile.Type);

                    foreach (AppInfo App in UWPAssocAppList)
                    {
                        RecommandLoadTaskList.Add(App.PackageFamilyName.ToLower(), ProgramPickerItem.CreateAsync(App));
                    }

                    SQLite.Current.UpdateProgramPickerRecord(OpenFile.Type, SystemAssocAppList.Concat(UWPAssocAppList.Select((Info) => new AssociationPackage(OpenFile.Type, Info.PackageFamilyName, true))).ToArray());
                }

                foreach (AssociationPackage Package in SQLite.Current.GetProgramPickerRecord(OpenFile.Type, false))
                {
                    try
                    {
                        if (await FileSystemStorageItemBase.OpenAsync(Package.ExecutablePath) is FileSystemStorageFile File)
                        {
                            if (Package.IsRecommanded)
                            {
                                RecommandLoadTaskList.Add(File.Path.ToLower(), ProgramPickerItem.CreateAsync(File));
                            }
                            else
                            {
                                NotRecommandList.Add(File);
                            }
                        }
                        else
                        {
                            SQLite.Current.DeleteProgramPickerRecord(Package);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "An exception was threw trying add to ApplicationList");
                    }
                }

                if (!string.IsNullOrEmpty(AdminExecutablePath))
                {
                    if (RecommandLoadTaskList.TryGetValue(AdminExecutablePath.ToLower(), out Task <ProgramPickerItem> RecommandItemTask))
                    {
                        CurrentUseProgramList.Items.Add(await RecommandItemTask);
                        CurrentUseProgramList.SelectedIndex = 0;
                        RecommandLoadTaskList.Remove(AdminExecutablePath.ToLower());
                    }
                    else if (NotRecommandList.FirstOrDefault((Item) => Item.Path.Equals(AdminExecutablePath, StringComparison.OrdinalIgnoreCase)) is FileSystemStorageFile NotRecommandFile)
                    {
                        CurrentUseProgramList.Items.Add(await ProgramPickerItem.CreateAsync(NotRecommandFile));
                        CurrentUseProgramList.SelectedIndex = 0;
                        NotRecommandList.Remove(NotRecommandFile);
                    }
                }

                if (CurrentUseProgramList.Items.Count == 0)
                {
                    switch (OpenFile.Type.ToLower())
                    {
                    case ".jpg":
                    case ".png":
                    case ".bmp":
                    case ".heic":
                    case ".gif":
                    case ".tiff":
                    case ".mkv":
                    case ".mp4":
                    case ".mp3":
                    case ".flac":
                    case ".wma":
                    case ".wmv":
                    case ".m4a":
                    case ".mov":
                    case ".alac":
                    case ".txt":
                    case ".pdf":
                    case ".exe":
                    {
                        Area1.Visibility = Visibility.Visible;
                        CurrentUseProgramList.Visibility = Visibility.Visible;

                        Title1.Text = Globalization.GetString("ProgramPicker_Dialog_Title_1");
                        Title2.Text = Globalization.GetString("ProgramPicker_Dialog_Title_2");

                        CurrentUseProgramList.Items.Add(ProgramPickerItem.InnerViewer);
                        CurrentUseProgramList.SelectedIndex = 0;
                        break;
                    }

                    default:
                    {
                        Area1.Visibility = Visibility.Collapsed;
                        CurrentUseProgramList.Visibility = Visibility.Collapsed;
                        Title2.Text = Globalization.GetString("ProgramPicker_Dialog_Title_2");
                        break;
                    }
                    }
                }
                else
                {
                    Area1.Visibility = Visibility.Visible;
                    CurrentUseProgramList.Visibility = Visibility.Visible;

                    Title1.Text = Globalization.GetString("ProgramPicker_Dialog_Title_1");
                    Title2.Text = Globalization.GetString("ProgramPicker_Dialog_Title_2");

                    switch (OpenFile.Type.ToLower())
                    {
                    case ".jpg":
                    case ".png":
                    case ".bmp":
                    case ".heic":
                    case ".gif":
                    case ".tiff":
                    case ".mkv":
                    case ".mp4":
                    case ".mp3":
                    case ".flac":
                    case ".wma":
                    case ".wmv":
                    case ".m4a":
                    case ".mov":
                    case ".alac":
                    case ".txt":
                    case ".pdf":
                    case ".exe":
                    {
                        ProgramCollection.Add(ProgramPickerItem.InnerViewer);
                        break;
                    }
                    }
                }

                if (RecommandLoadTaskList.Count == 0)
                {
                    ShowMore.Visibility        = Visibility.Collapsed;
                    OtherProgramList.MaxHeight = 300;

                    ProgramCollection.AddRange(await Task.WhenAll(NotRecommandList.Select((File) => ProgramPickerItem.CreateAsync(File))));
                }
                else
                {
                    ProgramCollection.AddRange(await Task.WhenAll(RecommandLoadTaskList.Values));
                }

                if (CurrentUseProgramList.SelectedIndex == -1)
                {
                    OtherProgramList.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, "An exception was threw when fetching association app data");
            }
            finally
            {
                LoadingText.Visibility = Visibility.Collapsed;
                WholeArea.Visibility   = Visibility.Visible;
            }
        }
示例#8
0
        private async void BrowserApp_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker Picker = new FileOpenPicker
            {
                SuggestedStartLocation = PickerLocationId.ComputerFolder,
                ViewMode = PickerViewMode.List
            };

            Picker.FileTypeFilter.Add(".exe");
            Picker.FileTypeFilter.Add(".lnk");

            if ((await Picker.PickSingleFileAsync()) is StorageFile ExecuteFile)
            {
                string ExecutablePath = ExecuteFile.Path;

                if (ExecuteFile.FileType.Equals(".lnk", StringComparison.OrdinalIgnoreCase))
                {
                    if (await FileSystemStorageItemBase.OpenAsync(ExecutablePath) is LinkStorageFile LinkFile)
                    {
                        if (await LinkFile.GetRawDataAsync() is LinkDataPackage Package && !string.IsNullOrEmpty(Package.LinkTargetPath))
                        {
                            ExecutablePath = Package.LinkTargetPath;
                        }
                    }
                }

                if (CurrentUseProgramList.Items.Cast <ProgramPickerItem>().Any((Item) => Item.Path.Equals(ExecutablePath, StringComparison.OrdinalIgnoreCase)))
                {
                    CurrentUseProgramList.SelectedIndex = 0;
                }
                else if (ProgramCollection.FirstOrDefault((Item) => Item.Path.Equals(ExecutablePath, StringComparison.OrdinalIgnoreCase)) is ProgramPickerItem Item)
                {
                    CurrentUseProgramList.SelectedItem = null;
                    OtherProgramList.SelectedItem      = Item;
                    OtherProgramList.ScrollIntoViewSmoothly(Item);
                }
                else if (NotRecommandList.Any((Item) => Item.Path.Equals(ExecutablePath, StringComparison.OrdinalIgnoreCase)))
                {
                    if (ShowMore.Visibility == Visibility.Visible)
                    {
                        ShowMore.Visibility        = Visibility.Collapsed;
                        OtherProgramList.MaxHeight = 300;

                        ProgramCollection.AddRange(await Task.WhenAll(NotRecommandList.Select((File) => ProgramPickerItem.CreateAsync(File))));
                    }

                    CurrentUseProgramList.SelectedItem = null;

                    if (ProgramCollection.FirstOrDefault((Item) => Item.Path.Equals(ExecutablePath, StringComparison.OrdinalIgnoreCase)) is ProgramPickerItem Item1)
                    {
                        OtherProgramList.SelectedItem = Item1;
                        OtherProgramList.ScrollIntoViewSmoothly(Item1);
                    }
                }
                else
                {
                    ProgramCollection.Add(await ProgramPickerItem.CreateAsync(ExecuteFile));
                    CurrentUseProgramList.SelectedItem = null;
                    OtherProgramList.SelectedItem      = ProgramCollection.Last();
                    OtherProgramList.ScrollIntoViewSmoothly(ProgramCollection.Last());
                }

                SQLite.Current.SetProgramPickerRecord(new AssociationPackage(OpenFile.Type, ExecutablePath, true));
            }
        }
示例#9
0
        private async Task Initialize()
        {
            try
            {
                ExitLocker   = new ManualResetEvent(false);
                Cancellation = new CancellationTokenSource();
                LoadQueue    = new Queue <int>();

                Behavior.Attach(Flip);

                if (await FileSystemStorageItemBase.OpenAsync(Path.GetDirectoryName(SelectedPhotoFile.Path)) is FileSystemStorageFolder Item)
                {
                    FileSystemStorageFile[] PictureFileList = (await Item.GetChildItemsAsync(SettingControl.IsDisplayHiddenItem, SettingControl.IsDisplayProtectedSystemItems, Filter: ItemFilters.File, AdvanceFilter: (Name) =>
                    {
                        string Extension = Path.GetExtension(Name);
                        return(Extension.Equals(".png", StringComparison.OrdinalIgnoreCase) || Extension.Equals(".jpg", StringComparison.OrdinalIgnoreCase) || Extension.Equals(".bmp", StringComparison.OrdinalIgnoreCase));
                    })).Cast <FileSystemStorageFile>().ToArray();

                    if (PictureFileList.Length == 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();

                        Frame.GoBack();
                    }
                    else
                    {
                        int LastSelectIndex = Array.FindIndex(PictureFileList, (Photo) => Photo.Path.Equals(SelectedPhotoFile.Path, StringComparison.OrdinalIgnoreCase));

                        if (LastSelectIndex < 0 || LastSelectIndex >= PictureFileList.Length)
                        {
                            LastSelectIndex = 0;
                        }

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

                        if (!await PhotoCollection[LastSelectIndex].ReplaceThumbnailBitmapAsync())
                        {
                            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();
                        }

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

                            EnterAnimation.Begin();
                        }
                    }
                }
                else
                {
                    throw new FileNotFoundException();
                }
            }
            catch (Exception ex)
            {
                CouldnotLoadTip.Visibility = Visibility.Visible;
                LogTracer.Log(ex, "An error was threw when initialize PhotoViewer");
            }
            finally
            {
                ExitLocker.Set();
            }
        }
示例#10
0
        private async void Grid_Drop(object sender, DragEventArgs e)
        {
            try
            {
                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();
                    }

                    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 (await FileSystemStorageItemBase.OpenAsync(OriginFilePath) is FileSystemStorageFile File)
                                {
                                    if (await File.EncryptAsync(SecureFolder.Path, EncryptionAESKey, AESKeySize, Cancellation.Token) is FileSystemStorageFile EncryptedFile)
                                    {
                                        SecureCollection.Add(EncryptedFile);

                                        await File.DeleteAsync(false);
                                    }
                                    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();
                                    }
                                }
                            }
                        }
                        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();
                        }
                        finally
                        {
                            Cancellation.Dispose();
                            Cancellation = null;

                            await Task.Delay(1000);

                            ActivateLoading(false);
                        }
                    }
                }
            }
            catch (Exception ex) when(ex.HResult is unchecked ((int)0x80040064)or unchecked ((int)0x8004006A))
            {
                QueueContentDialog dialog = new QueueContentDialog
                {
                    Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                    Content         = Globalization.GetString("QueueDialog_CopyFromUnsupportedArea_Content"),
                    CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                };

                _ = await dialog.ShowAsync();
            }
            catch
            {
                QueueContentDialog dialog = new QueueContentDialog
                {
                    Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                    Content         = Globalization.GetString("QueueDialog_FailToGetClipboardError_Content"),
                    CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                };

                _ = await dialog.ShowAsync();
            }
        }
示例#11
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 (await FileSystemStorageItemBase.OpenAsync(OriginFilePath) is FileSystemStorageFile File)
                        {
                            if (await File.EncryptAsync(SecureFolder.Path, EncryptionAESKey, AESKeySize, Cancellation.Token) is FileSystemStorageFile EncryptedFile)
                            {
                                SecureCollection.Add(EncryptedFile);

                                await File.DeleteAsync(false);
                            }
                            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();
                            }
                        }
                    }
                }
                catch (TaskCanceledException 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 Task.Delay(1500);

                    ActivateLoading(false);
                }
            }
        }
示例#12
0
        private async Task LaunchSelectedItem(FileSystemStorageItemBase Item)
        {
            try
            {
                switch (Item)
                {
                case FileSystemStorageFile File:
                {
                    if (!await FileSystemStorageItemBase.CheckExistAsync(File.Path))
                    {
                        QueueContentDialog Dialog = new QueueContentDialog
                        {
                            Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                            Content         = Globalization.GetString("QueueDialog_LocateFileFailure_Content"),
                            CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                        };

                        _ = await Dialog.ShowAsync();

                        return;
                    }

                    switch (File.Type.ToLower())
                    {
                    case ".exe":
                    case ".bat":
                    case ".msi":
                    {
                        using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController())
                        {
                            if (!await Exclusive.Controller.RunAsync(File.Path, Path.GetDirectoryName(File.Path)))
                            {
                                QueueContentDialog Dialog = new QueueContentDialog
                                {
                                    Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                    Content         = Globalization.GetString("QueueDialog_LaunchFailed_Content"),
                                    CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                                };

                                await Dialog.ShowAsync();
                            }
                        }

                        break;
                    }

                    case ".msc":
                    {
                        using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController())
                        {
                            if (!await Exclusive.Controller.RunAsync("powershell.exe", string.Empty, WindowState.Normal, false, true, false, "-Command", File.Path))
                            {
                                QueueContentDialog Dialog = new QueueContentDialog
                                {
                                    Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                    Content         = Globalization.GetString("QueueDialog_LaunchFailed_Content"),
                                    CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                                };

                                await Dialog.ShowAsync();
                            }
                        }

                        break;
                    }

                    case ".lnk":
                    {
                        if (File is LinkStorageFile LinkItem)
                        {
                            if (LinkItem.LinkType == ShellLinkType.Normal)
                            {
                                switch (await FileSystemStorageItemBase.OpenAsync(LinkItem.LinkTargetPath))
                                {
                                case FileSystemStorageFolder:
                                {
                                    if (WeakToFileControl.TryGetTarget(out FileControl Control))
                                    {
                                        Frame.GoBack();

                                        await Control.CurrentPresenter.DisplayItemsInFolder(LinkItem.LinkTargetPath);

                                        await JumpListController.Current.AddItemAsync(JumpListGroup.Recent, LinkItem.LinkTargetPath);

                                        if (Control.CurrentPresenter.FileCollection.FirstOrDefault((SItem) => SItem == LinkItem) is FileSystemStorageItemBase Target)
                                        {
                                            Control.CurrentPresenter.ItemPresenter.ScrollIntoView(Target);
                                            Control.CurrentPresenter.SelectedItem = Target;
                                        }
                                    }

                                    break;
                                }

                                case FileSystemStorageFile:
                                {
                                    await LinkItem.LaunchAsync();

                                    break;
                                }
                                }
                            }
                            else
                            {
                                await LinkItem.LaunchAsync();
                            }
                        }

                        break;
                    }

                    case ".url":
                    {
                        if (File is UrlStorageFile UrlItem)
                        {
                            await UrlItem.LaunchAsync();
                        }

                        break;
                    }

                    default:
                    {
                        string AdminExecutablePath = await SQLite.Current.GetDefaultProgramPickerRecordAsync(File.Type);

                        if (string.IsNullOrEmpty(AdminExecutablePath) || AdminExecutablePath == Package.Current.Id.FamilyName)
                        {
                            if (!TryOpenInternally(File))
                            {
                                if (await File.GetStorageItemAsync() is StorageFile SFile)
                                {
                                    if (!await Launcher.LaunchFileAsync(SFile))
                                    {
                                        using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController())
                                        {
                                            if (!await Exclusive.Controller.RunAsync(File.Path))
                                            {
                                                QueueContentDialog Dialog = new QueueContentDialog
                                                {
                                                    Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                                    Content         = Globalization.GetString("QueueDialog_LaunchFailed_Content"),
                                                    CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                                                };

                                                await Dialog.ShowAsync();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController())
                                    {
                                        if (!await Exclusive.Controller.RunAsync(File.Path))
                                        {
                                            QueueContentDialog Dialog = new QueueContentDialog
                                            {
                                                Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                                Content         = Globalization.GetString("QueueDialog_LaunchFailed_Content"),
                                                CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                                            };

                                            await Dialog.ShowAsync();
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (Path.IsPathRooted(AdminExecutablePath))
                            {
                                using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController())
                                {
                                    if (!await Exclusive.Controller.RunAsync(AdminExecutablePath, Path.GetDirectoryName(AdminExecutablePath), Parameters: File.Path))
                                    {
                                        QueueContentDialog Dialog = new QueueContentDialog
                                        {
                                            Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                            Content         = Globalization.GetString("QueueDialog_LaunchFailed_Content"),
                                            CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                                        };

                                        await Dialog.ShowAsync();
                                    }
                                }
                            }
                            else
                            {
                                if ((await Launcher.FindFileHandlersAsync(File.Type)).FirstOrDefault((Item) => Item.PackageFamilyName == AdminExecutablePath) is AppInfo Info)
                                {
                                    if (await File.GetStorageItemAsync() is StorageFile InnerFile)
                                    {
                                        if (!await Launcher.LaunchFileAsync(InnerFile, new LauncherOptions {
                                                    TargetApplicationPackageFamilyName = Info.PackageFamilyName, DisplayApplicationPicker = false
                                                }))
                                        {
                                            QueueContentDialog Dialog = new QueueContentDialog
                                            {
                                                Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                                Content         = Globalization.GetString("QueueDialog_LaunchFailed_Content"),
                                                CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                                            };

                                            await Dialog.ShowAsync();
                                        }
                                    }
                                    else
                                    {
                                        QueueContentDialog Dialog = new QueueContentDialog
                                        {
                                            Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                            Content         = Globalization.GetString("QueueDialog_UnableAccessFile_Content"),
                                            CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                                        };

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

                        break;
                    }
                    }

                    break;
                }

                case FileSystemStorageFolder Folder:
                {
                    if (await FileSystemStorageItemBase.CheckExistAsync(Folder.Path))
                    {
                        if (WeakToFileControl.TryGetTarget(out FileControl Control))
                        {
                            Frame.GoBack();

                            await Control.CurrentPresenter.DisplayItemsInFolder(Folder);

                            await JumpListController.Current.AddItemAsync(JumpListGroup.Recent, Folder.Path);

                            if (Control.CurrentPresenter.FileCollection.FirstOrDefault((SItem) => SItem == Folder) is FileSystemStorageItemBase Target)
                            {
                                Control.CurrentPresenter.ItemPresenter.ScrollIntoView(Target);
                                Control.CurrentPresenter.SelectedItem = Target;
                            }
                        }
                    }
                    else
                    {
                        QueueContentDialog Dialog = new QueueContentDialog
                        {
                            Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                            Content         = Globalization.GetString("QueueDialog_LocateFolderFailure_Content"),
                            CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                        };

                        _ = await Dialog.ShowAsync();
                    }

                    break;
                }
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, $"An error was threw in {nameof(LaunchSelectedItem)}");

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

                _ = await dialog.ShowAsync();
            }
        }
示例#13
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 (await FileSystemStorageItemBase.OpenAsync(OriginFilePath, ItemFilters.File).ConfigureAwait(true) 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);
                    }
                }
            }
        }