Gang Zhuo 10 years ago
parent
commit
72eb35b0ab
6 changed files with 87 additions and 6 deletions
  1. +22
    -0
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  2. +6
    -1
      shadowsocks-csharp/Controller/SystemProxy.cs
  3. +9
    -1
      shadowsocks-csharp/Data/cn.txt
  4. +2
    -0
      shadowsocks-csharp/Model/Configuration.cs
  5. +47
    -4
      shadowsocks-csharp/View/MenuViewController.cs
  6. +1
    -0
      shadowsocks-csharp/shadowsocks-csharp.csproj

+ 22
- 0
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -192,6 +192,28 @@ namespace Shadowsocks.Controller
} }
} }
public void SavePACUrl(string pacUrl)
{
_config.pacUrl = pacUrl;
UpdateSystemProxy();
SaveConfig(_config);
if (ConfigChanged != null)
{
ConfigChanged(this, new EventArgs());
}
}
public void UseOnlinePAC(bool useOnlinePac)
{
_config.useOnlinePac = useOnlinePac;
UpdateSystemProxy();
SaveConfig(_config);
if (ConfigChanged != null)
{
ConfigChanged(this, new EventArgs());
}
}
protected void Reload() protected void Reload()
{ {
// some logic in configuration updated the config when saving, we need to read it again // some logic in configuration updated the config when saving, we need to read it again


+ 6
- 1
shadowsocks-csharp/Controller/SystemProxy.cs View File

@@ -49,9 +49,14 @@ namespace Shadowsocks.Controller
} }
else else
{ {
string pacUrl;
if (config.useOnlinePac && !string.IsNullOrEmpty(config.pacUrl))
pacUrl = config.pacUrl;
else
pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now);
registry.SetValue("ProxyEnable", 0); registry.SetValue("ProxyEnable", 0);
registry.SetValue("ProxyServer", ""); registry.SetValue("ProxyServer", "");
registry.SetValue("AutoConfigURL", "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now));
registry.SetValue("AutoConfigURL", pacUrl);
} }
} }
else else


+ 9
- 1
shadowsocks-csharp/Data/cn.txt View File

@@ -40,6 +40,13 @@ New server=未配置的服务器


QRCode=二维码 QRCode=二维码


# PAC Url Form

Local PAC=使用本地 PAC
Online PAC=使用在线 PAC
Update Online PAC URL=更新在线 PAC 网址
Please input PAC Url=请输入 PAC 网址

# Messages # Messages


Shadowsocks Error: {0}=Shadowsocks 错误: {0} Shadowsocks Error: {0}=Shadowsocks 错误: {0}
@@ -63,4 +70,5 @@ No QRCode found. Try to zoom in or move it to the center of the screen.=未发
Failed to decode QRCode=无法解析二维码 Failed to decode QRCode=无法解析二维码
Failed to update registry=无法修改注册表 Failed to update registry=无法修改注册表
System Proxy On: =系统代理已启用: System Proxy On: =系统代理已启用:
Running: Port {0}=正在运行:端口 {0}
Running: Port {0}=正在运行:端口 {0}
PAC Url can not be blank=PAC 网址不能为空

+ 2
- 0
shadowsocks-csharp/Model/Configuration.cs View File

@@ -17,6 +17,8 @@ namespace Shadowsocks.Model
public bool shareOverLan; public bool shareOverLan;
public bool isDefault; public bool isDefault;
public int localPort; public int localPort;
public string pacUrl;
public bool useOnlinePac;
private static string CONFIG_FILE = "gui-config.json"; private static string CONFIG_FILE = "gui-config.json";


+ 47
- 4
shadowsocks-csharp/View/MenuViewController.cs View File

@@ -35,6 +35,8 @@ namespace Shadowsocks.View
private MenuItem ServersItem; private MenuItem ServersItem;
private MenuItem globalModeItem; private MenuItem globalModeItem;
private MenuItem PACModeItem; private MenuItem PACModeItem;
private MenuItem localPACItem;
private MenuItem onlinePACItem;
private ConfigForm configForm; private ConfigForm configForm;
private string _urlToOpen; private string _urlToOpen;
@@ -151,10 +153,15 @@ namespace Shadowsocks.View
CreateMenuItem("Show QRCode...", new EventHandler(this.QRCodeItem_Click)), CreateMenuItem("Show QRCode...", new EventHandler(this.QRCodeItem_Click)),
CreateMenuItem("Scan QRCode from Screen...", new EventHandler(this.ScanQRCodeItem_Click)) CreateMenuItem("Scan QRCode from Screen...", new EventHandler(this.ScanQRCodeItem_Click))
}), }),
new MenuItem("-"),
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)),
CreateMenuGroup("PAC", new MenuItem[] {
this.localPACItem = CreateMenuItem("Local PAC", new EventHandler(this.LocalPACItem_Click)),
this.onlinePACItem = CreateMenuItem("Online PAC", new EventHandler(this.OnlinePACItem_Click)),
new MenuItem("-"),
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)),
CreateMenuItem("Update Online PAC URL", new EventHandler(this.UpdateOnlinePACURLItem_Click)),
}),
new MenuItem("-"), new MenuItem("-"),
this.AutoStartupItem = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)), this.AutoStartupItem = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)),
this.ShareOverLANItem = CreateMenuItem("Allow Clients from LAN", new EventHandler(this.ShareOverLANItem_Click)), this.ShareOverLANItem = CreateMenuItem("Allow Clients from LAN", new EventHandler(this.ShareOverLANItem_Click)),
@@ -240,6 +247,9 @@ namespace Shadowsocks.View
PACModeItem.Checked = !config.global; PACModeItem.Checked = !config.global;
ShareOverLANItem.Checked = config.shareOverLan; ShareOverLANItem.Checked = config.shareOverLan;
AutoStartupItem.Checked = AutoStartup.Check(); AutoStartupItem.Checked = AutoStartup.Check();
onlinePACItem.Enabled = !string.IsNullOrEmpty(config.pacUrl);
onlinePACItem.Checked = onlinePACItem.Enabled && config.useOnlinePac;
localPACItem.Checked = !onlinePACItem.Checked;
} }
private void UpdateServersMenu() private void UpdateServersMenu()
@@ -481,5 +491,38 @@ namespace Shadowsocks.View
MessageBox.Show(I18N.GetString("Failed to update registry")); MessageBox.Show(I18N.GetString("Failed to update registry"));
} }
} }
private void LocalPACItem_Click(object sender, EventArgs e)
{
if (controller.GetConfiguration().useOnlinePac)
{
localPACItem.Checked = true;
onlinePACItem.Checked = false;
controller.UseOnlinePAC(false);
}
}
private void OnlinePACItem_Click(object sender, EventArgs e)
{
if (!controller.GetConfiguration().useOnlinePac)
{
localPACItem.Checked = false;
onlinePACItem.Checked = true;
controller.UseOnlinePAC(true);
}
}
private void UpdateOnlinePACURLItem_Click(object sender, EventArgs e)
{
string origPacUrl = controller.GetConfiguration().pacUrl;
string pacUrl = Microsoft.VisualBasic.Interaction.InputBox(
I18N.GetString("Please input PAC Url"),
I18N.GetString("Update Online PAC URL"),
origPacUrl, -1, -1);
if (!string.IsNullOrEmpty(pacUrl) && pacUrl != origPacUrl)
{
controller.SavePACUrl(pacUrl);
}
}
} }
} }

+ 1
- 0
shadowsocks-csharp/shadowsocks-csharp.csproj View File

@@ -63,6 +63,7 @@
<ApplicationManifest>app.manifest</ApplicationManifest> <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />


Loading…
Cancel
Save