diff --git a/.gitignore b/.gitignore index b416e378..b5d8031c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ .vs/ProjectSettings.json .vs/slnx.sqlite .vs/VSWorkspaceState.json +/v2rayN/v2rayUpgrade/bin/Debug +/v2rayN/v2rayUpgrade/obj/Debug +/v2rayN/v2rayUpgrade/bin/Release +/v2rayN/v2rayUpgrade/obj/Release \ No newline at end of file diff --git a/v2rayN/v2rayUpgrade/App.config b/v2rayN/v2rayUpgrade/App.config new file mode 100644 index 00000000..731f6de6 --- /dev/null +++ b/v2rayN/v2rayUpgrade/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/v2rayN/v2rayUpgrade/MainForm.Designer.cs b/v2rayN/v2rayUpgrade/MainForm.Designer.cs new file mode 100644 index 00000000..f212a9a9 --- /dev/null +++ b/v2rayN/v2rayUpgrade/MainForm.Designer.cs @@ -0,0 +1,106 @@ +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.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 = 6; + this.btnClose.Text = "&Exit(退出)"; + this.btnClose.UseVisualStyleBackColor = true; + this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + // + // btnOK + // + 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 = 7; + 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.Load += new System.EventHandler(this.MainForm_Load); + 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 new file mode 100644 index 00000000..966a4c77 --- /dev/null +++ b/v2rayN/v2rayUpgrade/MainForm.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace v2rayUpgrade +{ + public partial class MainForm : Form + { + private string[] _args; + + + public MainForm(string[] args) + { + InitializeComponent(); + _args = args; + } + + private void MainForm_Load(object sender, EventArgs e) + { + + } + + private void btnOK_Click(object sender, EventArgs e) + { + if (_args.Length <= 0) + { + return; + } + try + { + var fileName = _args[0]; + var startKey = "v2rayN/"; + + using (ZipArchive archive = ZipFile.OpenRead(fileName)) + { + foreach (ZipArchiveEntry entry in archive.Entries) + { + if (entry.Length == 0) + { + continue; + } + var fullName = entry.FullName; + if (fullName.StartsWith(startKey)) + { + fullName = fullName.Substring(startKey.Length, fullName.Length - startKey.Length); + } + + string entryOuputPath = GetPath(fullName); + + FileInfo fileInfo = new FileInfo(entryOuputPath); + fileInfo.Directory.Create(); + entry.ExtractToFile(entryOuputPath, true); + } + } + } + catch + { + MessageBox.Show("Upgrade Failed(升级失败)"); + return; + } + + MessageBox.Show("Upgrade successed(升级成功)"); + + try + { + Process.Start("v2rayN.exe"); + } + catch + { + } + Close(); + } + + private void btnClose_Click(object sender, EventArgs e) + { + Close(); + } + + public static string GetExePath() + { + return Application.ExecutablePath; + } + + public static string StartupPath() + { + try + { + string exePath = GetExePath(); + return exePath.Substring(0, exePath.LastIndexOf("\\", StringComparison.Ordinal)); + } + catch + { + 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 new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/v2rayN/v2rayUpgrade/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Program.cs b/v2rayN/v2rayUpgrade/Program.cs new file mode 100644 index 00000000..8d8d0633 --- /dev/null +++ b/v2rayN/v2rayUpgrade/Program.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace v2rayUpgrade +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main(string[] args) + { + if (args.Length <= 0) + { + MessageBox.Show("Please use v2rayN to upgrade(请用v2rayN升级)"); + return; + } + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm(args)); + } + } +} diff --git a/v2rayN/v2rayUpgrade/Properties/AssemblyInfo.cs b/v2rayN/v2rayUpgrade/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..c32abbf1 --- /dev/null +++ b/v2rayN/v2rayUpgrade/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("v2rayUpgrade")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("v2rayUpgrade")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("f82be52a-155c-492c-9e0a-1e917ec62c78")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/v2rayN/v2rayUpgrade/Properties/Resources.Designer.cs b/v2rayN/v2rayUpgrade/Properties/Resources.Designer.cs new file mode 100644 index 00000000..907a1553 --- /dev/null +++ b/v2rayN/v2rayUpgrade/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace v2rayUpgrade.Properties +{ + + + /// + /// 强类型资源类,用于查找本地化字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的缓存 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("v2rayUpgrade.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 覆盖当前线程的 CurrentUICulture 属性 + /// 使用此强类型的资源类的资源查找。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/v2rayN/v2rayUpgrade/Properties/Resources.resx b/v2rayN/v2rayUpgrade/Properties/Resources.resx new file mode 100644 index 00000000..af7dbebb --- /dev/null +++ b/v2rayN/v2rayUpgrade/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/v2rayN/v2rayUpgrade/Properties/Settings.Designer.cs b/v2rayN/v2rayUpgrade/Properties/Settings.Designer.cs new file mode 100644 index 00000000..5148ab07 --- /dev/null +++ b/v2rayN/v2rayUpgrade/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace v2rayUpgrade.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/v2rayN/v2rayUpgrade/Properties/Settings.settings b/v2rayN/v2rayUpgrade/Properties/Settings.settings new file mode 100644 index 00000000..39645652 --- /dev/null +++ b/v2rayN/v2rayUpgrade/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/v2rayN/v2rayUpgrade/v2rayUpgrade.csproj b/v2rayN/v2rayUpgrade/v2rayUpgrade.csproj new file mode 100644 index 00000000..1d7c5d2b --- /dev/null +++ b/v2rayN/v2rayUpgrade/v2rayUpgrade.csproj @@ -0,0 +1,85 @@ + + + + + Debug + AnyCPU + {F82BE52A-155C-492C-9E0A-1E917EC62C78} + WinExe + v2rayUpgrade + v2rayUpgrade + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/v2rayN/v2rayUpgrade/v2rayUpgrade.csproj.user b/v2rayN/v2rayUpgrade/v2rayUpgrade.csproj.user new file mode 100644 index 00000000..60d6da27 --- /dev/null +++ b/v2rayN/v2rayUpgrade/v2rayUpgrade.csproj.user @@ -0,0 +1,6 @@ + + + + D:\Github\v2rayN\v2rayN\v2rayUpgrade\bin\Debug\v2ray-windows.zip + + \ No newline at end of file