Exemplo n.º 1
0
        public Settings(String filename)
        {
            CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
            IniFile ini;

            if (File.Exists(filename))
            {
                ini = new IniFile(filename);

                this.Theme = ini.IniReadValue("theme", "name");
                this.UpdateFPS = Int32.Parse(ini.IniReadValue("theme", "updatefps"));
                this.LapCountdownFrom = Int32.Parse(ini.IniReadValue("theme", "lapcountdownfrom"));

                Single.TryParse(ini.IniReadValue("theme", "deltadistance"), NumberStyles.AllowDecimalPoint, culture, out this.DeltaDistance);
                if (this.DeltaDistance < 0.5)
                    this.DeltaDistance = 10;

                if (ini.IniReadValue("theme", "includeme").ToLower() == "true")
                    this.IncludeMe = true;

                this.OverlayX = Int32.Parse(ini.IniReadValue("overlay", "x"));
                this.OverlayY = Int32.Parse(ini.IniReadValue("overlay", "y"));
                this.OverlayW = Int32.Parse(ini.IniReadValue("overlay", "w"));
                this.OverlayH = Int32.Parse(ini.IniReadValue("overlay", "h"));

                this.RemoteControlServerPassword = ini.IniReadValue("remote control server", "password");
                this.RemoteControlServerPort = Int32.Parse(ini.IniReadValue("remote control server", "port"));
                if (ini.IniReadValue("remote control server", "autostart").ToLower() == "true")
                    this.RemoteControlServerAutostart = true;

                this.RemoteControlClientPassword = ini.IniReadValue("remote control client", "password");
                this.RemoteControlClientPort = Int32.Parse(ini.IniReadValue("remote control client", "port"));
                this.RemoteControlClientAddress = ini.IniReadValue("remote control client", "address");
                if (ini.IniReadValue("remote control client", "autostart").ToLower() == "true")
                    this.RemoteControlClientAutostart = true;

                this.WebTimingPassword = ini.IniReadValue("webtiming", "password");
                this.WebTimingUrl = ini.IniReadValue("webtiming", "url");
                this.WebTimingUpdateInterval = Int32.Parse(ini.IniReadValue("webtiming", "interval"));
                if (ini.IniReadValue("webtiming", "enable").ToLower() == "true")
                    this.WebTimingEnable = true;

                if (ini.IniReadValue("windows", "AlwaysOnTopMainWindow").ToLower() == "true")
                    this.AlwaysOnTopMainWindow = true;
                if (ini.IniReadValue("windows", "AlwaysOnTopCameraControls").ToLower() == "true")
                    this.AlwaysOnTopCameraControls = true;
                if (ini.IniReadValue("windows", "AlwaysOnTopLists").ToLower() == "true")
                    this.AlwaysOnTopLists = true;
                if (ini.IniReadValue("windows", "LoseFocus").ToLower() == "true")
                    this.LoseFocus = true;

                if (ini.IniReadValue("controls", "sortbynumber").ToLower() == "true")
                    this.CameraControlSortByNumber = true;
                if (ini.IniReadValue("controls", "saferycar").ToLower() == "true")
                    this.CameraControlIncludeSaferyCar = true;
                if (ini.IniHasValue("simulation", "api") )
                    this.SimulationApiName = ini.IniReadValue("simulation", "api");
                if (ini.IniHasValue("simulation", "connectdelay"))
                    this.SimulationConnectDelay = Math.Max( Int32.Parse(ini.IniReadValue("simulation", "connectdelay")),5); // Minimum delay 5 Seconds
            }
            else
            {
                ini = new IniFile(filename);

                ini.IniWriteValue("theme", "name", Properties.Settings.Default.theme);
                ini.IniWriteValue("theme", "updatefps", Properties.Settings.Default.UpdateFrequency.ToString());
                ini.IniWriteValue("theme", "lapcountdownfrom", Properties.Settings.Default.countdownThreshold.ToString());

                ini.IniWriteValue("overlay", "x", Properties.Settings.Default.OverlayLocationX.ToString());
                ini.IniWriteValue("overlay", "y", Properties.Settings.Default.OverlayLocationY.ToString());
                ini.IniWriteValue("overlay", "w", Properties.Settings.Default.OverlayWidth.ToString());
                ini.IniWriteValue("overlay", "h", Properties.Settings.Default.OverlayHeight.ToString());

                ini.IniWriteValue("remote control server", "password", Properties.Settings.Default.remoteServerKey);
                ini.IniWriteValue("remote control server", "port", Properties.Settings.Default.remoteServerPort.ToString());
                ini.IniWriteValue("remote control server", "autostart", Properties.Settings.Default.remoteServerAutostart.ToString().ToLower());

                ini.IniWriteValue("remote control client", "password", Properties.Settings.Default.remoteClientKey);
                ini.IniWriteValue("remote control client", "port", Properties.Settings.Default.remoteClientPort.ToString());
                ini.IniWriteValue("remote control client", "address", Properties.Settings.Default.remoteClientIp);
                ini.IniWriteValue("remote control client", "autostart", Properties.Settings.Default.remoteClientAutostart.ToString().ToLower());

                ini.IniWriteValue("webtiming", "password", Properties.Settings.Default.webTimingKey);
                ini.IniWriteValue("webtiming", "url", Properties.Settings.Default.webTimingUrl);
                ini.IniWriteValue("webtiming", "interval", Properties.Settings.Default.webTimingInterval.ToString());
                ini.IniWriteValue("webtiming", "enable", Properties.Settings.Default.webTimingEnable.ToString().ToLower());

                ini.IniWriteValue("windows", "AlwaysOnTopMainWindow", Properties.Settings.Default.AoTmain.ToString().ToLower());
                ini.IniWriteValue("windows", "AlwaysOnTopCameraControls", Properties.Settings.Default.AoTcontrols.ToString().ToLower());
                ini.IniWriteValue("windows", "AlwaysOnTopLists", Properties.Settings.Default.AoTlists.ToString().ToLower());

                ini.IniWriteValue("controls", "sortbynumber", Properties.Settings.Default.DriverListSortNumber.ToString().ToLower());
                ini.IniWriteValue("controls", "saferycar", Properties.Settings.Default.DriverListIncSC.ToString().ToLower());

            }

            // update ini
            ini.IniWriteValue("theme", "name", this.Theme);
            ini.IniWriteValue("theme", "updatefps", this.UpdateFPS.ToString());
            ini.IniWriteValue("theme", "lapcountdownfrom", this.LapCountdownFrom.ToString());
            ini.IniWriteValue("theme", "deltadistance", this.DeltaDistance.ToString("F5", culture));
            ini.IniWriteValue("theme", "includeme", this.IncludeMe.ToString().ToLower());

            ini.IniWriteValue("overlay", "x", this.OverlayX.ToString());
            ini.IniWriteValue("overlay", "y", this.OverlayY.ToString());
            ini.IniWriteValue("overlay", "w", this.OverlayW.ToString());
            ini.IniWriteValue("overlay", "h", this.OverlayH.ToString());

            ini.IniWriteValue("remote control server", "password", this.RemoteControlServerPassword);
            ini.IniWriteValue("remote control server", "port", this.RemoteControlServerPort.ToString());
            ini.IniWriteValue("remote control server", "autostart", this.RemoteControlServerAutostart.ToString().ToLower());

            ini.IniWriteValue("remote control client", "password", this.RemoteControlClientPassword);
            ini.IniWriteValue("remote control client", "port", this.RemoteControlClientPort.ToString());
            ini.IniWriteValue("remote control client", "address", this.RemoteControlClientAddress);
            ini.IniWriteValue("remote control client", "autostart", this.RemoteControlClientAutostart.ToString().ToLower());

            ini.IniWriteValue("webtiming", "password", this.WebTimingPassword);
            ini.IniWriteValue("webtiming", "url", this.WebTimingUrl);
            ini.IniWriteValue("webtiming", "interval", this.WebTimingUpdateInterval.ToString());
            ini.IniWriteValue("webtiming", "enable  ", this.WebTimingEnable.ToString().ToLower());

            ini.IniWriteValue("windows", "AlwaysOnTopMainWindow", this.AlwaysOnTopMainWindow.ToString().ToLower());
            ini.IniWriteValue("windows", "AlwaysOnTopCameraControls", this.AlwaysOnTopCameraControls.ToString().ToLower());
            ini.IniWriteValue("windows", "AlwaysOnTopLists", this.AlwaysOnTopLists.ToString().ToLower());
            ini.IniWriteValue("windows", "LoseFocus", this.LoseFocus.ToString().ToLower());

            ini.IniWriteValue("controls", "sortbynumber", this.CameraControlSortByNumber.ToString().ToLower());
            ini.IniWriteValue("controls", "saferycar", this.CameraControlIncludeSaferyCar.ToString().ToLower());

            ini.IniWriteValue("simulation","api",this.SimulationApiName);
            ini.IniWriteValue("simulation","connectdelay",this.SimulationConnectDelay.ToString());
        }