2022-06-30 01:46:41 +02:00
|
|
|
|
namespace Bit.Core.Test;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2021-02-22 22:35:16 +01:00
|
|
|
|
public class TempDirectory : IDisposable
|
|
|
|
|
{
|
|
|
|
|
public string Directory { get; private set; }
|
|
|
|
|
|
|
|
|
|
public TempDirectory()
|
2022-08-29 21:53:48 +02:00
|
|
|
|
{
|
2021-02-22 22:35:16 +01:00
|
|
|
|
Directory = Path.Combine(Path.GetTempPath(), $"bitwarden_{Guid.NewGuid().ToString().Replace("-", "")}");
|
2022-08-29 21:53:48 +02:00
|
|
|
|
}
|
2021-02-22 22:35:16 +01:00
|
|
|
|
|
|
|
|
|
public override string ToString() => Directory;
|
|
|
|
|
|
|
|
|
|
#region IDisposable implementation
|
|
|
|
|
~TempDirectory()
|
|
|
|
|
{
|
|
|
|
|
Dispose(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
2022-08-29 21:53:48 +02:00
|
|
|
|
{
|
2021-02-22 22:35:16 +01:00
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
2022-08-29 21:53:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-22 22:35:16 +01:00
|
|
|
|
public void Dispose(bool disposing)
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2021-02-22 22:35:16 +01:00
|
|
|
|
if (disposing)
|
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
try
|
2021-02-22 22:35:16 +01:00
|
|
|
|
{
|
|
|
|
|
System.IO.Directory.Delete(Directory, true);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# endregion
|
|
|
|
|
}
|