mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Change Download to DownloadAsync
Add error handling for download as well
This commit is contained in:
parent
a8dc1599d7
commit
bc63b9ebfa
2 changed files with 17 additions and 9 deletions
|
|
@ -75,17 +75,25 @@ namespace Flow.Launcher.Infrastructure.Http
|
|||
};
|
||||
}
|
||||
|
||||
public static async Task Download([NotNull] string url, [NotNull] string filePath)
|
||||
public static async Task DownloadAsync([NotNull] string url, [NotNull] string filePath)
|
||||
{
|
||||
using var response = await client.GetAsync(url);
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
try
|
||||
{
|
||||
await using var fileStream = new FileStream(filePath, FileMode.CreateNew);
|
||||
await response.Content.CopyToAsync(fileStream);
|
||||
using var response = await client.GetAsync(url);
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
await using var fileStream = new FileStream(filePath, FileMode.CreateNew);
|
||||
await response.Content.CopyToAsync(fileStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new HttpRequestException($"Error code <{response.StatusCode}> returned from <{url}>");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
throw new HttpRequestException($"Error code <{response.StatusCode}> returned from <{url}>");
|
||||
Log.Exception("Infrastructure.Http", "Http Request Error", e, "DownloadAsync");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_please_wait"));
|
||||
|
||||
await Http.Download(plugin.UrlDownload, filePath).ConfigureAwait(false);
|
||||
await Http.DownloadAsync(plugin.UrlDownload, filePath).ConfigureAwait(false);
|
||||
|
||||
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_download_success"));
|
||||
|
|
@ -217,7 +217,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_please_wait"));
|
||||
|
||||
await Http.Download(x.PluginNewUserPlugin.UrlDownload, downloadToFilePath).ConfigureAwait(false);
|
||||
await Http.DownloadAsync(x.PluginNewUserPlugin.UrlDownload, downloadToFilePath).ConfigureAwait(false);
|
||||
|
||||
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_download_success"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue