This commit is contained in:
JustArchi
2017-12-16 11:40:38 +01:00
parent bf6784eb9e
commit ad8898db77

View File

@@ -291,39 +291,45 @@ namespace ArchiSteamFarm {
return null; return null;
} }
ASF.ArchiLogger.LogGenericDebug("0%..."); ArchiLogger.LogGenericDebug("0%...");
using (MemoryStream ms = new MemoryStream()) { using (MemoryStream ms = new MemoryStream()) {
using (Stream contentStream = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false)) { try {
long contentLength = httpResponse.Content.Headers.ContentLength.GetValueOrDefault(); using (Stream contentStream = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false)) {
byte batch = 0; long contentLength = httpResponse.Content.Headers.ContentLength.GetValueOrDefault();
uint readThisBatch = 0; byte batch = 0;
byte[] buffer = new byte[8192]; // This is HttpClient's buffer, using more doesn't make sense uint readThisBatch = 0;
byte[] buffer = new byte[8192]; // This is HttpClient's buffer, using more doesn't make sense
while (contentStream.CanRead) { while (contentStream.CanRead) {
int read = await contentStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false); int read = await contentStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
if (read == 0) { if (read == 0) {
break; break;
}
await ms.WriteAsync(buffer, 0, read).ConfigureAwait(false);
if ((contentLength == 0) || (batch >= printPercentage)) {
continue;
}
readThisBatch += (uint) read;
if (readThisBatch < contentLength / printPercentage) {
continue;
}
readThisBatch = 0;
ArchiLogger.LogGenericDebug(++batch * printPercentage + "%...");
} }
await ms.WriteAsync(buffer, 0, read).ConfigureAwait(false);
if ((contentLength == 0) || (batch >= printPercentage)) {
continue;
}
readThisBatch += (uint) read;
if (readThisBatch < contentLength / printPercentage) {
continue;
}
readThisBatch = 0;
ASF.ArchiLogger.LogGenericDebug(++batch * printPercentage + "%...");
} }
} catch (Exception e) {
ArchiLogger.LogGenericDebuggingException(e);
ArchiLogger.LogGenericDebug(Strings.BotReconnecting);
return null;
} }
ASF.ArchiLogger.LogGenericDebug("100%"); ArchiLogger.LogGenericDebug("100%");
return ms.ToArray(); return ms.ToArray();
} }
} }