Adjusted TempFolder init concepts

Wasn't being awaited in the App ctor.  Swapped for a static factory that can be awaited to ensure initialization is complete
This commit is contained in:
Justin Swanson 2020-04-27 22:17:06 -05:00
parent 3548e42a64
commit 2b0866b4f3
5 changed files with 18 additions and 13 deletions

View File

@ -15,24 +15,28 @@ namespace Wabbajack.Common
static TempFolder()
{
_cleanTask = "tmp_files".RelativeTo(AbsolutePath.EntryPoint).DeleteDirectory();
_cleanTask = Task.Run(() => "tmp_files".RelativeTo(AbsolutePath.EntryPoint).DeleteDirectory());
}
public static async Task EnsureInited()
public static void Init()
{
Utils.Log("Cleaning temp files");
await _cleanTask;
// Nothing to do, as work is done in static ctor
}
public TempFolder(bool deleteAfter = true)
private TempFolder(bool deleteAfter = true)
{
_cleanTask.Wait();
Dir = Path.Combine("tmp_files", Guid.NewGuid().ToString()).RelativeTo(AbsolutePath.EntryPoint);
if (!Dir.Exists)
Dir.CreateDirectory();
DeleteAfter = deleteAfter;
}
public static async Task<TempFolder> Create(bool deleteAfter = true)
{
await _cleanTask;
return new TempFolder(deleteAfter: deleteAfter);
}
public TempFolder(AbsolutePath dir, bool deleteAfter = true)
{
Dir = dir;
@ -42,6 +46,7 @@ namespace Wabbajack.Common
}
DeleteAfter = deleteAfter;
}
public async ValueTask DisposeAsync()
{
Utils.Log($"Deleting {Dir}");

View File

@ -102,7 +102,7 @@ namespace Wabbajack.Lib.Downloaders
try
{
using var queue = new WorkQueue();
await using var folder = new TempFolder();
await using var folder = await TempFolder.Create();
folder.Dir.Combine("tracks").CreateDirectory();
var client = new YoutubeClient(Common.Http.ClientFactory.Client);
var meta = await client.Videos.GetAsync(Key);

View File

@ -25,7 +25,7 @@ namespace Wabbajack.VirtualFileSystem
if (Consts.SupportedBSAs.Contains(source.Extension))
return await ExtractAllWithBSA(queue, source);
else if (source.Extension == Consts.OMOD)
return ExtractAllWithOMOD(source);
return await ExtractAllWithOMOD(source);
else if (source.Extension == Consts.EXE)
return await ExtractAllExe(source);
else
@ -47,7 +47,7 @@ namespace Wabbajack.VirtualFileSystem
return await ExtractAllWith7Zip(source, null);
}
var dest = new TempFolder();
var dest = await TempFolder.Create();
Utils.Log($"Extracting {(string)source.FileName}");
var process = new ProcessHelper
@ -94,9 +94,9 @@ namespace Wabbajack.VirtualFileSystem
}
}
private static ExtractedFiles ExtractAllWithOMOD(AbsolutePath source)
private static async Task<ExtractedFiles> ExtractAllWithOMOD(AbsolutePath source)
{
var dest = new TempFolder();
var dest = await TempFolder.Create();
Utils.Log($"Extracting {(string)source.FileName}");
Framework.Settings.TempPath = (string)dest.Dir;
@ -128,7 +128,7 @@ namespace Wabbajack.VirtualFileSystem
private static async Task<ExtractedFiles> ExtractAllWith7Zip(AbsolutePath source, IEnumerable<RelativePath> onlyFiles)
{
TempFile tmpFile = null;
var dest = new TempFolder();
var dest = await TempFolder.Create();
Utils.Log(new GenericInfo($"Extracting {(string)source.FileName}", $"The contents of {(string)source.FileName} are being extracted to {(string)source.FileName} using 7zip.exe"));
var process = new ProcessHelper

View File

@ -20,7 +20,6 @@ namespace Wabbajack
{
public App()
{
TempFolder.EnsureInited();
CLIOld.ParseOptions(Environment.GetCommandLineArgs());
if (CLIArguments.Help)
CLIOld.DisplayHelpText();

View File

@ -23,6 +23,7 @@ namespace Wabbajack
public MainWindow()
{
TempFolder.Init();
Helpers.Init();
// Wire any unhandled crashing exceptions to log before exiting
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>