Browse Source

translate Microsoft language into human language

tags/2.3
clowwindy 9 years ago
parent
commit
e53873276f
4 changed files with 86 additions and 35 deletions
  1. +9
    -2
      shadowsocks-csharp/Controller/PACServer.cs
  2. +68
    -32
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  3. +3
    -1
      shadowsocks-csharp/Program.cs
  4. +6
    -0
      shadowsocks-csharp/View/MenuViewController.cs

+ 9
- 2
shadowsocks-csharp/Controller/PACServer.cs View File

@@ -58,8 +58,11 @@ namespace Shadowsocks.Controller
public void Stop()
{
_listener.Close();
_listener = null;
if (_listener != null)
{
_listener.Close();
_listener = null;
}
}
public string TouchPACFile()
@@ -107,6 +110,10 @@ namespace Shadowsocks.Controller
new AsyncCallback(AcceptCallback),
listener);
}
catch (ObjectDisposedException)
{
// do nothing
}
catch (Exception e)
{
Logging.LogUsefulException(e);


+ 68
- 32
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Net.Sockets;
namespace Shadowsocks.Controller
{
@@ -37,33 +38,34 @@ namespace Shadowsocks.Controller
// when user clicked Edit PAC, and PAC file has already created
public event EventHandler<PathEventArgs> PACFileReadyToOpen;
public event ErrorEventHandler Errored;
public ShadowsocksController()
{
_config = Configuration.Load();
polipoRunner = new PolipoRunner();
polipoRunner.Start(_config);
local = new Local(_config);
try
{
local.Start();
}
catch (Exception e)
{
Console.WriteLine(e);
}
try
{
pacServer = new PACServer();
pacServer.PACFileChanged += pacServer_PACFileChanged;
pacServer.Start(_config);
}
catch (Exception e)
}
public void Start()
{
Reload();
}
protected void ReportError(Exception e)
{
if (Errored != null)
{
Console.WriteLine(e);
// translate Microsoft language into human language
// i.e. 以一种访问权限不允许的方式做了一个访问套接字的尝试 => Port is already used
if (e is SocketException)
{
SocketException se = (SocketException)e;
if (se.SocketErrorCode == SocketError.AccessDenied)
{
e = new Exception("Port is already used", e);
}
}
Errored(this, new ErrorEventArgs(e));
}
UpdateSystemProxy();
StartReleasingMemory();
}
public Server GetCurrentServer()
@@ -128,8 +130,14 @@ namespace Shadowsocks.Controller
return;
}
stopped = true;
local.Stop();
polipoRunner.Stop();
if (local != null)
{
local.Stop();
}
if (polipoRunner != null)
{
polipoRunner.Stop();
}
if (_config.enabled)
{
SystemProxy.Disable();
@@ -153,36 +161,64 @@ namespace Shadowsocks.Controller
return "ss://" + base64;
}
protected void SaveConfig(Configuration newConfig)
protected void Reload()
{
Configuration.Save(newConfig);
// some logic in configuration updated the config when saving, we need to read it again
_config = Configuration.Load();
if (polipoRunner == null)
{
polipoRunner = new PolipoRunner();
}
if (pacServer == null)
{
pacServer = new PACServer();
pacServer.PACFileChanged += pacServer_PACFileChanged;
}
pacServer.Stop();
local.Stop();
if (local != null)
{
local.Stop();
}
// don't put polipoRunner.Start() before pacServer.Stop()
// or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
// though UseShellExecute is set to true now
// http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
polipoRunner.Stop();
polipoRunner.Start(_config);
try
{
polipoRunner.Start(_config);
local = new Local(_config);
local.Start();
pacServer.Start(_config);
local = new Local(_config);
local.Start();
pacServer.Start(_config);
}
catch (Exception e)
{
Logging.LogUsefulException(e);
ReportError(e);
}
if (ConfigChanged != null)
{
ConfigChanged(this, new EventArgs());
}
UpdateSystemProxy();
Util.Util.ReleaseMemory();
}
protected void SaveConfig(Configuration newConfig)
{
Configuration.Save(newConfig);
Reload();
}
private void UpdateSystemProxy()
{
if (_config.enabled)


+ 3
- 1
shadowsocks-csharp/Program.cs View File

@@ -41,7 +41,9 @@ namespace Shadowsocks
ShadowsocksController controller = new ShadowsocksController();
MenuViewController viewController = new MenuViewController(controller);
Util.Util.ReleaseMemory();
controller.Start();
Application.Run();
}
}


+ 6
- 0
shadowsocks-csharp/View/MenuViewController.cs View File

@@ -53,6 +53,7 @@ namespace Shadowsocks.View
controller.PACFileReadyToOpen += controller_PACFileReadyToOpen;
controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged;
controller.EnableGlobalChanged += controller_EnableGlobalChanged;
controller.Errored += controller_Errored;
this.updateChecker = new UpdateChecker();
updateChecker.NewVersionFound += updateChecker_NewVersionFound;
@@ -68,6 +69,11 @@ namespace Shadowsocks.View
}
}
void controller_Errored(object sender, System.IO.ErrorEventArgs e)
{
MessageBox.Show(e.GetException().ToString(), "Error: " + e.GetException().Message);
}
private void LoadTrayIcon()
{
int dpi;


Loading…
Cancel
Save