mirror of https://github.com/2dust/v2rayN
Improve subscription update
parent
f5ecda9255
commit
3079f1c651
|
@ -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);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
HttpResponseMessage response = await client.GetAsync(url, token);
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
throw new Exception(string.Format("The request returned with HTTP status code {0}", response.StatusCode));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.SaveLog("GetAsync", ex);
|
||||
}
|
||||
return null;
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
public async Task PutAsync(string url, Dictionary<string, string> headers)
|
||||
|
|
|
@ -166,6 +166,7 @@ namespace v2rayN.Handler
|
|||
catch (Exception ex)
|
||||
{
|
||||
Utils.SaveLog(ex.Message, ex);
|
||||
Error?.Invoke(this, new ErrorEventArgs(ex));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -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…
Reference in New Issue