2dust 2024-10-15 09:31:30 +08:00
parent 24afe8bde4
commit fd7cf164ff
12 changed files with 58 additions and 19 deletions

View File

@ -479,6 +479,12 @@ namespace ServiceLib.Common
#region 杂项 #region 杂项
public static bool UpgradeAppExists(out string fileName)
{
fileName = Path.Combine(Utils.StartupPath(), GetExeName("AmazTool"));
return File.Exists(fileName);
}
/// <summary> /// <summary>
/// 取得版本 /// 取得版本
/// </summary> /// </summary>

View File

@ -12,7 +12,7 @@ namespace ServiceLib.Handler
private WebDavClient? _client; private WebDavClient? _client;
private string? _lastDescription; private string? _lastDescription;
private string _webDir = Global.AppName + "_backup"; private string _webDir = Global.AppName + "_backup";
private string _webFileName = "backup.zip"; private readonly string _webFileName = "backup.zip";
private string _logTitle = "WebDav--"; private string _logTitle = "WebDav--";
public WebDavHandler() public WebDavHandler()
@ -130,7 +130,7 @@ namespace ServiceLib.Handler
try 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 var result = await _client.PutFile($"{_webDir}/{_webFileName}", fs); // upload a resource
if (result.IsSuccessful) if (result.IsSuccessful)
{ {
@ -162,8 +162,9 @@ namespace ServiceLib.Handler
SaveLog(response.Description); SaveLog(response.Description);
return false; 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; return true;
} }
catch (Exception ex) catch (Exception ex)

View File

@ -3696,5 +3696,14 @@ namespace ServiceLib.Resx {
return ResourceManager.GetString("UpdateStandalonePackageTip", resourceCulture); return ResourceManager.GetString("UpdateStandalonePackageTip", resourceCulture);
} }
} }
/// <summary>
/// 查找类似 UpgradeApp does not exist 的本地化字符串。
/// </summary>
public static string UpgradeAppNotExistTip {
get {
return ResourceManager.GetString("UpgradeAppNotExistTip", resourceCulture);
}
}
} }
} }

View File

@ -1330,4 +1330,7 @@
<data name="TbSettingsGeoFilesSource" xml:space="preserve"> <data name="TbSettingsGeoFilesSource" xml:space="preserve">
<value>Geo files source (optional)</value> <value>Geo files source (optional)</value>
</data> </data>
<data name="UpgradeAppNotExistTip" xml:space="preserve">
<value>UpgradeApp does not exist</value>
</data>
</root> </root>

View File

@ -1327,4 +1327,7 @@
<data name="TbSettingsGeoFilesSource" xml:space="preserve"> <data name="TbSettingsGeoFilesSource" xml:space="preserve">
<value>Geo文件来源(可选)</value> <value>Geo文件来源(可选)</value>
</data> </data>
<data name="UpgradeAppNotExistTip" xml:space="preserve">
<value>升级工具App不存在</value>
</data>
</root> </root>

View File

@ -1207,4 +1207,7 @@
<data name="TbSettingsGeoFilesSource" xml:space="preserve"> <data name="TbSettingsGeoFilesSource" xml:space="preserve">
<value>Geo文件來源(可選)</value> <value>Geo文件來源(可選)</value>
</data> </data>
<data name="UpgradeAppNotExistTip" xml:space="preserve">
<value>升级工具App不存在</value>
</data>
</root> </root>

View File

@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Version>6.60.0</Version> <Version>6.10.0</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -100,7 +100,7 @@ namespace ServiceLib.Services
}; };
HttpClient client = new(webRequestHandler); 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) if (response.StatusCode == HttpStatusCode.Redirect && response.Headers.Location is not null)
{ {
return response.Headers.Location.ToString(); return response.Headers.Location.ToString();
@ -253,15 +253,12 @@ namespace ServiceLib.Services
{ {
try try
{ {
if (webProxy == null) webProxy ??= GetWebProxy(true);
{
webProxy = GetWebProxy(true);
}
try try
{ {
var config = AppHandler.Instance.Config; 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; return responseTime;
} }
catch (Exception ex) catch (Exception ex)
@ -279,7 +276,7 @@ namespace ServiceLib.Services
public async Task<int> GetRealPingTime(string url, IWebProxy? webProxy, int downloadTimeout) public async Task<int> GetRealPingTime(string url, IWebProxy? webProxy, int downloadTimeout)
{ {
int responseTime = -1; var responseTime = -1;
try try
{ {
using var cts = new CancellationTokenSource(); using var cts = new CancellationTokenSource();
@ -290,8 +287,8 @@ namespace ServiceLib.Services
UseProxy = webProxy != null UseProxy = webProxy != null
}); });
List<int> oneTime = []; List<int> oneTime = new();
for (int i = 0; i < 2; i++) for (var i = 0; i < 2; i++)
{ {
var timer = Stopwatch.StartNew(); var timer = Stopwatch.StartNew();
await client.GetAsync(url, cts.Token); await client.GetAsync(url, cts.Token);

View File

@ -423,7 +423,7 @@ namespace ServiceLib.Services
&& File.Exists(Path.Combine(Utils.StartupPath(), "D3DCompiler_47_cor3.dll")) && 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 return RuntimeInformation.ProcessArchitecture switch

View File

@ -126,11 +126,16 @@ namespace ServiceLib.ViewModels
} }
//check //check
var lstFiles = FileManager.GetFilesFromZip(fileName); 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); DisplayOperationMsg(ResUI.LocalRestoreInvalidZipTips);
return; return;
} }
if (!Utils.UpgradeAppExists(out _))
{
DisplayOperationMsg(ResUI.UpgradeAppNotExistTip);
return;
}
//backup first //backup first
var fileBackup = Utils.GetBackupPath(BackupFileName); var fileBackup = Utils.GetBackupPath(BackupFileName);

View File

@ -235,6 +235,11 @@ namespace ServiceLib.ViewModels
{ {
return; return;
} }
if (!Utils.UpgradeAppExists(out _))
{
UpdateView(_v2rayN, ResUI.UpgradeAppNotExistTip);
return;
}
Locator.Current.GetService<MainWindowViewModel>()?.UpgradeApp(fileName); Locator.Current.GetService<MainWindowViewModel>()?.UpgradeApp(fileName);
} }
catch (Exception ex) catch (Exception ex)

View File

@ -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() Process process = new()
{ {
StartInfo = new ProcessStartInfo StartInfo = new ProcessStartInfo
{ {
FileName = "AmazTool", FileName = fileName,
Arguments = fileName.AppendQuotes(), Arguments = arg.AppendQuotes(),
WorkingDirectory = Utils.StartupPath() WorkingDirectory = Utils.StartupPath()
} }
}; };