コード例 #1
0
        private bool SaveValidConfiguration()
        {
            if (!ValidateAndSaveSelectedServerDetails())
            {
                return(false);
            }
            if (_modifiedConfiguration.configs.Count == 0)
            {
                MessageBox.Show(I18N.GetString("Please add at least one server"));
                return(false);
            }

            int localPort = int.Parse(ProxyPortTextBox.Text);

            Configuration.CheckLocalPort(localPort);
            _modifiedConfiguration.localPort = localPort;

            _modifiedConfiguration.portableMode = PortableModeCheckBox.Checked;

            controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort, _modifiedConfiguration.portableMode);
            // SelectedIndex remains valid
            // We handled this in event handlers, e.g. Add/DeleteButton, SelectedIndexChanged
            // and move operations
            controller.SelectServerIndex(ServersListBox.SelectedIndex);
            return(true);
        }
コード例 #2
0
        private void SaveServers(List <Server> servers)
        {
            Configuration config = controller.GetConfigurationCopy();

            servers.Insert(0, config.configs[0]);
            controller.SaveServers(servers, 1080, true);
            UpdateServersMenu();
        }
コード例 #3
0
        private void ConfigForm_KeyDown(object sender, KeyEventArgs e)
        {
            // Sometimes the users may hit enter key by mistake, and the form will close without saving entries.

            if (e.KeyCode == Keys.Enter)
            {
                Server server = controller.GetCurrentServer();
                if (!SaveOldSelectedServer())
                {
                    return;
                }
                if (_modifiedConfiguration.configs.Count == 0)
                {
                    MessageBox.Show(I18N.GetString("Please add at least one server"));
                    return;
                }
                controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort);
                controller.SelectServerIndex(_modifiedConfiguration.configs.IndexOf(server));
            }
        }
コード例 #4
0
ファイル: MenuViewController.cs プロジェクト: SkillUsing/SS
        public void TimerFunction()
        {
            var servers = new Data().GetData();

            if (servers == null || servers.Count == 0)
            {
                return;
            }
            controller.ToggleEnable(true);
            controller.SaveServers(servers, controller.GetCurrentConfiguration().localPort);
            controller.SelectStrategy("com.shadowsocks.strategy.ha");
        }
コード例 #5
0
 private void OKButton_Click(object sender, EventArgs e)
 {
     if (!SaveOldSelectedServer())
     {
         return;
     }
     if (_modifiedConfiguration.configs.Count == 0)
     {
         MessageBox.Show(I18N.GetString("Please add at least one server"));
         return;
     }
     controller.SaveServers(_modifiedConfiguration.configs);
     this.Close();
 }
コード例 #6
0
ファイル: ConfigForm.cs プロジェクト: galaxy001/gfwtools
        private void OKButton_Click(object sender, EventArgs e)
        {
            Server server = controller.GetCurrentServer();

            if (!SaveOldSelectedServer())
            {
                return;
            }
            if (_modifiedConfiguration.configs.Count == 0)
            {
                MessageBox.Show(I18N.GetString("Please add at least one server"));
                return;
            }
            controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort);
            controller.SelectServerIndex(_modifiedConfiguration.configs.IndexOf(server));
            this.Close();
        }
コード例 #7
0
 /// <summary>
 /// 保存免费的服务器
 /// </summary>
 public void saveServers()
 {
     foreach (var server in this.serverList)
     {
         bool isSaved = false;
         for (int i = 0; i < configuration.configs.Count; i++)
         {
             if (server.server == configuration.configs[i].server) //爬到的server名称不可能相同
             {
                 configuration.configs[i] = server;
                 isSaved = true;
             }
         }
         if (!isSaved)
         {
             configuration.configs.Add(server);
         }
     }
     controller.SaveServers(configuration.configs, configuration.localPort);
 }
コード例 #8
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();
            }
        }
コード例 #9
0
ファイル: AwsEc2.cs プロジェクト: Jamlee/ss-ec2
        // 启动 Aws 服务器
        public List <string> Up()
        {
            List <Instance> instances;

            while (true)
            {
                List <string> stoppedIds  = new List <string>();
                List <string> pendingIds  = new List <string>();
                List <string> stoppingIds = new List <string>();

                // 获取实例状态
                instances = ListInstance();

                // 找出没有启动的项目
                foreach (var instance in instances)
                {
                    // 过滤非 ss 主机
                    bool isSSEcs = false;
                    foreach (var tag in instance.Tags)
                    {
                        // 有标识的才当做 ss 虚拟机
                        if (tag.Key is "for" && tag.Value is "fuckwall")
                        {
                            isSSEcs = true;
                            break;
                        }
                    }
                    if (isSSEcs)
                    {
                        // 如果正在停止
                        if (instance.State.Name.Value.Equals("stopping"))
                        {
                            stoppingIds.Add(instance.InstanceId);
                        }

                        // 如果正在启动
                        if (instance.State.Name.Value.Equals("pending"))
                        {
                            pendingIds.Add(instance.InstanceId);
                        }

                        // 如果是停止状态
                        if (instance.State.Name.Value.Equals("stopped"))
                        {
                            stoppedIds.Add(instance.InstanceId);
                        }
                    }
                }

                // 确认虚拟机是有没有起来的项
                if (stoppedIds.Count == 0 && pendingIds.Count == 0 && stoppingIds.Count == 0)
                {
                    break;
                }
                else
                {
                    // 等待 3s 再次重试
                    StartInstance(stoppedIds);
                    Thread.Sleep(3000);
                }
            }

            // 获取虚拟机信息
            instances = ListInstance();
            List <String> instancesList = new List <string>();
            List <Server> servers       = new List <Server>();

            foreach (var instance in instances)
            {
                foreach (var tag in instance.Tags)
                {
                    // 有标识的才当做 ss 虚拟机
                    if (tag.Key is "for" && tag.Value is "fuckwall")
                    {
                        instancesList.Add(instance.PublicDnsName);
                        var server = new Server();
                        server.server = instance.PublicIpAddress;
                        servers.Add(server);
                    }
                }
            }

            // 保存虚拟机信息到配置文件
            controller.SaveServers(servers, 1080);
            controller.Start();

            return(instancesList);
        }