mirror of https://github.com/2dust/v2rayN
update geo files for sing-box
parent
59d397a3a0
commit
ec8f6478df
|
@ -20,6 +20,7 @@
|
|||
public const string tuicCoreUrl = "https://github.com/EAimTY/tuic/releases";
|
||||
public const string singboxCoreUrl = "https://github.com/SagerNet/sing-box/releases";
|
||||
public const string geoUrl = "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/{0}.dat";
|
||||
public const string singboxGeoUrl = "https://github.com/soffchen/sing-{0}/releases/latest/download/{0}.db";
|
||||
public const string SpeedPingTestUrl = @"https://www.google.com/generate_204";
|
||||
public const string CustomRoutingListUrl = @"https://raw.githubusercontent.com/2dust/v2rayCustomRoutingList/master/";
|
||||
|
||||
|
|
|
@ -62,12 +62,12 @@ namespace v2rayN.Handler
|
|||
return 0;
|
||||
}
|
||||
|
||||
public void DownloadFileAsync(string url, bool blProxy, int downloadTimeout)
|
||||
public async Task DownloadFileAsync(string url, bool blProxy, int downloadTimeout)
|
||||
{
|
||||
try
|
||||
{
|
||||
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
|
||||
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, ResUI.Downloading));
|
||||
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, $"{ResUI.Downloading} {url}"));
|
||||
|
||||
var progress = new Progress<double>();
|
||||
progress.ProgressChanged += (sender, value) =>
|
||||
|
@ -76,7 +76,7 @@ namespace v2rayN.Handler
|
|||
};
|
||||
|
||||
var webProxy = GetWebProxy(blProxy);
|
||||
_ = DownloaderHelper.Instance.DownloadFileAsync(webProxy,
|
||||
await DownloaderHelper.Instance.DownloadFileAsync(webProxy,
|
||||
url,
|
||||
Utils.GetTempPath(Utils.GetDownloadFileName(url)),
|
||||
progress,
|
||||
|
|
|
@ -206,19 +206,10 @@ namespace v2rayN.Handler
|
|||
{
|
||||
if ((dtNow - autoUpdateGeoTime).Hours % config.guiItem.autoUpdateInterval == 0)
|
||||
{
|
||||
updateHandle.UpdateGeoFile("geosite", config, (bool success, string msg) =>
|
||||
updateHandle.UpdateGeoFileAll(config, (bool success, string msg) =>
|
||||
{
|
||||
update(false, msg);
|
||||
if (success)
|
||||
Utils.SaveLog("geosite" + msg);
|
||||
});
|
||||
|
||||
updateHandle.UpdateGeoFile("geoip", config, (bool success, string msg) =>
|
||||
{
|
||||
update(false, msg);
|
||||
if (success)
|
||||
Utils.SaveLog("geoip" + msg);
|
||||
});
|
||||
update(false, msg);
|
||||
});
|
||||
autoUpdateGeoTime = dtNow;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace v2rayN.Handler
|
|||
_updateFunc(false, string.Format(ResUI.MsgParsingSuccessfully, "v2rayN"));
|
||||
|
||||
url = args.Msg;
|
||||
askToDownload(downloadHandle, url, true);
|
||||
_ = askToDownload(downloadHandle, url, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -135,7 +135,7 @@ namespace v2rayN.Handler
|
|||
{
|
||||
_updateFunc(false, string.Format(ResUI.MsgParsingSuccessfully, "Core"));
|
||||
url = args.Msg;
|
||||
askToDownload(downloadHandle, url, true);
|
||||
_ = askToDownload(downloadHandle, url, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -279,51 +279,16 @@ namespace v2rayN.Handler
|
|||
});
|
||||
}
|
||||
|
||||
public void UpdateGeoFile(string geoName, Config config, Action<bool, string> update)
|
||||
public void UpdateGeoFileAll(Config config, Action<bool, string> update)
|
||||
{
|
||||
_config = config;
|
||||
_updateFunc = update;
|
||||
var url = string.Format(Global.geoUrl, geoName);
|
||||
|
||||
DownloadHandle downloadHandle = new();
|
||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (args.Success)
|
||||
{
|
||||
_updateFunc(false, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, geoName));
|
||||
await UpdateGeoFile("geosite", _config, update);
|
||||
await UpdateGeoFile("geoip", _config, update);
|
||||
|
||||
try
|
||||
{
|
||||
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url));
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
//Global.coreTypes.ForEach(it =>
|
||||
//{
|
||||
// string targetPath = Utils.GetBinPath($"{geoName}.dat", (ECoreType)Enum.Parse(typeof(ECoreType), it));
|
||||
// File.Copy(fileName, targetPath, true);
|
||||
//});
|
||||
string targetPath = Utils.GetBinPath($"{geoName}.dat");
|
||||
File.Copy(fileName, targetPath, true);
|
||||
|
||||
File.Delete(fileName);
|
||||
//_updateFunc(true, "");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_updateFunc(false, ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_updateFunc(false, args.Msg);
|
||||
}
|
||||
};
|
||||
downloadHandle.Error += (sender2, args) =>
|
||||
{
|
||||
_updateFunc(false, args.GetException().Message);
|
||||
};
|
||||
askToDownload(downloadHandle, url, false);
|
||||
await UpdateGeoFile4Singbox("geosite", _config, update);
|
||||
await UpdateGeoFile4Singbox("geoip", _config, update);
|
||||
});
|
||||
}
|
||||
|
||||
public void RunAvailabilityCheck(Action<bool, string> update)
|
||||
|
@ -570,7 +535,7 @@ namespace v2rayN.Handler
|
|||
}
|
||||
}
|
||||
|
||||
private void askToDownload(DownloadHandle downloadHandle, string url, bool blAsk)
|
||||
private async Task askToDownload(DownloadHandle downloadHandle, string url, bool blAsk)
|
||||
{
|
||||
bool blDownload = false;
|
||||
if (blAsk)
|
||||
|
@ -586,10 +551,98 @@ namespace v2rayN.Handler
|
|||
}
|
||||
if (blDownload)
|
||||
{
|
||||
downloadHandle.DownloadFileAsync(url, true, 600);
|
||||
await downloadHandle.DownloadFileAsync(url, true, 600);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateGeoFile(string geoName, Config config, Action<bool, string> update)
|
||||
{
|
||||
_config = config;
|
||||
_updateFunc = update;
|
||||
var url = string.Format(Global.geoUrl, geoName);
|
||||
|
||||
DownloadHandle downloadHandle = new();
|
||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||
{
|
||||
if (args.Success)
|
||||
{
|
||||
_updateFunc(false, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, geoName));
|
||||
|
||||
try
|
||||
{
|
||||
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url));
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
//Global.coreTypes.ForEach(it =>
|
||||
//{
|
||||
// string targetPath = Utils.GetBinPath($"{geoName}.dat", (ECoreType)Enum.Parse(typeof(ECoreType), it));
|
||||
// File.Copy(fileName, targetPath, true);
|
||||
//});
|
||||
string targetPath = Utils.GetBinPath($"{geoName}.dat");
|
||||
File.Copy(fileName, targetPath, true);
|
||||
|
||||
File.Delete(fileName);
|
||||
//_updateFunc(true, "");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_updateFunc(false, ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_updateFunc(false, args.Msg);
|
||||
}
|
||||
};
|
||||
downloadHandle.Error += (sender2, args) =>
|
||||
{
|
||||
_updateFunc(false, args.GetException().Message);
|
||||
};
|
||||
await askToDownload(downloadHandle, url, false);
|
||||
}
|
||||
|
||||
private async Task UpdateGeoFile4Singbox(string geoName, Config config, Action<bool, string> update)
|
||||
{
|
||||
_config = config;
|
||||
_updateFunc = update;
|
||||
var url = string.Format(Global.singboxGeoUrl, geoName);
|
||||
|
||||
DownloadHandle downloadHandle = new();
|
||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||
{
|
||||
if (args.Success)
|
||||
{
|
||||
_updateFunc(false, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, geoName));
|
||||
|
||||
try
|
||||
{
|
||||
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url));
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
string targetPath = Utils.GetConfigPath($"{geoName}.db");
|
||||
File.Copy(fileName, targetPath, true);
|
||||
|
||||
File.Delete(fileName);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_updateFunc(false, ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_updateFunc(false, args.Msg);
|
||||
}
|
||||
};
|
||||
downloadHandle.Error += (sender2, args) =>
|
||||
{
|
||||
_updateFunc(false, args.GetException().Message);
|
||||
};
|
||||
await askToDownload(downloadHandle, url, false);
|
||||
}
|
||||
|
||||
#endregion private
|
||||
}
|
||||
}
|
|
@ -1460,12 +1460,7 @@ namespace v2rayN.ViewModels
|
|||
|
||||
private void CheckUpdateGeo()
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
var updateHandle = new UpdateHandle();
|
||||
updateHandle.UpdateGeoFile("geosite", _config, UpdateTaskHandler);
|
||||
updateHandle.UpdateGeoFile("geoip", _config, UpdateTaskHandler);
|
||||
});
|
||||
(new UpdateHandle()).UpdateGeoFileAll(_config, UpdateTaskHandler);
|
||||
}
|
||||
|
||||
#endregion CheckUpdate
|
||||
|
|
Loading…
Reference in New Issue