From e9f30410808c77717387e407c60527222ff8d7de Mon Sep 17 00:00:00 2001 From: Taiizor <41683699+Taiizor@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:58:58 +0300 Subject: [PATCH] Store Improvement --- .../Views/Controls/StoreCard.xaml | 8 ++ .../Views/Controls/StoreCard.xaml.cs | 86 ++++++++++++------- .../Sucrose.Shared.Store/Helper/Download.cs | 20 ++++- 3 files changed, 78 insertions(+), 36 deletions(-) diff --git a/src/Portal/Sucrose.Portal/Views/Controls/StoreCard.xaml b/src/Portal/Sucrose.Portal/Views/Controls/StoreCard.xaml index c0f280790..1fa293ad4 100644 --- a/src/Portal/Sucrose.Portal/Views/Controls/StoreCard.xaml +++ b/src/Portal/Sucrose.Portal/Views/Controls/StoreCard.xaml @@ -40,6 +40,14 @@ + + + + + + + + diff --git a/src/Portal/Sucrose.Portal/Views/Controls/StoreCard.xaml.cs b/src/Portal/Sucrose.Portal/Views/Controls/StoreCard.xaml.cs index df98e1d3c..4ce66663d 100644 --- a/src/Portal/Sucrose.Portal/Views/Controls/StoreCard.xaml.cs +++ b/src/Portal/Sucrose.Portal/Views/Controls/StoreCard.xaml.cs @@ -102,7 +102,7 @@ private void MenuInstall_Click(object sender, RoutedEventArgs e) Start(); } - private async void DownloadCache() + private async Task DownloadCache() { if (SPMI.StoreDownloader.ContainsKey(Theme)) { @@ -112,19 +112,31 @@ private async void DownloadCache() } Info = SSTHI.ReadJson(Path.Combine(Theme, SMR.SucroseInfo)); + + return true; } else { - SPMI.StoreDownloader[Theme] = true; + SPMI.StoreDownloader[Theme] = false; - SSSHD.Cache(Wallpaper, Theme, Agent, Key); + SPMI.StoreDownloader[Theme] = SSSHD.Cache(Wallpaper, Theme, Agent, Key); - while (!SPMI.StoreDownloading.ContainsKey(Theme) || !SPMI.StoreDownloading[Theme]) + if (SPMI.StoreDownloader[Theme]) { - await Task.Delay(100); - } + while (!SPMI.StoreDownloading.ContainsKey(Theme) || !SPMI.StoreDownloading[Theme]) + { + await Task.Delay(100); + } - Info = SSTHI.ReadJson(Path.Combine(Theme, SMR.SucroseInfo)); + Info = SSTHI.ReadJson(Path.Combine(Theme, SMR.SucroseInfo)); + + return true; + } + else + { + SPMI.StoreDownloader.Remove(Theme); + return false; + } } } @@ -230,48 +242,58 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e) private async void StoreCard_Loaded(object sender, RoutedEventArgs e) { - await Task.Run(DownloadCache); + bool Result = await Task.Run(DownloadCache); try { - ToolTip TitleTip = new() + if (Result) { - Content = Info.Title - }; + ToolTip TitleTip = new() + { + Content = Info.Title + }; - ToolTip DescriptionTip = new() - { - Content = Info.Description - }; + ToolTip DescriptionTip = new() + { + Content = Info.Description + }; - ThemeTitle.ToolTip = TitleTip; - ThemeDescription.ToolTip = DescriptionTip; + ThemeTitle.ToolTip = TitleTip; + ThemeDescription.ToolTip = DescriptionTip; - ThemeTitle.Text = Info.Title.Length > SMMM.TitleLength ? $"{SHA.Cut(Info.Title, SMMM.TitleLength)}..." : Info.Title; - ThemeDescription.Text = Info.Description.Length > SMMM.DescriptionLength ? $"{SHA.Cut(Info.Description, SMMM.DescriptionLength)}..." : Info.Description; + ThemeTitle.Text = Info.Title.Length > SMMM.TitleLength ? $"{SHA.Cut(Info.Title, SMMM.TitleLength)}..." : Info.Title; + ThemeDescription.Text = Info.Description.Length > SMMM.DescriptionLength ? $"{SHA.Cut(Info.Description, SMMM.DescriptionLength)}..." : Info.Description; - string ImagePath = Path.Combine(Theme, Info.Thumbnail); + string ImagePath = Path.Combine(Theme, Info.Thumbnail); - if (File.Exists(ImagePath)) - { - Imagine.ImageSource = await Loader.LoadOptimalAsync(ImagePath); - } + if (File.Exists(ImagePath)) + { + Imagine.ImageSource = await Loader.LoadOptimalAsync(ImagePath); + } - if (Info.AppVersion.CompareTo(SHV.Entry()) > 0) - { - DownloadSymbol.Visibility = Visibility.Hidden; - IncompatibleVersion.Visibility = Visibility.Visible; - } + if (Info.AppVersion.CompareTo(SHV.Entry()) > 0) + { + DownloadSymbol.Visibility = Visibility.Hidden; + IncompatibleVersion.Visibility = Visibility.Visible; + } - await Task.Delay(100); + await Task.Delay(100); - Card.Visibility = Visibility.Visible; - Progress.Visibility = Visibility.Collapsed; + Card.Visibility = Visibility.Visible; + Progress.Visibility = Visibility.Collapsed; + } + else + { + Warn.Visibility = Visibility.Visible; + Progress.Visibility = Visibility.Collapsed; + } Dispose(); } catch { + Warn.Visibility = Visibility.Visible; + Progress.Visibility = Visibility.Collapsed; Dispose(); } } diff --git a/src/Shared/Sucrose.Shared.Store/Helper/Download.cs b/src/Shared/Sucrose.Shared.Store/Helper/Download.cs index fef27d6b4..3329aaacb 100644 --- a/src/Shared/Sucrose.Shared.Store/Helper/Download.cs +++ b/src/Shared/Sucrose.Shared.Store/Helper/Download.cs @@ -132,11 +132,18 @@ public static bool Cache(KeyValuePair Wallpaper, string Theme, st InitializeClient(Agent, Key); - using HttpResponseMessage ResponseInfo = SSSMI.Client.GetAsync($"{SMR.RawWebsite}/{Wallpaper.Value.Source}/{Wallpaper.Key}/{SMR.SucroseInfo}").Result; - using HttpResponseMessage ResponseCover = SSSMI.Client.GetAsync($"{SMR.RawWebsite}/{Wallpaper.Value.Source}/{Wallpaper.Key}/{Wallpaper.Value.Cover}").Result; + using HttpResponseMessage ResponseInfo = SSSMI.Client.GetAsync(EncodeSpacesOnly($"{SMR.RawWebsite}/{Wallpaper.Value.Source}/{Wallpaper.Key}/{SMR.SucroseInfo}")).Result; + using HttpResponseMessage ResponseCover = SSSMI.Client.GetAsync(EncodeSpacesOnly($"{SMR.RawWebsite}/{Wallpaper.Value.Source}/{Wallpaper.Key}/{Wallpaper.Value.Cover}")).Result; - ResponseInfo.EnsureSuccessStatusCode(); - ResponseCover.EnsureSuccessStatusCode(); + try + { + ResponseInfo.EnsureSuccessStatusCode(); + ResponseCover.EnsureSuccessStatusCode(); + } + catch + { + return false; + } if (ResponseInfo.IsSuccessStatusCode && ResponseCover.IsSuccessStatusCode) { @@ -176,6 +183,11 @@ public static async Task Theme(string Source, string Output, string Agent, return await DownloadFolder(Source, Output, Agent, Keys, Key, Sub); } + private static string EncodeSpacesOnly(string Source) + { + return Source.Replace(" ", "%20"); + } + private static void InitializeClient(string Agent, string Key) { SSSHS.Apply();