mirror of https://github.com/2dust/v2rayN
parent
24afe8bde4
commit
fd7cf164ff
|
@ -479,6 +479,12 @@ namespace ServiceLib.Common
|
|||
|
||||
#region 杂项
|
||||
|
||||
public static bool UpgradeAppExists(out string fileName)
|
||||
{
|
||||
fileName = Path.Combine(Utils.StartupPath(), GetExeName("AmazTool"));
|
||||
return File.Exists(fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得版本
|
||||
/// </summary>
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace ServiceLib.Handler
|
|||
private WebDavClient? _client;
|
||||
private string? _lastDescription;
|
||||
private string _webDir = Global.AppName + "_backup";
|
||||
private string _webFileName = "backup.zip";
|
||||
private readonly string _webFileName = "backup.zip";
|
||||
private string _logTitle = "WebDav--";
|
||||
|
||||
public WebDavHandler()
|
||||
|
@ -130,7 +130,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
try
|
||||
{
|
||||
using var fs = File.OpenRead(fileName);
|
||||
await using var fs = File.OpenRead(fileName);
|
||||
var result = await _client.PutFile($"{_webDir}/{_webFileName}", fs); // upload a resource
|
||||
if (result.IsSuccessful)
|
||||
{
|
||||
|
@ -162,8 +162,9 @@ namespace ServiceLib.Handler
|
|||
SaveLog(response.Description);
|
||||
return false;
|
||||
}
|
||||
using var outputFileStream = new FileStream(fileName, FileMode.Create);
|
||||
response.Stream.CopyTo(outputFileStream);
|
||||
|
||||
await using var outputFileStream = new FileStream(fileName, FileMode.Create);
|
||||
await response.Stream.CopyToAsync(outputFileStream);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -3696,5 +3696,14 @@ namespace ServiceLib.Resx {
|
|||
return ResourceManager.GetString("UpdateStandalonePackageTip", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 UpgradeApp does not exist 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string UpgradeAppNotExistTip {
|
||||
get {
|
||||
return ResourceManager.GetString("UpgradeAppNotExistTip", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1330,4 +1330,7 @@
|
|||
<data name="TbSettingsGeoFilesSource" xml:space="preserve">
|
||||
<value>Geo files source (optional)</value>
|
||||
</data>
|
||||
<data name="UpgradeAppNotExistTip" xml:space="preserve">
|
||||
<value>UpgradeApp does not exist</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1327,4 +1327,7 @@
|
|||
<data name="TbSettingsGeoFilesSource" xml:space="preserve">
|
||||
<value>Geo文件来源(可选)</value>
|
||||
</data>
|
||||
<data name="UpgradeAppNotExistTip" xml:space="preserve">
|
||||
<value>升级工具App不存在</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1207,4 +1207,7 @@
|
|||
<data name="TbSettingsGeoFilesSource" xml:space="preserve">
|
||||
<value>Geo文件來源(可選)</value>
|
||||
</data>
|
||||
<data name="UpgradeAppNotExistTip" xml:space="preserve">
|
||||
<value>升级工具App不存在</value>
|
||||
</data>
|
||||
</root>
|
|
@ -4,7 +4,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>6.60.0</Version>
|
||||
<Version>6.10.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -100,7 +100,7 @@ namespace ServiceLib.Services
|
|||
};
|
||||
HttpClient client = new(webRequestHandler);
|
||||
|
||||
HttpResponseMessage response = await client.GetAsync(url);
|
||||
var response = await client.GetAsync(url);
|
||||
if (response.StatusCode == HttpStatusCode.Redirect && response.Headers.Location is not null)
|
||||
{
|
||||
return response.Headers.Location.ToString();
|
||||
|
@ -253,15 +253,12 @@ namespace ServiceLib.Services
|
|||
{
|
||||
try
|
||||
{
|
||||
if (webProxy == null)
|
||||
{
|
||||
webProxy = GetWebProxy(true);
|
||||
}
|
||||
webProxy ??= GetWebProxy(true);
|
||||
|
||||
try
|
||||
{
|
||||
var config = AppHandler.Instance.Config;
|
||||
int responseTime = await GetRealPingTime(config.speedTestItem.speedPingTestUrl, webProxy, 10);
|
||||
var responseTime = await GetRealPingTime(config.speedTestItem.speedPingTestUrl, webProxy, 10);
|
||||
return responseTime;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -279,7 +276,7 @@ namespace ServiceLib.Services
|
|||
|
||||
public async Task<int> GetRealPingTime(string url, IWebProxy? webProxy, int downloadTimeout)
|
||||
{
|
||||
int responseTime = -1;
|
||||
var responseTime = -1;
|
||||
try
|
||||
{
|
||||
using var cts = new CancellationTokenSource();
|
||||
|
@ -290,8 +287,8 @@ namespace ServiceLib.Services
|
|||
UseProxy = webProxy != null
|
||||
});
|
||||
|
||||
List<int> oneTime = [];
|
||||
for (int i = 0; i < 2; i++)
|
||||
List<int> oneTime = new();
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
var timer = Stopwatch.StartNew();
|
||||
await client.GetAsync(url, cts.Token);
|
||||
|
|
|
@ -423,7 +423,7 @@ namespace ServiceLib.Services
|
|||
&& File.Exists(Path.Combine(Utils.StartupPath(), "D3DCompiler_47_cor3.dll"))
|
||||
)
|
||||
{
|
||||
return coreInfo?.DownloadUrlWin64?.Replace("v2rayN.zip", "zz_v2rayN-SelfContained.zip");
|
||||
return coreInfo?.DownloadUrlWin64?.Replace(".zip", "-SelfContained.zip");
|
||||
}
|
||||
|
||||
return RuntimeInformation.ProcessArchitecture switch
|
||||
|
|
|
@ -126,11 +126,16 @@ namespace ServiceLib.ViewModels
|
|||
}
|
||||
//check
|
||||
var lstFiles = FileManager.GetFilesFromZip(fileName);
|
||||
if (lstFiles is null || !lstFiles.Where(t => t.Contains(_guiConfigs)).Any())
|
||||
if (lstFiles is null || !lstFiles.Any(t => t.Contains(_guiConfigs)))
|
||||
{
|
||||
DisplayOperationMsg(ResUI.LocalRestoreInvalidZipTips);
|
||||
return;
|
||||
}
|
||||
if (!Utils.UpgradeAppExists(out _))
|
||||
{
|
||||
DisplayOperationMsg(ResUI.UpgradeAppNotExistTip);
|
||||
return;
|
||||
}
|
||||
|
||||
//backup first
|
||||
var fileBackup = Utils.GetBackupPath(BackupFileName);
|
||||
|
|
|
@ -235,6 +235,11 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
return;
|
||||
}
|
||||
if (!Utils.UpgradeAppExists(out _))
|
||||
{
|
||||
UpdateView(_v2rayN, ResUI.UpgradeAppNotExistTip);
|
||||
return;
|
||||
}
|
||||
Locator.Current.GetService<MainWindowViewModel>()?.UpgradeApp(fileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -280,14 +280,21 @@ namespace ServiceLib.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public async Task UpgradeApp(string fileName)
|
||||
public async Task UpgradeApp(string arg)
|
||||
{
|
||||
if (!Utils.UpgradeAppExists(out var fileName))
|
||||
{
|
||||
NoticeHandler.Instance.SendMessageAndEnqueue(ResUI.UpgradeAppNotExistTip);
|
||||
Logging.SaveLog("UpgradeApp does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
Process process = new()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "AmazTool",
|
||||
Arguments = fileName.AppendQuotes(),
|
||||
FileName = fileName,
|
||||
Arguments = arg.AppendQuotes(),
|
||||
WorkingDirectory = Utils.StartupPath()
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue