This commit is contained in:
Kamushek
2020-08-23 14:07:22 +03:00
committed by GitHub
parent 02c6fa734e
commit a15a6e6fe7
2 changed files with 12 additions and 6 deletions

View File

@@ -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) {

View File

@@ -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());
}