diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs
index fc273dbe..c482d149 100644
--- a/v2rayN/ServiceLib/Common/Utils.cs
+++ b/v2rayN/ServiceLib/Common/Utils.cs
@@ -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);
+ }
+
///
/// 取得版本
///
diff --git a/v2rayN/ServiceLib/Handler/WebDavHandler.cs b/v2rayN/ServiceLib/Handler/WebDavHandler.cs
index 81386cc2..3eda381c 100644
--- a/v2rayN/ServiceLib/Handler/WebDavHandler.cs
+++ b/v2rayN/ServiceLib/Handler/WebDavHandler.cs
@@ -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)
diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs
index 598eb574..f219d43b 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs
+++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs
@@ -3696,5 +3696,14 @@ namespace ServiceLib.Resx {
return ResourceManager.GetString("UpdateStandalonePackageTip", resourceCulture);
}
}
+
+ ///
+ /// 查找类似 UpgradeApp does not exist 的本地化字符串。
+ ///
+ public static string UpgradeAppNotExistTip {
+ get {
+ return ResourceManager.GetString("UpgradeAppNotExistTip", resourceCulture);
+ }
+ }
}
}
diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx
index 725481df..5d0f1a44 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.resx
@@ -1330,4 +1330,7 @@
Geo files source (optional)
+
+ UpgradeApp does not exist
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
index e2355650..59cba9c2 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
@@ -1327,4 +1327,7 @@
Geo文件来源(可选)
+
+ 升级工具App不存在
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
index b85c239d..b53aa888 100644
--- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
+++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
@@ -1207,4 +1207,7 @@
Geo文件來源(可選)
+
+ 升级工具App不存在
+
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/ServiceLib.csproj b/v2rayN/ServiceLib/ServiceLib.csproj
index 3a598909..d9b47d73 100644
--- a/v2rayN/ServiceLib/ServiceLib.csproj
+++ b/v2rayN/ServiceLib/ServiceLib.csproj
@@ -4,7 +4,7 @@
net8.0
enable
enable
- 6.60.0
+ 6.10.0
diff --git a/v2rayN/ServiceLib/Services/DownloadService.cs b/v2rayN/ServiceLib/Services/DownloadService.cs
index 887ef88a..0a6c5ec7 100644
--- a/v2rayN/ServiceLib/Services/DownloadService.cs
+++ b/v2rayN/ServiceLib/Services/DownloadService.cs
@@ -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 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 oneTime = [];
- for (int i = 0; i < 2; i++)
+ List oneTime = new();
+ for (var i = 0; i < 2; i++)
{
var timer = Stopwatch.StartNew();
await client.GetAsync(url, cts.Token);
diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs
index d821d1db..8e9e54e4 100644
--- a/v2rayN/ServiceLib/Services/UpdateService.cs
+++ b/v2rayN/ServiceLib/Services/UpdateService.cs
@@ -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
diff --git a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs
index 3b96c3da..7deececd 100644
--- a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs
@@ -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);
diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs
index f7800ad8..aac02973 100644
--- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs
@@ -235,6 +235,11 @@ namespace ServiceLib.ViewModels
{
return;
}
+ if (!Utils.UpgradeAppExists(out _))
+ {
+ UpdateView(_v2rayN, ResUI.UpgradeAppNotExistTip);
+ return;
+ }
Locator.Current.GetService()?.UpgradeApp(fileName);
}
catch (Exception ex)
diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
index a691647e..084e0f86 100644
--- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
@@ -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()
}
};