diff --git a/README.md b/README.md index 1c597d14..75af682c 100644 --- a/README.md +++ b/README.md @@ -11,34 +11,7 @@ and [others](https://github.com/cg3s/v2rayN/wiki/List-of-supported-cores) ## How to use -Check [Release files introduction](https://github.com/cg3s/v2rayN/wiki/Release-files-introduction) and select the version you need to download - -### Windows - -- Run `v2rayN.exe` - -### Linux - -- `chmod +x v2rayN` Run `./v2rayN` under user permissions - -``` -Debian 9+ -Ubuntu 16.04+ -Fedora 30+ -``` - -### macOS - -- `chmod +x v2rayN` Run `./v2rayN` under user permissions - -``` -macOS 11+ -``` - -## Requirements - -- [Microsoft .NET 8.0 Desktop Runtime ](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) -- [Supported cores](https://github.com/cg3s/v2rayN/wiki/List-of-supported-cores) +Read the [Wiki](https://github.com/2dust/v2rayN/wiki) for details. ## Telegram Channel diff --git a/pkg2appimage.yml b/pkg2appimage.yml deleted file mode 100644 index ab52666e..00000000 --- a/pkg2appimage.yml +++ /dev/null @@ -1,37 +0,0 @@ -app: v2rayN -binpatch: true - -ingredients: - script: - - export FileName="v2rayN-${AppImageOutputArch}.zip" - - wget -nv -O $FileName "https://github.com/cg3s/v2rayN-core-bin/raw/refs/heads/master/${FileName}" - - 7z x $FileName -aoa - - cp -rf v2rayN-${AppImageOutputArch}/* $OutputPath - -script: - - mkdir -p usr/bin usr/lib - - cp -rf $OutputPath usr/lib/v2rayN - - echo "When this file exists, app will not store configs under this folder" > usr/lib/v2rayN/NotStoreConfigHere.txt - - ln -sf usr/lib/v2rayN/v2rayN usr/bin/v2rayN - - chmod a+x usr/lib/v2rayN/v2rayN - - find usr -type f -exec sh -c 'file "{}" | grep -qi "executable" && chmod +x "{}"' \; - - install -Dm644 usr/lib/v2rayN/v2rayN.png v2rayN.png - - install -Dm644 usr/lib/v2rayN/v2rayN.png usr/share/pixmaps/v2rayN.png - - cat > v2rayN.desktop < AppRun <<\EOF - - #!/bin/sh - - HERE="$(dirname "$(readlink -f "${0}")")" - - cd ${HERE}/usr/lib/v2rayN - - exec ${HERE}/usr/lib/v2rayN/v2rayN $@ - - EOF - - chmod a+x AppRun diff --git a/v2rayN/GlobalHotKeys b/v2rayN/GlobalHotKeys index ef73fa22..270f023f 160000 --- a/v2rayN/GlobalHotKeys +++ b/v2rayN/GlobalHotKeys @@ -1 +1 @@ -Subproject commit ef73fa22c46cfc7d1ec192ffe8497f6e61b4f0db +Subproject commit 270f023fcca4ef9149480c575d502815efd83531 diff --git a/v2rayN/PacLib/PacLib.csproj b/v2rayN/PacLib/PacLib.csproj deleted file mode 100644 index 6ccd5406..00000000 --- a/v2rayN/PacLib/PacLib.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - net8.0 - enable - - - - none - - - - none - - - - - True - True - Resources.resx - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index b402afb3..786f3aff 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -135,10 +135,6 @@ public static class ConfigHandler { config.SpeedTestItem.MixedConcurrencyCount = 5; } - if (config.SpeedTestItem.IPAPIUrl.IsNullOrEmpty()) - { - config.SpeedTestItem.IPAPIUrl = Global.IPAPIUrls.First(); - } config.Mux4RayItem ??= new() { diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index e801c796..1ce9d8e2 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -417,9 +417,6 @@ Opció beállítás - - Promóció - Újratöltés diff --git a/v2rayN/ServiceLib/ServiceLib.csproj b/v2rayN/ServiceLib/ServiceLib.csproj index c026edf8..dde35dc3 100644 --- a/v2rayN/ServiceLib/ServiceLib.csproj +++ b/v2rayN/ServiceLib/ServiceLib.csproj @@ -31,7 +31,7 @@ - + diff --git a/v2rayN/v2rayN.sln b/v2rayN/v2rayN.sln index 88a4064b..85f985fe 100644 --- a/v2rayN/v2rayN.sln +++ b/v2rayN/v2rayN.sln @@ -37,49 +37,29 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - Debug|ARM64 = Debug|ARM64 Release|Any CPU = Release|Any CPU - Release|ARM64 = Release|ARM64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6DE127CA-1763-4236-B297-D2EF9CB2EC9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6DE127CA-1763-4236-B297-D2EF9CB2EC9B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6DE127CA-1763-4236-B297-D2EF9CB2EC9B}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {6DE127CA-1763-4236-B297-D2EF9CB2EC9B}.Debug|ARM64.Build.0 = Debug|ARM64 {6DE127CA-1763-4236-B297-D2EF9CB2EC9B}.Release|Any CPU.ActiveCfg = Release|Any CPU {6DE127CA-1763-4236-B297-D2EF9CB2EC9B}.Release|Any CPU.Build.0 = Release|Any CPU - {6DE127CA-1763-4236-B297-D2EF9CB2EC9B}.Release|ARM64.ActiveCfg = Release|ARM64 - {6DE127CA-1763-4236-B297-D2EF9CB2EC9B}.Release|ARM64.Build.0 = Release|ARM64 {1B6456C4-FFAA-4298-80F6-7B689A6E9243}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1B6456C4-FFAA-4298-80F6-7B689A6E9243}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1B6456C4-FFAA-4298-80F6-7B689A6E9243}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {1B6456C4-FFAA-4298-80F6-7B689A6E9243}.Debug|ARM64.Build.0 = Debug|ARM64 {1B6456C4-FFAA-4298-80F6-7B689A6E9243}.Release|Any CPU.ActiveCfg = Release|Any CPU {1B6456C4-FFAA-4298-80F6-7B689A6E9243}.Release|Any CPU.Build.0 = Release|Any CPU - {1B6456C4-FFAA-4298-80F6-7B689A6E9243}.Release|ARM64.ActiveCfg = Release|ARM64 - {1B6456C4-FFAA-4298-80F6-7B689A6E9243}.Release|ARM64.Build.0 = Release|ARM64 {5D16541A-F971-4C17-9315-BB8955E3F984}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5D16541A-F971-4C17-9315-BB8955E3F984}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5D16541A-F971-4C17-9315-BB8955E3F984}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {5D16541A-F971-4C17-9315-BB8955E3F984}.Debug|ARM64.Build.0 = Debug|ARM64 {5D16541A-F971-4C17-9315-BB8955E3F984}.Release|Any CPU.ActiveCfg = Release|Any CPU {5D16541A-F971-4C17-9315-BB8955E3F984}.Release|Any CPU.Build.0 = Release|Any CPU - {5D16541A-F971-4C17-9315-BB8955E3F984}.Release|ARM64.ActiveCfg = Release|ARM64 - {5D16541A-F971-4C17-9315-BB8955E3F984}.Release|ARM64.Build.0 = Release|ARM64 {47D68B1C-601C-4C69-873B-FFF0DC13EC97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {47D68B1C-601C-4C69-873B-FFF0DC13EC97}.Debug|Any CPU.Build.0 = Debug|Any CPU - {47D68B1C-601C-4C69-873B-FFF0DC13EC97}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {47D68B1C-601C-4C69-873B-FFF0DC13EC97}.Debug|ARM64.Build.0 = Debug|ARM64 {47D68B1C-601C-4C69-873B-FFF0DC13EC97}.Release|Any CPU.ActiveCfg = Release|Any CPU {47D68B1C-601C-4C69-873B-FFF0DC13EC97}.Release|Any CPU.Build.0 = Release|Any CPU - {47D68B1C-601C-4C69-873B-FFF0DC13EC97}.Release|ARM64.ActiveCfg = Release|Any CPU - {47D68B1C-601C-4C69-873B-FFF0DC13EC97}.Release|ARM64.Build.0 = Release|Any CPU {CB3DE54F-3A26-AE02-1299-311132C32156}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CB3DE54F-3A26-AE02-1299-311132C32156}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CB3DE54F-3A26-AE02-1299-311132C32156}.Debug|ARM64.ActiveCfg = Debug|Any CPU {CB3DE54F-3A26-AE02-1299-311132C32156}.Release|Any CPU.ActiveCfg = Release|Any CPU {CB3DE54F-3A26-AE02-1299-311132C32156}.Release|Any CPU.Build.0 = Release|Any CPU - {CB3DE54F-3A26-AE02-1299-311132C32156}.Release|ARM64.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs deleted file mode 100644 index f33781c5..00000000 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ /dev/null @@ -1,1577 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Windows.Forms; -using v2rayN.Handler; -using v2rayN.HttpProxyHandler; -using v2rayN.Mode; -using v2rayN.Base; -using v2rayN.Tool; -using System.Diagnostics; -using System.Drawing; -using System.Net; - -namespace v2rayN.Forms -{ - public partial class MainForm : BaseForm - { - private V2rayHandler v2rayHandler; - private List lvSelecteds = new List(); - private StatisticsHandler statistics = null; - - #region Window 事件 - - public MainForm() - { - InitializeComponent(); - this.ShowInTaskbar = false; - this.WindowState = FormWindowState.Minimized; - HideForm(); - this.Text = Utils.GetVersion(); - Global.processJob = new Job(); - - Application.ApplicationExit += (sender, args) => - { - v2rayHandler.V2rayStop(); - - HttpProxyHandle.CloseHttpAgent(config); - PACServerHandle.Stop(); - - ConfigHandler.SaveConfig(ref config); - statistics?.SaveToFile(); - statistics?.Close(); - }; - } - - private void MainForm_Load(object sender, EventArgs e) - { - ConfigHandler.LoadConfig(ref config); - v2rayHandler = new V2rayHandler(); - v2rayHandler.ProcessEvent += v2rayHandler_ProcessEvent; - - if (config.enableStatistics) - { - statistics = new StatisticsHandler(config, UpdateStatisticsHandler); - } - } - - private void MainForm_VisibleChanged(object sender, EventArgs e) - { - if (statistics == null || !statistics.Enable) return; - if ((sender as Form).Visible) - { - statistics.UpdateUI = true; - } - else - { - statistics.UpdateUI = false; - } - } - - private void MainForm_Shown(object sender, EventArgs e) - { - InitServersView(); - RefreshServers(); - RestoreUI(); - - LoadV2ray(); - - HideForm(); - - } - - private void MainForm_FormClosing(object sender, FormClosingEventArgs e) - { - if (e.CloseReason == CloseReason.UserClosing) - { - StorageUI(); - e.Cancel = true; - HideForm(); - return; - } - } - - private void MainForm_Resize(object sender, EventArgs e) - { - //if (this.WindowState == FormWindowState.Minimized) - //{ - // HideForm(); - //} - //else - //{ - - //} - } - - - //private const int WM_QUERYENDSESSION = 0x0011; - //protected override void WndProc(ref Message m) - //{ - // switch (m.Msg) - // { - // case WM_QUERYENDSESSION: - // Utils.SaveLog("Windows shutdown UnsetProxy"); - - // ConfigHandler.ToJsonFile(config); - // statistics?.SaveToFile(); - // ProxySetting.UnsetProxy(); - // m.Result = (IntPtr)1; - // break; - // default: - // base.WndProc(ref m); - // break; - // } - //} - - private void RestoreUI() - { - scMain.Panel2Collapsed = true; - - if (!config.uiItem.mainSize.IsEmpty) - { - this.Width = config.uiItem.mainSize.Width; - this.Height = config.uiItem.mainSize.Height; - } - - for (int k = 0; k < lvServers.Columns.Count; k++) - { - var width = ConfigHandler.GetformMainLvColWidth(ref config, ((EServerColName)k).ToString(), lvServers.Columns[k].Width); - lvServers.Columns[k].Width = width; - } - } - - private void StorageUI() - { - config.uiItem.mainSize = new Size(this.Width, this.Height); - - for (int k = 0; k < lvServers.Columns.Count; k++) - { - ConfigHandler.AddformMainLvColWidth(ref config, ((EServerColName)k).ToString(), lvServers.Columns[k].Width); - } - } - - #endregion - - #region 显示服务器 listview 和 menu - - /// - /// 刷新服务器 - /// - private void RefreshServers() - { - RefreshServersView(); - //lvServers.AutoResizeColumns(); - RefreshServersMenu(); - } - - /// - /// 初始化服务器列表 - /// - private void InitServersView() - { - lvServers.BeginUpdate(); - lvServers.Items.Clear(); - - lvServers.GridLines = true; - lvServers.FullRowSelect = true; - lvServers.View = View.Details; - lvServers.Scrollable = true; - lvServers.MultiSelect = true; - lvServers.HeaderStyle = ColumnHeaderStyle.Clickable; - - lvServers.Columns.Add("", 30); - lvServers.Columns.Add(UIRes.I18N("LvServiceType"), 80); - lvServers.Columns.Add(UIRes.I18N("LvAlias"), 100); - lvServers.Columns.Add(UIRes.I18N("LvAddress"), 120); - lvServers.Columns.Add(UIRes.I18N("LvPort"), 50); - lvServers.Columns.Add(UIRes.I18N("LvEncryptionMethod"), 90); - lvServers.Columns.Add(UIRes.I18N("LvTransportProtocol"), 70); - lvServers.Columns.Add(UIRes.I18N("LvSubscription"), 50); - lvServers.Columns.Add(UIRes.I18N("LvTestResults"), 70, HorizontalAlignment.Right); - - if (statistics != null && statistics.Enable) - { - lvServers.Columns.Add(UIRes.I18N("LvTodayDownloadDataAmount"), 70); - lvServers.Columns.Add(UIRes.I18N("LvTodayUploadDataAmount"), 70); - lvServers.Columns.Add(UIRes.I18N("LvTotalDownloadDataAmount"), 70); - lvServers.Columns.Add(UIRes.I18N("LvTotalUploadDataAmount"), 70); - } - lvServers.EndUpdate(); - } - - /// - /// 刷新服务器列表 - /// - private void RefreshServersView() - { - lvServers.BeginUpdate(); - lvServers.Items.Clear(); - - for (int k = 0; k < config.vmess.Count; k++) - { - string def = string.Empty; - string totalUp = string.Empty, - totalDown = string.Empty, - todayUp = string.Empty, - todayDown = string.Empty; - if (config.index.Equals(k)) - { - def = "√"; - } - - VmessItem item = config.vmess[k]; - - void _addSubItem(ListViewItem i, string name, string text) - { - i.SubItems.Add(new ListViewItem.ListViewSubItem() { Name = name, Text = text }); - } - bool stats = statistics != null && statistics.Enable; - if (stats) - { - ServerStatItem sItem = statistics.Statistic.Find(item_ => item_.itemId == item.getItemId()); - if (sItem != null) - { - totalUp = Utils.HumanFy(sItem.totalUp); - totalDown = Utils.HumanFy(sItem.totalDown); - todayUp = Utils.HumanFy(sItem.todayUp); - todayDown = Utils.HumanFy(sItem.todayDown); - } - } - ListViewItem lvItem = new ListViewItem(def); - _addSubItem(lvItem, EServerColName.configType.ToString(), ((EConfigType)item.configType).ToString()); - _addSubItem(lvItem, EServerColName.remarks.ToString(), item.remarks); - _addSubItem(lvItem, EServerColName.address.ToString(), item.address); - _addSubItem(lvItem, EServerColName.port.ToString(), item.port.ToString()); - _addSubItem(lvItem, EServerColName.security.ToString(), item.security); - _addSubItem(lvItem, EServerColName.network.ToString(), item.network); - _addSubItem(lvItem, EServerColName.subRemarks.ToString(), item.getSubRemarks(config)); - _addSubItem(lvItem, EServerColName.testResult.ToString(), item.testResult); - if (stats) - { - _addSubItem(lvItem, EServerColName.todayDown.ToString(), todayDown); - _addSubItem(lvItem, EServerColName.todayUp.ToString(), todayUp); - _addSubItem(lvItem, EServerColName.totalDown.ToString(), totalDown); - _addSubItem(lvItem, EServerColName.totalUp.ToString(), totalUp); - } - - if (k % 2 == 1) // 隔行着色 - { - lvItem.BackColor = Color.WhiteSmoke; - } - if (config.index.Equals(k)) - { - //lvItem.Checked = true; - lvItem.ForeColor = Color.DodgerBlue; - lvItem.Font = new Font(lvItem.Font, FontStyle.Bold); - } - - if (lvItem != null) lvServers.Items.Add(lvItem); - } - lvServers.EndUpdate(); - - //if (lvServers.Items.Count > 0) - //{ - // if (lvServers.Items.Count <= testConfigIndex) - // { - // testConfigIndex = lvServers.Items.Count - 1; - // } - // lvServers.Items[testConfigIndex].Selected = true; - // lvServers.Select(); - //} - } - - /// - /// 刷新托盘服务器菜单 - /// - private void RefreshServersMenu() - { - menuServers.DropDownItems.Clear(); - - List lst = new List(); - for (int k = 0; k < config.vmess.Count; k++) - { - VmessItem item = config.vmess[k]; - string name = item.getSummary(); - - ToolStripMenuItem ts = new ToolStripMenuItem(name) - { - Tag = k - }; - if (config.index.Equals(k)) - { - ts.Checked = true; - } - ts.Click += new EventHandler(ts_Click); - lst.Add(ts); - } - menuServers.DropDownItems.AddRange(lst.ToArray()); - } - - private void ts_Click(object sender, EventArgs e) - { - try - { - ToolStripItem ts = (ToolStripItem)sender; - int index = Utils.ToInt(ts.Tag); - SetDefaultServer(index); - } - catch - { - } - } - - private void lvServers_SelectedIndexChanged(object sender, EventArgs e) - { - int index = -1; - try - { - if (lvServers.SelectedIndices.Count > 0) - { - index = lvServers.SelectedIndices[0]; - } - } - catch - { - } - if (index < 0) - { - return; - } - //qrCodeControl.showQRCode(index, config); - } - - private void DisplayToolStatus() - { - toolSslSocksPort.Text = - toolSslHttpPort.Text = - toolSslPacPort.Text = "OFF"; - - toolSslSocksPort.Text = $"{Global.Loopback}:{config.inbound[0].localPort}"; - - if (config.listenerType != (int)ListenerType.noHttpProxy) - { - toolSslHttpPort.Text = $"{Global.Loopback}:{Global.httpPort}"; - if (config.listenerType == ListenerType.GlobalPac || - config.listenerType == ListenerType.PacOpenAndClear || - config.listenerType == ListenerType.PacOpenOnly) - { - if (PACServerHandle.IsRunning) - { - toolSslPacPort.Text = $"{HttpProxyHandle.GetPacUrl()}"; - } - else - { - toolSslPacPort.Text = UIRes.I18N("StartPacFailed"); - } - } - } - - notifyMain.Icon = MainFormHandler.Instance.GetNotifyIcon(config, this.Icon); - } - private void ssMain_ItemClicked(object sender, ToolStripItemClickedEventArgs e) - { - if (!Utils.IsNullOrEmpty(e.ClickedItem.Text)) - { - Utils.SetClipboardData(e.ClickedItem.Text); - } - } - - private void lvServers_ColumnClick(object sender, ColumnClickEventArgs e) - { - if (e.Column < 0) - { - return; - } - - try - { - var tag = lvServers.Columns[e.Column].Tag?.ToString(); - bool asc = Utils.IsNullOrEmpty(tag) ? true : !Convert.ToBoolean(tag); - if (ConfigHandler.SortServers(ref config, (EServerColName)e.Column, asc) != 0) - { - return; - } - lvServers.Columns[e.Column].Tag = Convert.ToString(asc); - RefreshServers(); - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - } - - if (e.Column < 0) - { - return; - } - - } - #endregion - - #region v2ray 操作 - - /// - /// 载入V2ray - /// - private void LoadV2ray() - { - tsbReload.Enabled = false; - - if (Global.reloadV2ray) - { - ClearMsg(); - } - v2rayHandler.LoadV2ray(config); - Global.reloadV2ray = false; - ConfigHandler.SaveConfig(ref config, false); - statistics?.SaveToFile(); - - ChangePACButtonStatus(config.listenerType); - - tsbReload.Enabled = true; - } - - /// - /// 关闭V2ray - /// - private void CloseV2ray() - { - ConfigHandler.SaveConfig(ref config, false); - statistics?.SaveToFile(); - - ChangePACButtonStatus(0); - - v2rayHandler.V2rayStop(); - } - - #endregion - - #region 功能按钮 - - private void lvServers_Click(object sender, EventArgs e) - { - int index = -1; - try - { - if (lvServers.SelectedIndices.Count > 0) - { - index = lvServers.SelectedIndices[0]; - } - } - catch - { - } - if (index < 0) - { - return; - } - qrCodeControl.showQRCode(index, config); - } - - private void lvServers_DoubleClick(object sender, EventArgs e) - { - int index = GetLvSelectedIndex(); - if (index < 0) - { - return; - } - ShowServerForm(config.vmess[index].configType, index); - } - private void ShowServerForm(int configType, int index) - { - BaseServerForm fm; - switch (configType) - { - case (int)EConfigType.Vmess: - fm = new AddServerForm(); - break; - case (int)EConfigType.Shadowsocks: - fm = new AddServer3Form(); - break; - case (int)EConfigType.Socks: - fm = new AddServer4Form(); - break; - case (int)EConfigType.VLESS: - fm = new AddServer5Form(); - break; - case (int)EConfigType.Trojan: - fm = new AddServer6Form(); - break; - default: - fm = new AddServer2Form(); - break; - } - fm.EditIndex = index; - if (fm.ShowDialog() == DialogResult.OK) - { - //刷新 - RefreshServers(); - LoadV2ray(); - } - } - - - private void lvServers_KeyDown(object sender, KeyEventArgs e) - { - if (e.Control) - { - switch (e.KeyCode) - { - case Keys.A: - menuSelectAll_Click(null, null); - break; - case Keys.C: - menuExport2ShareUrl_Click(null, null); - break; - case Keys.V: - menuAddServers_Click(null, null); - break; - case Keys.P: - menuPingServer_Click(null, null); - break; - case Keys.O: - menuTcpingServer_Click(null, null); - break; - case Keys.R: - menuRealPingServer_Click(null, null); - break; - case Keys.S: - menuScanScreen_Click(null, null); - break; - case Keys.T: - menuSpeedServer_Click(null, null); - break; - } - } - else - { - switch (e.KeyCode) - { - case Keys.Enter: - menuSetDefaultServer_Click(null, null); - break; - case Keys.Delete: - menuRemoveServer_Click(null, null); - break; - case Keys.T: - menuMoveTop_Click(null, null); - break; - case Keys.B: - menuMoveBottom_Click(null, null); - break; - case Keys.U: - menuMoveUp_Click(null, null); - break; - case Keys.D: - menuMoveDown_Click(null, null); - break; - } - } - } - - private void menuAddVmessServer_Click(object sender, EventArgs e) - { - ShowServerForm((int)EConfigType.Vmess, -1); - } - - private void menuAddVlessServer_Click(object sender, EventArgs e) - { - ShowServerForm((int)EConfigType.VLESS, -1); - } - - private void menuRemoveServer_Click(object sender, EventArgs e) - { - - int index = GetLvSelectedIndex(); - if (index < 0) - { - return; - } - if (UI.ShowYesNo(UIRes.I18N("RemoveServer")) == DialogResult.No) - { - return; - } - for (int k = lvSelecteds.Count - 1; k >= 0; k--) - { - ConfigHandler.RemoveServer(ref config, lvSelecteds[k]); - } - //刷新 - RefreshServers(); - LoadV2ray(); - - } - - private void menuRemoveDuplicateServer_Click(object sender, EventArgs e) - { - Utils.DedupServerList(config.vmess, out List servers, config.keepOlderDedupl); - int oldCount = config.vmess.Count; - int newCount = servers.Count; - if (servers != null) - { - config.vmess = servers; - } - //刷新 - RefreshServers(); - LoadV2ray(); - UI.Show(string.Format(UIRes.I18N("RemoveDuplicateServerResult"), oldCount, newCount)); - } - - private void menuCopyServer_Click(object sender, EventArgs e) - { - int index = GetLvSelectedIndex(); - if (index < 0) - { - return; - } - if (ConfigHandler.CopyServer(ref config, index) == 0) - { - //刷新 - RefreshServers(); - } - } - - private void menuSetDefaultServer_Click(object sender, EventArgs e) - { - int index = GetLvSelectedIndex(); - if (index < 0) - { - return; - } - SetDefaultServer(index); - } - - - private void menuPingServer_Click(object sender, EventArgs e) - { - Speedtest("ping"); - } - private void menuTcpingServer_Click(object sender, EventArgs e) - { - Speedtest("tcping"); - } - - private void menuRealPingServer_Click(object sender, EventArgs e) - { - //if (!config.sysAgentEnabled) - //{ - // UI.Show(UIRes.I18N("NeedHttpGlobalProxy")); - // return; - //} - - //UI.Show(UIRes.I18N("SpeedServerTips")); - - Speedtest("realping"); - } - - private void menuSpeedServer_Click(object sender, EventArgs e) - { - //if (!config.sysAgentEnabled) - //{ - // UI.Show(UIRes.I18N("NeedHttpGlobalProxy")); - // return; - //} - - //UI.Show(UIRes.I18N("SpeedServerTips")); - - Speedtest("speedtest"); - } - private void Speedtest(string actionType) - { - if (GetLvSelectedIndex() < 0) return; - ClearTestResult(); - SpeedtestHandler statistics = new SpeedtestHandler(ref config, ref v2rayHandler, lvSelecteds, actionType, UpdateSpeedtestHandler); - } - - private void tsbTestMe_Click(object sender, EventArgs e) - { - string result = httpProxyTest() + "ms"; - AppendText(false, string.Format(UIRes.I18N("TestMeOutput"), result)); - } - private int httpProxyTest() - { - SpeedtestHandler statistics = new SpeedtestHandler(ref config, ref v2rayHandler, lvSelecteds, "", UpdateSpeedtestHandler); - return statistics.RunAvailabilityCheck(); - } - - private void menuExport2ClientConfig_Click(object sender, EventArgs e) - { - int index = GetLvSelectedIndex(); - MainFormHandler.Instance.Export2ClientConfig(index, config); - } - - private void menuExport2ServerConfig_Click(object sender, EventArgs e) - { - int index = GetLvSelectedIndex(); - MainFormHandler.Instance.Export2ServerConfig(index, config); - } - - private void menuExport2ShareUrl_Click(object sender, EventArgs e) - { - GetLvSelectedIndex(); - - StringBuilder sb = new StringBuilder(); - foreach (int v in lvSelecteds) - { - string url = ConfigHandler.GetVmessQRCode(config, v); - if (Utils.IsNullOrEmpty(url)) - { - continue; - } - sb.Append(url); - sb.AppendLine(); - } - if (sb.Length > 0) - { - Utils.SetClipboardData(sb.ToString()); - AppendText(false, UIRes.I18N("BatchExportURLSuccessfully")); - //UI.Show(UIRes.I18N("BatchExportURLSuccessfully")); - } - } - - private void menuExport2SubContent_Click(object sender, EventArgs e) - { - GetLvSelectedIndex(); - - StringBuilder sb = new StringBuilder(); - foreach (int v in lvSelecteds) - { - string url = ConfigHandler.GetVmessQRCode(config, v); - if (Utils.IsNullOrEmpty(url)) - { - continue; - } - sb.Append(url); - sb.AppendLine(); - } - if (sb.Length > 0) - { - Utils.SetClipboardData(Utils.Base64Encode(sb.ToString())); - UI.Show(UIRes.I18N("BatchExportSubscriptionSuccessfully")); - } - } - - private void tsbOptionSetting_Click(object sender, EventArgs e) - { - OptionSettingForm fm = new OptionSettingForm(); - if (fm.ShowDialog() == DialogResult.OK) - { - //刷新 - RefreshServers(); - LoadV2ray(); - HttpProxyHandle.RestartHttpAgent(config, true); - } - } - - private void tsbReload_Click(object sender, EventArgs e) - { - Global.reloadV2ray = true; - LoadV2ray(); - } - - private void tsbClose_Click(object sender, EventArgs e) - { - HideForm(); - //this.WindowState = FormWindowState.Minimized; - } - - /// - /// 设置活动服务器 - /// - /// - /// - private int SetDefaultServer(int index) - { - if (index < 0) - { - UI.Show(UIRes.I18N("PleaseSelectServer")); - return -1; - } - if (ConfigHandler.SetDefaultServer(ref config, index) == 0) - { - //刷新 - RefreshServers(); - LoadV2ray(); - } - return 0; - } - - /// - /// 取得ListView选中的行 - /// - /// - private int GetLvSelectedIndex() - { - int index = -1; - lvSelecteds.Clear(); - try - { - if (lvServers.SelectedIndices.Count <= 0) - { - UI.Show(UIRes.I18N("PleaseSelectServer")); - return index; - } - - index = lvServers.SelectedIndices[0]; - foreach (int i in lvServers.SelectedIndices) - { - lvSelecteds.Add(i); - } - return index; - } - catch - { - return index; - } - } - - private void menuAddCustomServer_Click(object sender, EventArgs e) - { - UI.Show(UIRes.I18N("CustomServerTips")); - - OpenFileDialog fileDialog = new OpenFileDialog - { - Multiselect = false, - Filter = "Config|*.json|All|*.*" - }; - if (fileDialog.ShowDialog() != DialogResult.OK) - { - return; - } - string fileName = fileDialog.FileName; - if (Utils.IsNullOrEmpty(fileName)) - { - return; - } - - if (ConfigHandler.AddCustomServer(ref config, fileName) == 0) - { - //刷新 - RefreshServers(); - //LoadV2ray(); - UI.Show(UIRes.I18N("SuccessfullyImportedCustomServer")); - } - else - { - UI.ShowWarning(UIRes.I18N("FailedImportedCustomServer")); - } - } - - private void menuAddShadowsocksServer_Click(object sender, EventArgs e) - { - ShowServerForm((int)EConfigType.Shadowsocks, -1); - ShowForm(); - } - - private void menuAddSocksServer_Click(object sender, EventArgs e) - { - ShowServerForm((int)EConfigType.Socks, -1); - ShowForm(); - } - - private void menuAddTrojanServer_Click(object sender, EventArgs e) - { - ShowServerForm((int)EConfigType.Trojan, -1); - ShowForm(); - } - - private void menuAddServers_Click(object sender, EventArgs e) - { - string clipboardData = Utils.GetClipboardData(); - int result = AddBatchServers(clipboardData); - if (result > 0) - { - UI.Show(string.Format(UIRes.I18N("SuccessfullyImportedServerViaClipboard"), result)); - } - } - - private void menuScanScreen_Click(object sender, EventArgs e) - { - HideForm(); - bgwScan.RunWorkerAsync(); - } - - private int AddBatchServers(string clipboardData, string subid = "") - { - int counter; - int _Add() - { - return ConfigHandler.AddBatchServers(ref config, clipboardData, subid); - } - counter = _Add(); - if (counter < 1) - { - clipboardData = Utils.Base64Decode(clipboardData); - counter = _Add(); - } - RefreshServers(); - return counter; - } - - private void menuUpdateSubscriptions_Click(object sender, EventArgs e) - { - UpdateSubscriptionProcess(); - } - - #endregion - - - #region 提示信息 - - /// - /// 消息委托 - /// - /// - /// - void v2rayHandler_ProcessEvent(bool notify, string msg) - { - AppendText(notify, msg); - } - - delegate void AppendTextDelegate(string text); - void AppendText(bool notify, string msg) - { - try - { - AppendText(msg); - if (notify) - { - notifyMsg(msg); - } - } - catch - { - } - } - - void AppendText(string text) - { - if (this.txtMsgBox.InvokeRequired) - { - Invoke(new AppendTextDelegate(AppendText), new object[] { text }); - } - else - { - //this.txtMsgBox.AppendText(text); - ShowMsg(text); - } - } - - /// - /// 提示信息 - /// - /// - private void ShowMsg(string msg) - { - if (txtMsgBox.Lines.Length > 999) - { - ClearMsg(); - } - this.txtMsgBox.AppendText(msg); - if (!msg.EndsWith(Environment.NewLine)) - { - this.txtMsgBox.AppendText(Environment.NewLine); - } - } - - /// - /// 清除信息 - /// - private void ClearMsg() - { - this.txtMsgBox.Clear(); - } - - /// - /// 托盘信息 - /// - /// - private void notifyMsg(string msg) - { - notifyMain.Text = msg; - } - - #endregion - - - #region 托盘事件 - - private void notifyMain_MouseClick(object sender, MouseEventArgs e) - { - if (e.Button == MouseButtons.Left) - { - ShowForm(); - } - } - - private void menuExit_Click(object sender, EventArgs e) - { - this.Visible = false; - this.Close(); - - Application.Exit(); - } - - - private void ShowForm() - { - this.Show(); - this.WindowState = FormWindowState.Normal; - this.Activate(); - this.ShowInTaskbar = true; - //this.notifyIcon1.Visible = false; - this.txtMsgBox.ScrollToCaret(); - if (config.index >= 0 && config.index < lvServers.Items.Count) - { - lvServers.EnsureVisible(config.index); // workaround - } - - SetVisibleCore(true); - } - - private void HideForm() - { - //this.WindowState = FormWindowState.Minimized; - this.Hide(); - //this.notifyMain.Icon = this.Icon; - this.notifyMain.Visible = true; - this.ShowInTaskbar = false; - - SetVisibleCore(false); - } - - #endregion - - #region 后台测速 - - private void SetTestResult(int k, string txt) - { - if (k < lvServers.Items.Count) - { - config.vmess[k].testResult = txt; - lvServers.Items[k].SubItems["testResult"].Text = txt; - } - } - private void ClearTestResult() - { - foreach (int s in lvSelecteds) - { - SetTestResult(s, ""); - } - } - private void UpdateSpeedtestHandler(int index, string msg) - { - lvServers.Invoke((MethodInvoker)delegate - { - SetTestResult(index, msg); - }); - } - - private void UpdateStatisticsHandler(ulong up, ulong down, List statistics) - { - try - { - up /= (ulong)(config.statisticsFreshRate / 1000f); - down /= (ulong)(config.statisticsFreshRate / 1000f); - toolSslServerSpeed.Text = string.Format("{0}/s↑ | {1}/s↓", Utils.HumanFy(up), Utils.HumanFy(down)); - - List datas = new List(); - for (int i = 0; i < config.vmess.Count; i++) - { - int index = statistics.FindIndex(item_ => item_.itemId == config.vmess[i].getItemId()); - if (index != -1) - { - lvServers.Invoke((MethodInvoker)delegate - { - lvServers.BeginUpdate(); - - lvServers.Items[i].SubItems["todayDown"].Text = Utils.HumanFy(statistics[index].todayDown); - lvServers.Items[i].SubItems["todayUp"].Text = Utils.HumanFy(statistics[index].todayUp); - lvServers.Items[i].SubItems["totalDown"].Text = Utils.HumanFy(statistics[index].totalDown); - lvServers.Items[i].SubItems["totalUp"].Text = Utils.HumanFy(statistics[index].totalUp); - - lvServers.EndUpdate(); - }); - } - } - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - } - } - - #endregion - - #region 移动服务器 - - private void menuMoveTop_Click(object sender, EventArgs e) - { - MoveServer(EMove.Top); - } - - private void menuMoveUp_Click(object sender, EventArgs e) - { - MoveServer(EMove.Up); - } - - private void menuMoveDown_Click(object sender, EventArgs e) - { - MoveServer(EMove.Down); - } - - private void menuMoveBottom_Click(object sender, EventArgs e) - { - MoveServer(EMove.Bottom); - } - - private void MoveServer(EMove eMove) - { - int index = GetLvSelectedIndex(); - if (index < 0) - { - UI.Show(UIRes.I18N("PleaseSelectServer")); - return; - } - if (ConfigHandler.MoveServer(ref config, index, eMove) == 0) - { - //TODO: reload is not good. - RefreshServers(); - //LoadV2ray(); - } - } - private void menuSelectAll_Click(object sender, EventArgs e) - { - foreach (ListViewItem item in lvServers.Items) - { - item.Selected = true; - } - } - - #endregion - - #region 系统代理相关 - - private void menuCopyPACUrl_Click(object sender, EventArgs e) - { - Utils.SetClipboardData(HttpProxyHandle.GetPacUrl()); - } - - private void menuNotEnabledHttp_Click(object sender, EventArgs e) - { - SetListenerType(ListenerType.noHttpProxy); - } - private void menuGlobal_Click(object sender, EventArgs e) - { - SetListenerType(ListenerType.GlobalHttp); - } - private void menuGlobalPAC_Click(object sender, EventArgs e) - { - SetListenerType(ListenerType.GlobalPac); - } - private void menuKeep_Click(object sender, EventArgs e) - { - SetListenerType(ListenerType.HttpOpenAndClear); - } - private void menuKeepPAC_Click(object sender, EventArgs e) - { - SetListenerType(ListenerType.PacOpenAndClear); - } - private void menuKeepNothing_Click(object sender, EventArgs e) - { - SetListenerType(ListenerType.HttpOpenOnly); - } - private void menuKeepPACNothing_Click(object sender, EventArgs e) - { - SetListenerType(ListenerType.PacOpenOnly); - } - private void SetListenerType(ListenerType type) - { - config.listenerType = type; - ChangePACButtonStatus(type); - } - - private void ChangePACButtonStatus(ListenerType type) - { - if (type != ListenerType.noHttpProxy) - { - HttpProxyHandle.RestartHttpAgent(config, false); - } - else - { - HttpProxyHandle.CloseHttpAgent(config); - } - - for (int k = 0; k < menuSysAgentMode.DropDownItems.Count; k++) - { - ToolStripMenuItem item = ((ToolStripMenuItem)menuSysAgentMode.DropDownItems[k]); - item.Checked = ((int)type == k); - } - - ConfigHandler.SaveConfig(ref config, false); - DisplayToolStatus(); - } - - #endregion - - - #region CheckUpdate - - private void askToDownload(DownloadHandle downloadHandle, string url) - { - if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.Yes) - { - if (httpProxyTest() > 0) - { - int httpPort = config.GetLocalPort(Global.InboundHttp); - WebProxy webProxy = new WebProxy(Global.Loopback, httpPort); - downloadHandle.DownloadFileAsync(url, webProxy, 600); - } - else - { - downloadHandle.DownloadFileAsync(url, null, 600); - } - } - } - private void tsbCheckUpdateN_Click(object sender, EventArgs e) - { - //System.Diagnostics.Process.Start(Global.UpdateUrl); - DownloadHandle downloadHandle = null; - if (downloadHandle == null) - { - downloadHandle = new DownloadHandle(); - downloadHandle.AbsoluteCompleted += (sender2, args) => - { - if (args.Success) - { - AppendText(false, string.Format(UIRes.I18N("MsgParsingSuccessfully"), "v2rayN")); - - string url = args.Msg; - this.Invoke((MethodInvoker)(delegate - { - askToDownload(downloadHandle, url); - })); - } - else - { - AppendText(false, args.Msg); - } - }; - downloadHandle.UpdateCompleted += (sender2, args) => - { - if (args.Success) - { - AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); - - try - { - string fileName = Utils.GetPath(downloadHandle.DownloadFileName); - Process process = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = "v2rayUpgrade.exe", - Arguments = "\"" + fileName + "\"", - WorkingDirectory = Utils.StartupPath() - } - }; - process.Start(); - 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, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayN")); - downloadHandle.CheckUpdateAsync("v2rayN"); - } - - private void tsbCheckUpdateCore_Click(object sender, EventArgs e) - { - DownloadHandle downloadHandle = null; - if (downloadHandle == null) - { - downloadHandle = new DownloadHandle(); - downloadHandle.AbsoluteCompleted += (sender2, args) => - { - if (args.Success) - { - AppendText(false, string.Format(UIRes.I18N("MsgParsingSuccessfully"), "v2rayCore")); - - string url = args.Msg; - this.Invoke((MethodInvoker)(delegate - { - askToDownload(downloadHandle, url); - })); - } - else - { - AppendText(false, args.Msg); - } - }; - downloadHandle.UpdateCompleted += (sender2, args) => - { - if (args.Success) - { - AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); - AppendText(false, UIRes.I18N("MsgUnpacking")); - - try - { - CloseV2ray(); - - string fileName = downloadHandle.DownloadFileName; - fileName = Utils.GetPath(fileName); - FileManager.ZipExtractToFile(fileName); - - AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfullyMore")); - - Global.reloadV2ray = true; - LoadV2ray(); - - AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfully")); - } - catch (Exception ex) - { - AppendText(false, ex.Message); - } - } - else - { - AppendText(false, args.Msg); - } - }; - downloadHandle.Error += (sender2, args) => - { - AppendText(true, args.GetException().Message); - }; - } - - AppendText(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayCore")); - downloadHandle.CheckUpdateAsync("Core"); - } - - private void tsbCheckUpdatePACList_Click(object sender, EventArgs e) - { - DownloadHandle pacListHandle = null; - if (pacListHandle == null) - { - pacListHandle = new DownloadHandle(); - pacListHandle.UpdateCompleted += (sender2, args) => - { - if (args.Success) - { - string result = args.Msg; - if (Utils.IsNullOrEmpty(result)) - { - return; - } - pacListHandle.GenPacFile(result); - - AppendText(false, UIRes.I18N("MsgPACUpdateSuccessfully")); - } - else - { - AppendText(false, UIRes.I18N("MsgPACUpdateFailed")); - } - }; - pacListHandle.Error += (sender2, args) => - { - AppendText(true, args.GetException().Message); - }; - } - AppendText(false, UIRes.I18N("MsgStartUpdatingPAC")); - pacListHandle.WebDownloadString(config.urlGFWList); - } - - private void tsbCheckClearPACList_Click(object sender, EventArgs e) - { - try - { - File.WriteAllText(Utils.GetPath(Global.pacFILE), Utils.GetEmbedText(Global.BlankPacFileName), Encoding.UTF8); - AppendText(false, UIRes.I18N("MsgSimplifyPAC")); - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - } - } - #endregion - - #region Help - - - private void tsbAbout_Click(object sender, EventArgs e) - { - Process.Start(Global.AboutUrl); - } - - private void tsbV2rayWebsite_Click(object sender, EventArgs e) - { - Process.Start(Global.v2rayWebsiteUrl); - } - - private void tsbPromotion_Click(object sender, EventArgs e) - { - Process.Start($"{Utils.Base64Decode(Global.PromotionUrl)}"); - } - #endregion - - #region ScanScreen - - - private void bgwScan_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) - { - string ret = Utils.ScanScreen(); - bgwScan.ReportProgress(0, ret); - } - - private void bgwScan_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) - { - ShowForm(); - - string result = Convert.ToString(e.UserState); - if (Utils.IsNullOrEmpty(result)) - { - UI.ShowWarning(UIRes.I18N("NoValidQRcodeFound")); - } - else - { - if (AddBatchServers(result) > 0) - { - UI.Show(UIRes.I18N("SuccessfullyImportedServerViaScan")); - } - } - } - - #endregion - - #region 订阅 - private void tsbSubSetting_Click(object sender, EventArgs e) - { - SubSettingForm fm = new SubSettingForm(); - if (fm.ShowDialog() == DialogResult.OK) - { - RefreshServers(); - } - } - - private void tsbSubUpdate_Click(object sender, EventArgs e) - { - UpdateSubscriptionProcess(); - } - - /// - /// the subscription update process - /// - private void UpdateSubscriptionProcess() - { - AppendText(false, UIRes.I18N("MsgUpdateSubscriptionStart")); - - if (config.subItem == null || config.subItem.Count <= 0) - { - AppendText(false, UIRes.I18N("MsgNoValidSubscription")); - return; - } - - for (int k = 1; k <= config.subItem.Count; k++) - { - string id = config.subItem[k - 1].id.TrimEx(); - string url = config.subItem[k - 1].url.TrimEx(); - string hashCode = $"{k}->"; - if (config.subItem[k - 1].enabled == false) - { - continue; - } - if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url)) - { - AppendText(false, $"{hashCode}{UIRes.I18N("MsgNoValidSubscription")}"); - continue; - } - - DownloadHandle downloadHandle3 = new DownloadHandle(); - downloadHandle3.UpdateCompleted += (sender2, args) => - { - if (args.Success) - { - AppendText(false, $"{hashCode}{UIRes.I18N("MsgGetSubscriptionSuccessfully")}"); - string result = Utils.Base64Decode(args.Msg); - if (Utils.IsNullOrEmpty(result)) - { - AppendText(false, $"{hashCode}{UIRes.I18N("MsgSubscriptionDecodingFailed")}"); - return; - } - - ConfigHandler.RemoveServerViaSubid(ref config, id); - AppendText(false, $"{hashCode}{UIRes.I18N("MsgClearSubscription")}"); - RefreshServers(); - if (AddBatchServers(result, id) > 0) - { - } - else - { - AppendText(false, $"{hashCode}{UIRes.I18N("MsgFailedImportSubscription")}"); - } - AppendText(false, $"{hashCode}{UIRes.I18N("MsgUpdateSubscriptionEnd")}"); - } - else - { - AppendText(false, args.Msg); - } - }; - downloadHandle3.Error += (sender2, args) => - { - AppendText(true, args.GetException().Message); - }; - - downloadHandle3.WebDownloadString(url); - AppendText(false, $"{hashCode}{UIRes.I18N("MsgStartGettingSubscriptions")}"); - } - } - - private void tsbQRCodeSwitch_CheckedChanged(object sender, EventArgs e) - { - bool bShow = tsbQRCodeSwitch.Checked; - scMain.Panel2Collapsed = !bShow; - } - #endregion - - #region Language - - private void tsbLanguageDef_Click(object sender, EventArgs e) - { - SetCurrentLanguage("en"); - } - - private void tsbLanguageZhHans_Click(object sender, EventArgs e) - { - SetCurrentLanguage("zh-Hans"); - } - private void SetCurrentLanguage(string value) - { - Utils.RegWriteValue(Global.MyRegPath, Global.MyRegKeyLanguage, value); - //Application.Restart(); - } - - - - - #endregion - - - } -} diff --git a/v2rayN/v2rayN/Global.cs b/v2rayN/v2rayN/Global.cs deleted file mode 100644 index 3d736b4e..00000000 --- a/v2rayN/v2rayN/Global.cs +++ /dev/null @@ -1,264 +0,0 @@ - -namespace v2rayN -{ - class Global - { - #region 常量 - - - public const string v2rayWebsiteUrl = @"https://www.v2fly.org/"; - public const string AboutUrl = @"https://github.com/cg3s/v2rayN"; - public const string UpdateUrl = AboutUrl + @"/releases"; - - - /// - /// SpeedTestUrl - /// - public const string SpeedTestUrl = @"http://cachefly.cachefly.net/10mb.test"; - public const string SpeedPingTestUrl = @"https://www.google.com/generate_204"; - public const string AvailabilityTestUrl = @"https://www.google.com/generate_204"; - - /// - /// CustomRoutingListUrl - /// - public const string CustomRoutingListUrl = @"https://raw.githubusercontent.com/cg3s/v2rayCustomRoutingList/master/"; - - public const string GFWLIST_URL = "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"; - - /// - /// PromotionUrl - /// - public const string PromotionUrl = @"aHR0cHM6Ly9naXRodWIuY29tL2NnM3MvdjJyYXlO"; - - /// - /// 本软件配置文件名 - /// - public const string ConfigFileName = "guiNConfig.json"; - - /// - /// v2ray配置文件名 - /// - public const string v2rayConfigFileName = "config.json"; - - /// - /// v2ray客户端配置样例文件名 - /// - public const string v2raySampleClient = "v2rayN.Sample.SampleClientConfig.txt"; - /// - /// v2ray服务端配置样例文件名 - /// - public const string v2raySampleServer = "v2rayN.Sample.SampleServerConfig.txt"; - /// - /// v2ray配置Httprequest文件名 - /// - public const string v2raySampleHttprequestFileName = "v2rayN.Sample.SampleHttprequest.txt"; - /// - /// v2ray配置Httpresponse文件名 - /// - public const string v2raySampleHttpresponseFileName = "v2rayN.Sample.SampleHttpresponse.txt"; - /// - /// 空白的pac文件 - /// - public const string BlankPacFileName = "v2rayN.Sample.BlankPac.txt"; - - public const string CustomRoutingFileName = "v2rayN.Sample.custom_routing_"; - - - /// - /// 默认加密方式 - /// - public const string DefaultSecurity = "auto"; - - /// - /// 默认传输协议 - /// - public const string DefaultNetwork = "tcp"; - - /// - /// Tcp伪装http - /// - public const string TcpHeaderHttp = "http"; - - /// - /// None值 - /// - public const string None = "none"; - - /// - /// 代理 tag值 - /// - public const string agentTag = "proxy"; - - /// - /// 直连 tag值 - /// - public const string directTag = "direct"; - - /// - /// 阻止 tag值 - /// - public const string blockTag = "block"; - - /// - /// - /// - public const string StreamSecurity = "tls"; - public const string StreamSecurityX = "xtls"; - - public const string InboundSocks = "socks"; - public const string InboundHttp = "http"; - public const string Loopback = "127.0.0.1"; - public const string InboundAPITagName = "api"; - public const string InboundAPIProtocal = "dokodemo-door"; - - - /// - /// vmess - /// - public const string vmessProtocol = "vmess://"; - /// - /// vmess - /// - public const string vmessProtocolLite = "vmess"; - /// - /// shadowsocks - /// - public const string ssProtocol = "ss://"; - /// - /// shadowsocks - /// - public const string ssProtocolLite = "shadowsocks"; - /// - /// socks - /// - public const string socksProtocol = "socks://"; - /// - /// socks - /// - public const string socksProtocolLite = "socks"; - /// - /// http - /// - public const string httpProtocol = "http://"; - /// - /// https - /// - public const string httpsProtocol = "https://"; - /// - /// vless - /// - public const string vlessProtocol = "vless://"; - /// - /// vless - /// - public const string vlessProtocolLite = "vless"; - /// - /// trojan - /// - public const string trojanProtocol = "trojan://"; - /// - /// trojan - /// - public const string trojanProtocolLite = "trojan"; - - /// - /// pac - /// - public const string pacFILE = "pac.txt"; - - /// - /// email - /// - public const string userEMail = "t@t.tt"; - - /// - /// MyRegPath - /// - public const string MyRegPath = "Software\\v2rayNGUI"; - - /// - /// Language - /// - public const string MyRegKeyLanguage = "CurrentLanguage"; - /// - /// Icon - /// - public const string CustomIconName = "v2rayN.ico"; - - public enum StatisticsFreshRate - { - quick = 1000, - medium = 2000, - slow = 3000 - } - public const string StatisticLogOverall = "StatisticLogOverall.json"; - - public const string IEProxyExceptions = "localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;192.168.*"; - - #endregion - - #region 全局变量 - - /// - /// 是否需要重启服务V2ray - /// - public static bool reloadV2ray - { - get; set; - } - - /// - /// 是否开启全局代理(http) - /// - public static bool sysAgent - { - get; set; - } - - /// - /// socks端口 - /// - public static int socksPort - { - get; set; - } - - /// - /// http端口 - /// - public static int httpPort - { - get; set; - } - - /// - /// PAC端口 - /// - public static int pacPort - { - get; set; - } - - /// - /// - /// - public static int statePort - { - get; set; - } - - public static Job processJob - { - get; set; - } - public static System.Threading.Mutex mutexObj - { - get; set; - } - - #endregion - - - - } -} diff --git a/v2rayN/v2rayN/Handler/DownloadHandle.cs b/v2rayN/v2rayN/Handler/DownloadHandle.cs deleted file mode 100644 index 1a186641..00000000 --- a/v2rayN/v2rayN/Handler/DownloadHandle.cs +++ /dev/null @@ -1,359 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Net; -using System.Net.Http; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using v2rayN.Base; -using v2rayN.Mode; -using v2rayN.Properties; - -namespace v2rayN.Handler -{ - /// - ///Download - /// - class DownloadHandle - { - public event EventHandler AbsoluteCompleted; - - public event EventHandler UpdateCompleted; - - public event ErrorEventHandler Error; - - public string DownloadFileName - { - get - { - return "v2ray-windows.zip"; - } - } - - public class ResultEventArgs : EventArgs - { - public bool Success; - public string Msg; - - public ResultEventArgs(bool success, string msg) - { - this.Success = success; - this.Msg = msg; - } - } - - private int progressPercentage = -1; - private long totalBytesToReceive = 0; - private DateTime totalDatetime = new DateTime(); - private int DownloadTimeout = -1; - - #region Check for updates - - private readonly string nLatestUrl = "https://github.com/cg3s/v2rayN/releases/latest"; - private const string nUrl = "https://github.com/cg3s/v2rayN/releases/download/{0}/v2rayN.zip"; - private readonly string coreLatestUrl = "https://github.com/v2fly/v2ray-core/releases/latest"; - private const string coreUrl = "https://github.com/v2fly/v2ray-core/releases/download/{0}/v2ray-windows-{1}.zip"; - - public async void CheckUpdateAsync(string type) - { - Utils.SetSecurityProtocol(); - WebRequestHandler webRequestHandler = new WebRequestHandler - { - AllowAutoRedirect = false - }; - HttpClient httpClient = new HttpClient(webRequestHandler); - - string url; - if (type == "Core") - { - url = coreLatestUrl; - } - else if (type == "v2rayN") - { - url = nLatestUrl; - } - else - { - throw new ArgumentException("Type"); - } - HttpResponseMessage response = await httpClient.GetAsync(url); - if (response.StatusCode.ToString() == "Redirect") - { - responseHandler(type, response.Headers.Location.ToString()); - } - else - { - Utils.SaveLog("StatusCode error: " + url); - return; - } - } - - /// - /// 获取V2RayCore版本 - /// - public string getV2rayVersion() - { - try - { - string filePath = Utils.GetPath("V2ray.exe"); - if (!File.Exists(filePath)) - { - string msg = string.Format(UIRes.I18N("NotFoundCore"), @"https://github.com/v2fly/v2ray-core/releases"); - //ShowMsg(true, msg); - return ""; - } - - Process p = new Process(); - p.StartInfo.FileName = filePath; - p.StartInfo.Arguments = "-version"; - p.StartInfo.WorkingDirectory = Utils.StartupPath(); - p.StartInfo.UseShellExecute = false; - p.StartInfo.RedirectStandardOutput = true; - p.StartInfo.CreateNoWindow = true; - p.StartInfo.StandardOutputEncoding = Encoding.UTF8; - p.Start(); - p.WaitForExit(5000); - string echo = p.StandardOutput.ReadToEnd(); - string version = Regex.Match(echo, "V2Ray ([0-9.]+) \\(").Groups[1].Value; - return version; - } - - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - return ""; - } - } - private void responseHandler(string type, string redirectUrl) - { - try - { - string version = redirectUrl.Substring(redirectUrl.LastIndexOf("/", StringComparison.Ordinal) + 1); - - string curVersion; - string message; - string url; - if (type == "Core") - { - curVersion = "v" + getV2rayVersion(); - message = string.Format(UIRes.I18N("IsLatestCore"), curVersion); - string osBit = Environment.Is64BitProcess ? "64" : "32"; - url = string.Format(coreUrl, version, osBit); - } - else if (type == "v2rayN") - { - curVersion = FileVersionInfo.GetVersionInfo(Utils.GetExePath()).FileVersion.ToString(); - message = string.Format(UIRes.I18N("IsLatestN"), curVersion); - url = string.Format(nUrl, version); - } - else - { - throw new ArgumentException("Type"); - } - - if (curVersion == version) - { - AbsoluteCompleted?.Invoke(this, new ResultEventArgs(false, message)); - return; - } - - AbsoluteCompleted?.Invoke(this, new ResultEventArgs(true, url)); - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - - Error?.Invoke(this, new ErrorEventArgs(ex)); - } - } - - #endregion - - #region Download - - public WebClientEx DownloadFileAsync(string url, WebProxy webProxy, int downloadTimeout) - { - WebClientEx ws = new WebClientEx(); - try - { - Utils.SetSecurityProtocol(); - UpdateCompleted?.Invoke(this, new ResultEventArgs(false, UIRes.I18N("Downloading"))); - - progressPercentage = -1; - totalBytesToReceive = 0; - - //WebClientEx ws = new WebClientEx(); - DownloadTimeout = downloadTimeout; - if (webProxy != null) - { - ws.Proxy = webProxy;// new WebProxy(Global.Loopback, Global.httpPort); - } - - ws.DownloadFileCompleted += ws_DownloadFileCompleted; - ws.DownloadProgressChanged += ws_DownloadProgressChanged; - ws.DownloadFileAsync(new Uri(url), Utils.GetPath(DownloadFileName)); - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - - Error?.Invoke(this, new ErrorEventArgs(ex)); - } - return ws; - } - - void ws_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) - { - if (UpdateCompleted != null) - { - if (totalBytesToReceive == 0) - { - totalDatetime = DateTime.Now; - totalBytesToReceive = e.BytesReceived; - return; - } - totalBytesToReceive = e.BytesReceived; - - if (DownloadTimeout != -1) - { - if ((DateTime.Now - totalDatetime).TotalSeconds > DownloadTimeout) - { - ((WebClientEx)sender).CancelAsync(); - } - } - if (progressPercentage != e.ProgressPercentage && e.ProgressPercentage % 10 == 0) - { - progressPercentage = e.ProgressPercentage; - string msg = string.Format("...{0}%", e.ProgressPercentage); - UpdateCompleted(this, new ResultEventArgs(false, msg)); - } - } - } - void ws_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) - { - try - { - if (UpdateCompleted != null) - { - if (e.Cancelled) - { - ((WebClientEx)sender).Dispose(); - TimeSpan ts = (DateTime.Now - totalDatetime); - string speed = string.Format("{0} M/s", (totalBytesToReceive / ts.TotalMilliseconds / 1000).ToString("#0.##")); - UpdateCompleted(this, new ResultEventArgs(true, speed)); - return; - } - - if (e.Error == null - || Utils.IsNullOrEmpty(e.Error.ToString())) - { - - TimeSpan ts = (DateTime.Now - totalDatetime); - string speed = string.Format("{0} M/s", (totalBytesToReceive / ts.TotalMilliseconds / 1000).ToString("#0.##")); - UpdateCompleted(this, new ResultEventArgs(true, speed)); - } - else - { - throw e.Error; - } - } - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - - Error?.Invoke(this, new ErrorEventArgs(ex)); - } - } - - /// - /// DownloadString - /// - /// - public void WebDownloadString(string url) - { - string source = string.Empty; - try - { - Utils.SetSecurityProtocol(); - - WebClientEx ws = new WebClientEx(); - ws.DownloadStringCompleted += Ws_DownloadStringCompleted; - ws.DownloadStringAsync(new Uri(url)); - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - } - } - - private void Ws_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) - { - try - { - if (e.Error == null - || Utils.IsNullOrEmpty(e.Error.ToString())) - { - string source = e.Result; - UpdateCompleted?.Invoke(this, new ResultEventArgs(true, source)); - } - else - { - throw e.Error; - } - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - - Error?.Invoke(this, new ErrorEventArgs(ex)); - } - } - - #endregion - - #region PAC - - public string GenPacFile(string result) - { - try - { - File.WriteAllText(Utils.GetTempPath("gfwlist.txt"), result, Encoding.UTF8); - List lines = ParsePacResult(result); - string abpContent = Utils.UnGzip(Resources.abp_js); - abpContent = abpContent.Replace("__RULES__", JsonConvert.SerializeObject(lines, Formatting.Indented)); - File.WriteAllText(Utils.GetPath(Global.pacFILE), abpContent, Encoding.UTF8); - } - catch (Exception ex) - { - Utils.SaveLog(ex.Message, ex); - return ex.Message; - } - return string.Empty; - } - - private List ParsePacResult(string response) - { - IEnumerable IgnoredLineBegins = new[] { '!', '[' }; - - byte[] bytes = Convert.FromBase64String(response); - string content = Encoding.UTF8.GetString(bytes); - List valid_lines = new List(); - using (StringReader sr = new StringReader(content)) - { - foreach (string line in sr.NonWhiteSpaceLines()) - { - if (line.BeginWithAny(IgnoredLineBegins)) - continue; - valid_lines.Add(line); - } - } - return valid_lines; - } - - #endregion - } -} diff --git a/v2rayN/v2rayN/Properties/AssemblyInfo.cs b/v2rayN/v2rayN/Properties/AssemblyInfo.cs deleted file mode 100644 index 8c214e64..00000000 --- a/v2rayN/v2rayN/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// 有关程序集的常规信息通过以下 -// 特性集控制。更改这些特性值可修改 -// 与程序集关联的信息。 -[assembly: AssemblyTitle("v2rayN")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("v2rayN")] -[assembly: AssemblyCopyright("Copyright © 2019-2020 (GPLv3)")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 将 ComVisible 设置为 false 使此程序集中的类型 -// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, -// 则将该类型上的 ComVisible 特性设置为 true。 -[assembly: ComVisible(false)] - -// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID -[assembly: Guid("72d9f089-5e7a-4c5f-be0a-8a211536b483")] - -// 程序集的版本信息由下面四个值组成: -// -// 主版本 -// 次版本 -// 生成号 -// 修订号 -// -// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, -// 方法是按如下所示使用“*”: -//[assembly: AssemblyVersion("1.0.*")] -//[assembly: AssemblyVersion("1.0.0")] -[assembly: AssemblyFileVersion("3.29")] diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index f4b5dfaf..0f5dfd55 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -272,23 +272,6 @@ - Resources\v2rayN.ico app.manifest 7.0 - AnyCPU;ARM64 - - - - none - - - - none - - - - none - - - - none