Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
完成基本切换功能
  • Loading branch information
zjyl1994 authored Nov 12, 2017
1 parent 162214a commit 585873a
Show file tree
Hide file tree
Showing 29 changed files with 717 additions and 0 deletions.
22 changes: 22 additions & 0 deletions V2Switcher.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "V2Switcher", "V2Switcher\V2Switcher.csproj", "{4C87BF6C-5F4A-4C03-ADCA-4FD38FCFAF61}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4C87BF6C-5F4A-4C03-ADCA-4FD38FCFAF61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C87BF6C-5F4A-4C03-ADCA-4FD38FCFAF61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C87BF6C-5F4A-4C03-ADCA-4FD38FCFAF61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C87BF6C-5F4A-4C03-ADCA-4FD38FCFAF61}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions V2Switcher/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup>
</configuration>
34 changes: 34 additions & 0 deletions V2Switcher/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace V2Switcher
{
class Config
{
private string configPath;
private string proxyAddr;
private string proxyName;
public Config(string configName)
{
configPath = configName+".json";
proxyAddr = "127.0.0.1:" + JObject.Parse(File.ReadAllText(configPath)).SelectToken("inbound.port").ToString();
proxyName = configName;
}
public string Filename {
get { return configPath; }
}
public string Name {
get { return proxyName; }
}
public string Address {
get {
return proxyAddr;
}
}
}
}
102 changes: 102 additions & 0 deletions V2Switcher/ProcessIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using V2Switcher.Properties;
using System.Diagnostics;
using System.ComponentModel;

namespace V2Switcher
{
public class ProcessIcon : IDisposable
{
NotifyIcon ni;
ContextMenuStrip cm;
ProxyManager pm;

public ProcessIcon()
{
ni = new NotifyIcon();
cm = new ContextMenuStrip();
cm.Opening += new CancelEventHandler(OnContextMenuOpening);
pm = ProxyManager.GetInstance();
pm.Current = new Config(Util.loadDefault());
}

public void Display()
{
ni.MouseDoubleClick += new MouseEventHandler(ni_MouseClick);
ni.Icon = pm.Enable ? Resource.v2enable:Resource.v2disable;
ni.Text = "V2Switcher";
ni.Visible = true;
ni.ContextMenuStrip = cm;
}

public void Dispose()
{
ni.Dispose();
}

void ni_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
pm.Enable = !pm.Enable;
ni.Icon = pm.Enable ? Resource.v2enable : Resource.v2disable;
}
}

void OnContextMenuOpening(object sender, CancelEventArgs e)
{
ToolStripMenuItem item;
ToolStripSeparator sep;

cm.Items.Clear();
item = new ToolStripMenuItem();
item.Text = "启用代理";
item.Click += new System.EventHandler(Proxy_Click);
item.Checked = pm.Enable;
cm.Items.Add(item);

sep = new ToolStripSeparator();
cm.Items.Add(sep);

foreach (string configname in Util.configsName)
{
item = new ToolStripMenuItem();
item.Text = configname;
item.Click += new System.EventHandler(Server_Click);
item.Checked = pm.currentConfigName == configname;
cm.Items.Add(item);
}

sep = new ToolStripSeparator();
cm.Items.Add(sep);

item = new ToolStripMenuItem();
item.Text = "退出";
item.Click += new System.EventHandler(Exit_Click);
cm.Items.Add(item);
}

void Exit_Click(object sender, EventArgs e)
{
Array.ForEach(Process.GetProcessesByName(Util.executeName), x => x.Kill());
Application.Exit();
}

void Proxy_Click(object sender, EventArgs e)
{
pm.Enable =! pm.Enable;
ni.Icon = pm.Enable ? Resource.v2enable : Resource.v2disable;
}

void Server_Click(object sender, EventArgs e)
{
ToolStripMenuItem Caller = (ToolStripMenuItem)sender;
pm.Current = new Config(Caller.Text);
}
}
}
33 changes: 33 additions & 0 deletions V2Switcher/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace V2Switcher
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (Util.checkEnvironment() == false)
{
MessageBox.Show("需要V2Ray核心程序和至少一个Json配置文件","V2Switcher无法启动",MessageBoxButtons.OK,MessageBoxIcon.Stop);
}
else
{
using (ProcessIcon pi = new ProcessIcon())
{
pi.Display();
Application.Run();
}
}
}
}
}
36 changes: 36 additions & 0 deletions V2Switcher/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("V2Switcher")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("V2Switcher")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("4c87bf6c-5f4a-4c03-adca-4fd38fcfaf61")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
83 changes: 83 additions & 0 deletions V2Switcher/Properties/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 585873a

Please sign in to comment.