예제 #1
0
        static void Main()
        {
            Util.Utils.ReleaseMemory();
            using (Mutex mutex = new Mutex(false, "Global\\" + "71981632-A427-497F-AB91-241CD227EC1F"))
            {
                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("Shadowsocks is already running.\n\nFind Shadowsocks icon in your notify tray.");
                    return;
                }
                Directory.SetCurrentDirectory(Application.StartupPath);
#if !DEBUG
                Logging.OpenLogFile();
#endif
                ShadowsocksController controller = new ShadowsocksController();

                MenuViewController viewController = new MenuViewController(controller);

                controller.Start();

                Application.Run();
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: cybort/I-wall
        static void Main()
        {
            Util.Utils.ReleaseMemory();
            using (Mutex mutex = new Mutex(false, "Global\\" + "71981632-A427-497F-AB91-241CD227EC1F"))
            {
                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("已经存在运行的I-WALL,请检查系统托盘。");
                    return;
                }
                Directory.SetCurrentDirectory(Application.StartupPath);
#if !DEBUG
                Logging.OpenLogFile();
#endif
                ShadowsocksController controller = new ShadowsocksController();

                MenuViewController viewController = new MenuViewController(controller);

                controller.Start();

                /* if (System.IO.File.Exists(@"C:\test.txt"))
                 *         System.IO.File.Delete(@"C:\test.txt");*/
                Application.Run();
            }
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
#if !_CONSOLE
            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 !DEBUG
                Logging.OpenLogFile();
                //#endif
#if !_CONSOLE
                int try_times = 0;
                while (Configuration.Load() == null)
                {
                    if (try_times >= 5)
                        return;
                    InputPassword dlg = new InputPassword();
                    dlg.ShowDialog();
                    Configuration.SetPassword(dlg.password);
                    try_times += 1;
                }
#endif
                _controller = new ShadowsocksController();

#if !_CONSOLE
                _viewController = new MenuViewController(_controller);
#endif

                _controller.Start();

#if !_CONSOLE
                //Util.Utils.ReleaseMemory();

                Application.Run();
            }
#else
            Console.ReadLine();
            _controller.Stop();
#endif
        }
예제 #5
0
        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.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();
            }
        }
예제 #6
0
        static void Main()
        {
            Util.Utils.ReleaseMemory(true);
            using (Mutex mutex = new Mutex(false, "Global\\Shadowsocks_" + Application.StartupPath.GetHashCode()))
            {
                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();
#endif
                //ShadowsocksController controller = new ShadowsocksController();

                //MenuViewController viewController = new MenuViewController(controller);

                //controller.Start();

                LoginForm loginForm = new LoginForm();
                if (loginForm.autologin)
                {
                    FunctionForm funcForm = new FunctionForm();
                    funcForm.Show();
                }
                else
                {
                    loginForm.Show();
                }

                Application.Run();
            }
        }
예제 #7
0
        static void Main()
        {
            Util.Utils.ReleaseMemory(true);
            using (Mutex mutex = new Mutex(false, "Global\\ShadowsocksElder_" + 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;

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                var processesName = Process.GetCurrentProcess().MainModule?.ModuleName ?? "Shadowsocks.exe";
                var processesNameWithoutExtension = Path.GetFileNameWithoutExtension(processesName);
                if (!mutex.WaitOne(0, false))
                {
                    Process[] oldProcesses = Process.GetProcessesByName(processesNameWithoutExtension);
                    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);

                Logging.OpenLogFile();

                ShadowsocksController controller = new ShadowsocksController();

                MenuViewController viewController = new MenuViewController(controller);

                Controller.Hotkeys.HotKeys.Init(controller, viewController);

                controller.Start();

                Application.Run();
            }
        }
예제 #8
0
        static void Main()
        {
            Utils.ReleaseMemory(true);
            using (Mutex mutex = new Mutex(false, "Global\\Shadowsocks_" + Application.StartupPath.GetHashCode()))
            {
                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();
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
#if !_CONSOLE
            using (Mutex mutex = new Mutex(false, "Global\\ShadowsocksV_" + Application.StartupPath.GetHashCode()))
            {
                Application.EnableVisualStyles();
                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("ShadowsocksV is already running."));
                    return;
                }
#endif
                Directory.SetCurrentDirectory(Application.StartupPath);
//#if !DEBUG
                Logging.OpenLogFile();
//#endif
                ShadowsocksController controller = new ShadowsocksController();

#if !_CONSOLE
                MenuViewController viewController = new MenuViewController(controller);
#endif

                controller.Start();

#if !_CONSOLE
                Util.Utils.ReleaseMemory();

                Application.Run();
            }
#else
            Console.ReadLine();
            controller.Stop();
#endif
        }
예제 #10
0
        static void Main(string[] args)
        {
            foreach (string arg in args)
            {
                if (arg == "-setfips")
                {
                    Controller.SystemProxy.SetFIPS(0);
                    return;
                }
            }
            if (Controller.SystemProxy.GetFIPS() > 0)
            {
                DialogResult result = MessageBox.Show("FIPS must be shutdown. Do you want to shut it down automatically?",
                                                      UpdateChecker.Name + ": FIPS setting",
                                                      MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    if (!Controller.SystemProxy.SetFIPS(0))
                    {
                        Process          process     = null;
                        ProcessStartInfo processInfo = new ProcessStartInfo();
                        processInfo.Verb      = "runas";
                        processInfo.FileName  = Application.ExecutablePath;
                        processInfo.Arguments = "-setfips";
                        try
                        {
                            process = Process.Start(processInfo);
                        }
                        catch (System.ComponentModel.Win32Exception)
                        {
                            MessageBox.Show("Not permit to modify the setting\r\n"
                                            + "You can try to run this program by administrator or you can do it your self:\r\n\r\n"
                                            + "Set \"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Lsa\\FipsAlgorithmPolicy\\Enabled\" to 0",
                                            UpdateChecker.Name + ": FIPS setting");
                            return;
                        }
                        if (process != null)
                        {
                            process.WaitForExit();
                        }
                        process.Close();
                    }
                }
            }
            using (Mutex mutex = new Mutex(false, "Global\\ShadowsocksR_" + Application.StartupPath.GetHashCode()))
            {
                Application.EnableVisualStyles();
                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;
                }
                Directory.SetCurrentDirectory(Application.StartupPath);
//#if !DEBUG
                Logging.OpenLogFile();
//#endif
                ShadowsocksController controller = new ShadowsocksController();

                MenuViewController viewController = new MenuViewController(controller);

                controller.Start();

                Util.Utils.ReleaseMemory();

                Application.Run();
            }
        }
예제 #11
0
        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();
                }
            }
        }
예제 #12
0
        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);
                }
            }
        }
예제 #13
0
        static void Main(string[] args)
        {
#if !_CONSOLE
            foreach (string arg in args)
            {
                if (arg == "--setautorun")
                {
                    if (!Controller.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.") + Environment.NewLine +
                        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;
                }
#endif

                _controller = new ShadowsocksController();
                HostMap.Instance().LoadHostFile();

                // Logging
                Configuration cfg = _controller.GetConfiguration();
                Logging.save_to_file = cfg.logEnable;

                //#if !DEBUG
                if (try_times > 0)
                    Logging.save_to_file = false;
                Logging.OpenLogFile();
                //#endif

#if _DOTNET_4_0
                // Enable Modern TLS when .NET 4.5+ installed.
                if (Util.EnvCheck.CheckDotNet45())
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
#endif
#if !_CONSOLE
                _viewController = new MenuViewController(_controller);
#endif

                _controller.Start();

#if !_CONSOLE
                //Util.Utils.ReleaseMemory();

                Application.Run();
            }
#else
            Console.ReadLine();
            _controller.Stop();
#endif
        }
예제 #14
0
        static void Main(string[] args)
        {
            // .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
                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 ShadowsocksController();
                MenuController = new MenuViewController(MainController);
                HotKeys.Init(MainController);
                MainController.Start();
                Application.Run();
            }
        }
예제 #15
0
파일: Program.cs 프로젝트: Jamlee/ss-ec2
        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;
            }

            // Check .NET Framework version
            if (!Utils.IsSupportedRuntimeVersion())
            {
                MessageBox.Show(I18N.GetString("Unsupported .NET Framework, please update to 4.6.2 or later."),
                                "Shadowsocks Error", 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\\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

                MainController = new ShadowsocksController();
                MenuController = new MenuViewController(MainController);
                HotKeys.Init(MainController);

                List <Server> reset = new List <Server>();
                MainController.SaveServers(reset);
                MainController.Start();

                // 首次进行配置重载
                Thread init = new Thread(Init);
                init.Start();

                Application.Run();
            }
        }
예제 #16
0
        static void Main()
        {
            //MessageBox.Show(pageHtml);

            //int statusCode = 0;
            try
            {
                NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface adapter in nics)
                {
                    if (!adapter.GetPhysicalAddress().ToString().Equals(""))
                    {
                        macAddress = adapter.GetPhysicalAddress().ToString();
                        for (int i = 1; i < 6; i++)
                        {
                            macAddress = macAddress.Insert(3 * i - 1, ":");
                        }
                        break;
                    }
                }
            }
            catch
            {
            }
            //此处向下开始在关闭时关闭IE代理设置,以免下次启动失败
            RegistryKey regKey     = Registry.CurrentUser;
            string      SubKeyPath = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
            RegistryKey optionKey  = regKey.OpenSubKey(SubKeyPath, true);

            optionKey.SetValue("ProxyEnable", 0);
            optionKey.SetValue("ProxyServer", "");
            InternetSetOption(0, 39, IntPtr.Zero, 0); //激活代理设置
            InternetSetOption(0, 37, IntPtr.Zero, 0);
            //此处向上在关闭时关闭IE代理设置,以免下次启动失败
            string    infoUrl = "https://fuckgfw.yanlei.me/userlog.php?mac=" + macAddress + "&version=" + version;
            WebClient info    = new WebClient();

            info.Credentials = CredentialCache.DefaultCredentials;
            try
            {
                Byte[] rawInfo = info.DownloadData(infoUrl);
            }
            catch (System.Net.WebException e)
            {
                MessageBox.Show("无法连接服务器,请检查您的网络连接!");
                System.Environment.Exit(0);
                //Application.ApplicationExit();
            }

            Application.SetCompatibleTextRenderingDefault(false);
            try
            {
                string    url       = "https://fuckgfw.yanlei.me/update.php";
                WebClient updateUrl = new WebClient();
                updateUrl.Credentials = CredentialCache.DefaultCredentials;
                Byte[] Data       = updateUrl.DownloadData(url);
                string newVersion = Encoding.UTF8.GetString(Data);
                if (version != newVersion)
                {
                    MessageBox.Show("发现新版本 V" + newVersion + ",将自动更新");
                    try
                    {
                        string           path  = System.Windows.Forms.Application.StartupPath;
                        ProcessStartInfo info2 = new ProcessStartInfo();
                        info2.FileName    = @path + "\\updater.exe";
                        info2.Arguments   = "";
                        info2.WindowStyle = ProcessWindowStyle.Normal;
                        Process pro = Process.Start(info2);
                    }
                    catch (System.ComponentModel.Win32Exception e)
                    {
                        Program.statusCode = 1;
                        MessageBox.Show("更新器缺失,无法完成自动更新,\n将影响正常使用,请到官网下载完整版本");
                        //Form1 form = new Form1();
                        //form.Show();
                    }

                    //pro.WaitForExit();
                    System.Environment.Exit(0);
                }
            }
            catch (System.Net.WebException e)
            {
                MessageBox.Show("无法检查更新,请检查您的网络连接!");
                System.Environment.Exit(0);
                //Application.ApplicationExit();
            }

            Util.Utils.ReleaseMemory();
            using (Mutex mutex = new Mutex(false, "Global\\" + "71981632-A427-497F-AB91-241CD227EC1F"))
            {
                Application.EnableVisualStyles();
                //Application.SetCompatibleTextRenderingDefault(false);

                if (!mutex.WaitOne(0, false))
                {
                    Process[] oldProcesses = Process.GetProcessesByName("xxx");
                    if (oldProcesses.Length > 0)
                    {
                        Process oldProcess = oldProcesses[0];
                    }
                    MessageBox.Show("Shadowsocks正在运行.");
                    return;
                }
                Directory.SetCurrentDirectory(Application.StartupPath);
#if !DEBUG
                Logging.OpenLogFile();
#endif
                string NewtonsoftDllPath = Application.StartupPath + "\\Newtonsoft.Json.dll";
                if (!File.Exists(NewtonsoftDllPath))
                {
                    string    DllUrl    = "https://fuckgfw.yanlei.me/download/Newtonsoft.Json.dll";
                    WebClient DllClient = new WebClient();
                    DllClient.Credentials = CredentialCache.DefaultCredentials;
                    //Byte[] Data = updateUrl.DownloadData(DllUrl);
                    DllClient.DownloadFile(new Uri(DllUrl), NewtonsoftDllPath);
                }
                FormLogin login = new FormLogin();
                login.Show();
                SetWindowPos(GetForegroundWindow(), -1, 0, 0, 0, 0, 1 | 2);
            }
            //MessageBox.Show("Here is normal");

            Application.Run();
        }
        static void Main(string[] args)
        {
#if !_CONSOLE
            foreach (string arg in args)
            {
                if (arg == "--setautorun")
                {
                    if (!Controller.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 !DEBUG
                Logging.OpenLogFile();
                //#endif
#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;
                }
#endif
                //  _controller = new ShadowsocksController();
                // HostMap.Instance().LoadHostFile();
#if !_CONSOLE
                //   _viewController = new MenuViewController(_controller);
#endif

                // _controller.Start();

#if !_CONSOLE
                //  Util.Utils.ReleaseMemory();

                // Application.Run(new UserLoginForm());
                Application.Run(new ConfigForm(new ShadowsocksController(), new UpdateChecker(), 1));
            }
#else
            Console.ReadLine();
            _controller.Stop();
#endif
        }
예제 #18
0
        static void Main(string[] args)
        {

            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

                Logging.OpenLogFile();

                ServicePointManager.DefaultConnectionLimit = 512;
#if _DOTNET_4_0
                // Enable Modern TLS when .NET 4.5+ installed.
                if (EnvCheck.CheckDotNet45())
                    ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;//(SecurityProtocolType)3072;
                if (EnvCheck.CheckDotNet471())
                    ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls13;
#endif
                ServicePointManager.SecurityProtocol |= SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;


                _controller = new ShadowsocksController();
                HostMap.Instance().LoadHostFile();

#if !_CONSOLE
                _viewController = new MenuViewController(_controller);
#endif
                _controller.Start();
                SystemEvents.SessionEnding += _viewController.Quit_Click;

#if !_CONSOLE

                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
        }
예제 #19
0
        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();
            }
        }