Example #1
0
        private void LoadConfig()
        {
            // 读取默认的配置信息
            programConfig = FileOperation.ReadConfig();

            if (programConfig != null)
            {
                if (programConfig.Client != null)
                {
                    client = programConfig.Client;
                }
                else
                {
                    client = new Client.Client();
                    programConfig.Client = client;
                }
            }
            else
            {
                // 做一些初始化的工作
                client        = new Client.Client();
                proxyServer   = new ProxyServer.ProxyServer();
                programConfig = new Config.Config(autoStartCheckBox.Checked,
                                                  closeWithoutQuitCheckBox.Checked, client, -1, 9000);
            }
            // 显示本机的有关信息
            ShowClientInfo(programConfig.Client);

            // checkbox状态
            autoStartCheckBox.Checked            = programConfig.AutoStartup;
            closeWithoutQuitCheckBox.Checked     = programConfig.EnableBackgroundMode;
            acceptControlRequestCheckBox.Checked = programConfig.AcceptControlRequest;

            // 显示代理服务器信息
            if (programConfig.SelectedServerIndex != -1)
            {
                var serverList = FileOperation.ReadServerList();
                if (serverList.Count > 0)
                {
                    if (programConfig.SelectedServerIndex < serverList.Count)
                    {
                        proxyServer = serverList[programConfig.SelectedServerIndex];
                    }
                    else
                    {
                        proxyServer = serverList[0];
                    }
                    ShowProxyServerInfo(proxyServer);
                }

                // 检查是否需要自动启动
                if (autoStartCheckBox.Checked)
                {
                    AutoStartService();
                }
            }
            else
            {
                // 打开编辑窗口,提示用户添加服务器
                MessageBox.Show("没有可以选择的代理服务器,请自行添加代理服务器后更换。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                EditServer();
                ChangeServer();
            }
        }