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 @@ + + + + + + + + + + + + + +