コード例 #1
0
        private void QueueContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            if (CurrentUseProgramList.SelectedItem is ProgramPickerItem CurrentItem)
            {
                SelectedProgram = CurrentItem;
            }
            else if (OtherProgramList.SelectedItem is ProgramPickerItem OtherItem)
            {
                SelectedProgram = OtherItem;

                if (UseAsAdmin.IsChecked.GetValueOrDefault())
                {
                    if (ApplicationData.Current.LocalSettings.Values["AdminProgramForExcute"] is string ProgramExcute)
                    {
                        string SaveUnit = ProgramExcute.Split(';', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault((Item) => Item.Split('|')[0] == OpenFile.FileType);
                        if (string.IsNullOrEmpty(SaveUnit))
                        {
                            ApplicationData.Current.LocalSettings.Values["AdminProgramForExcute"] = ProgramExcute + $"{OpenFile.FileType}|{OtherItem.Name};";
                        }
                        else
                        {
                            ApplicationData.Current.LocalSettings.Values["AdminProgramForExcute"] = ProgramExcute.Replace(SaveUnit, $"{OpenFile.FileType}|{OtherItem.Name}");
                        }
                    }
                    else
                    {
                        ApplicationData.Current.LocalSettings.Values["AdminProgramForExcute"] = $"{OpenFile.FileType}|{OtherItem.Name};";
                    }
                }
            }
        }
コード例 #2
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;

                    if (UseAsAdmin.IsChecked.GetValueOrDefault())
                    {
                        await SQLite.Current.SetDefaultProgramPickerRecordAsync(OpenFile.Type, OtherItem.Path).ConfigureAwait(true);
                    }
                }
                else
                {
                    args.Cancel = true;
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex);
            }
            finally
            {
                Deferral.Complete();
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
0
        private async void ProgramPickerDialog_Loading(FrameworkElement sender, object args)
        {
            LoadingText.Text       = Globalization.GetString("Progress_Tip_Loading");
            LoadingText.Visibility = Visibility.Visible;
            WholeArea.Visibility   = Visibility.Collapsed;

            List <ProgramPickerItem> TempList = new List <ProgramPickerItem>();

            string SystemAssociate = await FullTrustProcessController.Current.GetAssociateFromPathAsync(OpenFile.Path).ConfigureAwait(true);

            if (!string.IsNullOrEmpty(SystemAssociate))
            {
                await SQLite.Current.SetProgramPickerRecordAsync(OpenFile.FileType, SystemAssociate).ConfigureAwait(true);
            }

            try
            {
                AppInfo[] Apps = (await Launcher.FindFileHandlersAsync(OpenFile.FileType)).ToArray();
                foreach (AppInfo Info in Apps)
                {
                    using (IRandomAccessStreamWithContentType LogoStream = await Info.DisplayInfo.GetLogo(new Windows.Foundation.Size(150, 150)).OpenReadAsync())
                    {
                        BitmapImage Image = new BitmapImage();
                        await Image.SetSourceAsync(LogoStream);

                        TempList.Add(new ProgramPickerItem(Image, Info.DisplayInfo.DisplayName, Info.DisplayInfo.Description, Info.PackageFamilyName));
                    }
                }
            }
            catch
            {
            }

            foreach (string Path in await SQLite.Current.GetProgramPickerRecordAsync(OpenFile.FileType).ConfigureAwait(true))
            {
                try
                {
                    if (TempList.Where((Item) => Item.IsCustomApp).All((Item) => !Item.Path.Equals(Path, StringComparison.OrdinalIgnoreCase)))
                    {
                        StorageFile ExcuteFile = await StorageFile.GetFileFromPathAsync(Path);

                        string Description = Convert.ToString((await ExcuteFile.Properties.RetrievePropertiesAsync(new string[] { "System.FileDescription" }))["System.FileDescription"]);
                        TempList.Add(new ProgramPickerItem(await ExcuteFile.GetThumbnailBitmapAsync().ConfigureAwait(true), string.IsNullOrEmpty(Description) ? ExcuteFile.DisplayName : Description, Globalization.GetString("Application_Admin_Name"), Path: ExcuteFile.Path));
                    }
                }
                catch (Exception)
                {
                    await SQLite.Current.DeleteProgramPickerRecordAsync(OpenFile.FileType, Path).ConfigureAwait(true);
                }
            }

            if (Area1.Visibility == Visibility.Visible)
            {
                string AdminExcuteProgram = null;
                if (ApplicationData.Current.LocalSettings.Values["AdminProgramForExcute"] is string ProgramExcute)
                {
                    string SaveUnit = ProgramExcute.Split(';', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault((Item) => Item.Split('|')[0] == OpenFile.FileType);
                    if (!string.IsNullOrEmpty(SaveUnit))
                    {
                        AdminExcuteProgram = SaveUnit.Split('|')[1];
                    }
                }

                if (!string.IsNullOrEmpty(AdminExcuteProgram))
                {
                    ProgramPickerItem AdminItem = TempList.FirstOrDefault((Item) => Item.Name == AdminExcuteProgram);
                    if (AdminItem != null)
                    {
                        CurrentUseProgramList.Items.Add(AdminItem);
                        CurrentUseProgramList.SelectedIndex = 0;
                        TempList.Remove(AdminItem);
                    }
                }

                if (CurrentUseProgramList.Items.Count == 0)
                {
                    CurrentUseProgramList.Items.Add(new ProgramPickerItem(new BitmapImage(new Uri("ms-appx:///Assets/RX-icon.png")), Globalization.GetString("ProgramPicker_Dialog_BuiltInViewer"), Globalization.GetString("ProgramPicker_Dialog_BuiltInViewer_Description"), Package.Current.Id.FamilyName));
                    CurrentUseProgramList.SelectedIndex = 0;
                }
                else
                {
                    ProgramCollection.Add(new ProgramPickerItem(new BitmapImage(new Uri("ms-appx:///Assets/RX-icon.png")), Globalization.GetString("ProgramPicker_Dialog_BuiltInViewer"), Globalization.GetString("ProgramPicker_Dialog_BuiltInViewer_Description"), Package.Current.Id.FamilyName));
                }
            }

            foreach (var Item in TempList)
            {
                ProgramCollection.Add(Item);
            }

            if (CurrentUseProgramList.SelectedIndex == -1)
            {
                OtherProgramList.SelectedIndex = 0;
            }

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

            LoadingText.Visibility = Visibility.Collapsed;
            WholeArea.Visibility   = Visibility.Visible;
        }
コード例 #5
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;
            }
        }
コード例 #6
0
        private async void ShowMore_Click(object sender, RoutedEventArgs e)
        {
            ShowMore.Visibility        = Visibility.Collapsed;
            OtherProgramList.MaxHeight = 300;

            ProgramCollection.AddRange(await Task.WhenAll(NotRecommandList.Select((File) => ProgramPickerItem.CreateAsync(File))));
        }
コード例 #7
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));
            }
        }