Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
add noty for connection errors
Greedeks98ebfad0c7c5
diff --git a/.Source/GTweak/Core/Services/ToolsetDownloadService.cs b/.Source/GTweak/Core/Services/ToolsetDownloadService.csindex 8b4480d7..084d7bed 100644--- a/.Source/GTweak/Core/Services/ToolsetDownloadService.cs+++ b/.Source/GTweak/Core/Services/ToolsetDownloadService.cs@@ -29,60 +29,58 @@ namespace GTweak.Core.Servicesinternal static async Task<string> GetResolvedDownloadUrl(ToolsetModel model){- try+ if (model.Group.Equals("web", StringComparison.OrdinalIgnoreCase)){- if (model.Group.Equals("web", StringComparison.OrdinalIgnoreCase))+ if (string.IsNullOrEmpty(model.UrlPattern)){- if (string.IsNullOrEmpty(model.UrlPattern))- {- return model.DownloadPathStr;- }-- string htmlCode = await _httpClient.GetStringAsync(model.DownloadPathStr);- Match match = Regex.Match(htmlCode, model.UrlPattern);- return match.Success ? match.Value : null;+ return model.DownloadPathStr;}- if (model.Group.Equals("github", StringComparison.OrdinalIgnoreCase))- {- string apiUrl = $"https://api.github.com/repos/{model.DownloadPathStr}/releases/latest";+ string htmlCode = await _httpClient.GetStringAsync(model.DownloadPathStr);+ Match match = Regex.Match(htmlCode, model.UrlPattern);+ return match.Success ? match.Value : null;+ }- HttpResponseMessage response = await _httpClient.GetAsync(apiUrl);- if (!response.IsSuccessStatusCode)+ if (model.Group.Equals("github", StringComparison.OrdinalIgnoreCase))+ {+ string apiUrl = $"https://api.github.com/repos/{model.DownloadPathStr}/releases/latest";++ using HttpResponseMessage response = await _httpClient.GetAsync(apiUrl);++ if (!response.IsSuccessStatusCode)+ {+ if (response.StatusCode == HttpStatusCode.Forbidden || (int)response.StatusCode == 429){- return null;+ throw new Exception("GitHubRateLimit");}+ throw new HttpRequestException();+ }- string content = await response.Content.ReadAsStringAsync();- JObject json = JObject.Parse(content);+ string content = await response.Content.ReadAsStringAsync();+ JObject json = JObject.Parse(content);- if (json["assets"] is JArray assets && assets.Count > 0)+ if (json["assets"] is JArray assets && assets.Count > 0)+ {+ string firstFoundUrl = null;+ foreach (JToken asset in assets){- string firstFoundUrl = null;-- foreach (JToken asset in assets)+ string downloadUrl = asset["browser_download_url"]?.ToString();+ if (string.IsNullOrEmpty(downloadUrl)){- string downloadUrl = asset["browser_download_url"]?.ToString();- if (string.IsNullOrEmpty(downloadUrl))- {- continue;- }+ continue;+ }- firstFoundUrl ??= downloadUrl;+ firstFoundUrl ??= downloadUrl;- if (!string.IsNullOrEmpty(model.FilePattern) &&- Regex.IsMatch(downloadUrl, model.FilePattern, RegexOptions.IgnoreCase))- {- return downloadUrl;- }+ if (!string.IsNullOrEmpty(model.FilePattern) &&+ Regex.IsMatch(downloadUrl, model.FilePattern, RegexOptions.IgnoreCase))+ {+ return downloadUrl;}-- return firstFoundUrl;}+ return firstFoundUrl;}}- catch (Exception ex) { ErrorLogging.LogDebug(ex); }-return null;}diff --git a/.Source/GTweak/Core/ViewModel/Components/DownloadSession.cs b/.Source/GTweak/Core/ViewModel/Components/DownloadSession.csindex a9221934..1170a0a8 100644--- a/.Source/GTweak/Core/ViewModel/Components/DownloadSession.cs+++ b/.Source/GTweak/Core/ViewModel/Components/DownloadSession.cs@@ -1,11 +1,13 @@using System;using System.IO;+using System.Net.Http;using System.Threading;using System.Threading.Tasks;using GTweak.Core.Base;using GTweak.Core.Models;using GTweak.Core.Services;using GTweak.Utilities.Controls;+using GTweak.Utilities.Managers;namespace GTweak.Core.ViewModel.Components{@@ -50,32 +52,36 @@ namespace GTweak.Core.ViewModel.Componentspublic async Task Start(){- if (!IsDownloading)+ try{- IsDownloading = true;-- _cts?.Dispose();- _cts = new CancellationTokenSource();+ string finalUrl = await ToolsetDownloadService.GetResolvedDownloadUrl(_model);- try+ if (!string.IsNullOrEmpty(finalUrl)){- string finalUrl = await ToolsetDownloadService.GetResolvedDownloadUrl(_model);+ IsDownloading = true;+ _cts = new CancellationTokenSource();- if (!string.IsNullOrEmpty(finalUrl))- {- string destinationFolder = SettingsEngine.DownloadPath ?? Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);- await ToolsetDownloadService.DownloadFile(finalUrl, Path.Combine(destinationFolder, GetFileNameFromUrl(finalUrl)), _model.SourceUrl, new Progress<double>(value => Progress = value), _cts.Token);- }- }- catch (Exception ex) { ErrorLogging.LogDebug(ex); }- finally- {- IsDownloading = false;- _cts?.Dispose();- _cts = null;- System.Windows.Input.CommandManager.InvalidateRequerySuggested();+ string destinationFolder = SettingsEngine.DownloadPath ?? Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);+ string destinationPath = Path.Combine(destinationFolder, GetFileNameFromUrl(finalUrl));++ await ToolsetDownloadService.DownloadFile(finalUrl, destinationPath, _model.SourceUrl, new Progress<double>(v => Progress = v), _cts.Token);}}+ catch (Exception ex) when (ex.Message == "GitHubRateLimit")+ {+ NotificationManager.Show("warn", "error_git_limit_noty").Perform();+ }+ catch (HttpRequestException)+ {+ NotificationManager.Show("warn", "error_download_noty").Perform();+ }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }+ finally+ {+ IsDownloading = false;+ _cts?.Dispose();+ _cts = null;+ }}public void Cancel()diff --git a/.Source/GTweak/Languages/en/Localize.xaml b/.Source/GTweak/Languages/en/Localize.xamlindex 92783fdf..b7515f1d 100644--- a/.Source/GTweak/Languages/en/Localize.xaml+++ b/.Source/GTweak/Languages/en/Localize.xaml@@ -74,6 +74,8 @@<v:String x:Key="notsupport_ntfs_noty">The operation is unavailable because the directory is not located on an NTFS partition</v:String><v:String x:Key="success_reg_exporter_noty">Registry file saved successfully</v:String><v:String x:Key="error_reg_exporter_noty">An error occurred while saving the registry file</v:String>+ <v:String x:Key="error_git_limit_noty">GitHub has temporarily rate-limited API requests, please try again later</v:String>+ <v:String x:Key="error_download_noty">Failed to establish a connection with the server</v:String><!--#endregion--><!--#region Main Window -->diff --git a/.Source/GTweak/Languages/fr/Localize.xaml b/.Source/GTweak/Languages/fr/Localize.xamlindex 978f32ae..8f1ae913 100644--- a/.Source/GTweak/Languages/fr/Localize.xaml+++ b/.Source/GTweak/Languages/fr/Localize.xaml@@ -74,6 +74,8 @@<v:String x:Key="notsupport_ntfs_noty">L’opération est indisponible car le répertoire n’est pas situé sur une partition NTFS</v:String><v:String x:Key="success_reg_exporter_noty">Fichier de registre enregistré avec succès</v:String><v:String x:Key="error_reg_exporter_noty">Une erreur est survenue lors de l'enregistrement du fichier de registre</v:String>+ <v:String x:Key="error_git_limit_noty">GitHub has temporarily rate-limited API requests, please try again later</v:String>+ <v:String x:Key="error_download_noty">Failed to establish a connection with the server</v:String><!--#endregion--><!--#region Main Window -->diff --git a/.Source/GTweak/Languages/hu/Localize.xaml b/.Source/GTweak/Languages/hu/Localize.xamlindex c4456757..e8368e31 100644--- a/.Source/GTweak/Languages/hu/Localize.xaml+++ b/.Source/GTweak/Languages/hu/Localize.xaml@@ -74,6 +74,8 @@<v:String x:Key="notsupport_ntfs_noty">A művelet nem érhető el, mert a könyvtár nem NTFS-partíción található</v:String><v:String x:Key="success_reg_exporter_noty">A rendszerleíró adatbázis fájlja sikeresen mentve</v:String><v:String x:Key="error_reg_exporter_noty">Hiba történt a rendszerleíró adatbázis fájl mentése közben</v:String>+ <v:String x:Key="error_git_limit_noty">GitHub has temporarily rate-limited API requests, please try again later</v:String>+ <v:String x:Key="error_download_noty">Failed to establish a connection with the server</v:String><!--#endregion--><!--#region Main Window -->diff --git a/.Source/GTweak/Languages/it/Localize.xaml b/.Source/GTweak/Languages/it/Localize.xamlindex c60a7586..7ee19a6b 100644--- a/.Source/GTweak/Languages/it/Localize.xaml+++ b/.Source/GTweak/Languages/it/Localize.xaml@@ -74,6 +74,8 @@<v:String x:Key="notsupport_ntfs_noty">Operazione non disponibile perché la directory non si trova su una partizione NTFS</v:String><v:String x:Key="success_reg_exporter_noty">File di registro salvato con successo</v:String><v:String x:Key="error_reg_exporter_noty">Si è verificato un errore durante il salvataggio del file di registro</v:String>+ <v:String x:Key="error_git_limit_noty">GitHub has temporarily rate-limited API requests, please try again later</v:String>+ <v:String x:Key="error_download_noty">Failed to establish a connection with the server</v:String><!--#endregion--><!--#region Main Window -->diff --git a/.Source/GTweak/Languages/ko/Localize.xaml b/.Source/GTweak/Languages/ko/Localize.xamlindex cf27d867..8b2dbe09 100644--- a/.Source/GTweak/Languages/ko/Localize.xaml+++ b/.Source/GTweak/Languages/ko/Localize.xaml@@ -74,6 +74,8 @@<v:String x:Key="notsupport_ntfs_noty">디렉터리가 NTFS 파티션에 있지 않으므로 작업을 수행할 수 없습니다</v:String><v:String x:Key="success_reg_exporter_noty">레지스트리 파일이 성공적으로 저장되었습니다</v:String><v:String x:Key="error_reg_exporter_noty">레지스트리 파일을 저장하는 동안 오류가 발생했습니다</v:String>+ <v:String x:Key="error_git_limit_noty">GitHub has temporarily rate-limited API requests, please try again later</v:String>+ <v:String x:Key="error_download_noty">Failed to establish a connection with the server</v:String><!--#endregion--><!--#region Main Window -->diff --git a/.Source/GTweak/Languages/pl/Localize.xaml b/.Source/GTweak/Languages/pl/Localize.xamlindex c7751535..8d8909b1 100644--- a/.Source/GTweak/Languages/pl/Localize.xaml+++ b/.Source/GTweak/Languages/pl/Localize.xaml@@ -74,6 +74,8 @@<v:String x:Key="notsupport_ntfs_noty">Operacja niedostępna, ponieważ katalog nie znajduje się na partycji NTFS</v:String><v:String x:Key="success_reg_exporter_noty">Plik rejestru zapisany pomyślnie</v:String><v:String x:Key="error_reg_exporter_noty">Wystąpił błąd podczas zapisywania pliku rejestru</v:String>+ <v:String x:Key="error_git_limit_noty">GitHub has temporarily rate-limited API requests, please try again later</v:String>+ <v:String x:Key="error_download_noty">Failed to establish a connection with the server</v:String><!--#endregion--><!--#region Main Window -->diff --git a/.Source/GTweak/Languages/pt-BR/Localize.xaml b/.Source/GTweak/Languages/pt-BR/Localize.xamlindex e584a10d..a44c8e17 100644--- a/.Source/GTweak/Languages/pt-BR/Localize.xaml+++ b/.Source/GTweak/Languages/pt-BR/Localize.xaml@@ -74,6 +74,8 @@<v:String x:Key="notsupport_ntfs_noty">A operação não está disponível porque o diretório não está localizado em uma partição NTFS</v:String><v:String x:Key="success_reg_exporter_noty">Arquivo de registro salvo com sucesso</v:String><v:String x:Key="error_reg_exporter_noty">Ocorreu um erro ao salvar o arquivo de registro</v:String>+ <v:String x:Key="error_git_limit_noty">GitHub has temporarily rate-limited API requests, please try again later</v:String>+ <v:String x:Key="error_download_noty">Failed to establish a connection with the server</v:String><!--#endregion--><!--#region Main Window -->diff --git a/.Source/GTweak/Languages/ru/Localize.xaml b/.Source/GTweak/Languages/ru/Localize.xamlindex 1c7cb9b8..33320025 100644--- a/.Source/GTweak/Languages/ru/Localize.xaml+++ b/.Source/GTweak/Languages/ru/Localize.xaml@@ -74,6 +74,8 @@<v:String x:Key="notsupport_ntfs_noty">Операция недоступна, так как каталог не находится на NTFS-разделе</v:String><v:String x:Key="success_reg_exporter_noty">Файл реестра успешно сохранён</v:String><v:String x:Key="error_reg_exporter_noty">Произошла ошибка при сохранении файла реестра</v:String>+ <v:String x:Key="error_git_limit_noty">GitHub временно ограничил запросы к API, попробуйте позже</v:String>+ <v:String x:Key="error_download_noty">Не удалось установить соединение с сервером</v:String><!--#endregion--><!--#region Main Window -->diff --git a/.Source/GTweak/Languages/uk/Localize.xaml b/.Source/GTweak/Languages/uk/Localize.xamlindex f5f5f9fc..718e1bf1 100644--- a/.Source/GTweak/Languages/uk/Localize.xaml+++ b/.Source/GTweak/Languages/uk/Localize.xaml@@ -74,6 +74,8 @@<v:String x:Key="notsupport_ntfs_noty">Операція недоступна, оскільки каталог не знаходиться на NTFS-розділі</v:String><v:String x:Key="success_reg_exporter_noty">Файл реєстру успішно збережено</v:String><v:String x:Key="error_reg_exporter_noty">Виникла помилка під час збереження файлу реєстру</v:String>+ <v:String x:Key="error_git_limit_noty">GitHub has temporarily rate-limited API requests, please try again later</v:String>+ <v:String x:Key="error_download_noty">Failed to establish a connection with the server</v:String><!--#endregion--><!--#region Main Window -->diff --git a/.Source/GTweak/Languages/zh-CN/Localize.xaml b/.Source/GTweak/Languages/zh-CN/Localize.xamlindex 6dc3d393..0b2be7f9 100644--- a/.Source/GTweak/Languages/zh-CN/Localize.xaml+++ b/.Source/GTweak/Languages/zh-CN/Localize.xaml@@ -74,6 +74,8 @@<v:String x:Key="notsupport_ntfs_noty">此操作无法运行,因为目录未位于 NTFS 分区上</v:String><v:String x:Key="success_reg_exporter_noty">注册表已成功存储</v:String><v:String x:Key="error_reg_exporter_noty">存储注册表时发生错误</v:String>+ <v:String x:Key="error_git_limit_noty">GitHub has temporarily rate-limited API requests, please try again later</v:String>+ <v:String x:Key="error_download_noty">Failed to establish a connection with the server</v:String><!--#endregion--><!--#region Main Window -->diff --git a/.Source/GTweak/Languages/zh-TW/Localize.xaml b/.Source/GTweak/Languages/zh-TW/Localize.xamlindex 230dc43d..ca386889 100644--- a/.Source/GTweak/Languages/zh-TW/Localize.xaml+++ b/.Source/GTweak/Languages/zh-TW/Localize.xaml@@ -74,6 +74,8 @@<v:String x:Key="notsupport_ntfs_noty">此操作無法執行,因為目錄未位於 NTFS 分區上</v:String><v:String x:Key="success_reg_exporter_noty">登錄檔已成功儲存</v:String><v:String x:Key="error_reg_exporter_noty">儲存登錄檔時發生錯誤</v:String>+ <v:String x:Key="error_git_limit_noty">GitHub has temporarily rate-limited API requests, please try again later</v:String>+ <v:String x:Key="error_download_noty">Failed to establish a connection with the server</v:String><!--#endregion--><!--#region Main Window -->