|
|
@ -8,28 +8,24 @@ namespace v2rayUpgrade |
|
|
|
{ |
|
|
|
{ |
|
|
|
public partial class MainForm : Form |
|
|
|
public partial class MainForm : Form |
|
|
|
{ |
|
|
|
{ |
|
|
|
private string[] _args; |
|
|
|
private readonly string defaultFilename = "v2ray-windows.zip"; |
|
|
|
private string _tempFileName = "v2rayUpgradeTemp.zip"; |
|
|
|
private string fileName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MainForm(string[] args) |
|
|
|
public MainForm(string[] args) |
|
|
|
{ |
|
|
|
{ |
|
|
|
InitializeComponent(); |
|
|
|
InitializeComponent(); |
|
|
|
_args = args; |
|
|
|
if (args.Length > 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fileName = args[0]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void showWarn(string message) |
|
|
|
private void MainForm_Load(object sender, EventArgs e) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
MessageBox.Show(message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void btnOK_Click(object sender, EventArgs e) |
|
|
|
private void btnOK_Click(object sender, EventArgs e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (_args.Length <= 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
Process[] existing = Process.GetProcessesByName("v2rayN"); |
|
|
|
Process[] existing = Process.GetProcessesByName("v2rayN"); |
|
|
@ -45,19 +41,24 @@ namespace v2rayUpgrade |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
MessageBox.Show("Failed to close v2rayN(关闭v2rayN失败)." + ex.StackTrace); |
|
|
|
showWarn("Failed to close v2rayN(关闭v2rayN失败)." + ex.StackTrace); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string fileName = GetPath(_tempFileName); |
|
|
|
|
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
File.Delete(fileName); |
|
|
|
|
|
|
|
File.Copy(_args[0], fileName); |
|
|
|
|
|
|
|
if (!File.Exists(fileName)) |
|
|
|
if (!File.Exists(fileName)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
MessageBox.Show("Upgrade Failed, File Not Exist(升级失败,文件不存在)."); |
|
|
|
if (File.Exists(defaultFilename)) |
|
|
|
return; |
|
|
|
{ |
|
|
|
|
|
|
|
fileName = defaultFilename; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
showWarn("Upgrade Failed, File Not Exist(升级失败,文件不存在)."); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string startKey = "v2rayN/"; |
|
|
|
string startKey = "v2rayN/"; |
|
|
@ -86,23 +87,13 @@ namespace v2rayUpgrade |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
MessageBox.Show("Upgrade Failed(升级失败)." + ex.StackTrace); |
|
|
|
showWarn("Upgrade Failed(升级失败)." + ex.StackTrace); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
finally |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
File.Delete(fileName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MessageBox.Show("Upgrade successed(升级成功)"); |
|
|
|
Process.Start("v2rayN.exe"); |
|
|
|
|
|
|
|
MessageBox.Show("Upgrade successed(升级成功)", "", MessageBoxButtons.OK, MessageBoxIcon.Information); |
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Process.Start("v2rayN.exe"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Close(); |
|
|
|
Close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -118,15 +109,7 @@ namespace v2rayUpgrade |
|
|
|
|
|
|
|
|
|
|
|
public static string StartupPath() |
|
|
|
public static string StartupPath() |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
return Application.StartupPath; |
|
|
|
{ |
|
|
|
|
|
|
|
string exePath = GetExePath(); |
|
|
|
|
|
|
|
return exePath.Substring(0, exePath.LastIndexOf("\\", StringComparison.Ordinal)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Application.StartupPath; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
public static string GetPath(string fileName) |
|
|
|
public static string GetPath(string fileName) |
|
|
|
{ |
|
|
|
{ |
|
|
|