Various auto-update improvements

This commit is contained in:
JustArchi
2017-07-05 07:30:08 +02:00
parent ad09b1dec9
commit c46eee4499
6 changed files with 18 additions and 10 deletions

View File

@@ -189,7 +189,7 @@ namespace ArchiSteamFarm {
return;
}
ArchiLogger.LogGenericInfo(Strings.UpdateDownloadingNewVersion);
ArchiLogger.LogGenericInfo(string.Format(Strings.UpdateDownloadingNewVersion, newVersion, binaryAsset.Size / 1024 / 1024));
byte[] result = await Program.WebBrowser.UrlGetToBytesRetry(binaryAsset.DownloadURL).ConfigureAwait(false);
if (result == null) {

View File

@@ -55,6 +55,11 @@ namespace ArchiSteamFarm.JSON {
internal readonly string Name;
#pragma warning restore 649
#pragma warning disable 649
[JsonProperty(PropertyName = "size", Required = Required.Always)]
internal readonly uint Size;
#pragma warning restore 649
// Deserialized from JSON
private Asset() { }
}

View File

@@ -1306,7 +1306,7 @@ namespace ArchiSteamFarm.Localization {
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu Downloading new version... While waiting, consider donating if you appreciate the work being done! :).
/// Wyszukuje zlokalizowany ciąg podobny do ciągu Downloading new version: {0} ({1} MB)... While waiting, consider donating if you appreciate the work being done! :).
/// </summary>
internal static string UpdateDownloadingNewVersion {
get {

View File

@@ -247,7 +247,8 @@ StackTrace:
<value>Checking for new version...</value>
</data>
<data name="UpdateDownloadingNewVersion" xml:space="preserve">
<value>Downloading new version... While waiting, consider donating if you appreciate the work being done! :)</value>
<value>Downloading new version: {0} ({1} MB)... While waiting, consider donating if you appreciate the work being done! :)</value>
<comment>{0} will be replaced by version string, {1} will be replaced by update size (in megabytes)</comment>
</data>
<data name="UpdateFinished" xml:space="preserve">
<value>Update process finished!</value>

View File

@@ -309,7 +309,7 @@ namespace ArchiSteamFarm {
OS.Init(GlobalConfig.Headless);
WebBrowser.Init();
WebBrowser = new WebBrowser(ASF.ArchiLogger);
WebBrowser = new WebBrowser(ASF.ArchiLogger, true);
}
private static async Task<bool> InitShutdownSequence() {

View File

@@ -37,6 +37,7 @@ namespace ArchiSteamFarm {
internal sealed class WebBrowser {
internal const byte MaxRetries = 5; // Defines maximum number of retries, UrlRequest() does not handle retry by itself (it's app responsibility)
private const byte ExtendedTimeoutMultiplier = 10; // Multiplier for WebBrowsers dealing with huge data
private const byte MaxConnections = ServicePointManager.DefaultNonPersistentConnectionLimit; // Defines maximum number of connections per ServicePoint. Be careful, as it also defines maximum number of sockets in CLOSE_WAIT state
private const byte MaxIdleTime = 15; // In seconds, how long socket is allowed to stay in CLOSE_WAIT state after there are no connections to it
@@ -45,7 +46,7 @@ namespace ArchiSteamFarm {
private readonly ArchiLogger ArchiLogger;
private readonly HttpClient HttpClient;
internal WebBrowser(ArchiLogger archiLogger) {
internal WebBrowser(ArchiLogger archiLogger, bool extendedTimeout = false) {
ArchiLogger = archiLogger ?? throw new ArgumentNullException(nameof(archiLogger));
HttpClientHandler httpClientHandler = new HttpClientHandler {
@@ -54,7 +55,7 @@ namespace ArchiSteamFarm {
};
HttpClient = new HttpClient(httpClientHandler) {
Timeout = TimeSpan.FromSeconds(Program.GlobalConfig.ConnectionTimeout)
Timeout = TimeSpan.FromSeconds(extendedTimeout ? ExtendedTimeoutMultiplier * Program.GlobalConfig.ConnectionTimeout : Program.GlobalConfig.ConnectionTimeout)
};
// Most web services expect that UserAgent is set, so we declare it globally
@@ -380,12 +381,13 @@ namespace ArchiSteamFarm {
}
private async Task<HttpResponseMessage> UrlGetToResponse(string request, string referer = null) {
if (!string.IsNullOrEmpty(request)) {
return await UrlRequest(new Uri(request), HttpMethod.Get, null, referer).ConfigureAwait(false);
if (string.IsNullOrEmpty(request)) {
ArchiLogger.LogNullError(nameof(request));
return null;
}
ArchiLogger.LogNullError(nameof(request));
return null;
HttpResponseMessage result = await UrlRequest(new Uri(request), HttpMethod.Get, null, referer).ConfigureAwait(false);
return result;
}
private async Task<XmlDocument> UrlGetToXML(string request, string referer = null) {