mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-11-12 23:32:42 -05:00
[CLI] Fix deleting of temp files
This commit is contained in:
@ -196,7 +196,7 @@ namespace AssetStudio
|
||||
var hash = path.GetHashCode();
|
||||
path = Path.Combine(tempDir, $"{filename}_{hash:X}");
|
||||
}
|
||||
return new FileStream(path + ".temp", FileMode.Create, FileAccess.ReadWrite, FileShare.Read, 4096, FileOptions.DeleteOnClose);
|
||||
return new TempFileStream(path + ".temp", FileMode.Create);
|
||||
}
|
||||
|
||||
private Stream ReadBlocksAndDirectory(FileReader reader)
|
||||
|
||||
40
AssetStudio/TempFileStream.cs
Normal file
40
AssetStudio/TempFileStream.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public class TempFileStream : FileStream
|
||||
{
|
||||
private readonly string _tempFilePath;
|
||||
private bool _disposed;
|
||||
|
||||
public TempFileStream(string path, FileMode fileMode, FileAccess fileAccess = FileAccess.ReadWrite, FileShare fileShare = FileShare.Read, int bufferSize = 4096)
|
||||
: base(path, fileMode, fileAccess, fileShare, bufferSize, FileOptions.DeleteOnClose)
|
||||
{
|
||||
_tempFilePath = path;
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && File.Exists(_tempFilePath))
|
||||
{
|
||||
File.Delete(_tempFilePath);
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -73,6 +73,7 @@ namespace AssetStudioCLI
|
||||
}
|
||||
finally
|
||||
{
|
||||
Studio.Clear();
|
||||
cliLogger.LogToFile(LoggerEvent.Verbose, "---Program ended---");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1303,5 +1303,11 @@ namespace AssetStudioCLI
|
||||
"Nothing exported.";
|
||||
Logger.Default.Log(LoggerEvent.Info, status, ignoreLevel: true);
|
||||
}
|
||||
|
||||
public static void Clear()
|
||||
{
|
||||
assetsManager.Clear();
|
||||
assemblyLoader.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user