mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
IProgress (#1945)
This commit is contained in:
@@ -298,7 +298,12 @@ namespace ArchiSteamFarm {
|
||||
|
||||
ArchiLogger.LogGenericInfo(string.Format(Strings.UpdateDownloadingNewVersion, newVersion, binaryAsset.Size / 1024 / 1024));
|
||||
|
||||
WebBrowser.BinaryResponse? response = await WebBrowser.UrlGetToBinaryWithProgress(binaryAsset.DownloadURL!).ConfigureAwait(false);
|
||||
Progress<int> progressReporter = new Progress<int>();
|
||||
progressReporter.ProgressChanged += ReportHandler;
|
||||
|
||||
WebBrowser.BinaryResponse? response = await WebBrowser.UrlGetToBinary(binaryAsset.DownloadURL!, progressReporter: progressReporter).ConfigureAwait(false);
|
||||
|
||||
progressReporter.ProgressChanged -= ReportHandler;
|
||||
|
||||
if (response?.Content == null) {
|
||||
return null;
|
||||
@@ -344,6 +349,8 @@ namespace ArchiSteamFarm {
|
||||
} finally {
|
||||
UpdateSemaphore.Release();
|
||||
}
|
||||
|
||||
static void ReportHandler(object? sender, int progressPercentage) => ArchiLogger.LogGenericDebug($"{progressPercentage}%...");
|
||||
}
|
||||
|
||||
private static async Task<bool> CanHandleWriteEvent(string filePath) {
|
||||
|
||||
@@ -426,7 +426,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task<BinaryResponse?> UrlGetToBinaryWithProgress(string request, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries) {
|
||||
internal async Task<BinaryResponse?> UrlGetToBinary(string request, string? referer = null, ERequestOptions requestOptions = ERequestOptions.None, byte maxTries = MaxTries, IProgress<int>? progressReporter = null) {
|
||||
if (string.IsNullOrEmpty(request) || (maxTries == 0)) {
|
||||
throw new ArgumentNullException(nameof(request) + " || " + nameof(maxTries));
|
||||
}
|
||||
@@ -451,8 +451,7 @@ namespace ArchiSteamFarm {
|
||||
continue;
|
||||
}
|
||||
|
||||
ArchiLogger.LogGenericDebug("0%...");
|
||||
|
||||
progressReporter?.Report(0);
|
||||
#if NETFRAMEWORK
|
||||
using MemoryStream ms = new MemoryStream((int) response.Length);
|
||||
#else
|
||||
@@ -484,7 +483,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
readThisBatch -= response.Length / printPercentage;
|
||||
ArchiLogger.LogGenericDebug((++batch * printPercentage) + "%...");
|
||||
progressReporter?.Report(++batch * printPercentage);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ArchiLogger.LogGenericDebuggingException(e);
|
||||
@@ -492,7 +491,7 @@ namespace ArchiSteamFarm {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArchiLogger.LogGenericDebug("100%");
|
||||
progressReporter?.Report(100);
|
||||
|
||||
return new BinaryResponse(response, ms.ToArray());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user