Ejemplo n.º 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};";
                    }
                }
            }
        }
Ejemplo n.º 2
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;
        }
        private async void QueueContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var Deferral = args.GetDeferral();

            if (CurrentUseProgramList.SelectedItem is ProgramPickerItem CurrentItem)
            {
                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}|{CurrentItem.Name};";
                        }
                        else
                        {
                            ApplicationData.Current.LocalSettings.Values["AdminProgramForExcute"] = ProgramExcute.Replace(SaveUnit, $"{OpenFile.FileType}|{CurrentItem.Name}");
                        }
                    }
                    else
                    {
                        ApplicationData.Current.LocalSettings.Values["AdminProgramForExcute"] = $"{OpenFile.FileType}|{CurrentItem.Name};";
                    }
                }

                if (CurrentItem.PackageName == Package.Current.Id.FamilyName)
                {
                    ContinueUseInnerViewer = true;
                }
                else
                {
                    if (CurrentItem.IsCustomApp)
                    {
                        await FullTrustExcutorController.Current.RunAsync(CurrentItem.Path, OpenFile.Path).ConfigureAwait(true);
                    }
                    else
                    {
                        if (!await Launcher.LaunchFileAsync(OpenFile, new LauncherOptions {
                            TargetApplicationPackageFamilyName = CurrentItem.PackageName, DisplayApplicationPicker = false
                        }))
                        {
                            OpenFailed = true;
                            if (ApplicationData.Current.LocalSettings.Values["AdminProgramForExcute"] is string ProgramExcute)
                            {
                                ApplicationData.Current.LocalSettings.Values["AdminProgramForExcute"] = ProgramExcute.Replace($"{OpenFile.FileType}|{CurrentItem.Name};", string.Empty);
                            }
                        }
                    }
                }
            }
            else if (OtherProgramList.SelectedItem is ProgramPickerItem 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};";
                    }
                }

                if (OtherItem.PackageName == Package.Current.Id.FamilyName)
                {
                    ContinueUseInnerViewer = true;
                }
                else
                {
                    if (OtherItem.IsCustomApp)
                    {
                        await FullTrustExcutorController.Current.RunAsync(OtherItem.Path, OpenFile.Path).ConfigureAwait(true);
                    }
                    else
                    {
                        if (!await Launcher.LaunchFileAsync(OpenFile, new LauncherOptions {
                            TargetApplicationPackageFamilyName = OtherItem.PackageName, DisplayApplicationPicker = false
                        }))
                        {
                            OpenFailed = true;
                            if (ApplicationData.Current.LocalSettings.Values["AdminProgramForExcute"] is string ProgramExcute)
                            {
                                ApplicationData.Current.LocalSettings.Values["AdminProgramForExcute"] = ProgramExcute.Replace($"{OpenFile.FileType}|{OtherItem.Name};", string.Empty);
                            }
                        }
                    }
                }
            }

            Deferral.Complete();
        }