Beispiel #1
0
        // Returns true when file settings are active
        public bool Startup()
        {
            if (RawAccelSettings.Exists())
            {
                try
                {
                    RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields());
                    UpdateFieldsFromGUISettings();
                    if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup)
                    {
                        TryUpdateAccel(RawAccelSettings.AccelerationSettings);
                    }
                    return(RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup);
                }
                catch (JsonException e)
                {
                    Console.WriteLine($"bad settings: {e}");
                }
            }

            RawAccelSettings = new RawAccelSettings(
                DriverInterop.GetActiveSettings(),
                MakeGUISettingsFromFields());
            RawAccelSettings.Save();
            return(true);
        }
Beispiel #2
0
        public SettingsErrors TryUpdateActiveSettings(DriverSettings settings)
        {
            var errors = TryUpdateAccel(settings);

            if (errors.Empty())
            {
                RawAccelSettings.AccelerationSettings = settings;
                RawAccelSettings.GUISettings          = MakeGUISettingsFromFields();
                RawAccelSettings.Save();
            }

            return(errors);
        }
Beispiel #3
0
        public void Startup()
        {
            if (RawAccelSettings.Exists())
            {
                try
                {
                    RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields());
                    UpdateFieldsFromGUISettings();
                    UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings);
                    return;
                }
                catch (JsonException e)
                {
                    Console.WriteLine($"bad settings: {e}");
                }
            }

            RawAccelSettings = new RawAccelSettings(
                DriverInterop.GetActiveSettings(),
                MakeGUISettingsFromFields());
            RawAccelSettings.Save();
        }
Beispiel #4
0
        public static RawAccelSettings Load(string file, Func <GUISettings> DefaultGUISettingsSupplier)
        {
            try
            {
                RawAccelSettings settings = null;

                JObject settingsJObject = JObject.Parse(File.ReadAllText(file));
                if (settingsJObject.ContainsKey(DriverSettings.Key))
                {
                    settings = settingsJObject.ToObject <RawAccelSettings>(JsonSerializer.Create(SerializerSettings));
                }
                else
                {
                    settings = new RawAccelSettings
                    {
                        AccelerationSettings = settingsJObject.ToObject <DriverSettings>(),
                        GUISettings          = DefaultGUISettingsSupplier()
                    };
                }

                if (settings is null || settings.AccelerationSettings is null)
                {
                    throw new JsonException($"{file} contains invalid JSON");
                }

                return(settings);
            }
            catch (FileNotFoundException e)
            {
                throw new FileNotFoundException($"Settings file does not exist at {file}", e);
            }
            catch (JsonException e)
            {
                throw new JsonException($"Settings file at {file} does not contain valid Raw Accel Settings.", e);
            }
        }