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