示例#1
0
        private async void QuickStartGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (e.ClickedItem is QuickStartItem Item && !string.IsNullOrEmpty(Item.Protocol))
            {
                Uri Ur = new Uri(Item.Protocol);

                if (Ur.IsFile)
                {
                    if (WIN_Native_API.CheckExist(Item.Protocol))
                    {
                        await FullTrustExcutorController.Current.RunAsync(Item.Protocol).ConfigureAwait(true);
                    }
                    else
                    {
                        QueueContentDialog Dialog = new QueueContentDialog
                        {
                            Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                            Content         = Globalization.GetString("QueueDialog_ApplicationNotFound_Content"),
                            CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                        };
                        _ = await Dialog.ShowAsync().ConfigureAwait(true);
                    }
                }
                else
                {
                    await Launcher.LaunchUriAsync(Ur);
                }
            }
示例#2
0
        private async void QuickStartGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (e.ClickedItem is QuickStartItem Item)
            {
                if ((sender as GridView).Name == nameof(QuickStartGridView))
                {
                    Uri Ur = new Uri(Item.Protocol);

                    if (Ur.IsFile)
                    {
                        if (WIN_Native_API.CheckExist(Item.Protocol))
                        {
                            using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController())
                            {
                                try
                                {
                                    if (Path.GetExtension(Item.Protocol).ToLower() == ".msc")
                                    {
                                        await Exclusive.Controller.RunAsync("powershell.exe", false, true, false, "-Command", Item.Protocol).ConfigureAwait(true);
                                    }
                                    else
                                    {
                                        await Exclusive.Controller.RunAsync(Item.Protocol).ConfigureAwait(true);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    LogTracer.Log(ex, "Could not execute program in quick start");
                                }
                            }
                        }
                        else
                        {
                            QueueContentDialog Dialog = new QueueContentDialog
                            {
                                Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                Content         = Globalization.GetString("QueueDialog_ApplicationNotFound_Content"),
                                CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                            };
                            _ = await Dialog.ShowAsync().ConfigureAwait(true);
                        }
                    }
                    else
                    {
                        await Launcher.LaunchUriAsync(Ur);
                    }
                }
                else
                {
                    await Launcher.LaunchUriAsync(new Uri(Item.Protocol));
                }
            }
        }
示例#3
0
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Microsoft.Toolkit.Uwp.Helpers.SystemInformation.TrackAppUse(e);

            ApplicationViewTitleBar TitleBar = ApplicationView.GetForCurrentView().TitleBar;

            TitleBar.ButtonBackgroundColor         = Colors.Transparent;
            TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;

            if (Window.Current.Content is Frame frame)
            {
                if (frame.Content is MainPage Main && Main.Nav.Content is TabViewContainer TabContainer)
                {
                    if (!string.IsNullOrWhiteSpace(e.Arguments) && WIN_Native_API.CheckExist(e.Arguments))
                    {
                        TabContainer.CreateNewTab(null, new string[] { e.Arguments });
                    }
                    else
                    {
                        TabContainer.CreateNewTab(null, Array.Empty <string>());
                    }
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(e.Arguments) && WIN_Native_API.CheckExist(e.Arguments))
                {
                    ExtendedSplash extendedSplash = new ExtendedSplash(e.SplashScreen, new string[] { e.Arguments });
                    Window.Current.Content = extendedSplash;
                }
                else
                {
                    ExtendedSplash extendedSplash = new ExtendedSplash(e.SplashScreen);
                    Window.Current.Content = extendedSplash;
                }
            }

            Window.Current.Activate();
        }
示例#4
0
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            ApplicationViewTitleBar TitleBar = ApplicationView.GetForCurrentView().TitleBar;

            TitleBar.ButtonBackgroundColor         = Colors.Transparent;
            TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;

            if (Window.Current.Content is Frame frame)
            {
                if (frame.Content is MainPage Main && Main.Nav.Content is TabViewContainer TabContainer)
                {
                    if (!string.IsNullOrWhiteSpace(e.Arguments) && WIN_Native_API.CheckExist(e.Arguments))
                    {
                        await TabContainer.CreateNewTabAndOpenTargetFolder(e.Arguments).ConfigureAwait(true);
                    }
                    else
                    {
                        await TabContainer.CreateNewTabAndOpenTargetFolder(string.Empty).ConfigureAwait(true);
                    }
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(e.Arguments) && WIN_Native_API.CheckExist(e.Arguments))
                {
                    ExtendedSplash extendedSplash = new ExtendedSplash(e.SplashScreen, $"PathActivate||{e.Arguments}");
                    Window.Current.Content = extendedSplash;
                }
                else
                {
                    ExtendedSplash extendedSplash = new ExtendedSplash(e.SplashScreen);
                    Window.Current.Content = extendedSplash;
                }
            }

            Window.Current.Activate();
        }
        private async void GetImageAutomatic_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(Protocol.Text))
            {
                EmptyTip.Target = Protocol;
                EmptyTip.IsOpen = true;
                return;
            }

            switch (Type)
            {
            case QuickStartType.Application:
            case QuickStartType.UpdateApp:
            {
                if (Uri.TryCreate(Protocol.Text, UriKind.Absolute, out Uri Result))
                {
                    if (Result.IsFile)
                    {
                        if (WIN_Native_API.CheckExist(Protocol.Text))
                        {
                            try
                            {
                                StorageFile ExcuteFile = await StorageFile.GetFileFromPathAsync(Protocol.Text);

                                DisplayName.Text = Convert.ToString((await ExcuteFile.Properties.RetrievePropertiesAsync(new string[] { "System.FileDescription" }))["System.FileDescription"]);

                                if (await ExcuteFile.GetThumbnailBitmapAsync().ConfigureAwait(true) is BitmapImage Image)
                                {
                                    Icon.Source = Image;
                                }
                                else
                                {
                                    Icon.Source = new BitmapImage(new Uri("ms-appx:///Assets/Page_Solid_White.png"));
                                }

                                RenderTargetBitmap RTB = new RenderTargetBitmap();
                                await RTB.RenderAsync(Icon);

                                StorageFile FileThumbnail = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("FileThumbnail.png", CreationCollisionOption.ReplaceExisting);

                                using (IRandomAccessStream Stream = await FileThumbnail.OpenAsync(FileAccessMode.ReadWrite))
                                {
                                    BitmapEncoder Encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, Stream);

                                    byte[] PixelData = (await RTB.GetPixelsAsync()).ToArray();

                                    Encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, (uint)RTB.PixelWidth, (uint)RTB.PixelHeight, DisplayInformation.GetForCurrentView().LogicalDpi, DisplayInformation.GetForCurrentView().LogicalDpi, PixelData);

                                    await Encoder.FlushAsync();
                                }

                                ImageFile = FileThumbnail;
                            }
                            catch
                            {
                                FailureTips.IsOpen = true;
                            }
                        }
                        else
                        {
                            FailureTips.IsOpen = true;
                        }
                    }
                    else
                    {
                        if ((await Launcher.FindUriSchemeHandlersAsync(Result.Scheme)).ToList().FirstOrDefault() is AppInfo App)
                        {
                            DisplayName.Text = App.DisplayInfo.DisplayName;

                            using (IRandomAccessStreamWithContentType LogoStream = await App.DisplayInfo.GetLogo(new Windows.Foundation.Size(120, 120)).OpenReadAsync())
                            {
                                BitmapDecoder Decoder = await BitmapDecoder.CreateAsync(LogoStream);

                                using (SoftwareBitmap SBitmap = await Decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied))
                                    using (SoftwareBitmap ResizeBitmap = ComputerVisionProvider.ResizeToActual(SBitmap))
                                    {
                                        StorageFile FileThumbnail = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("FileThumbnail.png", CreationCollisionOption.ReplaceExisting);

                                        using (IRandomAccessStream Stream = await FileThumbnail.OpenAsync(FileAccessMode.ReadWrite))
                                        {
                                            BitmapEncoder Encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, Stream);

                                            Encoder.SetSoftwareBitmap(ResizeBitmap);

                                            await Encoder.FlushAsync();
                                        }

                                        ImageFile = FileThumbnail;

                                        using (IRandomAccessStream Stream = await FileThumbnail.OpenAsync(FileAccessMode.Read))
                                        {
                                            BitmapImage Source = new BitmapImage();
                                            await Source.SetSourceAsync(Stream);

                                            Icon.Source = Source;
                                        }
                                    }
                            }
                        }
                        else
                        {
                            FormatErrorTip.IsOpen = true;
                        }
                    }
                }
                else
                {
                    FormatErrorTip.IsOpen = true;
                }

                break;
            }

            case QuickStartType.WebSite:
            case QuickStartType.UpdateWeb:
            {
                try
                {
                    if (Uri.TryCreate(Protocol.Text, UriKind.Absolute, out Uri Result))
                    {
                        Uri ImageUri = new Uri(Result, "favicon.ico");

                        HttpWebRequest Request = WebRequest.CreateHttp(ImageUri);
                        using (WebResponse Response = await Request.GetResponseAsync().ConfigureAwait(true))
                            using (Stream ImageStream = Response.GetResponseStream())
                            {
                                StorageFile DownloadImage = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("DownloadFile.ico", CreationCollisionOption.ReplaceExisting);

                                using (Stream FileStream = await DownloadImage.OpenStreamForWriteAsync().ConfigureAwait(true))
                                {
                                    await ImageStream.CopyToAsync(FileStream).ConfigureAwait(true);
                                }

                                ImageFile = DownloadImage;
                            }

                        Icon.Source = new BitmapImage(ImageUri);
                    }
                    else
                    {
                        FailureTips.IsOpen = true;
                    }
                }
                catch
                {
                    try
                    {
                        Uri QueryUrl = Globalization.CurrentLanguage == LanguageEnum.Chinese_Simplified
                                    ? new Uri($"http://statics.dnspod.cn/proxy_favicon/_/favicon?domain={new Uri(Protocol.Text).Host}")
                                    : new Uri($"http://www.google.com/s2/favicons?domain={new Uri(Protocol.Text).Host}");

                        HttpWebRequest Request = WebRequest.CreateHttp(QueryUrl);
                        using (WebResponse Response = await Request.GetResponseAsync().ConfigureAwait(true))
                            using (Stream ImageStream = Response.GetResponseStream())
                            {
                                StorageFile DownloadImage = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("DownloadFile.ico", CreationCollisionOption.ReplaceExisting);

                                using (Stream FileStream = await DownloadImage.OpenStreamForWriteAsync().ConfigureAwait(true))
                                {
                                    await ImageStream.CopyToAsync(FileStream).ConfigureAwait(true);
                                }

                                ImageFile = DownloadImage;
                            }

                        Icon.Source = new BitmapImage(QueryUrl);
                    }
                    catch
                    {
                        FailureTips.IsOpen = true;
                    }
                }

                break;
            }
            }
        }
        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> RecommandList = new List <ProgramPickerItem>();

            try
            {
                using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController())
                {
                    List <AssociationPackage> AssocList = await Exclusive.Controller.GetAssociateFromPathAsync(OpenFile.Path).ConfigureAwait(true);

                    List <AppInfo> AppInfoList = (await Launcher.FindFileHandlersAsync(OpenFile.Type)).ToList();

                    await SQLite.Current.UpdateProgramPickerRecordAsync(OpenFile.Type, AssocList.Concat(AppInfoList.Select((Info) => new AssociationPackage(OpenFile.Type, Info.PackageFamilyName, true)))).ConfigureAwait(true);

                    foreach (AppInfo Info in AppInfoList)
                    {
                        try
                        {
                            using (IRandomAccessStreamWithContentType LogoStream = await Info.DisplayInfo.GetLogo(new Windows.Foundation.Size(128, 128)).OpenReadAsync())
                            {
                                BitmapDecoder Decoder = await BitmapDecoder.CreateAsync(LogoStream);

                                using (SoftwareBitmap SBitmap = await Decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied))
                                    using (SoftwareBitmap ResizeBitmap = ComputerVisionProvider.ResizeToActual(SBitmap))
                                        using (InMemoryRandomAccessStream Stream = new InMemoryRandomAccessStream())
                                        {
                                            BitmapEncoder Encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, Stream);

                                            Encoder.SetSoftwareBitmap(ResizeBitmap);
                                            await Encoder.FlushAsync();

                                            BitmapImage Image = new BitmapImage();
                                            await Image.SetSourceAsync(Stream);

                                            RecommandList.Add(new ProgramPickerItem(Image, Info.DisplayInfo.DisplayName, Info.DisplayInfo.Description, Info.PackageFamilyName));
                                        }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogTracer.Log(ex, "An exception was threw when getting or processing App Logo");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, "An exception was threw when fetching association data");
            }

            foreach (AssociationPackage Package in await SQLite.Current.GetProgramPickerRecordAsync(OpenFile.Type, false).ConfigureAwait(true))
            {
                try
                {
                    if (WIN_Native_API.CheckExist(Package.ExecutablePath))
                    {
                        StorageFile ExecuteFile = await StorageFile.GetFileFromPathAsync(Package.ExecutablePath);

                        IDictionary <string, object> PropertiesDictionary = await ExecuteFile.Properties.RetrievePropertiesAsync(new string[] { "System.FileDescription" });

                        string ExtraAppName = string.Empty;

                        if (PropertiesDictionary.TryGetValue("System.FileDescription", out object DescriptionRaw))
                        {
                            ExtraAppName = Convert.ToString(DescriptionRaw);
                        }

                        if (await ExecuteFile.GetThumbnailRawStreamAsync().ConfigureAwait(true) is IRandomAccessStream ThumbnailStream)
                        {
                            using (ThumbnailStream)
                            {
                                BitmapDecoder Decoder = await BitmapDecoder.CreateAsync(ThumbnailStream);

                                using (SoftwareBitmap SBitmap = await Decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied))
                                    using (SoftwareBitmap ResizeBitmap = ComputerVisionProvider.ResizeToActual(SBitmap))
                                        using (InMemoryRandomAccessStream ResizeBitmapStream = new InMemoryRandomAccessStream())
                                        {
                                            BitmapEncoder Encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, ResizeBitmapStream);

                                            Encoder.SetSoftwareBitmap(ResizeBitmap);
                                            await Encoder.FlushAsync();

                                            BitmapImage ThumbnailBitmap = new BitmapImage();
                                            await ThumbnailBitmap.SetSourceAsync(ResizeBitmapStream);

                                            if (Package.IsRecommanded)
                                            {
                                                RecommandList.Add(new ProgramPickerItem(ThumbnailBitmap, string.IsNullOrEmpty(ExtraAppName) ? ExecuteFile.DisplayName : ExtraAppName, Globalization.GetString("Application_Admin_Name"), ExecuteFile.Path));
                                            }
                                            else
                                            {
                                                NotRecommandList.Add(new ProgramPickerItem(ThumbnailBitmap, string.IsNullOrEmpty(ExtraAppName) ? ExecuteFile.DisplayName : ExtraAppName, Globalization.GetString("Application_Admin_Name"), ExecuteFile.Path));
                                            }
                                        }
                            }
                        }
                        else
                        {
                            if (Package.IsRecommanded)
                            {
                                RecommandList.Add(new ProgramPickerItem(new BitmapImage(AppThemeController.Current.Theme == ElementTheme.Dark ? new Uri("ms-appx:///Assets/Page_Solid_White.png") : new Uri("ms-appx:///Assets/Page_Solid_Black.png")), string.IsNullOrEmpty(ExtraAppName) ? ExecuteFile.DisplayName : ExtraAppName, Globalization.GetString("Application_Admin_Name"), ExecuteFile.Path));
                            }
                            else
                            {
                                NotRecommandList.Add(new ProgramPickerItem(new BitmapImage(AppThemeController.Current.Theme == ElementTheme.Dark ? new Uri("ms-appx:///Assets/Page_Solid_White.png") : new Uri("ms-appx:///Assets/Page_Solid_Black.png")), string.IsNullOrEmpty(ExtraAppName) ? ExecuteFile.DisplayName : ExtraAppName, Globalization.GetString("Application_Admin_Name"), ExecuteFile.Path));
                            }
                        }
                    }
                    else
                    {
                        await SQLite.Current.DeleteProgramPickerRecordAsync(Package).ConfigureAwait(true);
                    }
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, "An exception was threw trying add to ApplicationList");
                }
            }


            string AdminExecutablePath = await SQLite.Current.GetDefaultProgramPickerRecordAsync(OpenFile.Type).ConfigureAwait(true);

            if (!string.IsNullOrEmpty(AdminExecutablePath))
            {
                if (RecommandList.FirstOrDefault((Item) => Item.Path.Equals(AdminExecutablePath, StringComparison.OrdinalIgnoreCase)) is ProgramPickerItem RecommandItem)
                {
                    CurrentUseProgramList.Items.Add(RecommandItem);
                    CurrentUseProgramList.SelectedIndex = 0;
                    RecommandList.Remove(RecommandItem);
                }
                else if (NotRecommandList.FirstOrDefault((Item) => Item.Path.Equals(AdminExecutablePath, StringComparison.OrdinalIgnoreCase)) is ProgramPickerItem NotRecommandItem)
                {
                    CurrentUseProgramList.Items.Add(NotRecommandItem);
                    CurrentUseProgramList.SelectedIndex = 0;
                    NotRecommandList.Remove(NotRecommandItem);
                }
            }

            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(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;
                    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(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));
                    break;
                }
                }
            }

            if (RecommandList.Count == 0)
            {
                ShowMore.Visibility = Visibility.Collapsed;

                foreach (ProgramPickerItem Item in NotRecommandList)
                {
                    ProgramCollection.Add(Item);
                }

                OtherProgramList.MaxHeight = 300;
            }
            else
            {
                foreach (ProgramPickerItem Item in RecommandList)
                {
                    ProgramCollection.Add(Item);
                }
            }

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

            LoadingText.Visibility = Visibility.Collapsed;
            WholeArea.Visibility   = Visibility.Visible;
        }
示例#7
0
        private async void GetImageAutomatic_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(Protocol.Text))
            {
                EmptyTip.Target = Protocol;
                EmptyTip.IsOpen = true;
                return;
            }

            switch (Type)
            {
            case QuickStartType.Application:
            case QuickStartType.UpdateApp:
            {
                if (Uri.TryCreate(Protocol.Text, UriKind.Absolute, out Uri Result))
                {
                    if (Result.IsFile)
                    {
                        if (WIN_Native_API.CheckExist(Protocol.Text))
                        {
                            try
                            {
                                StorageFile ExecuteFile = await StorageFile.GetFileFromPathAsync(Protocol.Text);

                                IDictionary <string, object> PropertiesDictionary = await ExecuteFile.Properties.RetrievePropertiesAsync(new string[] { "System.FileDescription" });

                                string ExtraAppName = string.Empty;

                                if (PropertiesDictionary.TryGetValue("System.FileDescription", out object DescriptionRaw))
                                {
                                    ExtraAppName = Convert.ToString(DescriptionRaw);
                                }

                                DisplayName.Text = string.IsNullOrEmpty(ExtraAppName) ? ExecuteFile.DisplayName : ExtraAppName;

                                StorageFile FileThumbnail = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("FileThumbnail.png", CreationCollisionOption.ReplaceExisting);

                                if (await ExecuteFile.GetThumbnailRawStreamAsync().ConfigureAwait(true) is IRandomAccessStream ThumbnailStream)
                                {
                                    BitmapDecoder Decoder = await BitmapDecoder.CreateAsync(ThumbnailStream);

                                    using (SoftwareBitmap SBitmap = await Decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied))
                                        using (SoftwareBitmap ResizeBitmap = ComputerVisionProvider.ResizeToActual(SBitmap))
                                            using (InMemoryRandomAccessStream ResizeBitmapStream = new InMemoryRandomAccessStream())
                                            {
                                                BitmapEncoder Encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, ResizeBitmapStream);

                                                Encoder.SetSoftwareBitmap(ResizeBitmap);
                                                await Encoder.FlushAsync();

                                                BitmapImage Image = new BitmapImage();
                                                Icon.Source = Image;
                                                await Image.SetSourceAsync(ResizeBitmapStream);

                                                ResizeBitmapStream.Seek(0);
                                                using (Stream TransformStream = ResizeBitmapStream.AsStreamForRead())
                                                    using (Stream FileStream = await FileThumbnail.OpenStreamForWriteAsync().ConfigureAwait(true))
                                                    {
                                                        await TransformStream.CopyToAsync(FileStream).ConfigureAwait(true);
                                                    }
                                            }
                                }
                                else
                                {
                                    Uri PageUri = AppThemeController.Current.Theme == ElementTheme.Dark ? new Uri("ms-appx:///Assets/Page_Solid_White.png") : new Uri("ms-appx:///Assets/Page_Solid_Black.png");

                                    StorageFile PageFile = await StorageFile.GetFileFromApplicationUriAsync(PageUri);

                                    using (IRandomAccessStream PageStream = await PageFile.OpenAsync(FileAccessMode.Read))
                                    {
                                        BitmapImage Image = new BitmapImage();
                                        Icon.Source = Image;
                                        await Image.SetSourceAsync(PageStream);

                                        PageStream.Seek(0);

                                        using (Stream TransformStream = PageStream.AsStreamForRead())
                                            using (Stream FileStream = await FileThumbnail.OpenStreamForWriteAsync().ConfigureAwait(true))
                                            {
                                                await TransformStream.CopyToAsync(FileStream).ConfigureAwait(true);
                                            }
                                    }
                                }

                                ImageFile = FileThumbnail;
                            }
                            catch
                            {
                                FailureTips.IsOpen = true;
                            }
                        }
                        else
                        {
                            FailureTips.IsOpen = true;
                        }
                    }
                    else
                    {
                        if ((await Launcher.FindUriSchemeHandlersAsync(Result.Scheme)).ToList().FirstOrDefault() is AppInfo App)
                        {
                            DisplayName.Text = App.DisplayInfo.DisplayName;

                            using (IRandomAccessStreamWithContentType LogoStream = await App.DisplayInfo.GetLogo(new Windows.Foundation.Size(120, 120)).OpenReadAsync())
                            {
                                BitmapDecoder Decoder = await BitmapDecoder.CreateAsync(LogoStream);

                                using (SoftwareBitmap SBitmap = await Decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied))
                                    using (SoftwareBitmap ResizeBitmap = ComputerVisionProvider.ResizeToActual(SBitmap))
                                    {
                                        StorageFile FileThumbnail = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("FileThumbnail.png", CreationCollisionOption.ReplaceExisting);

                                        using (IRandomAccessStream Stream = await FileThumbnail.OpenAsync(FileAccessMode.ReadWrite))
                                        {
                                            BitmapEncoder Encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, Stream);

                                            Encoder.SetSoftwareBitmap(ResizeBitmap);

                                            await Encoder.FlushAsync();
                                        }

                                        ImageFile = FileThumbnail;

                                        using (IRandomAccessStream Stream = await FileThumbnail.OpenAsync(FileAccessMode.Read))
                                        {
                                            BitmapImage Source = new BitmapImage();
                                            await Source.SetSourceAsync(Stream);

                                            Icon.Source = Source;
                                        }
                                    }
                            }
                        }
                        else
                        {
                            FormatErrorTip.IsOpen = true;
                        }
                    }
                }
                else
                {
                    FormatErrorTip.IsOpen = true;
                }

                break;
            }

            case QuickStartType.WebSite:
            case QuickStartType.UpdateWeb:
            {
                try
                {
                    if (Uri.TryCreate(Protocol.Text, UriKind.Absolute, out Uri Result))
                    {
                        Uri ImageUri = new Uri(Result, "favicon.ico");

                        HttpWebRequest Request = WebRequest.CreateHttp(ImageUri);
                        using (WebResponse Response = await Request.GetResponseAsync().ConfigureAwait(true))
                            using (Stream ImageStream = Response.GetResponseStream())
                            {
                                StorageFile DownloadImage = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("DownloadFile.ico", CreationCollisionOption.ReplaceExisting);

                                using (Stream FileStream = await DownloadImage.OpenStreamForWriteAsync().ConfigureAwait(true))
                                {
                                    await ImageStream.CopyToAsync(FileStream).ConfigureAwait(true);
                                }

                                ImageFile = DownloadImage;
                            }

                        Icon.Source = new BitmapImage(ImageUri);
                    }
                    else
                    {
                        FailureTips.IsOpen = true;
                    }
                }
                catch
                {
                    try
                    {
                        Uri QueryUrl = Globalization.CurrentLanguage == LanguageEnum.Chinese_Simplified
                                    ? new Uri($"http://statics.dnspod.cn/proxy_favicon/_/favicon?domain={new Uri(Protocol.Text).Host}")
                                    : new Uri($"http://www.google.com/s2/favicons?domain={new Uri(Protocol.Text).Host}");

                        HttpWebRequest Request = WebRequest.CreateHttp(QueryUrl);
                        using (WebResponse Response = await Request.GetResponseAsync().ConfigureAwait(true))
                            using (Stream ImageStream = Response.GetResponseStream())
                            {
                                StorageFile DownloadImage = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("DownloadFile.ico", CreationCollisionOption.ReplaceExisting);

                                using (Stream FileStream = await DownloadImage.OpenStreamForWriteAsync().ConfigureAwait(true))
                                {
                                    await ImageStream.CopyToAsync(FileStream).ConfigureAwait(true);
                                }

                                ImageFile = DownloadImage;
                            }

                        Icon.Source = new BitmapImage(QueryUrl);
                    }
                    catch
                    {
                        FailureTips.IsOpen = true;
                    }
                }

                break;
            }
            }
        }
示例#8
0
        private async void QuickStartGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (e.ClickedItem is QuickStartItem Item)
            {
                if ((sender as GridView).Name == nameof(QuickStartGridView))
                {
                    Uri Ur = new Uri(Item.Protocol);

                    if (Ur.IsFile)
                    {
                        if (WIN_Native_API.CheckExist(Item.Protocol))
                        {
Retry:
                            try
                            {
                                if (Path.GetExtension(Item.Protocol).ToLower() == ".msc")
                                {
                                    await FullTrustProcessController.Current.RunAsync(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "WindowsPowerShell\\v1.0\\powershell.exe"), false, true, "-Command", Item.Protocol).ConfigureAwait(true);
                                }
                                else
                                {
                                    await FullTrustProcessController.Current.RunAsync(Item.Protocol).ConfigureAwait(true);
                                }
                            }
                            catch (InvalidOperationException)
                            {
                                QueueContentDialog UnauthorizeDialog = new QueueContentDialog
                                {
                                    Title             = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                    Content           = Globalization.GetString("QueueDialog_UnauthorizedExecute_Content"),
                                    PrimaryButtonText = Globalization.GetString("Common_Dialog_GrantButton"),
                                    CloseButtonText   = Globalization.GetString("Common_Dialog_CancelButton")
                                };

                                if (await UnauthorizeDialog.ShowAsync().ConfigureAwait(true) == ContentDialogResult.Primary)
                                {
                                    if (await FullTrustProcessController.Current.SwitchToAdminMode().ConfigureAwait(true))
                                    {
                                        goto Retry;
                                    }
                                    else
                                    {
                                        QueueContentDialog ErrorDialog = new QueueContentDialog
                                        {
                                            Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                            Content         = Globalization.GetString("QueueDialog_DenyElevation_Content"),
                                            CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                                        };

                                        _ = await ErrorDialog.ShowAsync().ConfigureAwait(true);
                                    }
                                }
                            }
                        }
                        else
                        {
                            QueueContentDialog Dialog = new QueueContentDialog
                            {
                                Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                                Content         = Globalization.GetString("QueueDialog_ApplicationNotFound_Content"),
                                CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                            };
                            _ = await Dialog.ShowAsync().ConfigureAwait(true);
                        }
                    }
                    else
                    {
                        await Launcher.LaunchUriAsync(Ur);
                    }
                }
                else
                {
                    await Launcher.LaunchUriAsync(new Uri(Item.Protocol));
                }
            }
        }