static void Main() { // Check OS since we are using dual-mode socket if (!Utils.IsWinVistaOrHigher()) { MessageBox.Show(I18N.GetString("Unsupported operating system, use Windows Vista at least."), "Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Utils.ReleaseMemory(true); using (Mutex mutex = new Mutex(false, $"Global\\Shadowsocks_{Application.StartupPath.GetHashCode()}")) { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // handle UI exceptions Application.ThreadException += Application_ThreadException; // handle non-UI exceptions AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ApplicationExit += (sender, args) => HotKeys.Destroy(); 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.") + Environment.NewLine + 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 _controller = new ShadowsocksController(); new LoginForm(_controller).ShowDialog(); _viewController = new MenuViewController(_controller); HotKeys.Init(); _controller.Start(); Application.Run(); } }
static void Main() { // setup profile optimization System.Runtime.ProfileOptimization.SetProfileRoot(Utils.GetTempPath()); System.Runtime.ProfileOptimization.StartProfile("fs-runtime-opt.profile"); TFOSupported = Utils.IsTcpFastOpenSupported(); using (Mutex mutex = new Mutex(false, $"Global\\Fuckshadows_{Application.StartupPath.GetHashCode()}")) { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // handle UI exceptions Application.ThreadException += Application_ThreadException; // handle non-UI exceptions AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // handle unobserved Task exceptions TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; Application.ApplicationExit += Application_ApplicationExit; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (!mutex.WaitOne(0, false)) { Process[] oldProcesses = Process.GetProcessesByName("Fuckshadows"); if (oldProcesses.Length > 0) { Process oldProcess = oldProcesses[0]; } MessageBox.Show(I18N.GetString("Find Fuckshadows icon in your notify tray.") + Environment.NewLine + I18N.GetString( "If you want to start multiple Fuckshadows, make a copy in another directory."), I18N.GetString("Fuckshadows 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 MainController = new FuckshadowsController(); MenuController = new MenuViewController(MainController); HotKeys.Init(MainController); MainController.Start(); Application.Run(); } }
public void Start(bool regHotkeys = true) { Reload(); if (regHotkeys && _config.hotkey.RegHotkeysAtStartup) { HotKeys.Init(); HotkeyReg.RegAllHotkeys(); } }
static void Main(string[] args) { Directory.SetCurrentDirectory(Application.StartupPath); // todo: initialize the NLog configuartion Model.NLogConfig.TouchAndApplyNLogConfig(); // .NET Framework 4.7.2 on Win7 compatibility System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12; // store args for further use Args = args; // Check OS since we are using dual-mode socket if (!Utils.IsWinVistaOrHigher()) { MessageBox.Show(I18N.GetString("Unsupported operating system, use Windows Vista at least."), "Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check .NET Framework version if (!Utils.IsSupportedRuntimeVersion()) { if (DialogResult.OK == MessageBox.Show(I18N.GetString("Unsupported .NET Framework, please update to {0} or later.", "4.7.2"), "Shadowsocks Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)) { //Process.Start("https://www.microsoft.com/download/details.aspx?id=53344"); // 4.6.2 Process.Start("https://dotnet.microsoft.com/download/dotnet-framework/net472"); } return; } Utils.ReleaseMemory(true); using (Mutex mutex = new Mutex(false, $"Global\\Shadowsocks_{Application.StartupPath.GetHashCode()}")) { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // handle UI exceptions Application.ThreadException += Application_ThreadException; // handle non-UI exceptions AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AutoStartup.RegisterForRestart(true); 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.") + Environment.NewLine + 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 // truncate privoxy log file while debugging string privoxyLogFilename = Utils.GetTempPath("privoxy.log"); if (File.Exists(privoxyLogFilename)) { using (new FileStream(privoxyLogFilename, FileMode.Truncate)) { } } #endif MainController = new ShadowsocksController(); MenuController = new MenuViewController(MainController); HotKeys.Init(MainController); MainController.Start(); Application.Run(); } }
static void Main(string[] args) { BimtRemoting.RegeistChanel(); bool ok = true; //Utils.IsVip(ref ok, args); //if (!ok) //{ // return; //} LoadBimtProxySetting(); // Check OS since we are using dual-mode socket //为了xp拼了 if (!Utils.IsWinVistaOrHigher()) { MessageBox.Show(I18N.GetString("Unsupported operating system, use Windows Vista at least."), "Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; //BimtProxyService<ProxyEntity> proxy = new BimtProxyService<ProxyEntity>(ProxyEntity.URL); //proxy.Entity.StartUp(); //BIMTClassLibrary.frmGoogleSearch frm = new BIMTClassLibrary.frmGoogleSearch(); //frm.Show(); //Application.Run(); } else { Utils.ReleaseMemory(true); using (Mutex mutex = new Mutex(false, $"Global\\Shadowsocks_{Application.StartupPath.GetHashCode()}")) { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // handle UI exceptions Application.ThreadException += Application_ThreadException; // handle non-UI exceptions AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; 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.") + Environment.NewLine + 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 _controller = new ShadowsocksController(); _viewController = new MenuViewController(_controller); HotKeys.Init(); _controller.Start(); string path = string.Format("{0}\\SmartReader.View.exe", Application.StartupPath); string[] arg = new string[2]; //arg[0] = User.GetInstance().IsVip().ToString(); //arg[1] = User.GetInstance().Id; StartProcess(path, args); Application.Run(); } } }
private static void Main(string[] args) { #region Single Instance and IPC bool hasAnotherInstance = !mutex.WaitOne(TimeSpan.Zero, true); // store args for further use Args = args; Parser.Default.ParseArguments <CommandLineOption>(args) .WithParsed(opt => Options = opt) .WithNotParsed(e => e.Output()); if (hasAnotherInstance) { if (!string.IsNullOrWhiteSpace(Options.OpenUrl)) { IPCService.RequestOpenUrl(Options.OpenUrl); } else { MessageBox.Show(I18N.GetString("Find Shadowsocks icon in your notify tray.") + Environment.NewLine + I18N.GetString("If you want to start multiple Shadowsocks, make a copy in another directory."), I18N.GetString("Shadowsocks is already running.")); } return; } #endregion #region Enviroment Setup Directory.SetCurrentDirectory(WorkingDirectory); // todo: initialize the NLog configuartion Model.NLogConfig.TouchAndApplyNLogConfig(); // .NET Framework 4.7.2 on Win7 compatibility ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; #endregion #region Compactibility Check // Check OS since we are using dual-mode socket if (!Utils.IsWinVistaOrHigher()) { MessageBox.Show(I18N.GetString("Unsupported operating system, use Windows Vista at least."), "Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check .NET Framework version if (!Utils.IsSupportedRuntimeVersion()) { if (DialogResult.OK == MessageBox.Show(I18N.GetString("Unsupported .NET Framework, please update to {0} or later.", "4.7.2"), "Shadowsocks Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)) { Process.Start("https://dotnet.microsoft.com/download/dotnet-framework/net472"); } return; } #endregion #region Event Handlers Setup Utils.ReleaseMemory(true); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // handle UI exceptions Application.ThreadException += Application_ThreadException; // handle non-UI exceptions AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AutoStartup.RegisterForRestart(true); #endregion #if DEBUG // truncate privoxy log file while debugging string privoxyLogFilename = Utils.GetTempPath("privoxy.log"); if (File.Exists(privoxyLogFilename)) { using (new FileStream(privoxyLogFilename, FileMode.Truncate)) { } } #endif MainController = new ShadowsocksController(); MenuController = new MenuViewController(MainController); HotKeys.Init(MainController); MainController.Start(); // Update online config Task.Run(async() => { await Task.Delay(10 * 1000); await MainController.UpdateAllOnlineConfig(); }); #region IPC Handler and Arguement Process IPCService ipcService = new IPCService(); Task.Run(() => ipcService.RunServer()); ipcService.OpenUrlRequested += (_1, e) => MainController.AskAddServerBySSURL(e.Url); if (!string.IsNullOrWhiteSpace(Options.OpenUrl)) { MainController.AskAddServerBySSURL(Options.OpenUrl); } #endregion Application.Run(); }
static void Main(string[] args) { //string TheProxyModeInLaunching; if (Utils.IsVirusExist()) { return; } #if !_CONSOLE foreach (string arg in args) { if (arg == "--setautorun") { if (!AutoStartup.Switch()) { Environment.ExitCode = 1; } return; } } using (Mutex mutex = new Mutex(false, "Global\\ShadowsocksR_" + Application.StartupPath.GetHashCode())) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.EnableVisualStyles(); Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.SetCompatibleTextRenderingDefault(false); if (!mutex.WaitOne(0, false)) { 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("ShadowsocksR is already running.")); return; } #endif Directory.SetCurrentDirectory(Application.StartupPath); #if !_CONSOLE int try_times = 0; while (Configuration.Load() == null) { if (try_times >= 5) return; using (InputPassword dlg = new InputPassword()) { if (dlg.ShowDialog() == DialogResult.OK) Configuration.SetPassword(dlg.password); else return; } try_times += 1; } if (try_times > 0) Logging.save_to_file = false; #endif //#if !DEBUG Logging.OpenLogFile(); //#endif _controller = new ShadowsocksController(); HostMap.Instance().LoadHostFile(); #if _DOTNET_4_0 // Enable Modern TLS when .NET 4.5+ installed. if (EnvCheck.CheckDotNet45()) ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; #endif #if !_CONSOLE _viewController = new MenuViewController(_controller); #endif HotKeys.Init(); _controller.Start(); #if !_CONSOLE //Util.Utils.ReleaseMemory(true); foreach (string arg in args) { if (arg == "-Direct") { _viewController.DirectItem_Click(); break; } else if(arg == "-Pac") { _viewController.PACModeItem_Click(); break; } else if(arg == "-Global") { _viewController.GlobalModeItem_Click(); break; } } Application.Run(); } #else Console.ReadLine(); _controller.Stop(); #endif }
static void Main() { // Check OS since we are using dual-mode socket if (!Utils.IsWinVistaOrHigher()) { MessageBox.Show(I18N.GetString("Unsupported operating system, use Windows Vista at least."), "Fuckshadows Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check .NET Framework version if (!Utils.IsSupportedRuntimeVersion()) { MessageBox.Show(I18N.GetString("Unsupported .NET Framework, please update to 4.6.2 or later."), "Fuckshadows Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Process.Start( "http://dotnetsocial.cloudapp.net/GetDotnet?tfm=.NETFramework,Version=v4.6.2"); return; } using (Mutex mutex = new Mutex(false, $"Global\\Fuckshadows_{Application.StartupPath.GetHashCode()}")) { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // handle UI exceptions Application.ThreadException += Application_ThreadException; // handle non-UI exceptions AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (!mutex.WaitOne(0, false)) { Process[] oldProcesses = Process.GetProcessesByName("Fuckshadows"); if (oldProcesses.Length > 0) { Process oldProcess = oldProcesses[0]; } MessageBox.Show(I18N.GetString("Find Fuckshadows icon in your notify tray.") + Environment.NewLine + I18N.GetString( "If you want to start multiple Fuckshadows, make a copy in another directory."), I18N.GetString("Fuckshadows 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 MainController = new FuckshadowsController(); MenuController = new MenuViewController(MainController); HotKeys.Init(MainController); MainController.Start(); Application.Run(); } }
private static void Main(string[] args) { Directory.SetCurrentDirectory(Application.StartupPath); // todo: initialize the NLog configuartion Model.NLogConfig.TouchAndApplyNLogConfig(); // .NET Framework 4.7.2 on Win7 compatibility ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; // store args for further use Args = args; // Check OS since we are using dual-mode socket if (!Utils.IsWinVistaOrHigher()) { MessageBox.Show(I18N.GetString("Unsupported operating system, use Windows Vista at least."), "Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check .NET Framework version if (!Utils.IsSupportedRuntimeVersion()) { if (DialogResult.OK == MessageBox.Show(I18N.GetString("Unsupported .NET Framework, please update to {0} or later.", "4.7.2"), "Shadowsocks Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)) { Process.Start("https://dotnet.microsoft.com/download/dotnet-framework/net472"); } return; } string pipename = $"Shadowsocks\\{Application.StartupPath.GetHashCode()}"; string addedUrl = null; using (NamedPipeClientStream pipe = new NamedPipeClientStream(pipename)) { bool pipeExist = false; try { pipe.Connect(10); pipeExist = true; } catch (TimeoutException) { pipeExist = false; } // TODO: switch to better argv parser when it's getting complicate List <string> alist = Args.ToList(); // check --open-url param int urlidx = alist.IndexOf("--open-url") + 1; if (urlidx > 0) { if (Args.Length <= urlidx) { return; } // --open-url exist, and no other instance, add it later if (!pipeExist) { addedUrl = Args[urlidx]; } // has other instance, send url via pipe then exit else { byte[] b = Encoding.UTF8.GetBytes(Args[urlidx]); byte[] opAddUrl = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(1)); byte[] blen = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(b.Length)); pipe.Write(opAddUrl, 0, 4); // opcode addurl pipe.Write(blen, 0, 4); pipe.Write(b, 0, b.Length); pipe.Close(); return; } } // has another instance, and no need to communicate with it return else if (pipeExist) { Process[] oldProcesses = Process.GetProcessesByName("Shadowsocks"); if (oldProcesses.Length > 0) { Process oldProcess = oldProcesses[0]; } MessageBox.Show(I18N.GetString("Find Shadowsocks icon in your notify tray.") + Environment.NewLine + I18N.GetString("If you want to start multiple Shadowsocks, make a copy in another directory."), I18N.GetString("Shadowsocks is already running.")); return; } } Utils.ReleaseMemory(true); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // handle UI exceptions Application.ThreadException += Application_ThreadException; // handle non-UI exceptions AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AutoStartup.RegisterForRestart(true); Directory.SetCurrentDirectory(Application.StartupPath); #if DEBUG // truncate privoxy log file while debugging string privoxyLogFilename = Utils.GetTempPath("privoxy.log"); if (File.Exists(privoxyLogFilename)) { using (new FileStream(privoxyLogFilename, FileMode.Truncate)) { } } #endif MainController = new ShadowsocksController(); MenuController = new MenuViewController(MainController); HotKeys.Init(MainController); MainController.Start(); NamedPipeServer namedPipeServer = new NamedPipeServer(); Task.Run(() => namedPipeServer.Run(pipename)); namedPipeServer.AddUrlRequested += (_1, e) => MainController.AskAddServerBySSURL(e.Url); if (!addedUrl.IsNullOrEmpty()) { MainController.AskAddServerBySSURL(addedUrl); } Application.Run(); }
static void Main() { // Check OS since we are using dual-mode socket if (!Utils.IsWinVistaOrHigher()) { MessageBox.Show(I18N.GetString("Unsupported operating system, use Windows Vista at least."), "Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Utils.ReleaseMemory(true); using (Mutex mutex = new Mutex(false, "Global\\Shadowsocks_" + Application.StartupPath.GetHashCode())) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ApplicationExit += (sender, args) => HotKeys.Destroy(); 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; } /** * 当前用户是管理员的时候,直接启动应用程序 * 如果不是管理员,则使用启动对象启动程序,以确保使用管理员身份运行 */ //获得当前登录的Windows用户标示 System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent(); System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity); //判断当前登录用户是否为管理员 if (!principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) { var process = System.Diagnostics.Process.GetCurrentProcess(); var filename = process.MainModule.FileName; //创建启动对象 var p = new System.Diagnostics.Process(); p.StartInfo.UseShellExecute = true; p.StartInfo.WorkingDirectory = new FileInfo(filename).DirectoryName; p.StartInfo.FileName = filename; //设置启动动作,确保以管理员身份运行 p.StartInfo.Verb = "runas"; try { p.Start(); } catch { } //退出 Environment.Exit(0); } 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 _controller = new NewShadowsocksController(); _viewController = new NewMenuViewController(_controller); HotKeys.Init(); _controller.Start(); Application.Run(); } }
static void Main() { /*******************************************************************/ // For auto updater /*******************************************************************/ if (File.Exists(Application.StartupPath + @"\ShadowFog.exe.old")) { try { File.Delete(Application.StartupPath + @"\ShadowFog.exe.old"); } catch (Exception AcessErr) { } //skip it, for next time starting, delete it again; } /*******************************************************************/ // For auto updater /*******************************************************************/ // Check OS since we are using dual-mode socket if (!Utils.IsWinVistaOrHigher()) { MessageBox.Show(I18N.GetString("Unsupported operating system, use Windows Vista at least."), "Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Utils.ReleaseMemory(true); using (Mutex mutex = new Mutex(false, "Global\\Shadowsocks_" + Application.StartupPath.GetHashCode())) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ApplicationExit += (sender, args) => HotKeys.Destroy(); 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 _controller = new ShadowsocksController(); _viewController = new MenuViewController(_controller); HotKeys.Init(); _controller.Start(); try { Application.Run(); } catch (ObjectDisposedException bug) { MessageBox.Show("Connection crashed due to: " + bug.Message); } } }
static void Main() { if (!Utils.IsWinVistaOrHigher()) { MessageBox.Show( "不支持的操作系统版本,最低需求为Windows Vista。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error ); return; } if (!Utils.IsSupportedRuntimeVersion()) { MessageBox.Show( "当前 .NET Framework 版本过低,请升级至4.6.2或更新版本。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error ); Process.Start("http://dotnetsocial.cloudapp.net/GetDotnet?tfm=.NETFramework,Version=v4.6.2"); return; } Utils.ReleaseMemory(true); using (Mutex mutex = new Mutex(false, $"Global\\GreenDot_{Application.StartupPath.GetHashCode()}")) { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (!mutex.WaitOne(0, false)) { Process[] oldProcesses = Process.GetProcessesByName("GreenDot Windows"); if (oldProcesses.Length > 0) { Process oldProcess = oldProcesses[0]; } MessageBox.Show( "加速服务正在运行中,请在任务栏查找相关图标。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information ); return; } Directory.SetCurrentDirectory(Application.StartupPath); Logging.OpenLogFile(); HotKeys.Init(ViewManager.instance.MainController); Login loginForm = new Login(); Application.Run(loginForm); } }
static void Main(string[] args) { #region Single Instance and IPC bool hasAnotherInstance = !mutex.WaitOne(TimeSpan.Zero, true); // store args for further use Args = args; Parser.Default.ParseArguments <CommandLineOption>(args) .WithParsed(opt => Options = opt) .WithNotParsed(e => e.Output()); if (hasAnotherInstance) { if (!string.IsNullOrWhiteSpace(Options.OpenUrl)) { IPCService.RequestOpenUrl(Options.OpenUrl); } else { MessageBox.Show(I18N.GetString("Find Shadowsocks icon in your notify tray.") + Environment.NewLine + I18N.GetString("If you want to start multiple Shadowsocks, make a copy in another directory."), I18N.GetString("Shadowsocks is already running.")); } return; } #endregion #region Enviroment Setup Directory.SetCurrentDirectory(WorkingDirectory); // todo: initialize the NLog configuartion Model.NLogConfig.TouchAndApplyNLogConfig(); #endregion #region Event Handlers Setup Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // handle UI exceptions Application.ThreadException += Application_ThreadException; // handle non-UI exceptions AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AutoStartup.RegisterForRestart(true); #endregion // See https://github.com/dotnet/runtime/issues/13051 // we have to do this for self-contained executables Directory.SetCurrentDirectory(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName)); // We would use this in v5. // Parameters would have to be dropped from views' constructors (VersionUpdatePromptView) //Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly()); // Workaround for hosting WPF controls in a WinForms app. // We have to manually set the culture for the LocalizeDictionary instance. // https://stackoverflow.com/questions/374518/localizing-a-winforms-application-with-embedded-wpf-user-controls // https://stackoverflow.com/questions/14668640/wpf-localize-extension-translate-window-at-run-time LocalizeDictionary.Instance.Culture = Thread.CurrentThread.CurrentCulture; #if DEBUG // truncate privoxy log file while debugging string privoxyLogFilename = Utils.GetTempPath("privoxy.log"); if (File.Exists(privoxyLogFilename)) { using (new FileStream(privoxyLogFilename, FileMode.Truncate)) { } } #endif MainController = new ShadowsocksController(); MenuController = new MenuViewController(MainController); HotKeys.Init(MainController); MainController.Start(); // Update online config Task.Run(async() => { await Task.Delay(10 * 1000); await MainController.UpdateAllOnlineConfig(); }); #region IPC Handler and Arguement Process IPCService ipcService = new IPCService(); Task.Run(() => ipcService.RunServer()); ipcService.OpenUrlRequested += (_1, e) => MainController.AskAddServerBySSURL(e.Url); if (!string.IsNullOrWhiteSpace(Options.OpenUrl)) { MainController.AskAddServerBySSURL(Options.OpenUrl); } #endregion Application.Run(); }