Default to in-memory AppConfig and UserConfig

This commit is contained in:
Ben Olden-Cooligan 2018-11-26 14:09:50 -05:00
parent 2b1dc944f3
commit e3a7d16002
7 changed files with 55 additions and 9 deletions

View File

@ -76,11 +76,7 @@ namespace NAPS2.DI.Modules
Bind<IBlankDetector>().To<ThresholdBlankDetector>();
Bind<IAutoSave>().To<AutoSave>();
Log.Logger = new NLogLogger();
if (PlatformCompat.System.CanUseWin32)
{
Log.EventLogger = Kernel.Get<WindowsEventLogger>();
}
StaticConfiguration.Initialize();
#if DEBUG
Debug.Listeners.Add(new NLogTraceListener());
#endif

View File

@ -94,6 +94,7 @@
<Compile Include="NLogLogger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="EntryPoints\WinFormsEntryPoint.cs" />
<Compile Include="StaticConfiguration.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NAPS2.Config;
using NAPS2.Logging;
using NAPS2.Platform;
namespace NAPS2.DI
{
public static class StaticConfiguration
{
public static void Initialize()
{
Log.Logger = new NLogLogger();
if (PlatformCompat.System.CanUseWin32)
{
Log.EventLogger = new WindowsEventLogger();
}
UserConfig.Manager = new ConfigManager<UserConfig>("config.xml", Paths.AppData, Paths.Executable, () => new UserConfig { Version = UserConfig.CURRENT_VERSION });
AppConfig.Manager = new ConfigManager<AppConfig>("appsettings.xml", Paths.Executable, null, () => new AppConfig { Version = AppConfig.CURRENT_VERSION });
}
}
}

View File

@ -13,7 +13,7 @@ namespace NAPS2.Config
{
public const int CURRENT_VERSION = 2;
private static IConfigManager<AppConfig> _manager = new ConfigManager<AppConfig>("appsettings.xml", Paths.Executable, null, () => new AppConfig { Version = CURRENT_VERSION });
private static IConfigManager<AppConfig> _manager = new StubConfigManager<AppConfig>(new AppConfig { Version = CURRENT_VERSION });
public static IConfigManager<AppConfig> Manager
{
@ -76,14 +76,14 @@ namespace NAPS2.Config
public double OcrTimeoutInSeconds { get; set; }
public OcrState OcrState { get; set; }
public string OcrDefaultLanguage { get; set; }
public OcrMode OcrDefaultMode { get; set; }
public bool OcrDefaultAfterScanning { get; set; }
public PdfCompat ForcePdfCompat { get; set; }
public PdfCompat ForcePdfCompat { get; set; }
public EventType EventLogging { get; set; }

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace NAPS2.Config
{
public class StubConfigManager<T> : IConfigManager<T>
{
public StubConfigManager(T config)
{
Config = config;
}
public T Config { get; }
public void Load()
{
}
public void Save()
{
}
}
}

View File

@ -16,7 +16,7 @@ namespace NAPS2.Config
{
public const int CURRENT_VERSION = 2;
private static IConfigManager<UserConfig> _manager = new ConfigManager<UserConfig>("config.xml", Paths.AppData, Paths.Executable, () => new UserConfig { Version = CURRENT_VERSION });
private static IConfigManager<UserConfig> _manager = new StubConfigManager<UserConfig>(new UserConfig { Version = CURRENT_VERSION });
public static IConfigManager<UserConfig> Manager
{

View File

@ -157,6 +157,7 @@
<Compile Include="ClientServer\ScanCallback.cs" />
<Compile Include="ClientServer\ScanService.cs" />
<Compile Include="ClientServer\ServerDiscovery.cs" />
<Compile Include="Config\StubConfigManager.cs" />
<Compile Include="Dependencies\ComponentManager.cs" />
<Compile Include="Dependencies\DownloadMirror.cs" />
<Compile Include="Dependencies\MultiFileExternalComponent.cs" />