wabbajack/Wabbajack.Common/Util/TempFolder.cs
Timothy Baldridge bb9ef89dee BSA archives are now lazily extracted.
7Zip extracted archives now only extract the fewest files required.
Audited the uses of .Wait
Lazily init the VFS cleaning
2020-04-16 21:52:19 -06:00

41 lines
1022 B
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Wabbajack.Common
{
public class TempFolder : IAsyncDisposable
{
public AbsolutePath Dir { get; }
public bool DeleteAfter = true;
public TempFolder(bool deleteAfter = true)
{
Dir = Path.Combine("tmp_files", Guid.NewGuid().ToString()).RelativeTo(AbsolutePath.EntryPoint);
if (!Dir.Exists)
Dir.CreateDirectory();
DeleteAfter = deleteAfter;
}
public TempFolder(AbsolutePath dir, bool deleteAfter = true)
{
Dir = dir;
if (!dir.Exists)
{
Dir.Create();
}
DeleteAfter = deleteAfter;
}
public async ValueTask DisposeAsync()
{
if (DeleteAfter && Dir.Exists)
{
await Utils.DeleteDirectory(Dir);
}
}
}
}