mirror of
https://github.com/microsoft/DirectXTex
synced 2024-11-22 12:30:05 +00:00
clean up image files on failed write
This commit is contained in:
parent
51bc3d5b16
commit
b0d443f526
@ -21,30 +21,6 @@ using namespace DirectX;
|
||||
|
||||
namespace
|
||||
{
|
||||
class auto_delete_file
|
||||
{
|
||||
public:
|
||||
auto_delete_file(HANDLE hFile) : m_handle(hFile) {}
|
||||
|
||||
auto_delete_file(const auto_delete_file&) = delete;
|
||||
auto_delete_file& operator=(const auto_delete_file&) = delete;
|
||||
|
||||
~auto_delete_file()
|
||||
{
|
||||
if (m_handle)
|
||||
{
|
||||
FILE_DISPOSITION_INFO info = { 0 };
|
||||
info.DeleteFile = TRUE;
|
||||
(void)SetFileInformationByHandle(m_handle, FileDispositionInfo, &info, sizeof(info));
|
||||
}
|
||||
}
|
||||
|
||||
void clear() { m_handle = 0; }
|
||||
|
||||
private:
|
||||
HANDLE m_handle;
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
// Legacy format mapping table (used for DDS files without 'DX10' extended header)
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
@ -1310,6 +1310,8 @@ HRESULT DirectX::SaveToTGAFile(const Image& image, const wchar_t* szFile)
|
||||
return HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
|
||||
auto_delete_file delonfail(hFile.get());
|
||||
|
||||
// Determine size for TGA pixel data
|
||||
size_t rowPitch, slicePitch;
|
||||
if (convFlags & CONV_FLAGS_888)
|
||||
@ -1392,5 +1394,7 @@ HRESULT DirectX::SaveToTGAFile(const Image& image, const wchar_t* szFile)
|
||||
}
|
||||
}
|
||||
|
||||
delonfail.clear();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
@ -30,3 +30,33 @@ struct handle_closer { void operator()(HANDLE h) { assert(h != INVALID_HANDLE_VA
|
||||
typedef public std::unique_ptr<void, handle_closer> ScopedHandle;
|
||||
|
||||
inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; }
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
struct find_closer { void operator()(HANDLE h) { assert(h != INVALID_HANDLE_VALUE); if (h) FindClose(h); } };
|
||||
|
||||
typedef public std::unique_ptr<void, find_closer> ScopedFindHandle;
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
class auto_delete_file
|
||||
{
|
||||
public:
|
||||
auto_delete_file(HANDLE hFile) : m_handle(hFile) {}
|
||||
|
||||
auto_delete_file(const auto_delete_file&) = delete;
|
||||
auto_delete_file& operator=(const auto_delete_file&) = delete;
|
||||
|
||||
~auto_delete_file()
|
||||
{
|
||||
if (m_handle)
|
||||
{
|
||||
FILE_DISPOSITION_INFO info = { 0 };
|
||||
info.DeleteFile = TRUE;
|
||||
(void)SetFileInformationByHandle(m_handle, FileDispositionInfo, &info, sizeof(info));
|
||||
}
|
||||
}
|
||||
|
||||
void clear() { m_handle = 0; }
|
||||
|
||||
private:
|
||||
HANDLE m_handle;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user