mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
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:
parent
3548e42a64
commit
2b0866b4f3
@ -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}");
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -20,7 +20,6 @@ namespace Wabbajack
|
||||
{
|
||||
public App()
|
||||
{
|
||||
TempFolder.EnsureInited();
|
||||
CLIOld.ParseOptions(Environment.GetCommandLineArgs());
|
||||
if (CLIArguments.Help)
|
||||
CLIOld.DisplayHelpText();
|
||||
|
@ -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) =>
|
||||
|
Loading…
Reference in New Issue
Block a user