diff --git a/v2rayN/v2rayN.sln b/v2rayN/v2rayN.sln index 02f175e5..0b906d27 100644 --- a/v2rayN/v2rayN.sln +++ b/v2rayN/v2rayN.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28010.2050 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "v2rayN", "v2rayN\v2rayN.csproj", "{0A9785E6-D256-4B73-9757-4EF59955FD1E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "v2rayUpgrade", "v2rayUpgrade\v2rayUpgrade.csproj", "{F82BE52A-155C-492C-9E0A-1E917EC62C78}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -20,6 +22,14 @@ Global {0A9785E6-D256-4B73-9757-4EF59955FD1E}.Release|Any CPU.ActiveCfg = Release|Any CPU {0A9785E6-D256-4B73-9757-4EF59955FD1E}.Release|Any CPU.Build.0 = Release|Any CPU {0A9785E6-D256-4B73-9757-4EF59955FD1E}.Release|x86.ActiveCfg = Release|Any CPU + {F82BE52A-155C-492C-9E0A-1E917EC62C78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F82BE52A-155C-492C-9E0A-1E917EC62C78}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F82BE52A-155C-492C-9E0A-1E917EC62C78}.Debug|x86.ActiveCfg = Debug|Any CPU + {F82BE52A-155C-492C-9E0A-1E917EC62C78}.Debug|x86.Build.0 = Debug|Any CPU + {F82BE52A-155C-492C-9E0A-1E917EC62C78}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F82BE52A-155C-492C-9E0A-1E917EC62C78}.Release|Any CPU.Build.0 = Release|Any CPU + {F82BE52A-155C-492C-9E0A-1E917EC62C78}.Release|x86.ActiveCfg = Release|Any CPU + {F82BE52A-155C-492C-9E0A-1E917EC62C78}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 5add9efd..718dd74b 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -10,6 +10,7 @@ using v2rayN.HttpProxyHandler; using v2rayN.Mode; using v2rayN.Base; using v2rayN.Tool; +using System.Diagnostics; namespace v2rayN.Forms { @@ -17,7 +18,6 @@ namespace v2rayN.Forms { private V2rayHandler v2rayHandler; private PACListHandle pacListHandle; - private DownloadHandle downloadHandle; private List lvSelecteds = new List(); private StatisticsHandler statistics = null; @@ -34,8 +34,6 @@ namespace v2rayN.Forms Application.ApplicationExit += (sender, args) => { - Utils.ClearTempPath(); - v2rayHandler.V2rayStop(); HttpProxyHandle.CloseHttpAgent(config); @@ -1134,11 +1132,74 @@ namespace v2rayN.Forms private void tsbCheckUpdateN_Click(object sender, EventArgs e) { - System.Diagnostics.Process.Start(Global.UpdateUrl); + //System.Diagnostics.Process.Start(Global.UpdateUrl); + DownloadHandle downloadHandle = null; + if (downloadHandle == null) + { + downloadHandle = new DownloadHandle(); + downloadHandle.AbsoluteCompleted += (sender2, args) => + { + if (args.Success) + { + AppendText(false, UIRes.I18N("MsgParsingV2rayCoreSuccessfully")); + + string url = args.Msg; + this.Invoke((MethodInvoker)(delegate + { + + if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.No) + { + return; + } + else + { + downloadHandle.DownloadFileAsync(config, url, null, -1); + } + })); + } + else + { + AppendText(false, args.Msg); + } + }; + downloadHandle.UpdateCompleted += (sender2, args) => + { + if (args.Success) + { + AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); + + try + { + var fileName = Utils.GetPath(downloadHandle.DownloadFileName); + var process = Process.Start("v2rayUpgrade.exe", fileName); + if (process.Id > 0) + { + menuExit_Click(null, null); + } + } + catch (Exception ex) + { + AppendText(false, ex.Message); + } + } + else + { + AppendText(false, args.Msg); + } + }; + downloadHandle.Error += (sender2, args) => + { + AppendText(true, args.GetException().Message); + }; + } + + AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore")); + downloadHandle.AbsoluteV2rayN(config); } private void tsbCheckUpdateCore_Click(object sender, EventArgs e) { + DownloadHandle downloadHandle = null; if (downloadHandle == null) { downloadHandle = new DownloadHandle(); @@ -1180,8 +1241,8 @@ namespace v2rayN.Forms string fileName = downloadHandle.DownloadFileName; fileName = Utils.GetPath(fileName); - FileManager.ZipExtractToFile(fileName); - + FileManager.ZipExtractToFile(fileName); + AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfullyMore")); Global.reloadV2ray = true; diff --git a/v2rayN/v2rayN/Handler/DownloadHandle.cs b/v2rayN/v2rayN/Handler/DownloadHandle.cs index 68f5d9db..7044e48e 100644 --- a/v2rayN/v2rayN/Handler/DownloadHandle.cs +++ b/v2rayN/v2rayN/Handler/DownloadHandle.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using System.Net; using v2rayN.Base; @@ -37,17 +38,69 @@ namespace v2rayN.Handler } } - private string latestUrl = "https://github.com/v2ray/v2ray-core/releases/latest"; - private const string coreURL = "https://github.com/v2ray/v2ray-core/releases/download/{0}/v2ray-windows-{1}.zip"; private int progressPercentage = -1; private long totalBytesToReceive = 0; private DateTime totalDatetime = new DateTime(); private int DownloadTimeout = -1; + + + #region v2rayN + + private string nLatestUrl = "https://github.com/2dust/v2rayN/releases/latest"; + private const string nUrl = "https://github.com/2dust/v2rayN/releases/download/{0}/v2rayN.zip"; + + public void AbsoluteV2rayN(Config config) + { + Utils.SetSecurityProtocol(); + WebRequest request = WebRequest.Create(nLatestUrl); + request.BeginGetResponse(new AsyncCallback(OnResponseV2rayN), request); + } + + private void OnResponseV2rayN(IAsyncResult ar) + { + try + { + HttpWebRequest request = (HttpWebRequest)ar.AsyncState; + HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(ar); + string redirectUrl = response.ResponseUri.AbsoluteUri; + string version = redirectUrl.Substring(redirectUrl.LastIndexOf("/", StringComparison.Ordinal) + 1); + + var curVersion = FileVersionInfo.GetVersionInfo(Utils.GetExePath()).FileVersion.ToString(); + if (curVersion == version) + { + if (AbsoluteCompleted != null) + { + AbsoluteCompleted(this, new ResultEventArgs(false, "Already the latest version")); + } + } + + string url = string.Format(nUrl, version); + if (AbsoluteCompleted != null) + { + AbsoluteCompleted(this, new ResultEventArgs(true, url)); + } + } + catch (Exception ex) + { + Utils.SaveLog(ex.Message, ex); + + if (Error != null) + Error(this, new ErrorEventArgs(ex)); + } + } + + #endregion + + #region Core + + private string coreLatestUrl = "https://github.com/v2ray/v2ray-core/releases/latest"; + private const string coreUrl = "https://github.com/v2ray/v2ray-core/releases/download/{0}/v2ray-windows-{1}.zip"; + public void AbsoluteV2rayCore(Config config) { - SetSecurityProtocol(); - WebRequest request = WebRequest.Create(latestUrl); + Utils.SetSecurityProtocol(); + WebRequest request = WebRequest.Create(coreLatestUrl); request.BeginGetResponse(new AsyncCallback(OnResponseV2rayCore), request); } @@ -69,7 +122,7 @@ namespace v2rayN.Handler { osBit = "32"; } - string url = string.Format(coreURL, version, osBit); + string url = string.Format(coreUrl, version, osBit); if (AbsoluteCompleted != null) { AbsoluteCompleted(this, new ResultEventArgs(true, url)); @@ -84,12 +137,15 @@ namespace v2rayN.Handler } } + #endregion + + #region Download public void DownloadFileAsync(Config config, string url, WebProxy webProxy, int downloadTimeout) { try { - SetSecurityProtocol(); + Utils.SetSecurityProtocol(); if (UpdateCompleted != null) { UpdateCompleted(this, new ResultEventArgs(false, "Downloading...")); @@ -107,7 +163,7 @@ namespace v2rayN.Handler ws.DownloadFileCompleted += ws_DownloadFileCompleted; ws.DownloadProgressChanged += ws_DownloadProgressChanged; - ws.DownloadFileAsync(new Uri(url), Utils.GetPath(DownloadFileName)); + ws.DownloadFileAsync(new Uri(url), Utils.GetPath(DownloadFileName)); } catch (Exception ex) { @@ -193,7 +249,7 @@ namespace v2rayN.Handler string source = string.Empty; try { - SetSecurityProtocol(); + Utils.SetSecurityProtocol(); WebClientEx ws = new WebClientEx(); ws.DownloadStringCompleted += Ws_DownloadStringCompleted; @@ -232,13 +288,6 @@ namespace v2rayN.Handler } } - private void SetSecurityProtocol() - { - ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 - | SecurityProtocolType.Tls - | SecurityProtocolType.Tls11 - | SecurityProtocolType.Tls12; - ServicePointManager.DefaultConnectionLimit = 256; - } + #endregion } } diff --git a/v2rayN/v2rayN/LIB/libs.zip b/v2rayN/v2rayN/LIB/libs.zip index aa07c530..df1a7e39 100644 Binary files a/v2rayN/v2rayN/LIB/libs.zip and b/v2rayN/v2rayN/LIB/libs.zip differ diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index 58b42c18..e80f0555 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -394,7 +394,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Download V2rayCore successfully 的本地化字符串。 + /// 查找类似 Download V2ray successfully 的本地化字符串。 /// internal static string MsgDownloadV2rayCoreSuccessfully { get { @@ -448,7 +448,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Resolve V2rayCore successfully 的本地化字符串。 + /// 查找类似 Resolve V2ray successfully 的本地化字符串。 /// internal static string MsgParsingV2rayCoreSuccessfully { get { @@ -484,7 +484,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Start updating V2rayCore... 的本地化字符串。 + /// 查找类似 Start updating V2ray... 的本地化字符串。 /// internal static string MsgStartUpdatingV2rayCore { get { diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index 9db82297..74280a36 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -269,7 +269,7 @@ Clear original subscription content - Download V2rayCore successfully + Download V2ray successfully Failed to import subscription content @@ -287,7 +287,7 @@ PAC update succeeded - Resolve V2rayCore successfully + Resolve V2ray successfully Simplify PAC Success @@ -299,7 +299,7 @@ Start updating PAC... - Start updating V2rayCore... + Start updating V2ray... Subscription content decoding failed (non-BASE64 code) diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index b775c152..cf7cab26 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -269,7 +269,7 @@ 清除原订阅内容 - 下载V2rayCore成功 + 下载V2ray成功 导入订阅内容失败 @@ -287,7 +287,7 @@ PAC更新成功 - 解析V2rayCore成功 + 解析V2ray成功 简化PAC成功 @@ -299,7 +299,7 @@ 开始更新PAC... - 开始更新V2rayCore... + 开始更新V2ray... 订阅内容解码失败(非BASE64码) diff --git a/v2rayN/v2rayN/Tool/FileManager.cs b/v2rayN/v2rayN/Tool/FileManager.cs index 96841c96..fffeda94 100644 --- a/v2rayN/v2rayN/Tool/FileManager.cs +++ b/v2rayN/v2rayN/Tool/FileManager.cs @@ -89,5 +89,31 @@ namespace v2rayN.Tool } return true; } + + public static bool ZipExtractToFullFile(string fileName) + { + try + { + using (ZipArchive archive = ZipFile.OpenRead(fileName)) + { + foreach (ZipArchiveEntry entry in archive.Entries) + { + if (entry.Length == 0) + continue; + + string entryOuputPath = Utils.GetPath(entry.FullName); + FileInfo fileInfo = new FileInfo(entryOuputPath); + fileInfo.Directory.Create(); + entry.ExtractToFile(entryOuputPath, true); + } + } + } + catch (Exception ex) + { + Utils.SaveLog(ex.Message, ex); + return false; + } + return true; + } } } diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs index cff43678..2e840ecd 100644 --- a/v2rayN/v2rayN/Tool/Utils.cs +++ b/v2rayN/v2rayN/Tool/Utils.cs @@ -657,7 +657,14 @@ namespace v2rayN return lstIPAddress; } - + public static void SetSecurityProtocol() + { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 + | SecurityProtocolType.Tls + | SecurityProtocolType.Tls11 + | SecurityProtocolType.Tls12; + ServicePointManager.DefaultConnectionLimit = 256; + } #endregion #region 杂项 @@ -779,16 +786,13 @@ namespace v2rayN #region TempPath - private static string _tempPath = null; - // return path to store temporary files public static string GetTempPath() { - if (_tempPath == null) + string _tempPath = Path.Combine(StartupPath(), "v2ray_win_temp"); + if (!Directory.Exists(_tempPath)) { - Directory.CreateDirectory(Path.Combine(StartupPath(), "v2ray_win_temp")); - // don't use "/", it will fail when we call explorer /select xxx/ss_win_temp\xxx.log - _tempPath = Path.Combine(StartupPath(), "v2ray_win_temp"); + Directory.CreateDirectory(_tempPath); } return _tempPath; } @@ -796,13 +800,7 @@ namespace v2rayN public static string GetTempPath(string filename) { return Path.Combine(GetTempPath(), filename); - } - - public static void ClearTempPath() - { - //Directory.Delete(GetTempPath(), true); - //_tempPath = null; - } + } public static string UnGzip(byte[] buf) { diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj index c07fc9c8..d3561b38 100644 --- a/v2rayN/v2rayN/v2rayN.csproj +++ b/v2rayN/v2rayN/v2rayN.csproj @@ -287,6 +287,7 @@ SubSettingControl.cs + Designer SubSettingControl.cs