From eb2e5cc242149b2da0fe628b67c1b338f5af2314 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Fri, 6 Mar 2015 23:02:07 +0800 Subject: [PATCH] add GUI for user rule support --- shadowsocks-csharp/Controller/PACServer.cs | 13 +++++++++++++ .../Controller/ShadowsocksController.cs | 10 ++++++++++ shadowsocks-csharp/Data/cn.txt | 1 + shadowsocks-csharp/Data/user-rule.txt | 2 ++ .../Properties/Resources.Designer.cs | 18 +++++++++++++----- shadowsocks-csharp/Properties/Resources.resx | 3 +++ shadowsocks-csharp/View/MenuViewController.cs | 16 ++++++++++++---- shadowsocks-csharp/shadowsocks-csharp.csproj | 1 + 8 files changed, 55 insertions(+), 9 deletions(-) create mode 100755 shadowsocks-csharp/Data/user-rule.txt diff --git a/shadowsocks-csharp/Controller/PACServer.cs b/shadowsocks-csharp/Controller/PACServer.cs index 934a7855..e193d9b4 100755 --- a/shadowsocks-csharp/Controller/PACServer.cs +++ b/shadowsocks-csharp/Controller/PACServer.cs @@ -96,6 +96,19 @@ namespace Shadowsocks.Controller } } + internal string TouchUserRuleFile() + { + if (File.Exists(USER_RULE_FILE)) + { + return USER_RULE_FILE; + } + else + { + File.WriteAllText(USER_RULE_FILE, Resources.user_rule); + return USER_RULE_FILE; + } + } + private string GetPACContent() { if (File.Exists(PAC_FILE)) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 203417c2..8d271372 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -38,6 +38,7 @@ namespace Shadowsocks.Controller // when user clicked Edit PAC, and PAC file has already created public event EventHandler PACFileReadyToOpen; + public event EventHandler UserRuleFileReadyToOpen; public event EventHandler UpdatePACFromGFWListCompleted; @@ -166,6 +167,15 @@ namespace Shadowsocks.Controller } } + public void TouchUserRuleFile() + { + string userRuleFilename = _pacServer.TouchUserRuleFile(); + if (UserRuleFileReadyToOpen != null) + { + UserRuleFileReadyToOpen(this, new PathEventArgs() { Path = userRuleFilename }); + } + } + public string GetQRCodeForCurrentServer() { Server server = GetCurrentServer(); diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index 32765e9e..6e6371d5 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -8,6 +8,7 @@ Edit Servers...=编辑服务器... Start on Boot=开机启动 Allow Clients from LAN=允许来自局域网的连接 Edit PAC File...=编辑 PAC 文件... +Edit User Rule for GFWList...=编辑 GFWList 的用户规则... Show QRCode...=显示二维码... Scan QRCode from Screen...=扫描屏幕上的二维码... Show Logs...=显示日志... diff --git a/shadowsocks-csharp/Data/user-rule.txt b/shadowsocks-csharp/Data/user-rule.txt new file mode 100755 index 00000000..8a7fab80 --- /dev/null +++ b/shadowsocks-csharp/Data/user-rule.txt @@ -0,0 +1,2 @@ +! Put user rules line by line in this file. +! See https://adblockplus.org/en/filter-cheatsheet diff --git a/shadowsocks-csharp/Properties/Resources.Designer.cs b/shadowsocks-csharp/Properties/Resources.Designer.cs index c44569de..a5d9c107 100755 --- a/shadowsocks-csharp/Properties/Resources.Designer.cs +++ b/shadowsocks-csharp/Properties/Resources.Designer.cs @@ -81,6 +81,7 @@ namespace Shadowsocks.Properties { ///Start on Boot=开机启动 ///Allow Clients from LAN=允许来自局域网的连接 ///Edit PAC File...=编辑 PAC 文件... + ///Edit User Rule for GFWList...=编辑 GFWList 的用户规则... ///Show QRCode...=显示二维码... ///Scan QRCode from Screen...=扫描屏幕上的二维码... ///Show Logs...=显示日志... @@ -96,11 +97,7 @@ namespace Shadowsocks.Properties { ///Encryption=加密 ///Proxy Port=代理端口 ///Remarks=备注 - ///OK=确定 - ///Cancel=取消 - ///New server=未配置的服务器 - ///QRCode=二维码 - ///Shadows [rest of string was truncated]";. + ///OK= [rest of string was truncated]";. /// internal static string cn { get { @@ -195,5 +192,16 @@ namespace Shadowsocks.Properties { return ((System.Drawing.Bitmap)(obj)); } } + + /// + /// Looks up a localized string similar to ! Put user rules line by line in this file. + ///! See https://adblockplus.org/en/filter-cheatsheet + ///. + /// + internal static string user_rule { + get { + return ResourceManager.GetString("user_rule", resourceCulture); + } + } } } diff --git a/shadowsocks-csharp/Properties/Resources.resx b/shadowsocks-csharp/Properties/Resources.resx index ee5f98ea..aa851e6b 100755 --- a/shadowsocks-csharp/Properties/Resources.resx +++ b/shadowsocks-csharp/Properties/Resources.resx @@ -148,4 +148,7 @@ ..\Resources\ssw128.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\data\user-rule.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + \ No newline at end of file diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 9fe9fcd3..0660f182 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -46,7 +46,8 @@ namespace Shadowsocks.View controller.EnableStatusChanged += controller_EnableStatusChanged; controller.ConfigChanged += controller_ConfigChanged; - controller.PACFileReadyToOpen += controller_PACFileReadyToOpen; + controller.PACFileReadyToOpen += controller_FileReadyToOpen; + controller.UserRuleFileReadyToOpen += controller_FileReadyToOpen; controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged; controller.EnableGlobalChanged += controller_EnableGlobalChanged; controller.Errored += controller_Errored; @@ -151,10 +152,12 @@ namespace Shadowsocks.View CreateMenuItem("Scan QRCode from Screen...", new EventHandler(this.ScanQRCodeItem_Click)) }), new MenuItem("-"), - this.AutoStartupItem = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)), - this.ShareOverLANItem = CreateMenuItem("Allow Clients from LAN", new EventHandler(this.ShareOverLANItem_Click)), CreateMenuItem("Edit PAC File...", new EventHandler(this.EditPACFileItem_Click)), CreateMenuItem("Update PAC from GFWList", new EventHandler(this.UpdatePACFromGFWListItem_Click)), + CreateMenuItem("Edit User Rule for GFWList...", new EventHandler(this.EditUserRuleFileForGFWListItem_Click)), + new MenuItem("-"), + this.AutoStartupItem = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)), + this.ShareOverLANItem = CreateMenuItem("Allow Clients from LAN", new EventHandler(this.ShareOverLANItem_Click)), new MenuItem("-"), CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)), CreateMenuItem("About...", new EventHandler(this.AboutItem_Click)), @@ -186,7 +189,7 @@ namespace Shadowsocks.View PACModeItem.Checked = !globalModeItem.Checked; } - void controller_PACFileReadyToOpen(object sender, ShadowsocksController.PathEventArgs e) + void controller_FileReadyToOpen(object sender, ShadowsocksController.PathEventArgs e) { string argument = @"/select, " + e.Path; @@ -352,6 +355,11 @@ namespace Shadowsocks.View controller.UpdatePACFromGFWList(); } + private void EditUserRuleFileForGFWListItem_Click(object sender, EventArgs e) + { + controller.TouchUserRuleFile(); + } + private void AServerItem_Click(object sender, EventArgs e) { MenuItem item = (MenuItem)sender; diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 3d51fabb..fd849f85 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -198,6 +198,7 @@ +