private void LoadProperty(AppSettings settings, string propertyName)
        {
            var propertyInfo = GetPropertyInfo(settings, propertyName);

            var propertyType = propertyInfo.PropertyType;

            object value;

            if (propertyType == typeof(string))
            {
                value = (string)NSUserDefaults.StandardUserDefaults.StringForKey(propertyName);
            }
            else if (propertyType == typeof(int))
            {
                value = (int)NSUserDefaults.StandardUserDefaults.IntForKey(propertyName);
            }
            else if (propertyType == typeof(bool))
            {
                value = (bool)NSUserDefaults.StandardUserDefaults.BoolForKey(propertyName);
            }
            else if (propertyType.BaseType == typeof(Enum))
            {
                value = Enum.ToObject(propertyType, (int)NSUserDefaults.StandardUserDefaults.IntForKey(propertyName));
            }

            /*else if (propertyType == typeof (DateTime))
             * {
             *  NSDate date = (NSDate) NSUserDefaults.StandardUserDefaults.ValueForKey (MacLib.MacHelpers.ToNSString (propertyName));
             *  value = MacLib.MacHelpers.NSDateToDateTime (date);
             * }*/
            else if (propertyType == Type.GetType("System.Collections.Generic.List`1[System.String]"))
            {
                try
                {
                    string        serialized = (string)NSUserDefaults.StandardUserDefaults.StringForKey(propertyName);
                    XmlSerializer xs         = new XmlSerializer(typeof(List <string>));
                    List <string> newList    = (List <string>)xs.Deserialize(new StringReader(serialized));
                    value = newList;
                }
                catch { value = new List <string>(); }
            }
            else if (propertyType == typeof(ServersFilterConfig))
            {
                value = ServersFilterConfig.Deserialize((string)NSUserDefaults.StandardUserDefaults.StringForKey(propertyName));
            }
            else if (propertyType == typeof(NetworkActionsConfig))
            {
                value = NetworkActionsConfig.Deserialize((string)NSUserDefaults.StandardUserDefaults.StringForKey(propertyName));
            }
            else
            {
                throw new InvalidOperationException("Trying to load property from AppSettings with unsupported type");
            }

            propertyInfo.SetValue(settings, value);
        }
Example #2
0
        public void Load(AppSettings settings)
        {
            try
            {
                settings.IsAutomaticServerSelection = Properties.Settings.Default.IsAutomaticServerSelection;
                settings.LastUsedServerId           = Properties.Settings.Default.ServerId;
                settings.LastUsedExitServerId       = Properties.Settings.Default.ExitServerId;

                settings.IsAutomaticServerSelectionWg = Properties.Settings.Default.IsAutomaticServerSelectionWg;
                settings.LastUsedWgServerId           = Properties.Settings.Default.LastUsedWgServerId;
                settings.LastUsedWgExitServerId       = Properties.Settings.Default.LastUsedWgExitServerId;

                // Fastest server
                settings.LastOvpnFastestServerId = Properties.Settings.Default.LastOvpnFastestServerId;
                settings.LastWgFastestServerId   = Properties.Settings.Default.LastWgFastestServerId;

                settings.AlternateAPIHost = Properties.Settings.Default.AlternateAPIHost;

                string username = Properties.Settings.Default.Username;

                if (string.IsNullOrEmpty(username))
                {
                    settings.DeleteSession();
                    settings.SetWireGuardCredentials(null, null, true, null);
                }
                else
                {
                    // SESSION
                    settings.SetSession(username,
                                        Properties.Settings.Default.SessionToken,
                                        Properties.Settings.Default.VpnUser,
                                        Properties.Settings.Default.VpnSafePass,
                                        isPassEncrypded: true);
                }

                // Connection settings
                settings.IsAutoPortSelection = Properties.Settings.Default.IsAutoPortSelection;
                settings.PreferredPortIndex  = Properties.Settings.Default.PreferredPortIndex;
                LoadProxySettings(settings);

                // General settings
                settings.RunOnLogin                   = GetRunOnLoginFromRegistry();
                settings.MinimizeToTray               = Properties.Settings.Default.MinimizeToTray;
                settings.LaunchMinimized              = Properties.Settings.Default.LaunchMinimized;
                settings.AutoConnectOnStart           = Properties.Settings.Default.AutoConnectOnLaunch;
                settings.StopServerOnClientDisconnect = Properties.Settings.Default.StopServerOnClientDisconnect;
                settings.DoNotShowDialogOnAppClose    = Properties.Settings.Default.DoNotShowDialogOnAppClose;

                // Advanced
                settings.ServiceUseObfsProxy          = Properties.Settings.Default.ServiceUseObfsProxy;
                settings.ServiceConnectOnInsecureWifi = Properties.Settings.Default.ServiceConnectOnInsecureWifi;

                settings.FirewallDisableAutoOnOff          = Properties.Settings.Default.FirewallDisableAutoOnOff;
                settings.FirewallDisableDeactivationOnExit = Properties.Settings.Default.FirewallDisableDeactivationOnExit;
                settings.FirewallLastStatus             = Properties.Settings.Default.FirewallLastStatus;
                settings.FirewallAllowLAN               = Properties.Settings.Default.FirewallAllowLAN;
                settings.FirewallAllowLANMulticast      = Properties.Settings.Default.FirewallAllowMulticast;
                settings.IsIVPNFirewalIntoduced         = Properties.Settings.Default.IsIVPNFirewalIntoduced;
                settings.IsIVPNAlwaysOnWarningDisplayed = Properties.Settings.Default.IsIVPNAlwaysOnWarningDisplayed;
                settings.LastWindowPosition             = Properties.Settings.Default.LastWindowPosition;
                settings.LastNotificationWindowPosition = Properties.Settings.Default.LastNotificationWindowPosition;
                settings.IsMultiHop   = Properties.Settings.Default.IsMultiHop;
                settings.FirewallType = LoadFirewallType();

                // Diagnostics
                settings.IsLoggingEnabled = Properties.Settings.Default.IsLoggingEnabled;

                // Additional OpenVPN parameters defined by user
                settings.OpenVPNExtraParameters = Properties.Settings.Default.OpenVPNExtraParameters;

                settings.DisableFirewallNotificationWindow = Properties.Settings.Default.DisableFirewallNotificationWindow;

                // Actions for Trusted\Untrusted networks
                settings.IsNetworkActionsEnabled = Properties.Settings.Default.IsNetworkActionsEnabled;
                settings.NetworkActions          = NetworkActionsConfig.Deserialize(Properties.Settings.Default.NetworkActions);

                //Servers filter
                settings.ServersFilter = ServersFilterConfig.Deserialize(Properties.Settings.Default.ServersFilter);

                //DNS filter
                settings.IsAntiTrackerHardcore = Properties.Settings.Default.IsAntiTrackerHardcore;
                settings.IsAntiTracker         = Properties.Settings.Default.IsAntiTracker;
                settings.IsCustomDns           = Properties.Settings.Default.IsCustomDns;
                settings.CustomDns             = Properties.Settings.Default.CustomDns;

                // VPN type
                settings.VpnProtocolType = (VpnType)Properties.Settings.Default.VpnProtocolType;

                // WireGuard
                DateTime wgKeyTimestamp;
                try
                {
                    wgKeyTimestamp = DateTime.ParseExact(Properties.Settings.Default.WireGuardKeysTimestamp,
                                                         DateTimeSerializationFormatString, System.Globalization.CultureInfo.InvariantCulture);
                }
                catch
                {
                    wgKeyTimestamp = default(DateTime);
                }
                settings.SetWireGuardCredentials(Properties.Settings.Default.WireGuardClientPrivateKey, Properties.Settings.Default.WireGuardClientPublicKey, true, Properties.Settings.Default.WireGuardClientInternalIp, wgKeyTimestamp);
                settings.WireGuardKeysRegenerationIntervalHours = Properties.Settings.Default.WireGuardKeysRegenerationIntervalHours;
                settings.WireGuardPreferredPortIndex            = Properties.Settings.Default.WireGuardPreferredPortIndex;

                settings.UpdateEnabledServerPorts();
            }
            catch (Exception ex)
            {
                Logging.Info("Settings loading error: " + (string.IsNullOrEmpty(ex.Message) ? "<no error information>" : ex.Message));
            }
        }
Example #3
0
        public void Load(AppSettings settings)
        {
            try
            {
                settings.IsAutomaticServerSelection = Properties.Settings.Default.IsAutomaticServerSelection;
                settings.LastUsedServerId           = Properties.Settings.Default.ServerId;
                settings.LastUsedExitServerId       = Properties.Settings.Default.ExitServerId;

                settings.IsAutomaticServerSelectionWg = Properties.Settings.Default.IsAutomaticServerSelectionWg;
                settings.LastUsedWgServerId           = Properties.Settings.Default.LastUsedWgServerId;
                settings.LastUsedWgExitServerId       = Properties.Settings.Default.LastUsedWgExitServerId;

                // Fastest server
                settings.LastOvpnFastestServerId = Properties.Settings.Default.LastOvpnFastestServerId;
                settings.LastWgFastestServerId   = Properties.Settings.Default.LastWgFastestServerId;

                settings.AlternateAPIHost = Properties.Settings.Default.AlternateAPIHost;

                // Connection settings
                settings.IsAutoPortSelection = Properties.Settings.Default.IsAutoPortSelection;
                settings.PreferredPortIndex  = Properties.Settings.Default.PreferredPortIndex;
                LoadProxySettings(settings);

                // General settings
                settings.RunOnLogin                   = GetRunOnLoginFromRegistry();
                settings.MinimizeToTray               = Properties.Settings.Default.MinimizeToTray;
                settings.LaunchMinimized              = Properties.Settings.Default.LaunchMinimized;
                settings.AutoConnectOnStart           = Properties.Settings.Default.AutoConnectOnLaunch;
                settings.StopServerOnClientDisconnect = Properties.Settings.Default.StopServerOnClientDisconnect;
                settings.DoNotShowDialogOnAppClose    = Properties.Settings.Default.DoNotShowDialogOnAppClose;

                // Advanced
                settings.ServiceUseObfsProxy          = Properties.Settings.Default.ServiceUseObfsProxy;
                settings.ServiceConnectOnInsecureWifi = Properties.Settings.Default.ServiceConnectOnInsecureWifi;

                settings.FirewallDisableAutoOnOff          = Properties.Settings.Default.FirewallDisableAutoOnOff;
                settings.FirewallDisableDeactivationOnExit = Properties.Settings.Default.FirewallDisableDeactivationOnExit;
                settings.FirewallLastStatus             = Properties.Settings.Default.FirewallLastStatus;
                settings.FirewallAllowLAN               = Properties.Settings.Default.FirewallAllowLAN;
                settings.FirewallAllowLANMulticast      = Properties.Settings.Default.FirewallAllowMulticast;
                settings.IsIVPNFirewalIntoduced         = Properties.Settings.Default.IsIVPNFirewalIntoduced;
                settings.IsIVPNAlwaysOnWarningDisplayed = Properties.Settings.Default.IsIVPNAlwaysOnWarningDisplayed;
                settings.LastWindowPosition             = Properties.Settings.Default.LastWindowPosition;
                settings.LastNotificationWindowPosition = Properties.Settings.Default.LastNotificationWindowPosition;
                settings.IsMultiHop   = Properties.Settings.Default.IsMultiHop;
                settings.FirewallType = LoadFirewallType();

                // Diagnostics
                settings.IsLoggingEnabled = Properties.Settings.Default.IsLoggingEnabled;

                settings.DisableFirewallNotificationWindow = Properties.Settings.Default.DisableFirewallNotificationWindow;

                // Actions for Trusted\Untrusted networks
                settings.IsNetworkActionsEnabled = Properties.Settings.Default.IsNetworkActionsEnabled;
                settings.NetworkActions          = NetworkActionsConfig.Deserialize(Properties.Settings.Default.NetworkActions);

                //Servers filter
                settings.ServersFilter = ServersFilterConfig.Deserialize(Properties.Settings.Default.ServersFilter);

                //DNS filter
                settings.IsAntiTrackerHardcore = Properties.Settings.Default.IsAntiTrackerHardcore;
                settings.IsAntiTracker         = Properties.Settings.Default.IsAntiTracker;
                settings.IsCustomDns           = Properties.Settings.Default.IsCustomDns;
                settings.CustomDns             = Properties.Settings.Default.CustomDns;

                // VPN type
                settings.VpnProtocolType = (VpnType)Properties.Settings.Default.VpnProtocolType;

                // WireGuard
                settings.WireGuardPreferredPortIndex = Properties.Settings.Default.WireGuardPreferredPortIndex;

                settings.UpdateEnabledServerPorts();
            }
            catch (Exception ex)
            {
                Logging.Info("Settings loading error: " + (string.IsNullOrEmpty(ex.Message) ? "<no error information>" : ex.Message));
            }
        }