Browse Source

Improve subscription update

pull/2447/head
2dust 2 years ago
parent
commit
3079f1c651
  1. 24
      v2rayN/v2rayN/Base/HttpClientHelper.cs
  2. 1
      v2rayN/v2rayN/Handler/DownloadHandle.cs
  3. 17
      v2rayN/v2rayN/Handler/UpdateHandle.cs

24
v2rayN/v2rayN/Base/HttpClientHelper.cs

@ -45,17 +45,9 @@ namespace v2rayN.Base
{
return null;
}
try
{
HttpResponseMessage response = await httpClient.GetAsync(url);
HttpResponseMessage response = await httpClient.GetAsync(url);
return await response.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
Utils.SaveLog("GetAsync", ex);
}
return null;
return await response.Content.ReadAsStringAsync();
}
public async Task<string> GetAsync(HttpClient client, string url, CancellationToken token)
{
@ -63,16 +55,12 @@ namespace v2rayN.Base
{
return null;
}
try
{
HttpResponseMessage response = await client.GetAsync(url, token);
return await response.Content.ReadAsStringAsync();
}
catch (Exception ex)
HttpResponseMessage response = await client.GetAsync(url, token);
if (!response.IsSuccessStatusCode)
{
Utils.SaveLog("GetAsync", ex);
throw new Exception(string.Format("The request returned with HTTP status code {0}", response.StatusCode));
}
return null;
return await response.Content.ReadAsStringAsync();
}
public async Task PutAsync(string url, Dictionary<string, string> headers)

1
v2rayN/v2rayN/Handler/DownloadHandle.cs

@ -166,6 +166,7 @@ namespace v2rayN.Handler
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
Error?.Invoke(this, new ErrorEventArgs(ex));
}
return null;
}

17
v2rayN/v2rayN/Handler/UpdateHandle.cs

@ -198,20 +198,31 @@ namespace v2rayN.Handler
continue;
}
var downloadHandle = new DownloadHandle();
downloadHandle.Error += (sender2, args) =>
{
_updateFunc(false, $"{hashCode}{args.GetException().Message}");
};
_updateFunc(false, $"{hashCode}{ResUI.MsgStartGettingSubscriptions}");
var result = await (new DownloadHandle()).DownloadStringAsync(url, blProxy, userAgent);
var result = await downloadHandle.DownloadStringAsync(url, blProxy, userAgent);
if (blProxy && Utils.IsNullOrEmpty(result))
{
result = await (new DownloadHandle()).DownloadStringAsync(url, false, userAgent);
result = await downloadHandle.DownloadStringAsync(url, false, userAgent);
}
_updateFunc(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}");
if (Utils.IsNullOrEmpty(result))
{
_updateFunc(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}");
}
else
{
_updateFunc(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}");
if (result.Length < 99)
{
_updateFunc(false, $"{hashCode}{result}");
}
int ret = ConfigHandler.AddBatchServers(ref config, result, id, groupId);
_updateFunc(false,
ret > 0

Loading…
Cancel
Save