mirror of https://github.com/2dust/v2rayN
add up
parent
86229bf73b
commit
5cadf59e10
|
@ -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
|
||||
|
|
|
@ -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<int> lvSelecteds = new List<int>();
|
||||
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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -394,7 +394,7 @@ namespace v2rayN.Resx {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Download V2rayCore successfully 的本地化字符串。
|
||||
/// 查找类似 Download V2ray successfully 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string MsgDownloadV2rayCoreSuccessfully {
|
||||
get {
|
||||
|
@ -448,7 +448,7 @@ namespace v2rayN.Resx {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Resolve V2rayCore successfully 的本地化字符串。
|
||||
/// 查找类似 Resolve V2ray successfully 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string MsgParsingV2rayCoreSuccessfully {
|
||||
get {
|
||||
|
@ -484,7 +484,7 @@ namespace v2rayN.Resx {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Start updating V2rayCore... 的本地化字符串。
|
||||
/// 查找类似 Start updating V2ray... 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string MsgStartUpdatingV2rayCore {
|
||||
get {
|
||||
|
|
|
@ -269,7 +269,7 @@
|
|||
<value>Clear original subscription content</value>
|
||||
</data>
|
||||
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
||||
<value>Download V2rayCore successfully</value>
|
||||
<value>Download V2ray successfully</value>
|
||||
</data>
|
||||
<data name="MsgFailedImportSubscription" xml:space="preserve">
|
||||
<value>Failed to import subscription content</value>
|
||||
|
@ -287,7 +287,7 @@
|
|||
<value>PAC update succeeded</value>
|
||||
</data>
|
||||
<data name="MsgParsingV2rayCoreSuccessfully" xml:space="preserve">
|
||||
<value>Resolve V2rayCore successfully</value>
|
||||
<value>Resolve V2ray successfully</value>
|
||||
</data>
|
||||
<data name="MsgSimplifyPAC" xml:space="preserve">
|
||||
<value>Simplify PAC Success</value>
|
||||
|
@ -299,7 +299,7 @@
|
|||
<value>Start updating PAC...</value>
|
||||
</data>
|
||||
<data name="MsgStartUpdatingV2rayCore" xml:space="preserve">
|
||||
<value>Start updating V2rayCore...</value>
|
||||
<value>Start updating V2ray...</value>
|
||||
</data>
|
||||
<data name="MsgSubscriptionDecodingFailed" xml:space="preserve">
|
||||
<value>Subscription content decoding failed (non-BASE64 code)</value>
|
||||
|
|
|
@ -269,7 +269,7 @@
|
|||
<value>清除原订阅内容</value>
|
||||
</data>
|
||||
<data name="MsgDownloadV2rayCoreSuccessfully" xml:space="preserve">
|
||||
<value>下载V2rayCore成功</value>
|
||||
<value>下载V2ray成功</value>
|
||||
</data>
|
||||
<data name="MsgFailedImportSubscription" xml:space="preserve">
|
||||
<value>导入订阅内容失败</value>
|
||||
|
@ -287,7 +287,7 @@
|
|||
<value>PAC更新成功</value>
|
||||
</data>
|
||||
<data name="MsgParsingV2rayCoreSuccessfully" xml:space="preserve">
|
||||
<value>解析V2rayCore成功</value>
|
||||
<value>解析V2ray成功</value>
|
||||
</data>
|
||||
<data name="MsgSimplifyPAC" xml:space="preserve">
|
||||
<value>简化PAC成功</value>
|
||||
|
@ -299,7 +299,7 @@
|
|||
<value>开始更新PAC...</value>
|
||||
</data>
|
||||
<data name="MsgStartUpdatingV2rayCore" xml:space="preserve">
|
||||
<value>开始更新V2rayCore...</value>
|
||||
<value>开始更新V2ray...</value>
|
||||
</data>
|
||||
<data name="MsgSubscriptionDecodingFailed" xml:space="preserve">
|
||||
<value>订阅内容解码失败(非BASE64码)</value>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -287,6 +287,7 @@
|
|||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\SubSettingControl.resx">
|
||||
<DependentUpon>SubSettingControl.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\SubSettingControl.zh-Hans.resx">
|
||||
<DependentUpon>SubSettingControl.cs</DependentUpon>
|
||||
|
|
Loading…
Reference in New Issue