Skip to content

Commit 054c0a2

Browse files
Merge pull request #62 from InvisibleManVPN/develop
InvisibleMan XRay version 0.9.1
2 parents 2d518f2 + 6bcc7c9 commit 054c0a2

33 files changed

Lines changed: 1350 additions & 84 deletions

InvisibleMan-XRay/App.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<ResourceDictionary Source="Styles/Components/RadioButtons.xaml"/>
1313
<ResourceDictionary Source="Styles/Components/TextBoxes.xaml"/>
1414
<ResourceDictionary Source="Styles/Components/ScrollViews.xaml"/>
15+
<ResourceDictionary Source="Styles/Components/ComboBoxes.xaml"/>
16+
<ResourceDictionary Source="Styles/Components/CheckBoxes.xaml"/>
1517
</ResourceDictionary.MergedDictionaries>
1618

1719
<FontFamily x:Key="SegoeUI">pack://application:,,,/Assets/Fonts/#SegoeUI</FontFamily>

InvisibleMan-XRay/Assets/Icons.xaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@
4545
</VisualBrush.Visual>
4646
</VisualBrush>
4747

48+
<VisualBrush x:Key="Icon.Settings">
49+
<VisualBrush.Visual>
50+
<Canvas>
51+
<Path Data="M495.9 166.6c3.2 8.7 .5 18.4-6.4 24.6l-43.3 39.4c1.1 8.3 1.7 16.8 1.7 25.4s-.6 17.1-1.7 25.4l43.3 39.4c6.9 6.2 9.6 15.9 6.4 24.6c-4.4 11.9-9.7 23.3-15.8 34.3l-4.7 8.1c-6.6 11-14 21.4-22.1 31.2c-5.9 7.2-15.7 9.6-24.5 6.8l-55.7-17.7c-13.4 10.3-28.2 18.9-44 25.4l-12.5 57.1c-2 9.1-9 16.3-18.2 17.8c-13.8 2.3-28 3.5-42.5 3.5s-28.7-1.2-42.5-3.5c-9.2-1.5-16.2-8.7-18.2-17.8l-12.5-57.1c-15.8-6.5-30.6-15.1-44-25.4L83.1 425.9c-8.8 2.8-18.6 .3-24.5-6.8c-8.1-9.8-15.5-20.2-22.1-31.2l-4.7-8.1c-6.1-11-11.4-22.4-15.8-34.3c-3.2-8.7-.5-18.4 6.4-24.6l43.3-39.4C64.6 273.1 64 264.6 64 256s.6-17.1 1.7-25.4L22.4 191.2c-6.9-6.2-9.6-15.9-6.4-24.6c4.4-11.9 9.7-23.3 15.8-34.3l4.7-8.1c6.6-11 14-21.4 22.1-31.2c5.9-7.2 15.7-9.6 24.5-6.8l55.7 17.7c13.4-10.3 28.2-18.9 44-25.4l12.5-57.1c2-9.1 9-16.3 18.2-17.8C227.3 1.2 241.5 0 256 0s28.7 1.2 42.5 3.5c9.2 1.5 16.2 8.7 18.2 17.8l12.5 57.1c15.8 6.5 30.6 15.1 44 25.4l55.7-17.7c8.8-2.8 18.6-.3 24.5 6.8c8.1 9.8 15.5 20.2 22.1 31.2l4.7 8.1c6.1 11 11.4 22.4 15.8 34.3zM256 336a80 80 0 1 0 0-160 80 80 0 1 0 0 160z" Fill="#2d2d2d" />
52+
</Canvas>
53+
</VisualBrush.Visual>
54+
</VisualBrush>
55+
4856
<VisualBrush x:Key="Icon.Update">
4957
<VisualBrush.Visual>
5058
<Canvas>
@@ -93,6 +101,14 @@
93101
</VisualBrush.Visual>
94102
</VisualBrush>
95103

104+
<VisualBrush x:Key="Icon.Log">
105+
<VisualBrush.Visual>
106+
<Canvas>
107+
<Path Data="M64 0C28.7 0 0 28.7 0 64V448c0 35.3 28.7 64 64 64H320c35.3 0 64-28.7 64-64V160H256c-17.7 0-32-14.3-32-32V0H64zM256 0V128H384L256 0zM112 256H272c8.8 0 16 7.2 16 16s-7.2 16-16 16H112c-8.8 0-16-7.2-16-16s7.2-16 16-16zm0 64H272c8.8 0 16 7.2 16 16s-7.2 16-16 16H112c-8.8 0-16-7.2-16-16s7.2-16 16-16zm0 64H272c8.8 0 16 7.2 16 16s-7.2 16-16 16H112c-8.8 0-16-7.2-16-16s7.2-16 16-16z" Fill="#ffffff" />
108+
</Canvas>
109+
</VisualBrush.Visual>
110+
</VisualBrush>
111+
96112
<VisualBrush x:Key="Icon.Edit">
97113
<VisualBrush.Visual>
98114
<Canvas>
@@ -151,6 +167,14 @@
151167
</VisualBrush.Visual>
152168
</VisualBrush>
153169

170+
<VisualBrush x:Key="Icon.Settings.MintyGreen">
171+
<VisualBrush.Visual>
172+
<Canvas>
173+
<Path Data="M495.9 166.6c3.2 8.7 .5 18.4-6.4 24.6l-43.3 39.4c1.1 8.3 1.7 16.8 1.7 25.4s-.6 17.1-1.7 25.4l43.3 39.4c6.9 6.2 9.6 15.9 6.4 24.6c-4.4 11.9-9.7 23.3-15.8 34.3l-4.7 8.1c-6.6 11-14 21.4-22.1 31.2c-5.9 7.2-15.7 9.6-24.5 6.8l-55.7-17.7c-13.4 10.3-28.2 18.9-44 25.4l-12.5 57.1c-2 9.1-9 16.3-18.2 17.8c-13.8 2.3-28 3.5-42.5 3.5s-28.7-1.2-42.5-3.5c-9.2-1.5-16.2-8.7-18.2-17.8l-12.5-57.1c-15.8-6.5-30.6-15.1-44-25.4L83.1 425.9c-8.8 2.8-18.6 .3-24.5-6.8c-8.1-9.8-15.5-20.2-22.1-31.2l-4.7-8.1c-6.1-11-11.4-22.4-15.8-34.3c-3.2-8.7-.5-18.4 6.4-24.6l43.3-39.4C64.6 273.1 64 264.6 64 256s.6-17.1 1.7-25.4L22.4 191.2c-6.9-6.2-9.6-15.9-6.4-24.6c4.4-11.9 9.7-23.3 15.8-34.3l4.7-8.1c6.6-11 14-21.4 22.1-31.2c5.9-7.2 15.7-9.6 24.5-6.8l55.7 17.7c13.4-10.3 28.2-18.9 44-25.4l12.5-57.1c2-9.1 9-16.3 18.2-17.8C227.3 1.2 241.5 0 256 0s28.7 1.2 42.5 3.5c9.2 1.5 16.2 8.7 18.2 17.8l12.5 57.1c15.8 6.5 30.6 15.1 44 25.4l55.7-17.7c8.8-2.8 18.6-.3 24.5 6.8c8.1 9.8 15.5 20.2 22.1 31.2l4.7 8.1c6.1 11 11.4 22.4 15.8 34.3zM256 336a80 80 0 1 0 0-160 80 80 0 1 0 0 160z" Fill="#6dcc8e" />
174+
</Canvas>
175+
</VisualBrush.Visual>
176+
</VisualBrush>
177+
154178
<VisualBrush x:Key="Icon.Update.MintyGreen">
155179
<VisualBrush.Visual>
156180
<Canvas>

InvisibleMan-XRay/Core/InvisibleManXRayCore.cs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ namespace InvisibleManXRay.Core
1010

1111
public class InvisibleManXRayCore
1212
{
13-
private const string LOCAL_HOST = "127.0.0.1";
14-
private const int DEFAULT_PORT = 10801;
15-
private const int TEST_PORT = 10802;
16-
1713
private Func<Config> getConfig;
1814
private Func<Mode> getMode;
15+
private Func<Protocol> getProtocol;
16+
private Func<LogLevel> getLogLevel;
17+
private Func<string> getLogPath;
18+
private Func<int> getProxyPort;
19+
private Func<int> getTunPort;
20+
private Func<int> getTestPort;
21+
private Func<bool> getUdpEnabled;
1922
private Func<string> getTunIp;
2023
private Func<string> getDns;
2124
private Func<IProxy> getProxy;
@@ -25,6 +28,13 @@ public class InvisibleManXRayCore
2528
public void Setup(
2629
Func<Config> getConfig,
2730
Func<Mode> getMode,
31+
Func<Protocol> getProtocol,
32+
Func<LogLevel> getLogLevel,
33+
Func<string> getLogPath,
34+
Func<int> getProxyPort,
35+
Func<int> getTunPort,
36+
Func<int> getTestPort,
37+
Func<bool> getUdpEnabled,
2838
Func<string> getTunIp,
2939
Func<string> getDns,
3040
Func<IProxy> getProxy,
@@ -33,6 +43,13 @@ public void Setup(
3343
{
3444
this.getConfig = getConfig;
3545
this.getMode = getMode;
46+
this.getProtocol = getProtocol;
47+
this.getLogLevel = getLogLevel;
48+
this.getLogPath = getLogPath;
49+
this.getProxyPort = getProxyPort;
50+
this.getTunPort = getTunPort;
51+
this.getTestPort = getTestPort;
52+
this.getUdpEnabled = getUdpEnabled;
3653
this.getTunIp = getTunIp;
3754
this.getDns = getDns;
3855
this.getProxy = getProxy;
@@ -86,7 +103,13 @@ public void DisableMode()
86103
public void Run(string config)
87104
{
88105
Mode mode = getMode.Invoke();
89-
XRayCoreWrapper.StartServer(config, DEFAULT_PORT, mode == Mode.TUN);
106+
int port = mode == Mode.PROXY ? getProxyPort.Invoke() : getTunPort.Invoke();
107+
LogLevel logLevel = getLogLevel.Invoke();
108+
string logPath = System.IO.Path.GetFullPath($"{getLogPath.Invoke()}/{getConfig.Invoke().Name}");
109+
bool isSocks = getProtocol.Invoke() == Protocol.SOCKS || mode == Mode.TUN;
110+
bool isUdpEnabled = getUdpEnabled.Invoke();
111+
112+
XRayCoreWrapper.StartServer(config, port, logLevel, logPath, isSocks, isUdpEnabled);
90113
}
91114

92115
public void Stop()
@@ -102,16 +125,21 @@ public void Cancel()
102125

103126
public bool Test(string config)
104127
{
105-
return XRayCoreWrapper.TestConnection(config, TEST_PORT);
128+
return XRayCoreWrapper.TestConnection(config, getTestPort.Invoke());
129+
}
130+
131+
public string GetVersion()
132+
{
133+
return XRayCoreWrapper.GetVersion();
106134
}
107135

108136
private Status EnableProxy()
109137
{
110138
IProxy proxy = getProxy.Invoke();
111139

112140
return proxy.Enable(
113-
ip: LOCAL_HOST,
114-
port: DEFAULT_PORT
141+
ip: Global.LOCAL_HOST,
142+
port: getProxyPort.Invoke()
115143
);
116144
}
117145

@@ -132,14 +160,15 @@ private Status EnableTunnel()
132160
parent: "outbounds",
133161
jsonString: configStatus.Content.ToString()
134162
);
163+
int port = getTunPort.Invoke();
135164
string address = getTunIp.Invoke();
136165
string dns = getDns.Invoke();
137166

138167
ITunnel tunnel = getTunnel.Invoke();
139168

140169
return tunnel.Enable(
141-
ip: LOCAL_HOST,
142-
port: DEFAULT_PORT,
170+
ip: Global.LOCAL_HOST,
171+
port: port,
143172
address: address,
144173
server: server,
145174
dns: dns

InvisibleMan-XRay/Core/XRayCoreWrapper.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace InvisibleManXRay.Core
55
{
6+
using Models;
67
using Values;
78

89
internal class XRayCoreWrapper
@@ -31,12 +32,12 @@ public static string LoadConfig(string fileFormat, string filePath)
3132
static extern IntPtr LoadConfig(string format, string file);
3233
}
3334

34-
public static void StartServer(string config, int port, bool isSocks)
35+
public static void StartServer(string config, int port, LogLevel logLevel, string logPath, bool isSocks, bool isUdpEnabled)
3536
{
36-
StartServer(config, port, isSocks);
37+
StartServer(config, port, logLevel.ToString(), logPath, isSocks, isUdpEnabled);
3738

3839
[DllImport(Path.XRAY_CORE_DLL, EntryPoint = "StartServer")]
39-
static extern void StartServer(string config, int port, bool isSocks);
40+
static extern void StartServer(string config, int port, string logLevel, string logPath, bool isSocks, bool isUdpEnabled);
4041
}
4142

4243
public static void StopServer()
@@ -54,5 +55,13 @@ public static bool TestConnection(string config, int port)
5455
[DllImport(Path.XRAY_CORE_DLL, EntryPoint = "TestConnection")]
5556
static extern bool TestConnection(string config, int port);
5657
}
58+
59+
public static string GetVersion()
60+
{
61+
return Marshal.PtrToStringAnsi(GetXRayCoreVersion());
62+
63+
[DllImport(Path.XRAY_CORE_DLL, EntryPoint = "GetXrayCoreVersion")]
64+
static extern IntPtr GetXRayCoreVersion();
65+
}
5766
}
5867
}

InvisibleMan-XRay/Factories/WindowFactory.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace InvisibleManXRay.Factories
44
{
55
using Core;
6+
using Models;
67
using Managers;
78
using Handlers;
89

@@ -34,6 +35,7 @@ public MainWindow CreateMainWindow()
3435
checkForUpdate: updateHandler.CheckForUpdate,
3536
checkForBroadcast: broadcastHandler.CheckForBroadcast,
3637
openServerWindow: CreateServerWindow,
38+
openSettingsWindow: CreateSettingsWindow,
3739
openUpdateWindow: CreateUpdateWindow,
3840
openAboutWindow: CreateAboutWindow,
3941
onRunServer: core.Run,
@@ -48,6 +50,37 @@ public MainWindow CreateMainWindow()
4850
return mainWindow;
4951
}
5052

53+
public SettingsWindow CreateSettingsWindow()
54+
{
55+
SettingsHandler settingsHandler = handlersManager.GetHandler<SettingsHandler>();
56+
NotifyHandler notifyHandler = handlersManager.GetHandler<NotifyHandler>();
57+
58+
SettingsWindow settingsWindow = new SettingsWindow();
59+
settingsWindow.Setup(
60+
getMode: settingsHandler.UserSettings.GetMode,
61+
getProtocol: settingsHandler.UserSettings.GetProtocol,
62+
getUdpEnabled: settingsHandler.UserSettings.GetUdpEnabled,
63+
getRunAtStartupEnabled: settingsHandler.UserSettings.GetRunAtStartupEnabled,
64+
getProxyPort: settingsHandler.UserSettings.GetProxyPort,
65+
getTunPort: settingsHandler.UserSettings.GetTunPort,
66+
getTestPort: settingsHandler.UserSettings.GetTestPort,
67+
getDeviceIp: settingsHandler.UserSettings.GetTunIp,
68+
getDns: settingsHandler.UserSettings.GetDns,
69+
getLogLevel: settingsHandler.UserSettings.GetLogLevel,
70+
getLogPath: settingsHandler.UserSettings.GetLogPath,
71+
onUpdateUserSettings: UpdateUserSettings
72+
);
73+
74+
return settingsWindow;
75+
76+
void UpdateUserSettings(UserSettings userSettings)
77+
{
78+
settingsHandler.UpdateUserSettings(userSettings);
79+
notifyHandler.CheckModeItem(userSettings.GetMode());
80+
GetMainWindow().TryDisableModeAndRerun();
81+
}
82+
}
83+
5184
public UpdateWindow CreateUpdateWindow()
5285
{
5386
UpdateHandler updateHandler = handlersManager.GetHandler<UpdateHandler>();
@@ -64,16 +97,30 @@ public UpdateWindow CreateUpdateWindow()
6497

6598
public AboutWindow CreateAboutWindow()
6699
{
100+
VersionHandler versionHandler = handlersManager.GetHandler<VersionHandler>();
67101
LinkHandler linkHandler = handlersManager.GetHandler<LinkHandler>();
68102

69103
AboutWindow aboutWindow = new AboutWindow();
70104
aboutWindow.Setup(
105+
getApplicationVersion: GetApplicationVersion,
106+
getXRayCoreVersion: GetXRayCoreVersion,
71107
onEmailClick: linkHandler.OpenEmailLink,
72108
onWebsiteClick: linkHandler.OpenWebsiteLink,
73109
onBugReportingClick: linkHandler.OpenBugReportingLink
74110
);
75111

76112
return aboutWindow;
113+
114+
string GetApplicationVersion()
115+
{
116+
AppVersion appVersion = versionHandler.GetApplicationVersion();
117+
return $"{appVersion.Major}.{appVersion.Feature}.{appVersion.BugFix}";
118+
}
119+
120+
string GetXRayCoreVersion()
121+
{
122+
return core.GetVersion();
123+
}
77124
}
78125

79126
private ServerWindow CreateServerWindow()
@@ -90,6 +137,7 @@ private ServerWindow CreateServerWindow()
90137
convertConfigLinkToV2Ray: templateHandler.ConverLinkToV2Ray,
91138
loadConfig: core.LoadConfig,
92139
testConnection: core.Test,
140+
getLogPath: settingsHandler.UserSettings.GetLogPath,
93141
onCopyConfig: configHandler.CopyConfig,
94142
onCreateConfig: configHandler.CreateConfig,
95143
onDeleteConfig: configHandler.LoadConfigFiles,

InvisibleMan-XRay/Handlers/NotifyHandler.cs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Drawing;
44
using System.Windows.Forms;
5+
using System.Collections.Generic;
56

67
namespace InvisibleManXRay.Handlers
78
{
@@ -19,6 +20,8 @@ public class NotifyHandler : Handler
1920
private Action onProxyModeClick;
2021
private Action onTunnelModeClick;
2122

23+
private Dictionary<Mode, ToolStripMenuItem> modeItems;
24+
2225
public NotifyHandler()
2326
{
2427
InitializeNotifyIcon();
@@ -46,6 +49,13 @@ Action onTunnelModeClick
4649
AddMenuStrip();
4750
}
4851

52+
public void CheckModeItem(Mode mode)
53+
{
54+
ToolStripMenuItem modeItem = modeItems[mode];
55+
UncheckAllItems();
56+
CheckItem(modeItem);
57+
}
58+
4959
private void InitializeNotifyIcon()
5060
{
5161
notifyIcon = new NotifyIcon();
@@ -71,12 +81,13 @@ private void HandleNotifyIconClick()
7181
private void AddMenuStrip()
7282
{
7383
ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
84+
modeItems = new Dictionary<Mode, ToolStripMenuItem>() {
85+
{ Mode.PROXY, CreateItem("Proxy", onProxyModeClick, true, getMode.Invoke() == Mode.PROXY) },
86+
{ Mode.TUN, CreateItem("TUN (Experimental)", onTunnelModeClick, true, getMode.Invoke() == Mode.TUN) }
87+
};
7488

7589
AddMenuItem("Open Invisible Man XRay", onOpenClick);
76-
AddMenuItem("Mode", delegate { }, new ToolStripMenuItem[] {
77-
CreateItem("Proxy", onProxyModeClick, true, getMode.Invoke() == Mode.PROXY),
78-
CreateItem("TUN (Experimental)", onTunnelModeClick, true, getMode.Invoke() == Mode.TUN)
79-
});
90+
AddMenuItem("Mode", delegate { }, modeItems.Values.ToArray());
8091
AddMenuItem("Check for updates", onUpdateClick);
8192
AddMenuItem("About", onAboutClick);
8293
AddMenuItem("Close", onCloseClick);
@@ -117,18 +128,18 @@ void HandleToggleClick()
117128
UncheckAllItems();
118129
CheckItem(item);
119130
}
131+
}
132+
}
120133

121-
void UncheckAllItems()
122-
{
123-
foreach(ToolStripMenuItem item in item.GetCurrentParent().Items)
124-
item.Checked = false;
125-
}
134+
private void UncheckAllItems()
135+
{
136+
foreach(ToolStripMenuItem itemElement in modeItems.Values)
137+
itemElement.Checked = false;
138+
}
126139

127-
void CheckItem(ToolStripMenuItem item)
128-
{
129-
item.Checked = true;
130-
}
131-
}
140+
private void CheckItem(ToolStripMenuItem item)
141+
{
142+
item.Checked = true;
132143
}
133144
}
134145
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace InvisibleManXRay.Handlers.Settings.Startup
2+
{
3+
public interface IStartupSetting
4+
{
5+
void EnableRunAtStartup();
6+
void DisableRunAtStartup();
7+
}
8+
}

0 commit comments

Comments
 (0)