diff --git a/v2rayN/v2rayUpgrade/App.xaml b/v2rayN/v2rayUpgrade/App.xaml
new file mode 100644
index 00000000..3693a05b
--- /dev/null
+++ b/v2rayN/v2rayUpgrade/App.xaml
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/v2rayN/v2rayUpgrade/App.xaml.cs b/v2rayN/v2rayUpgrade/App.xaml.cs
new file mode 100644
index 00000000..2df0e5fe
--- /dev/null
+++ b/v2rayN/v2rayUpgrade/App.xaml.cs
@@ -0,0 +1,10 @@
+using System.Windows;
+
+namespace v2rayUpgrade;
+
+///
+/// Interaction logic for App.xaml
+///
+public partial class App : Application
+{
+}
\ No newline at end of file
diff --git a/v2rayN/v2rayUpgrade/MainForm.Designer.cs b/v2rayN/v2rayUpgrade/MainForm.Designer.cs
deleted file mode 100644
index bdfa4379..00000000
--- a/v2rayN/v2rayUpgrade/MainForm.Designer.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-namespace v2rayUpgrade
-{
- partial class MainForm
- {
- ///
- /// 必需的设计器变量。
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// 清理所有正在使用的资源。
- ///
- /// 如果应释放托管资源,为 true;否则为 false。
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows 窗体设计器生成的代码
-
- ///
- /// 设计器支持所需的方法 - 不要修改
- /// 使用代码编辑器修改此方法的内容。
- ///
- private void InitializeComponent()
- {
- this.btnClose = new System.Windows.Forms.Button();
- this.btnOK = new System.Windows.Forms.Button();
- this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.SuspendLayout();
- //
- // btnClose
- //
- this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this.btnClose.Font = new System.Drawing.Font("微软雅黑", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.btnClose.ImeMode = System.Windows.Forms.ImeMode.NoControl;
- this.btnClose.Location = new System.Drawing.Point(367, 118);
- this.btnClose.Name = "btnClose";
- this.btnClose.Size = new System.Drawing.Size(184, 89);
- this.btnClose.TabIndex = 1;
- this.btnClose.Text = "&Exit(退出)";
- this.btnClose.UseVisualStyleBackColor = true;
- this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
- //
- // btnOK
- //
- this.btnOK.Font = new System.Drawing.Font("微软雅黑", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.btnOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
- this.btnOK.Location = new System.Drawing.Point(81, 118);
- this.btnOK.Name = "btnOK";
- this.btnOK.Size = new System.Drawing.Size(184, 89);
- this.btnOK.TabIndex = 0;
- this.btnOK.Text = "&Upgrade(升级)";
- this.btnOK.UseVisualStyleBackColor = true;
- this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Font = new System.Drawing.Font("微软雅黑", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.label1.Location = new System.Drawing.Point(79, 64);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(205, 15);
- this.label1.TabIndex = 8;
- this.label1.Text = "升级成功后将自动重启v2rayN";
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Font = new System.Drawing.Font("微软雅黑", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.label2.Location = new System.Drawing.Point(79, 37);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(471, 15);
- this.label2.TabIndex = 9;
- this.label2.Text = "v2rayN will restart automatically after successful upgrade";
- //
- // MainForm
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(616, 284);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.btnClose);
- this.Controls.Add(this.btnOK);
- this.Name = "MainForm";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "v2rayUpgrade";
- this.ResumeLayout(false);
- this.PerformLayout();
-
- }
-
- #endregion
-
- private System.Windows.Forms.Button btnClose;
- private System.Windows.Forms.Button btnOK;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Label label2;
- }
-}
-
diff --git a/v2rayN/v2rayUpgrade/MainForm.cs b/v2rayN/v2rayUpgrade/MainForm.cs
deleted file mode 100644
index 6b9ff16c..00000000
--- a/v2rayN/v2rayUpgrade/MainForm.cs
+++ /dev/null
@@ -1,148 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.IO;
-using System.IO.Compression;
-using System.Text;
-using System.Web;
-using System.Windows.Forms;
-
-namespace v2rayUpgrade
-{
- public partial class MainForm : Form
- {
- private readonly string defaultFilename = "v2ray-windows.zip";
- private string fileName;
-
- public MainForm(string[] args)
- {
- InitializeComponent();
- if (args.Length > 0)
- {
- fileName = string.Join(" ", args);
- fileName = HttpUtility.UrlDecode(fileName);
- }
- }
- private void showWarn(string message)
- {
- MessageBox.Show(message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
-
- private void btnOK_Click(object sender, EventArgs e)
- {
- try
- {
- Process[] existing = Process.GetProcessesByName("v2rayN");
- foreach (Process p in existing)
- {
- string path = p.MainModule.FileName;
- if (path == GetPath("v2rayN.exe"))
- {
- p.Kill();
- p.WaitForExit(100);
- }
- }
- }
- catch (Exception ex)
- {
- // Access may be denied without admin right. The user may not be an administrator.
- showWarn("Failed to close v2rayN(关闭v2rayN失败).\n" +
- "Close it manually, or the upgrade may fail.(请手动关闭正在运行的v2rayN,否则可能升级失败。\n\n" + ex.StackTrace);
- }
-
- StringBuilder sb = new StringBuilder();
- try
- {
- if (!File.Exists(fileName))
- {
- if (File.Exists(defaultFilename))
- {
- fileName = defaultFilename;
- }
- else
- {
- showWarn("Upgrade Failed, File Not Exist(升级失败,文件不存在).");
- return;
- }
- }
-
- string thisAppOldFile = Application.ExecutablePath + ".tmp";
- File.Delete(thisAppOldFile);
- string startKey = "v2rayN/";
-
-
- using (ZipArchive archive = ZipFile.OpenRead(fileName))
- {
- foreach (ZipArchiveEntry entry in archive.Entries)
- {
- try
- {
- if (entry.Length == 0)
- {
- continue;
- }
- string fullName = entry.FullName;
- if (fullName.StartsWith(startKey))
- {
- fullName = fullName.Substring(startKey.Length, fullName.Length - startKey.Length);
- }
- if (Application.ExecutablePath.ToLower() == GetPath(fullName).ToLower())
- {
- File.Move(Application.ExecutablePath, thisAppOldFile);
- }
-
- string entryOuputPath = GetPath(fullName);
-
- FileInfo fileInfo = new FileInfo(entryOuputPath);
- fileInfo.Directory.Create();
- entry.ExtractToFile(entryOuputPath, true);
- }
- catch (Exception ex)
- {
- sb.Append(ex.StackTrace);
- }
- }
- }
- }
- catch (Exception ex)
- {
- showWarn("Upgrade Failed(升级失败)." + ex.StackTrace);
- return;
- }
- if (sb.Length > 0)
- {
- showWarn("Upgrade Failed,Hold ctrl + c to copy to clipboard.\n" +
- "(升级失败,按住ctrl+c可以复制到剪贴板)." + sb.ToString());
- return;
- }
-
- Process.Start("v2rayN.exe");
- MessageBox.Show("Upgrade successed(升级成功)", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
-
- Close();
- }
-
- private void btnClose_Click(object sender, EventArgs e)
- {
- Close();
- }
-
- public static string GetExePath()
- {
- return Application.ExecutablePath;
- }
-
- public static string StartupPath()
- {
- return Application.StartupPath;
- }
- public static string GetPath(string fileName)
- {
- string startupPath = StartupPath();
- if (string.IsNullOrEmpty(fileName))
- {
- return startupPath;
- }
- return Path.Combine(startupPath, fileName);
- }
- }
-}
diff --git a/v2rayN/v2rayUpgrade/MainForm.resx b/v2rayN/v2rayUpgrade/MainForm.resx
deleted file mode 100644
index 1af7de15..00000000
--- a/v2rayN/v2rayUpgrade/MainForm.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file
diff --git a/v2rayN/v2rayUpgrade/MainWindow.xaml b/v2rayN/v2rayUpgrade/MainWindow.xaml
new file mode 100644
index 00000000..41e68325
--- /dev/null
+++ b/v2rayN/v2rayUpgrade/MainWindow.xaml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/v2rayN/v2rayUpgrade/MainWindow.xaml.cs b/v2rayN/v2rayUpgrade/MainWindow.xaml.cs
new file mode 100644
index 00000000..ac45f8e4
--- /dev/null
+++ b/v2rayN/v2rayUpgrade/MainWindow.xaml.cs
@@ -0,0 +1,155 @@
+using System.Diagnostics;
+using System.IO;
+using System.IO.Compression;
+using System.Text;
+using System.Web;
+using System.Windows;
+
+namespace v2rayUpgrade;
+
+///
+/// Interaction logic for MainWindow.xaml
+///
+public partial class MainWindow : Window
+{
+ private const string DefaultFilename = "v2rayN.zip_temp";
+ private string _fileName;
+
+ public MainWindow()
+ {
+ InitializeComponent();
+ var args = Environment.GetCommandLineArgs();
+ if (args.Length == 2)
+ {
+ _fileName = args[1];
+ _fileName = HttpUtility.UrlDecode(_fileName);
+ }
+ else
+ {
+ _fileName = DefaultFilename;
+ }
+ }
+
+ private static void ShowWarn(string message)
+ {
+ MessageBox.Show(message, "", MessageBoxButton.OK, MessageBoxImage.Warning);
+ }
+
+ private void ButtonOK_OnClick(object sender, EventArgs e)
+ {
+ try
+ {
+ var existing = Process.GetProcessesByName("v2rayN");
+ foreach (var p in existing)
+ {
+ var path = p.MainModule!.FileName;
+ if (path != GetPath("v2rayN.exe")) continue;
+ p.Kill();
+ p.WaitForExit(100);
+ }
+ }
+ catch (Exception ex)
+ {
+ // Access may be denied without admin right. The user may not be an administrator.
+ ShowWarn(
+ $"Failed to close v2rayN(关闭v2rayN失败).\nClose it manually, or the upgrade may fail.(请手动关闭正在运行的v2rayN,否则可能升级失败。\n\n{ex.StackTrace}");
+ }
+
+ var sb = new StringBuilder();
+ try
+ {
+ if (!File.Exists(_fileName))
+ {
+ if (File.Exists(DefaultFilename))
+ {
+ _fileName = DefaultFilename;
+ }
+ else
+ {
+ ShowWarn("Upgrade Failed, File Not Exist(升级失败,文件不存在).");
+ return;
+ }
+ }
+
+ var thisAppOldFile = ExePath() + ".tmp";
+ File.Delete(thisAppOldFile);
+ const string startKey = "v2rayN/";
+
+
+ using var archive = ZipFile.OpenRead(_fileName);
+ foreach (var entry in archive.Entries)
+ {
+ try
+ {
+ if (entry.Length == 0)
+ {
+ continue;
+ }
+
+ var fullName = entry.FullName;
+ if (fullName.StartsWith(startKey))
+ {
+ fullName = fullName.Substring(startKey.Length, fullName.Length - startKey.Length);
+ }
+
+ if (string.Equals(ExePath(), GetPath(fullName), StringComparison.CurrentCultureIgnoreCase))
+ {
+ File.Move(ExePath(), thisAppOldFile);
+ }
+
+ var entryOutputPath = GetPath(fullName);
+
+ var fileInfo = new FileInfo(entryOutputPath);
+ fileInfo.Directory!.Create();
+ entry.ExtractToFile(entryOutputPath, true);
+ }
+ catch (Exception ex)
+ {
+ sb.Append(ex.StackTrace);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ ShowWarn("Upgrade Failed(升级失败)." + ex.StackTrace);
+ return;
+ }
+
+ if (sb.Length > 0)
+ {
+ ShowWarn($"Upgrade Failed,Hold ctrl + c to copy to clipboard.\n(升级失败,按住ctrl+c可以复制到剪贴板).{sb}");
+ return;
+ }
+
+ Process.Start("v2rayN.exe");
+ MessageBox.Show("Upgrade succeeded(升级成功)", "", MessageBoxButton.OK, MessageBoxImage.Information);
+
+ Close();
+ }
+
+ private void ButtonClose_OnClick(object sender, EventArgs e)
+ {
+ Close();
+ }
+
+ private static string ExePath()
+ {
+ return Process.GetCurrentProcess().MainModule.FileName;
+ }
+
+ private static string StartupPath()
+ {
+ return Path.GetDirectoryName(ExePath())!;
+ }
+
+ private static string GetPath(string fileName)
+ {
+ var startupPath = StartupPath();
+ if (string.IsNullOrEmpty(fileName))
+ {
+ return startupPath;
+ }
+
+ return Path.Combine(startupPath, fileName);
+ }
+}
\ No newline at end of file
diff --git a/v2rayN/v2rayUpgrade/Program.cs b/v2rayN/v2rayUpgrade/Program.cs
deleted file mode 100644
index f35e72a4..00000000
--- a/v2rayN/v2rayUpgrade/Program.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System;
-using System.Windows.Forms;
-
-namespace v2rayUpgrade
-{
- static class Program
- {
- ///
- /// 应用程序的主入口点。
- ///
- [STAThread]
- static void Main(string[] args)
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new MainForm(args));
- }
- }
-}
diff --git a/v2rayN/v2rayUpgrade/v2rayUpgrade.csproj b/v2rayN/v2rayUpgrade/v2rayUpgrade.csproj
index d3a7d721..2608eb91 100644
--- a/v2rayN/v2rayUpgrade/v2rayUpgrade.csproj
+++ b/v2rayN/v2rayUpgrade/v2rayUpgrade.csproj
@@ -1,11 +1,14 @@
+ preview
net48
WinExe
- true
+ enable
+ true
Copyright © 2019-2020 (GPLv3)
1.1.0.0
app.manifest
+ enable