|
@ -27,11 +27,11 @@ namespace IPA.Config |
|
|
|
|
|
|
|
|
private static readonly ConcurrentBag<Config> configs = new(); |
|
|
private static readonly ConcurrentBag<Config> configs = new(); |
|
|
private static readonly AutoResetEvent configsChangedWatcher = new(false); |
|
|
private static readonly AutoResetEvent configsChangedWatcher = new(false); |
|
|
public static readonly BlockingCollection<IConfigStore> RequiresSave = new(); |
|
|
|
|
|
private static readonly ConcurrentDictionary<DirectoryInfo, FileSystemWatcher> watchers |
|
|
private static readonly ConcurrentDictionary<DirectoryInfo, FileSystemWatcher> watchers |
|
|
= new ConcurrentDictionary<DirectoryInfo, FileSystemWatcher>(new DirInfoEqComparer()); |
|
|
= new ConcurrentDictionary<DirectoryInfo, FileSystemWatcher>(new DirInfoEqComparer()); |
|
|
private static readonly ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>> watcherTrackConfigs |
|
|
private static readonly ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>> watcherTrackConfigs |
|
|
= new ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>>(); |
|
|
= new ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>>(); |
|
|
|
|
|
private static BlockingCollection<IConfigStore> requiresSave = new(); |
|
|
private static SingleThreadTaskScheduler loadScheduler; |
|
|
private static SingleThreadTaskScheduler loadScheduler; |
|
|
private static TaskFactory loadFactory; |
|
|
private static TaskFactory loadFactory; |
|
|
private static Thread saveThread; |
|
|
private static Thread saveThread; |
|
@ -62,6 +62,11 @@ namespace IPA.Config |
|
|
AppDomain.CurrentDomain.ProcessExit += ShutdownRuntime; |
|
|
AppDomain.CurrentDomain.ProcessExit += ShutdownRuntime; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal static void AddRequiresSave(IConfigStore configStore) |
|
|
|
|
|
{ |
|
|
|
|
|
requiresSave?.Add(configStore); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private static void ShutdownRuntime(object sender, EventArgs e) |
|
|
private static void ShutdownRuntime(object sender, EventArgs e) |
|
|
=> ShutdownRuntime(); |
|
|
=> ShutdownRuntime(); |
|
|
internal static void ShutdownRuntime() |
|
|
internal static void ShutdownRuntime() |
|
@ -79,6 +84,9 @@ namespace IPA.Config |
|
|
saveThread.Abort(); // eww, but i don't like any of the other potential solutions
|
|
|
saveThread.Abort(); // eww, but i don't like any of the other potential solutions
|
|
|
|
|
|
|
|
|
SaveAll(); |
|
|
SaveAll(); |
|
|
|
|
|
|
|
|
|
|
|
requiresSave.Dispose(); |
|
|
|
|
|
requiresSave = null; |
|
|
} |
|
|
} |
|
|
catch |
|
|
catch |
|
|
{ |
|
|
{ |
|
@ -218,9 +226,14 @@ namespace IPA.Config |
|
|
|
|
|
|
|
|
private static void SaveThread() |
|
|
private static void SaveThread() |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (requiresSave == null) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
foreach (var item in RequiresSave.GetConsumingEnumerable()) |
|
|
|
|
|
|
|
|
foreach (var item in requiresSave.GetConsumingEnumerable()) |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
@ -242,10 +255,6 @@ namespace IPA.Config |
|
|
{ |
|
|
{ |
|
|
// we got aborted :(
|
|
|
// we got aborted :(
|
|
|
} |
|
|
} |
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
RequiresSave.Dispose(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static void LegacySaveThread() |
|
|
private static void LegacySaveThread() |
|
|