diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2025-04-30 15:39:34 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2025-05-05 11:03:20 +0000 |
commit | a31bafffadc5466f4a588aee04b98dfd4441166c (patch) | |
tree | 15b0c9513c0c15a209234150fd57dd892ff6cc91 | |
parent | 72b7d1f6cef044de76ce0edc444dab84242f9855 (diff) |
Rename QmlLanguageServerDownloader to FileDownloader
Prepares this class for more general purposes, such as downloading
development release packages, etc. Also fixed some typos in the code.
Change-Id: I0988896623f64d437259a857037c5e554a284f2b
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r-- | QtVsTools.Core/FileDownloader.cs (renamed from QtVsTools.Core/QmlLanguageServerDownloader.cs) | 14 | ||||
-rw-r--r-- | QtVsTools.Core/QmlLanguageServerManager.cs | 2 | ||||
-rw-r--r-- | QtVsTools.Core/QmlLanguageServerMonitorTask.cs | 6 | ||||
-rw-r--r-- | QtVsTools.Core/QtVsTools.Core.csproj | 2 |
4 files changed, 10 insertions, 14 deletions
diff --git a/QtVsTools.Core/QmlLanguageServerDownloader.cs b/QtVsTools.Core/FileDownloader.cs index 2ab75bb1..c3dac027 100644 --- a/QtVsTools.Core/QmlLanguageServerDownloader.cs +++ b/QtVsTools.Core/FileDownloader.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace QtVsTools.Core { - internal static class QmlLanguageServerDownloader + internal static class FileDownloader { private const int MaxRetries = 3; private const int MaxRedirects = 10; @@ -19,7 +19,7 @@ namespace QtVsTools.Core internal static async Task DownloadAsync(string url, string destPath, CancellationToken token, - Func<(long CurrentBytes, long MaxBytyes), Task> callback = null) + Func<(long CurrentBytes, long MaxBytes), Task> callback = null) { var downloadUrl = url; for (var i = 0; i < MaxRedirects; ++i) { @@ -38,26 +38,22 @@ namespace QtVsTools.Core continue; } - await DownloadOctetStreamAsync(response, destPath, token, callback); + await DownloadFileAsync(response, destPath, token, callback); return; } throw new InvalidOperationException("Too many redirects."); } - private static async Task DownloadOctetStreamAsync(HttpResponseMessage response, + private static async Task DownloadFileAsync(HttpResponseMessage response, string destPath, CancellationToken token, - Func<(long CurrentBytes, long MaxBytyes), Task> callback = null) + Func<(long CurrentBytes, long MaxBytes), Task> callback = null) { if (!response.IsSuccessStatusCode) { throw new InvalidOperationException($"Unexpected status: {response.StatusCode} " + $"for URL: '{response.RequestMessage?.RequestUri}'."); } - var contentType = response.Content.Headers.ContentType?.MediaType; - if (contentType != "application/octet-stream") - Messages.Print("Warning: Content type is not 'application/octet-stream'."); - var contentLength = response.Content.Headers.ContentLength; long downloadedBytes = 0; var buffer = new byte[BufferSize]; diff --git a/QtVsTools.Core/QmlLanguageServerManager.cs b/QtVsTools.Core/QmlLanguageServerManager.cs index 8f8252d2..998308b9 100644 --- a/QtVsTools.Core/QmlLanguageServerManager.cs +++ b/QtVsTools.Core/QmlLanguageServerManager.cs @@ -97,7 +97,7 @@ namespace QtVsTools.Core try { var tmpPath = Path.Combine(downloadDir, asset.Name); - await QmlLanguageServerDownloader.DownloadAsync(asset.BrowserDownloadUrl, tmpPath, + await FileDownloader.DownloadAsync(asset.BrowserDownloadUrl, tmpPath, token, downloadCallback); await Utils.ExtractArchiveAsync(tmpPath, ExtractDir, token, extractCallback); diff --git a/QtVsTools.Core/QmlLanguageServerMonitorTask.cs b/QtVsTools.Core/QmlLanguageServerMonitorTask.cs index dca9bb1e..f18da5c8 100644 --- a/QtVsTools.Core/QmlLanguageServerMonitorTask.cs +++ b/QtVsTools.Core/QmlLanguageServerMonitorTask.cs @@ -100,15 +100,15 @@ namespace QtVsTools.Core await StatusBar.ResetProgressAsync(); var tmpPath = Path.Combine(downloadDir, asset.Name); - await QmlLanguageServerDownloader.DownloadAsync(asset.BrowserDownloadUrl, + await FileDownloader.DownloadAsync(asset.BrowserDownloadUrl, tmpPath, cancellationToken, async download => { await StatusBar.ProgressAsync( "Updating QML Language Server... Downloading " + $"{BytesToKilobytes(download.CurrentBytes)} / " - + $"{BytesToKilobytes(download.MaxBytyes)}", - (uint)download.MaxBytyes, (uint)download.CurrentBytes); + + $"{BytesToKilobytes(download.MaxBytes)}", + (uint)download.MaxBytes, (uint)download.CurrentBytes); } ); diff --git a/QtVsTools.Core/QtVsTools.Core.csproj b/QtVsTools.Core/QtVsTools.Core.csproj index ca2a73ab..7fead354 100644 --- a/QtVsTools.Core/QtVsTools.Core.csproj +++ b/QtVsTools.Core/QtVsTools.Core.csproj @@ -163,7 +163,7 @@ <Compile Include="VisualStudio\IdleTaskManager.cs" /> <Compile Include="Options\QtOptionsPageSettings.cs" /> <Compile Include="Common\SettingsBase.cs" /> - <Compile Include="QmlLanguageServerDownloader.cs" /> + <Compile Include="FileDownloader.cs" /> <Compile Include="QmlLanguageServerManager.cs" /> <Compile Include="QtBuildTool.cs" /> <Compile Include="QtPaths.cs" /> |