Squashed commit of the following: commite280c2385cMerge:579039f87aa9ebAuthor: Gang Zhuo <gang.zhuo@gmail.com> Date: Wed Mar 16 04:02:27 2016 -0400 Merge remote-tracking branch 'origin/master' commit579039fe40Author: Gang Zhuo <gang.zhuo@gmail.com> Date: Fri Mar 4 21:45:23 2016 +0800 log unhandle exception commit8d863f1d5fAuthor: Gang Zhuo <gang.zhuo@gmail.com> Date: Fri Mar 4 21:44:54 2016 +0800 fix Availability Statistics commitb3ce1c698aAuthor: Gang Zhuo <gang.zhuo@gmail.com> Date: Fri Mar 4 21:07:54 2016 +0800 tiny refactor commit0f7d39e27eMerge:bd7078ab01acedAuthor: Gang Zhuo <gang.zhuo@gmail.com> Date: Fri Mar 4 20:02:58 2016 +0800 Merge remote-tracking branch 'origin/master' commitbd7078aa4fAuthor: Gang Zhuo <gang.zhuo@gmail.com> Date: Fri Mar 4 20:01:58 2016 +0800 tiny refactor commit49adb95b6eAuthor: Gang Zhuo <gang.zhuo@gmail.com> Date: Fri Mar 4 03:44:26 2016 -0500 log more Ping information for debug commit2aa0620dddAuthor: Gang Zhuo <gang.zhuo@gmail.com> Date: Fri Mar 4 03:04:10 2016 -0500 reduce 3rd packages [solve conflicts and squash to make history clean] Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
73 lines
2.9 KiB
C#
Executable File
73 lines
2.9 KiB
C#
Executable File
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
using Shadowsocks.Controller;
|
|
using Shadowsocks.Util;
|
|
using Shadowsocks.View;
|
|
|
|
namespace Shadowsocks
|
|
{
|
|
static class Program
|
|
{
|
|
/// <summary>
|
|
/// 应用程序的主入口点。
|
|
/// </summary>
|
|
[STAThread]
|
|
static void Main()
|
|
{
|
|
Utils.ReleaseMemory(true);
|
|
using (Mutex mutex = new Mutex(false, "Global\\Shadowsocks_" + Application.StartupPath.GetHashCode()))
|
|
{
|
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
|
|
if (!mutex.WaitOne(0, false))
|
|
{
|
|
Process[] oldProcesses = Process.GetProcessesByName("Shadowsocks");
|
|
if (oldProcesses.Length > 0)
|
|
{
|
|
Process oldProcess = oldProcesses[0];
|
|
}
|
|
MessageBox.Show(I18N.GetString("Find Shadowsocks icon in your notify tray.") + "\n" +
|
|
I18N.GetString("If you want to start multiple Shadowsocks, make a copy in another directory."),
|
|
I18N.GetString("Shadowsocks is already running."));
|
|
return;
|
|
}
|
|
Directory.SetCurrentDirectory(Application.StartupPath);
|
|
#if DEBUG
|
|
Logging.OpenLogFile();
|
|
|
|
// truncate privoxy log file while debugging
|
|
string privoxyLogFilename = Utils.GetTempPath("privoxy.log");
|
|
if (File.Exists(privoxyLogFilename))
|
|
using (new FileStream(privoxyLogFilename, FileMode.Truncate)) { }
|
|
#else
|
|
Logging.OpenLogFile();
|
|
#endif
|
|
ShadowsocksController controller = new ShadowsocksController();
|
|
MenuViewController viewController = new MenuViewController(controller);
|
|
controller.Start();
|
|
Application.Run();
|
|
}
|
|
}
|
|
|
|
private static int exited = 0;
|
|
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
{
|
|
if (Interlocked.Increment(ref exited) == 1)
|
|
{
|
|
Logging.Error(e.ExceptionObject?.ToString());
|
|
MessageBox.Show(I18N.GetString("Unexpect error, shadowsocks will be exit. Please report to") +
|
|
" https://github.com/shadowsocks/shadowsocks-windows/issues " +
|
|
Environment.NewLine + (e.ExceptionObject?.ToString()),
|
|
"Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
Application.Exit();
|
|
}
|
|
}
|
|
}
|
|
}
|