mirror of https://github.com/2dust/v2rayN
Improve subscription update
parent
f5ecda9255
commit
3079f1c651
|
@ -45,17 +45,9 @@ namespace v2rayN.Base
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try
|
HttpResponseMessage response = await httpClient.GetAsync(url);
|
||||||
{
|
|
||||||
HttpResponseMessage response = await httpClient.GetAsync(url);
|
|
||||||
|
|
||||||
return await response.Content.ReadAsStringAsync();
|
return await response.Content.ReadAsStringAsync();
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Utils.SaveLog("GetAsync", ex);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
public async Task<string> GetAsync(HttpClient client, string url, CancellationToken token)
|
public async Task<string> GetAsync(HttpClient client, string url, CancellationToken token)
|
||||||
{
|
{
|
||||||
|
@ -63,16 +55,12 @@ namespace v2rayN.Base
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try
|
HttpResponseMessage response = await client.GetAsync(url, token);
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
HttpResponseMessage response = await client.GetAsync(url, token);
|
throw new Exception(string.Format("The request returned with HTTP status code {0}", response.StatusCode));
|
||||||
return await response.Content.ReadAsStringAsync();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
return await response.Content.ReadAsStringAsync();
|
||||||
{
|
|
||||||
Utils.SaveLog("GetAsync", ex);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PutAsync(string url, Dictionary<string, string> headers)
|
public async Task PutAsync(string url, Dictionary<string, string> headers)
|
||||||
|
|
|
@ -166,6 +166,7 @@ namespace v2rayN.Handler
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Utils.SaveLog(ex.Message, ex);
|
Utils.SaveLog(ex.Message, ex);
|
||||||
|
Error?.Invoke(this, new ErrorEventArgs(ex));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,20 +198,31 @@ namespace v2rayN.Handler
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var downloadHandle = new DownloadHandle();
|
||||||
|
downloadHandle.Error += (sender2, args) =>
|
||||||
|
{
|
||||||
|
_updateFunc(false, $"{hashCode}{args.GetException().Message}");
|
||||||
|
};
|
||||||
|
|
||||||
_updateFunc(false, $"{hashCode}{ResUI.MsgStartGettingSubscriptions}");
|
_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))
|
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))
|
if (Utils.IsNullOrEmpty(result))
|
||||||
{
|
{
|
||||||
_updateFunc(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}");
|
_updateFunc(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
_updateFunc(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}");
|
||||||
|
if (result.Length < 99)
|
||||||
|
{
|
||||||
|
_updateFunc(false, $"{hashCode}{result}");
|
||||||
|
}
|
||||||
|
|
||||||
int ret = ConfigHandler.AddBatchServers(ref config, result, id, groupId);
|
int ret = ConfigHandler.AddBatchServers(ref config, result, id, groupId);
|
||||||
_updateFunc(false,
|
_updateFunc(false,
|
||||||
ret > 0
|
ret > 0
|
||||||
|
|
Loading…
Reference in New Issue