Skip to content

Portable Tool for an Ideal Windows Setup

fix align loading dots and make cancellation instant

Greedekse1636deb334f
diff --git a/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml b/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml
index bc5e39d2..d68f3053 100644
--- a/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml
+++ b/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml
@@ -167,9 +167,9 @@
</Style.Triggers>
</Style>
</TextBlock.Style>
- <Run Text="{DynamicResource connecting_ts}" /><InlineUIContainer>
- <Border Width="15">
- <TextBlock x:Name="DotText" Text="" Style="{StaticResource TextDefault}" FontSize="13px">
+ <Run Text="{DynamicResource connecting_ts}" /><InlineUIContainer BaselineAlignment="Baseline">
+ <Border Width="15" Margin="0,0,0,-2" Background="Transparent" VerticalAlignment="Bottom">
+ <TextBlock x:Name="DotText" Style="{StaticResource TextDefault}" FontSize="13px">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
diff --git a/.Source/GTweak/Core/Services/ToolsetDownloadService.cs b/.Source/GTweak/Core/Services/ToolsetDownloadService.cs
index 2fba3a08..762b9b10 100644
--- a/.Source/GTweak/Core/Services/ToolsetDownloadService.cs
+++ b/.Source/GTweak/Core/Services/ToolsetDownloadService.cs
@@ -29,7 +29,7 @@ namespace GTweak.Core.Services
internal static DownloadSession GetOrCreateSession(ToolsetModel model) => _sessions.GetOrAdd(!string.IsNullOrWhiteSpace(model.SourceUrl) ? model.SourceUrl : model.AppName, _ => new DownloadSession(model));
- internal static async Task<string> GetResolvedDownloadUrl(ToolsetModel model)
+ internal static async Task<string> GetResolvedDownloadUrl(ToolsetModel model, CancellationToken token = default)
{
if (model.Group.Equals("web", StringComparison.OrdinalIgnoreCase))
{
@@ -38,7 +38,9 @@ namespace GTweak.Core.Services
return model.DownloadPath;
}
- string htmlCode = await _httpClient.GetStringAsync(model.DownloadPath);
+ using HttpResponseMessage response = await _httpClient.GetAsync(model.DownloadPath, token);
+ response.EnsureSuccessStatusCode();
+ string htmlCode = await response.Content.ReadAsStringAsync();
Match match = Regex.Match(htmlCode, model.UrlPattern, RegexOptions.IgnoreCase);
if (match.Success)
@@ -60,7 +62,7 @@ namespace GTweak.Core.Services
if (model.Group.Equals("github", StringComparison.OrdinalIgnoreCase))
{
string apiUrl = PathLocator.Links.DownloadSources.GitHubLatest(model.DownloadPath);
- using HttpResponseMessage response = await _httpClient.GetAsync(apiUrl);
+ using HttpResponseMessage response = await _httpClient.GetAsync(apiUrl, token);
if (!response.IsSuccessStatusCode)
{
@@ -104,7 +106,7 @@ namespace GTweak.Core.Services
string bestReleaseUrl = PathLocator.Links.DownloadSources.SourceForgeBest(projectName);
try
{
- using HttpResponseMessage response = await _httpClient.GetAsync(bestReleaseUrl);
+ using HttpResponseMessage response = await _httpClient.GetAsync(bestReleaseUrl, token);
if (response.IsSuccessStatusCode)
{
string content = await response.Content.ReadAsStringAsync();
@@ -128,7 +130,9 @@ namespace GTweak.Core.Services
try
{
string rssUrl = PathLocator.Links.DownloadSources.SourceForgeRss(projectName);
- string rssContent = await _httpClient.GetStringAsync(rssUrl);
+ using HttpResponseMessage rssResponse = await _httpClient.GetAsync(rssUrl, token);
+ rssResponse.EnsureSuccessStatusCode();
+ string rssContent = await rssResponse.Content.ReadAsStringAsync();
MatchCollection rssMatches = Regex.Matches(rssContent, PathLocator.Links.DownloadSources.SourceForgeRssRegex(projectName), RegexOptions.IgnoreCase);
@@ -161,7 +165,11 @@ namespace GTweak.Core.Services
if (model.Group.Equals("techpowerup", StringComparison.OrdinalIgnoreCase))
{
- Match idMatch = Regex.Match(await _httpClient.GetStringAsync(model.DownloadPath), @"name=""id""\s+value=""(?<id>\d+)""", RegexOptions.IgnoreCase);
+ using HttpResponseMessage initialResponse = await _httpClient.GetAsync(model.DownloadPath, token);
+ initialResponse.EnsureSuccessStatusCode();
+ string initialHtml = await initialResponse.Content.ReadAsStringAsync();
+
+ Match idMatch = Regex.Match(initialHtml, @"name=""id""\s+value=""(?<id>\d+)""", RegexOptions.IgnoreCase);
if (!idMatch.Success)
{
@@ -172,7 +180,7 @@ namespace GTweak.Core.Services
FormUrlEncodedContent firstStepPayload = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("id", fileId) });
- using HttpResponseMessage firstResponse = await _httpClient.PostAsync(model.DownloadPath, firstStepPayload);
+ using HttpResponseMessage firstResponse = await _httpClient.PostAsync(model.DownloadPath, firstStepPayload, token);
string serverSelectionHtml = await firstResponse.Content.ReadAsStringAsync();
MatchCollection serverMatches = Regex.Matches(serverSelectionHtml, @"(?is)<button[^>]+?name=""server_id""[^>]+?value=""(?<sid>\d+)""[^>]*>(?<content>.*?)</button>");
@@ -207,7 +215,7 @@ namespace GTweak.Core.Services
finalRequest.Headers.Referrer = new Uri(model.DownloadPath);
- using HttpResponseMessage finalResponse = await _httpClient.SendAsync(finalRequest, HttpCompletionOption.ResponseHeadersRead);
+ using HttpResponseMessage finalResponse = await _httpClient.SendAsync(finalRequest, HttpCompletionOption.ResponseHeadersRead, token);
return finalResponse.RequestMessage.RequestUri.ToString();
}
diff --git a/.Source/GTweak/Core/ViewModel/Components/DownloadSession.cs b/.Source/GTweak/Core/ViewModel/Components/DownloadSession.cs
index dc988cad..4ab914d6 100644
--- a/.Source/GTweak/Core/ViewModel/Components/DownloadSession.cs
+++ b/.Source/GTweak/Core/ViewModel/Components/DownloadSession.cs
@@ -53,12 +53,13 @@ namespace GTweak.Core.ViewModel.Components
public async Task Start()
{
+ _cts = new CancellationTokenSource();
IsDownloading = true;
Progress = 0;
try
{
- string finalUrl = await ToolsetDownloadService.GetResolvedDownloadUrl(_model);
+ string finalUrl = await ToolsetDownloadService.GetResolvedDownloadUrl(_model, _cts.Token);
if (string.IsNullOrEmpty(finalUrl))
{
@@ -66,7 +67,6 @@ namespace GTweak.Core.ViewModel.Components
return;
}
- _cts = new CancellationTokenSource();
string destinationFolder = SettingsEngine.DownloadPath ?? Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string destinationPath = Path.Combine(destinationFolder, GetFileNameFromUrl(finalUrl));
@@ -79,6 +79,11 @@ namespace GTweak.Core.ViewModel.Components
}
catch (Exception ex)
{
+ if (ex is OperationCanceledException || ex is TaskCanceledException)
+ {
+ return;
+ }
+
await Task.Delay(500);
switch (ex)
@@ -89,8 +94,6 @@ namespace GTweak.Core.ViewModel.Components
case HttpRequestException _:
NotificationManager.Show("warn", "error_download_noty").Perform();
break;
- case OperationCanceledException _:
- break;
default:
ErrorLogging.LogDebug(ex);
break;