Browse Source

Also abort legacy save thread, null check config Store

feature/system-text-json
Meivyn 1 year ago
parent
commit
8eee59db27
No known key found for this signature in database GPG Key ID: 8BDD3E48158B2F71
2 changed files with 8 additions and 9 deletions
  1. +6
    -7
      IPA.Loader/Config/ConfigRuntime.cs
  2. +2
    -2
      IPA/Program.cs

+ 6
- 7
IPA.Loader/Config/ConfigRuntime.cs View File

@ -27,10 +27,8 @@ 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);
private static readonly ConcurrentDictionary<DirectoryInfo, FileSystemWatcher> watchers
= new ConcurrentDictionary<DirectoryInfo, FileSystemWatcher>(new DirInfoEqComparer());
private static readonly ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>> watcherTrackConfigs
= new ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>>();
private static readonly ConcurrentDictionary<DirectoryInfo, FileSystemWatcher> watchers = new(new DirInfoEqComparer());
private static readonly ConcurrentDictionary<FileSystemWatcher, ConcurrentBag<Config>> watcherTrackConfigs = new();
private static BlockingCollection<IConfigStore> requiresSave = new(); private static BlockingCollection<IConfigStore> requiresSave = new();
private static SingleThreadTaskScheduler loadScheduler; private static SingleThreadTaskScheduler loadScheduler;
private static TaskFactory loadFactory; private static TaskFactory loadFactory;
@ -82,13 +80,14 @@ namespace IPA.Config
loadScheduler.Join(); // we can wait for the loads to finish loadScheduler.Join(); // we can wait for the loads to finish
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
legacySaveThread.Abort();
SaveAll(); SaveAll();
requiresSave.Dispose(); requiresSave.Dispose();
requiresSave = null; requiresSave = null;
} }
catch
catch
{ {
} }
} }
@ -237,7 +236,7 @@ namespace IPA.Config
{ {
try try
{ {
Save(configs.First((c) => ReferenceEquals(c.Store.WriteSyncObject, item.WriteSyncObject)));
Save(configs.First((c) => c.Store != null && ReferenceEquals(c.Store.WriteSyncObject, item.WriteSyncObject)));
} }
catch (ThreadAbortException) catch (ThreadAbortException)
{ {
@ -263,7 +262,7 @@ namespace IPA.Config
{ {
while (true) while (true)
{ {
var configArr = configs.Where(c => c.Store != null).Where(c => c.Store.SyncObject != null).ToArray();
var configArr = configs.Where(c => c.Store?.SyncObject != null).ToArray();
int index = -1; int index = -1;
try try
{ {


+ 2
- 2
IPA/Program.cs View File

@ -334,9 +334,9 @@ namespace IPA
LineBack(); LineBack();
ClearLine(); ClearLine();
} }
catch (Exception ex)
catch (IOException)
{ {
// Might throw IOException due to an invalid handle when accessing IsConsole from a MSBuild task.
// Might throw due to an invalid handle when accessing IsConsole from a MSBuild task.
} }
Console.WriteLine(@"Copying {0}", targetFile.FullName); Console.WriteLine(@"Copying {0}", targetFile.FullName);


Loading…
Cancel
Save