diff --git a/Eve-O-Preview/Configuration/AppConfig.cs b/Eve-O-Preview/Configuration/AppConfig.cs index 150bb52..f78f891 100644 --- a/Eve-O-Preview/Configuration/AppConfig.cs +++ b/Eve-O-Preview/Configuration/AppConfig.cs @@ -157,5 +157,32 @@ namespace EveOPreview.Configuration { this.ClientHotkey[currentClient] = (new KeysConverter()).ConvertToInvariantString(hotkey); } + + /// + /// Applies restrictions to different parameters of the config + /// + public void ApplyRestrictions() + { + this.ThumbnailRefreshPeriod = AppConfig.ApplyRestrictions(this.ThumbnailRefreshPeriod, 300, 1000); + this.ThumbnailSize = new Size(AppConfig.ApplyRestrictions(this.ThumbnailSize.Width, this.ThumbnailMinimumSize.Width, this.ThumbnailMaximumSize.Width), + AppConfig.ApplyRestrictions(this.ThumbnailSize.Height, this.ThumbnailMinimumSize.Height, this.ThumbnailMaximumSize.Height)); + this.ThumbnailOpacity = AppConfig.ApplyRestrictions((int)(this.ThumbnailOpacity * 100.00), 20, 100) / 100.00; + this.ThumbnailZoomFactor = AppConfig.ApplyRestrictions(this.ThumbnailZoomFactor, 2, 10); + } + + private static int ApplyRestrictions(int value, int minimum, int maximum) + { + if (value <= minimum) + { + return minimum; + } + + if (value >= maximum) + { + return maximum; + } + + return value; + } } } \ No newline at end of file diff --git a/Eve-O-Preview/Configuration/ConfigurationStorage.cs b/Eve-O-Preview/Configuration/ConfigurationStorage.cs index 076d967..513b73e 100644 --- a/Eve-O-Preview/Configuration/ConfigurationStorage.cs +++ b/Eve-O-Preview/Configuration/ConfigurationStorage.cs @@ -24,6 +24,9 @@ namespace EveOPreview.Configuration string rawData = File.ReadAllText(ConfigurationStorage.ConfigurationFileName); JsonConvert.PopulateObject(rawData, this._configuration); + + // Validate data after loading it + this._configuration.ApplyRestrictions(); } public void Save() diff --git a/Eve-O-Preview/Configuration/IAppConfig.cs b/Eve-O-Preview/Configuration/IAppConfig.cs index 3c75043..5e2cd81 100644 --- a/Eve-O-Preview/Configuration/IAppConfig.cs +++ b/Eve-O-Preview/Configuration/IAppConfig.cs @@ -38,5 +38,7 @@ namespace EveOPreview.Configuration Keys GetClientHotkey(string currentClient); void SetClientHotkey(string currentClient, Keys hotkey); + + void ApplyRestrictions(); } } \ No newline at end of file