2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-07-01 16:33:43 -04:00

Export, plugin archive install, and herald cache race condition fixes (#82)

* WIP: Grid export and plugin extraction

* Tweak export process

* Check for recursion of the same assembly load.

* Individual screens aren't always primary?

* Wait for cache to be writable

* Export selection only.

* Update built xml docs

* Ignore invalid archives.

* Need to ensure task is started.
This commit is contained in:
Jonathan Miller
2022-05-09 11:11:57 -02:30
committed by GitHub
parent a67cf7f6bb
commit fb45b5c3e2
10 changed files with 227 additions and 26 deletions

View File

@ -229,7 +229,7 @@ namespace Observatory.Herald
return demonym;
}
private void UpdateAndPruneCache(FileInfo currentFile)
private async void UpdateAndPruneCache(FileInfo currentFile)
{
Dictionary<string, CacheData> cacheIndex;
@ -289,12 +289,40 @@ namespace Observatory.Herald
cacheIndex.Remove(staleFile);
}
File.WriteAllText(cacheIndexFile, JsonSerializer.Serialize(cacheIndex));
// Purge cache from earlier versions, if still present.
var legacyCache = cacheLocation.GetFiles("*.wav");
Array.ForEach(legacyCache, file => File.Delete(file.FullName));
// Race conditions between title and detail speech make a collision here possible.
// Wait for file to become writable, but return control to call site while we wait.
System.Diagnostics.Stopwatch stopwatch = new();
stopwatch.Start();
while (!IsFileWritable(cacheIndexFile) && stopwatch.ElapsedMilliseconds < 1000)
await Task.Factory.StartNew(() => System.Threading.Thread.Sleep(100));
// 1000ms should be more than enough for a conflicting title or detail to complete,
// if we're still waiting something else is locking the file, just give up.
if (stopwatch.ElapsedMilliseconds < 1000)
{
File.WriteAllText(cacheIndexFile, JsonSerializer.Serialize(cacheIndex));
// Purge cache from earlier versions, if still present.
var legacyCache = cacheLocation.GetFiles("*.wav");
Array.ForEach(legacyCache, file => File.Delete(file.FullName));
}
stopwatch.Stop();
}
private static bool IsFileWritable(string path)
{
try
{
using FileStream fs = File.OpenWrite(path);
fs.Close();
return true;
}
catch
{
return false;
}
}
public class CacheData