Allow users to have multiple configuration files
This commit is contained in:
@@ -7,21 +7,23 @@ namespace EveOPreview.Configuration
|
||||
{
|
||||
private const string ConfigurationFileName = "EVE-O Preview.json";
|
||||
|
||||
private readonly IAppConfig _configuration;
|
||||
private readonly IThumbnailConfig _configuration;
|
||||
|
||||
public ConfigurationStorage(IAppConfig configuration)
|
||||
public ConfigurationStorage(IThumbnailConfig configuration)
|
||||
{
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
public void Load()
|
||||
{
|
||||
if (!File.Exists(ConfigurationStorage.ConfigurationFileName))
|
||||
string filename = this.GetConfigFileName();
|
||||
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string rawData = File.ReadAllText(ConfigurationStorage.ConfigurationFileName);
|
||||
string rawData = File.ReadAllText(filename);
|
||||
|
||||
JsonConvert.PopulateObject(rawData, this._configuration);
|
||||
|
||||
@@ -33,7 +35,12 @@ namespace EveOPreview.Configuration
|
||||
{
|
||||
string rawData = JsonConvert.SerializeObject(this._configuration, Formatting.Indented);
|
||||
|
||||
File.WriteAllText(ConfigurationStorage.ConfigurationFileName, rawData);
|
||||
File.WriteAllText(this.GetConfigFileName(), rawData);
|
||||
}
|
||||
|
||||
private string GetConfigFileName()
|
||||
{
|
||||
return string.IsNullOrEmpty(this._configuration.ConfigFileName) ? ConfigurationStorage.ConfigurationFileName : this._configuration.ConfigFileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,10 @@ using System.Windows.Forms;
|
||||
|
||||
namespace EveOPreview.Configuration
|
||||
{
|
||||
public interface IAppConfig
|
||||
public interface IThumbnailConfig
|
||||
{
|
||||
string ConfigFileName { get; set; }
|
||||
|
||||
bool MinimizeToTray { get; set; }
|
||||
int ThumbnailRefreshPeriod { get; set; }
|
||||
|
||||
@@ -5,11 +5,13 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace EveOPreview.Configuration
|
||||
{
|
||||
public class AppConfig : IAppConfig
|
||||
public class ThumbnailConfig : IThumbnailConfig
|
||||
{
|
||||
public AppConfig()
|
||||
public ThumbnailConfig()
|
||||
{
|
||||
// Default values
|
||||
this.ConfigFileName = null;
|
||||
|
||||
this.MinimizeToTray = false;
|
||||
this.ThumbnailRefreshPeriod = 500;
|
||||
|
||||
@@ -41,6 +43,9 @@ namespace EveOPreview.Configuration
|
||||
this.ClientHotkey = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public string ConfigFileName { get; set; }
|
||||
|
||||
public bool MinimizeToTray { get; set; }
|
||||
public int ThumbnailRefreshPeriod { get; set; }
|
||||
|
||||
@@ -163,11 +168,11 @@ namespace EveOPreview.Configuration
|
||||
/// </summary>
|
||||
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);
|
||||
this.ThumbnailRefreshPeriod = ThumbnailConfig.ApplyRestrictions(this.ThumbnailRefreshPeriod, 300, 1000);
|
||||
this.ThumbnailSize = new Size(ThumbnailConfig.ApplyRestrictions(this.ThumbnailSize.Width, this.ThumbnailMinimumSize.Width, this.ThumbnailMaximumSize.Width),
|
||||
ThumbnailConfig.ApplyRestrictions(this.ThumbnailSize.Height, this.ThumbnailMinimumSize.Height, this.ThumbnailMaximumSize.Height));
|
||||
this.ThumbnailOpacity = ThumbnailConfig.ApplyRestrictions((int)(this.ThumbnailOpacity * 100.00), 20, 100) / 100.00;
|
||||
this.ThumbnailZoomFactor = ThumbnailConfig.ApplyRestrictions(this.ThumbnailZoomFactor, 2, 10);
|
||||
}
|
||||
|
||||
private static int ApplyRestrictions(int value, int minimum, int maximum)
|
||||
Reference in New Issue
Block a user