Example #1
0
        public override NSObject GetObjectValue(NSTableView tableView,
                                                NSTableColumn tableColumn,
                                                int row)
        {
            TableRoutingControllerItem i = Items [row];

            if (tableColumn.Identifier == "Icon")
            {
                if (i.Icon == "in")
                {
                    return(NSImage.ImageNamed("routes_in.png"));
                }
                else
                {
                    return(NSImage.ImageNamed("routes_out.png"));
                }
            }
            else if (tableColumn.Identifier == "Ip")
            {
                return(new NSString(i.Ip));
            }
            else if (tableColumn.Identifier == "Action")
            {
                return(new NSString(WindowPreferencesController.RouteDirectionToDescription(i.Action)));
            }
            else if (tableColumn.Identifier == "Notes")
            {
                return(new NSString(i.Notes));
            }
            else
            {
                throw new NotImplementedException(string.Format("{0} is not recognized", tableColumn.Identifier));
            }
        }
        void RouteEdit()
        {
            nint i = TableRoutes.SelectedRow;

            if (i != -1)
            {
                TableRoutingControllerItem item = TableRoutingController.Items[(int)i];

                WindowPreferencesRouteController.Item = item;
                WindowPreferencesRouteController dlg = new WindowPreferencesRouteController();
                dlg.Window.ReleasedWhenClosed = true;
                NSApplication.SharedApplication.RunModalForWindow(dlg.Window);
                dlg.Window.Close();

                TableRoutingController.RefreshUI();
                this.EnableIde();
            }
        }
        void RouteAdd()
        {
            TableRoutingControllerItem item = new TableRoutingControllerItem();

            item.Ip     = "";
            item.Icon   = "out";
            item.Action = "out";
            item.Notes  = "";

            WindowPreferencesRouteController.Item = item;
            WindowPreferencesRouteController dlg = new WindowPreferencesRouteController();

            dlg.Window.ReleasedWhenClosed = true;
            NSApplication.SharedApplication.RunModalForWindow(dlg.Window);
            dlg.Window.Close();

            if (dlg.Accepted)
            {
                TableRoutingController.Items.Add(item);
                TableRoutingController.RefreshUI();
            }

            this.EnableIde();
        }
        void ReadOptions()
        {
            Storage s = Engine.Instance.Storage;

            // General

            GuiUtils.SetCheck(ChkConnect, s.GetBool("connect"));
            GuiUtils.SetCheck(ChkNetLock, s.GetBool("netlock"));

            GuiUtils.SetCheck(ChkGeneralStartLast, s.GetBool("servers.startlast"));
            GuiUtils.SetCheck(ChkGeneralOsxVisible, s.GetBool("gui.osx.visible"));
            // GuiUtils.SetCheck (ChkGeneralOsxDock, s.GetBool ("gui.osx.dock")); // See this FAQ: https://airvpn.org/topic/13331-its-possible-to-hide-the-icon-in-dock-bar-under-os-x/
            GuiUtils.SetCheck(ChkGeneralOsxNotifications, s.GetBool("gui.osx.notifications"));
            GuiUtils.SetCheck(ChkUiSystemBarShowInfo, s.GetBool("gui.osx.sysbar.show_info"));
            GuiUtils.SetCheck(ChkUiSystemBarShowSpeed, s.GetBool("gui.osx.sysbar.show_speed"));
            GuiUtils.SetCheck(ChkUiSystemBarShowServer, s.GetBool("gui.osx.sysbar.show_server"));

            GuiUtils.SetCheck(ChkExitConfirm, s.GetBool("gui.exit_confirm"));

            // UI
            string uiUnit = s.Get("ui.unit");

            if (uiUnit == "bytes")
            {
                GuiUtils.SetSelected(CboUiUnit, Messages.WindowsSettingsUiUnit1);
            }
            else if (uiUnit == "bits")
            {
                GuiUtils.SetSelected(CboUiUnit, Messages.WindowsSettingsUiUnit2);
            }
            else
            {
                GuiUtils.SetSelected(CboUiUnit, Messages.WindowsSettingsUiUnit0);
            }
            GuiUtils.SetCheck(ChkUiIEC, s.GetBool("ui.iec"));

            /*
             * string interfaceMode = GuiUtils.InterfaceColorMode ();
             * if (interfaceMode == "Dark")
             *      GuiUtils.SetSelected (CboGeneralOsxInterfaceStyle,"Dark");
             * else
             *      GuiUtils.SetSelected (CboGeneralOsxInterfaceStyle,"Default");
             */

            // Protocols
            String protocol = s.Get("mode.protocol").ToUpperInvariant();
            int    port     = s.GetInt("mode.port");
            int    entryIP  = s.GetInt("mode.alt");

            if (protocol == "AUTO")
            {
                GuiUtils.SetCheck(ChkProtocolsAutomatic, true);
            }
            else
            {
                bool found = false;

                int iRow = 0;
                foreach (TableProtocolsControllerItem itemProtocol in TableProtocolsController.Items)
                {
                    if ((itemProtocol.Protocol == protocol) &&
                        (itemProtocol.Port == port) &&
                        (itemProtocol.IP == entryIP))
                    {
                        found = true;
                        TableProtocols.SelectRow(iRow, false);
                        TableProtocols.ScrollRowToVisible(iRow);
                        break;
                    }
                    iRow++;
                }

                if (found == false)
                {
                    GuiUtils.SetCheck(ChkProtocolsAutomatic, true);
                }
                else
                {
                    GuiUtils.SetCheck(ChkProtocolsAutomatic, false);
                }
            }

            // Proxy

            GuiUtils.SetSelected(CboProxyType, s.Get("proxy.mode"));
            if (s.Get("proxy.when") == "always")
            {
                GuiUtils.SetSelected(CboProxyWhen, Messages.WindowsSettingsProxyWhenAlways);
            }
            else if (s.Get("proxy.when") == "web")
            {
                GuiUtils.SetSelected(CboProxyWhen, Messages.WindowsSettingsProxyWhenWeb);
            }
            else if (s.Get("proxy.when") == "openvpn")
            {
                GuiUtils.SetSelected(CboProxyWhen, Messages.WindowsSettingsProxyWhenOpenVPN);
            }
            else if (s.Get("proxy.when") == "none")
            {
                GuiUtils.SetSelected(CboProxyWhen, Messages.WindowsSettingsProxyWhenNone);
            }
            else
            {
                GuiUtils.SetSelected(CboProxyWhen, Messages.WindowsSettingsProxyWhenAlways);
            }
            TxtProxyHost.StringValue = s.Get("proxy.host");
            TxtProxyPort.StringValue = s.Get("proxy.port");
            GuiUtils.SetSelected(CboProxyAuthentication, s.Get("proxy.auth"));
            TxtProxyLogin.StringValue              = s.Get("proxy.login");
            TxtProxyPassword.StringValue           = s.Get("proxy.password");
            TxtProxyTorControlPort.StringValue     = s.Get("proxy.tor.control.port");
            TxtProxyTorControlPassword.StringValue = s.Get("proxy.tor.control.password");

            // Routes
            GuiUtils.SetSelected(CboRoutesOtherwise, RouteDirectionToDescription(s.Get("routes.default")));

            string routes = s.Get("routes.custom");

            string[] routes2 = routes.Split(';');
            foreach (string route in routes2)
            {
                string[] routeEntries = route.Split(',');
                if (routeEntries.Length < 2)
                {
                    continue;
                }

                TableRoutingControllerItem item = new TableRoutingControllerItem();
                item.Ip     = routeEntries[0];
                item.Action = routeEntries[1];
                item.Icon   = routeEntries[1];
                if (routeEntries.Length == 3)
                {
                    item.Notes = routeEntries[2];
                }
                TableRoutingController.Items.Add(item);
            }

            TableRoutingController.RefreshUI();

            // Advanced - General

            GuiUtils.SetCheck(ChkAdvancedExpertMode, s.GetBool("advanced.expert"));
            GuiUtils.SetCheck(ChkAdvancedCheckRoute, s.GetBool("advanced.check.route"));
            string ipV6Mode = s.Get("ipv6.mode");

            if (ipV6Mode == "none")
            {
                GuiUtils.SetSelected(CboIpV6, "None");
            }
            else if (ipV6Mode == "disable")
            {
                GuiUtils.SetSelected(CboIpV6, "Disable");
            }
            else
            {
                GuiUtils.SetSelected(CboIpV6, "None");
            }

            GuiUtils.SetCheck(ChkAdvancedPingerEnabled, s.GetBool("pinger.enabled"));
            GuiUtils.SetCheck(ChkRouteRemoveDefaultGateway, s.GetBool("routes.remove_default"));

            TxtAdvancedOpenVpnPath.StringValue = s.Get("tools.openvpn.path");
            GuiUtils.SetCheck(ChkAdvancedSkipAlreadyRun, s.GetBool("advanced.skip_alreadyrun"));
            GuiUtils.SetCheck(ChkAdvancedProviders, s.GetBool("advanced.providers"));

            int manifestRefresh = s.GetInt("advanced.manifest.refresh");

            if (manifestRefresh == 60)
            {
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Every one hour");
            }
            else if (manifestRefresh == 10)
            {
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Every ten minute");
            }
            else if (manifestRefresh == 1)
            {
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Every minute");
            }
            else if (manifestRefresh == 0)
            {
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Never");
            }
            else
            {
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Automatic");
            }

            int openVpnSndBuf = s.GetInt("openvpn.sndbuf");

            if (openVpnSndBuf == -2)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, Messages.Automatic);
            }
            else if (openVpnSndBuf == -1)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, Messages.WindowsSettingsOpenVpnDefault);
            }
            else if (openVpnSndBuf == 1024 * 8)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "8 KB");
            }
            else if (openVpnSndBuf == 1024 * 16)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "16 KB");
            }
            else if (openVpnSndBuf == 1024 * 32)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "32 KB");
            }
            else if (openVpnSndBuf == 1024 * 64)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "64 KB");
            }
            else if (openVpnSndBuf == 1024 * 128)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "128 KB");
            }
            else if (openVpnSndBuf == 1024 * 256)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "256 KB");
            }
            else if (openVpnSndBuf == 1024 * 512)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "512 KB");
            }

            int openVpnRcvBuf = s.GetInt("openvpn.rcvbuf");

            if (openVpnRcvBuf == -2)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, Messages.Automatic);
            }
            else if (openVpnRcvBuf == -1)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, Messages.WindowsSettingsOpenVpnDefault);
            }
            else if (openVpnRcvBuf == 1024 * 8)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "8 KB");
            }
            else if (openVpnRcvBuf == 1024 * 16)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "16 KB");
            }
            else if (openVpnRcvBuf == 1024 * 32)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "32 KB");
            }
            else if (openVpnRcvBuf == 1024 * 64)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "64 KB");
            }
            else if (openVpnRcvBuf == 1024 * 128)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "128 KB");
            }
            else if (openVpnRcvBuf == 1024 * 256)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "256 KB");
            }
            else if (openVpnRcvBuf == 1024 * 512)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "512 KB");
            }

            // Advanced - DNS

            string dnsMode = s.Get("dns.mode");

            if (dnsMode == "none")
            {
                GuiUtils.SetSelected(CboDnsSwitchMode, "Disabled");
            }
            else
            {
                GuiUtils.SetSelected(CboDnsSwitchMode, "Automatic");
            }

            GuiUtils.SetCheck(ChkDnsCheck, s.GetBool("dns.check"));

            TableDnsServersController.Clear();
            string[] dnsServers = s.Get("dns.servers").Split(',');
            foreach (string dnsServer in dnsServers)
            {
                if (IpAddress.IsIP(dnsServer))
                {
                    TableDnsServersController.Add(dnsServer);
                }
            }

            // Advanced - Lock
            string lockMode = s.Get("netlock.mode");

            GuiUtils.SetSelected(CboLockMode, "None");
            if (lockMode == "auto")
            {
                GuiUtils.SetSelected(CboLockMode, "Automatic");
            }
            else
            {
                foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes)
                {
                    if (lockPlugin.GetCode() == lockMode)
                    {
                        GuiUtils.SetSelected(CboLockMode, lockPlugin.GetName());
                    }
                }
            }
            GuiUtils.SetCheck(ChkLockAllowPrivate, s.GetBool("netlock.allow_private"));
            GuiUtils.SetCheck(ChkLockAllowPing, s.GetBool("netlock.allow_ping"));
            GuiUtils.SetCheck(ChkLockAllowDNS, s.GetBool("netlock.allow_dns"));
            TxtLockAllowedIPS.StringValue = s.Get("netlock.allowed_ips");

            // Advanced - Logging
            GuiUtils.SetCheck(ChkLoggingEnabled, s.GetBool("log.file.enabled"));
            GuiUtils.SetCheck(ChkLogLevelDebug, s.GetBool("log.level.debug"));
            TxtLoggingPath.StringValue = s.Get("log.file.path");

            // Advanced - OVPN Directives
            GuiUtils.SetSelected(CboOpenVpnDirectivesSkipDefault, (s.GetBool("openvpn.skip_defaults") ? Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip2 : Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip1));
            TxtAdvancedOpenVpnDirectivesDefault.StringValue = s.Get("openvpn.directives");
            TxtAdvancedOpenVpnDirectivesCustom.StringValue  = s.Get("openvpn.custom");
            TxtOpenVpnDirectivesCustomPath.StringValue      = s.Get("openvpn.directives.path");

            // Advanced - Events
            ReadOptionsEvent("app.start", 0);
            ReadOptionsEvent("app.stop", 1);
            ReadOptionsEvent("session.start", 2);
            ReadOptionsEvent("session.stop", 3);
            ReadOptionsEvent("vpn.pre", 4);
            ReadOptionsEvent("vpn.up", 5);
            ReadOptionsEvent("vpn.down", 6);

            TableAdvancedEventsController.RefreshUI();
        }
        void RouteAdd()
        {
            TableRoutingControllerItem item = new TableRoutingControllerItem();
            item.Ip = "";
            item.Icon = "out";
            item.Action = "out";
            item.Notes = "";

            WindowPreferencesRouteController.Item = item;
            WindowPreferencesRouteController dlg = new WindowPreferencesRouteController ();
            dlg.Window.ReleasedWhenClosed = true;
            NSApplication.SharedApplication.RunModalForWindow (dlg.Window);
            dlg.Window.Close ();

            if(dlg.Accepted) {
                TableRoutingController.Items.Add(item);
                TableRoutingController.RefreshUI ();
            }

            this.EnableIde();
        }
        void ReadOptions()
        {
            Storage s = Engine.Instance.Storage;

            // General

            GuiUtils.SetCheck (ChkConnect, s.GetBool ("connect"));
            GuiUtils.SetCheck (ChkNetLock, s.GetBool ("netlock"));

            GuiUtils.SetCheck (ChkGeneralStartLast, s.GetBool("servers.startlast"));
            GuiUtils.SetCheck (ChkGeneralOsxVisible, s.GetBool ("gui.osx.visible"));
            // GuiUtils.SetCheck (ChkGeneralOsxDock, s.GetBool ("gui.osx.dock")); // See this FAQ: https://airvpn.org/topic/13331-its-possible-to-hide-the-icon-in-dock-bar-under-os-x/
            GuiUtils.SetCheck (ChkGeneralOsxNotifications, s.GetBool ("gui.osx.notifications"));
            GuiUtils.SetCheck (ChkUiSystemBarShowInfo, s.GetBool ("gui.osx.sysbar.show_info"));
            GuiUtils.SetCheck (ChkUiSystemBarShowSpeed, s.GetBool ("gui.osx.sysbar.show_speed"));
            GuiUtils.SetCheck (ChkUiSystemBarShowServer, s.GetBool ("gui.osx.sysbar.show_server"));

            GuiUtils.SetCheck (ChkExitConfirm, s.GetBool("gui.exit_confirm"));

            // UI
            string uiUnit = s.Get ("ui.unit");
            if (uiUnit == "bytes")
                GuiUtils.SetSelected (CboUiUnit, Messages.WindowsSettingsUiUnit1);
            else if (uiUnit == "bits")
                GuiUtils.SetSelected (CboUiUnit, Messages.WindowsSettingsUiUnit2);
            else
                GuiUtils.SetSelected (CboUiUnit, Messages.WindowsSettingsUiUnit0);
            GuiUtils.SetCheck(ChkUiIEC, s.GetBool("ui.iec"));
            /*
            string interfaceMode = GuiUtils.InterfaceColorMode ();
            if (interfaceMode == "Dark")
                GuiUtils.SetSelected (CboGeneralOsxInterfaceStyle,"Dark");
            else
                GuiUtils.SetSelected (CboGeneralOsxInterfaceStyle,"Default");
            */

            // Protocols
            String protocol = s.Get ("mode.protocol").ToUpperInvariant ();
            int port = s.GetInt ("mode.port");
            int alternate = s.GetInt ("mode.alt");
            if (protocol == "AUTO") {
                GuiUtils.SetCheck (ChkProtocolsAutomatic, true);
            } else {
                bool found = false;

                int iRow = 0;
                foreach (TableProtocolsControllerItem itemProtocol in TableProtocolsController.Items) {
                    if ((itemProtocol.Protocol == protocol) &&
                       (itemProtocol.Port == port) &&
                       (itemProtocol.Entry == alternate)) {
                        found = true;
                        TableProtocols.SelectRow (iRow, false);
                        TableProtocols.ScrollRowToVisible (iRow);
                        break;
                    }
                    iRow++;
                }

                if(found == false)
                    GuiUtils.SetCheck (ChkProtocolsAutomatic, true);
                else
                    GuiUtils.SetCheck (ChkProtocolsAutomatic, false);
            }

            // Proxy

            GuiUtils.SetSelected (CboProxyType, s.Get("proxy.mode"));
            TxtProxyHost.StringValue = s.Get ("proxy.host");
            TxtProxyPort.StringValue = s.Get ("proxy.port");
            GuiUtils.SetSelected (CboProxyAuthentication, s.Get ("proxy.auth"));
            TxtProxyLogin.StringValue = s.Get ("proxy.login");
            TxtProxyPassword.StringValue = s.Get ("proxy.password");
            TxtProxyTorControlPort.StringValue = s.Get ("proxy.tor.control.port");
            TxtProxyTorControlPassword.StringValue = s.Get ("proxy.tor.control.password");

            // Routes
            GuiUtils.SetSelected(CboRoutesOtherwise, RouteDirectionToDescription(s.Get("routes.default")));

            string routes = s.Get ("routes.custom");
            string[] routes2 = routes.Split (';');
            foreach (string route in routes2) {
                string[] routeEntries = route.Split (',');
                if (routeEntries.Length < 2)
                    continue;

                TableRoutingControllerItem item = new TableRoutingControllerItem ();
                item.Ip = routeEntries [0];
                item.Action = routeEntries [1];
                item.Icon = routeEntries [1];
                if(routeEntries.Length == 3)
                    item.Notes = routeEntries [2];
                TableRoutingController.Items.Add (item);
            }

            TableRoutingController.RefreshUI();

            // Advanced - General

            GuiUtils.SetCheck (ChkAdvancedExpertMode, s.GetBool ("advanced.expert"));
            GuiUtils.SetCheck (ChkAdvancedCheckRoute, s.GetBool ("advanced.check.route"));
            string ipV6Mode = s.Get ("ipv6.mode");
            if (ipV6Mode == "none")
                GuiUtils.SetSelected (CboIpV6, "None");
            else if (ipV6Mode == "disable")
                GuiUtils.SetSelected (CboIpV6, "Disable");
            else
                GuiUtils.SetSelected (CboIpV6, "None");

            GuiUtils.SetCheck (ChkAdvancedPingerEnabled, s.GetBool ("pinger.enabled"));
            GuiUtils.SetCheck (ChkRouteRemoveDefaultGateway, s.GetBool("routes.remove_default"));

            TxtAdvancedOpenVpnPath.StringValue = s.Get ("executables.openvpn");

            int manifestRefresh = s.GetInt("advanced.manifest.refresh");
            if (manifestRefresh == 60)
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Every one hour");
            else if (manifestRefresh == 10)
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Every ten minute");
            else if (manifestRefresh == 1)
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Every minute");
            else if (manifestRefresh == 0)
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Never");
            else
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Automatic");

            int openVpnSndBuf = s.GetInt("openvpn.sndbuf");
            if (openVpnSndBuf == -2)
                GuiUtils.SetSelected(CboOpenVpnSndBuf, Messages.Automatic);
            else if (openVpnSndBuf == -1)
                GuiUtils.SetSelected(CboOpenVpnSndBuf, Messages.WindowsSettingsOpenVpnDefault);
            else if (openVpnSndBuf == 1024 * 8)
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "8 KB");
            else if (openVpnSndBuf == 1024 * 16)
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "16 KB");
            else if (openVpnSndBuf == 1024 * 32)
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "32 KB");
            else if (openVpnSndBuf == 1024 * 64)
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "64 KB");
            else if (openVpnSndBuf == 1024 * 128)
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "128 KB");
            else if (openVpnSndBuf == 1024 * 256)
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "256 KB");
            else if (openVpnSndBuf == 1024 * 512)
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "512 KB");

            int openVpnRcvBuf = s.GetInt("openvpn.rcvbuf");
            if (openVpnRcvBuf == -2)
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, Messages.Automatic);
            else if (openVpnRcvBuf == -1)
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, Messages.WindowsSettingsOpenVpnDefault);
            else if (openVpnRcvBuf == 1024 * 8)
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "8 KB");
            else if (openVpnRcvBuf == 1024 * 16)
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "16 KB");
            else if (openVpnRcvBuf == 1024 * 32)
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "32 KB");
            else if (openVpnRcvBuf == 1024 * 64)
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "64 KB");
            else if (openVpnRcvBuf == 1024 * 128)
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "128 KB");
            else if (openVpnRcvBuf == 1024 * 256)
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "256 KB");
            else if (openVpnRcvBuf == 1024 * 512)
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "512 KB");

            // Advanced - DNS

            string dnsMode = s.Get ("dns.mode");
            if (dnsMode == "none")
                GuiUtils.SetSelected (CboDnsSwitchMode, "Disabled");
            else
                GuiUtils.SetSelected (CboDnsSwitchMode, "Automatic");

            GuiUtils.SetCheck (ChkDnsCheck, s.GetBool ("dns.check"));

            TableDnsServersController.Clear ();
            string[] dnsServers = s.Get ("dns.servers").Split (',');
            foreach (string dnsServer in dnsServers) {
                if (IpAddress.IsIP (dnsServer))
                    TableDnsServersController.Add (dnsServer);
            }

            // Advanced - Lock
            string lockMode = s.Get ("netlock.mode");
            GuiUtils.SetSelected (CboLockMode, "None");
            if (lockMode == "auto")
                GuiUtils.SetSelected (CboLockMode, "Automatic");
            else {
                foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes) {
                    if (lockPlugin.GetCode () == lockMode) {
                        GuiUtils.SetSelected(CboLockMode, lockPlugin.GetName());
                    }
                }
            }
            GuiUtils.SetCheck(ChkLockAllowPrivate, s.GetBool("netlock.allow_private"));
            GuiUtils.SetCheck(ChkLockAllowPing, s.GetBool("netlock.allow_ping"));
            TxtLockAllowedIPS.StringValue = s.Get("netlock.allowed_ips");

            // Advanced - Logging
            GuiUtils.SetCheck (ChkLoggingEnabled, s.GetBool ("log.file.enabled"));
            GuiUtils.SetCheck (ChkLogLevelDebug, s.GetBool ("log.level.debug"));
            TxtLoggingPath.StringValue = s.Get ("log.file.path");

            // Advanced - OVPN Directives
            GuiUtils.SetSelected(CboOpenVpnDirectivesSkipDefault, (s.GetBool("openvpn.skip_defaults") ? Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip2 : Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip1));
            TxtAdvancedOpenVpnDirectivesDefault.StringValue = s.Get ("openvpn.directives");
            TxtAdvancedOpenVpnDirectivesCustom.StringValue = s.Get ("openvpn.custom");

            // Advanced - Events
            ReadOptionsEvent ("app.start", 0);
            ReadOptionsEvent ("app.stop", 1);
            ReadOptionsEvent ("session.start", 2);
            ReadOptionsEvent ("session.stop", 3);
            ReadOptionsEvent ("vpn.pre", 4);
            ReadOptionsEvent ("vpn.up", 5);
            ReadOptionsEvent ("vpn.down", 6);

            TableAdvancedEventsController.RefreshUI ();
        }