Skip to content

Commit

Permalink
Always use CreateFile2
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Dec 6, 2024
1 parent 83bd7fa commit 64e154d
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 175 deletions.
25 changes: 0 additions & 25 deletions Auxiliary/DirectXTexEXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,10 @@ HRESULT DirectX::GetMetadataFromEXRFile(const wchar_t* szFile, TexMetadata& meta
}
}

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(
szFile,
GENERIC_READ, FILE_SHARE_READ,
nullptr,
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN,
nullptr)));
#endif
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -358,19 +349,10 @@ HRESULT DirectX::LoadFromEXRFile(const wchar_t* szFile, TexMetadata* metadata, S
}
}

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(
szFile,
GENERIC_READ, FILE_SHARE_READ,
nullptr,
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN,
nullptr)));
#endif
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -508,19 +490,12 @@ HRESULT DirectX::SaveToEXRFile(const Image& image, const wchar_t* szFile)
}

// Create file and write header
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_WRITE, 0, CREATE_ALWAYS,
nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(
szFile,
GENERIC_WRITE, 0,
nullptr,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
nullptr)));
#endif
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down
32 changes: 12 additions & 20 deletions Auxiliary/DirectXTexXboxDDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,10 @@ HRESULT Xbox::GetMetadataFromDDSFileEx(

isXbox = false;

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
#endif
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -591,13 +589,10 @@ HRESULT Xbox::LoadFromDDSFileEx(

xbox.Release();

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
#endif

ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -742,13 +737,10 @@ HRESULT Xbox::SaveToDDSFile(const XboxImage& xbox, const wchar_t* szFile)
return hr;

// Create file and write header
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile,
GENERIC_WRITE, 0, CREATE_ALWAYS, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile,
GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)));
#endif
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_WRITE, 0, CREATE_ALWAYS,
nullptr)));
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down
18 changes: 9 additions & 9 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},

{
"name": "Win7",
"name": "Win8",
"cacheVariables": {
"BUILD_DX12": false
},
Expand Down Expand Up @@ -294,10 +294,10 @@
{ "name": "arm64-Debug-UWP" , "description": "MSVC for ARM64 (Debug) for UWP", "inherits": [ "base", "ARM64", "Debug", "MSVC", "UWP" ] },
{ "name": "arm64-Release-UWP", "description": "MSVC for ARM64 (Release) for UWP", "inherits": [ "base", "ARM64", "Release", "MSVC", "UWP" ] },

{ "name": "x64-Debug-Win7" , "description": "MSVC for x64 (Debug) for Windows 7", "inherits": [ "base", "x64", "Debug", "MSVC", "Win7" ] },
{ "name": "x64-Release-Win7" , "description": "MSVC for x64 (Release) for Windows 7", "inherits": [ "base", "x64", "Release", "MSVC", "Win7" ] },
{ "name": "x86-Debug-Win7" , "description": "MSVC for x86 (Debug) for Windows 7", "inherits": [ "base", "x86", "Debug", "MSVC", "Win7" ] },
{ "name": "x86-Release-Win7" , "description": "MSVC for x86 (Release) for Windows 7", "inherits": [ "base", "x86", "Release", "MSVC", "Win7" ] },
{ "name": "x64-Debug-Win8" , "description": "MSVC for x64 (Debug) for Windows 8.1", "inherits": [ "base", "x64", "Debug", "MSVC", "Win8" ] },
{ "name": "x64-Release-Win8" , "description": "MSVC for x64 (Release) for Windows 8.1", "inherits": [ "base", "x64", "Release", "MSVC", "Win8" ] },
{ "name": "x86-Debug-Win8" , "description": "MSVC for x86 (Debug) for Windows 8.1", "inherits": [ "base", "x86", "Debug", "MSVC", "Win8" ] },
{ "name": "x86-Release-Win8" , "description": "MSVC for x86 (Release) for Windows 8.1", "inherits": [ "base", "x86", "Release", "MSVC", "Win8" ] },

{ "name": "x64-Debug-Scarlett" , "description": "MSVC for x64 (Debug) for Xbox Series X|S", "inherits": [ "base", "x64", "Debug", "MSVC", "Scarlett" ] },
{ "name": "x64-Release-Scarlett" , "description": "MSVC for x64 (Release) for Xbox Series X|S", "inherits": [ "base", "x64", "Release", "MSVC", "Scarlett" ] },
Expand Down Expand Up @@ -337,10 +337,10 @@
{ "name": "arm64-Debug-UWP-Clang" , "description": "Clang/LLVM for AArch64 (Debug) for UWP", "inherits": [ "base", "ARM64", "Debug", "Clang", "Clang-AArch64", "UWP" ] },
{ "name": "arm64-Release-UWP-Clang", "description": "Clang/LLVM for AArch64 (Release) for UWP", "inherits": [ "base", "ARM64", "Release", "Clang", "Clang-AArch64", "UWP" ] },

{ "name": "x64-Debug-Win7-Clang" , "description": "Clang/LLVM for x64 (Debug) for Windows 7", "inherits": [ "base", "x64", "Debug", "Clang", "Win7" ] },
{ "name": "x64-Release-Win7-Clang", "description": "Clang/LLVM for x64 (Release) for Windows 7", "inherits": [ "base", "x64", "Release", "Clang", "Win7" ] },
{ "name": "x86-Debug-Win7-Clang" , "description": "Clang/LLVM for x86 (Debug) for Windows 7", "inherits": [ "base", "x86", "Debug", "Clang", "Clang-X86", "Win7" ] },
{ "name": "x86-Release-Win7-Clang", "description": "Clang/LLVM for x86 (Release) for Windows 7", "inherits": [ "base", "x86", "Release", "Clang", "Clang-X86", "Win7" ] },
{ "name": "x64-Debug-Win8-Clang" , "description": "Clang/LLVM for x64 (Debug) for Windows 8.1", "inherits": [ "base", "x64", "Debug", "Clang", "Win8" ] },
{ "name": "x64-Release-Win8-Clang", "description": "Clang/LLVM for x64 (Release) for Windows 8.1", "inherits": [ "base", "x64", "Release", "Clang", "Win8" ] },
{ "name": "x86-Debug-Win8-Clang" , "description": "Clang/LLVM for x86 (Debug) for Windows 8.1", "inherits": [ "base", "x86", "Debug", "Clang", "Clang-X86", "Win8" ] },
{ "name": "x86-Release-Win8-Clang", "description": "Clang/LLVM for x86 (Release) for Windows 8.1", "inherits": [ "base", "x86", "Release", "Clang", "Clang-X86", "Win8" ] },

{ "name": "x64-Debug-Clang-VCPKG" , "description": "Clang/LLVM for x64 (Debug) using VCPKG/OpenEXR", "inherits": [ "base", "x64", "Debug", "Clang", "VCPKG" ] },
{ "name": "x64-Release-Clang-VCPKG" , "description": "Clang/LLVM for x64 (Release) using VCPKG/OpenEXR", "inherits": [ "base", "x64", "Release", "Clang", "VCPKG" ] },
Expand Down
10 changes: 0 additions & 10 deletions DDSTextureLoader/DDSTextureLoader11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,10 @@ namespace
*bitSize = 0;

// open the file
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(
fileName,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(
fileName,
GENERIC_READ, FILE_SHARE_READ,
nullptr,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr)));
#endif

if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down
18 changes: 3 additions & 15 deletions DDSTextureLoader/DDSTextureLoader9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,10 @@ namespace
*bitSize = 0;

// open the file
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(fileName,
GENERIC_READ,
FILE_SHARE_READ,
OPEN_EXISTING,
ScopedHandle hFile(safe_handle(CreateFile2(
fileName,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(fileName,
GENERIC_READ,
FILE_SHARE_READ,
nullptr,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
nullptr)));
#endif

if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down
28 changes: 10 additions & 18 deletions DirectXTex/DirectXTexDDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1878,12 +1878,10 @@ HRESULT DirectX::GetMetadataFromDDSFileEx(
return E_INVALIDARG;

#ifdef _WIN32
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
#endif
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -2064,12 +2062,10 @@ HRESULT DirectX::LoadFromDDSFileEx(
image.Release();

#ifdef _WIN32
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
#endif
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -2548,13 +2544,9 @@ HRESULT DirectX::SaveToDDSFile(

// Create file and write header
#ifdef _WIN32
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile,
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_WRITE | DELETE, 0, CREATE_ALWAYS, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile,
GENERIC_WRITE | DELETE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)));
#endif
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down
28 changes: 10 additions & 18 deletions DirectXTex/DirectXTexHDR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,10 @@ HRESULT DirectX::GetMetadataFromHDRFile(const wchar_t* szFile, TexMetadata& meta
return E_INVALIDARG;

#ifdef _WIN32
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
#endif
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -921,12 +919,10 @@ HRESULT DirectX::LoadFromHDRFile(const wchar_t* szFile, TexMetadata* metadata, S
image.Release();

#ifdef _WIN32
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
#endif
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -1144,13 +1140,9 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce

// Create file and write header
#ifdef _WIN32
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile,
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_WRITE, 0, CREATE_ALWAYS, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile,
GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)));
#endif
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down
31 changes: 12 additions & 19 deletions DirectXTex/DirectXTexTGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,12 +1492,10 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TGA_FLAGS flags,
return E_INVALIDARG;

#ifdef _WIN32
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
#endif
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -1758,12 +1756,10 @@ HRESULT DirectX::LoadFromTGAFile(
image.Release();

#ifdef _WIN32
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
#endif
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -2357,13 +2353,10 @@ HRESULT DirectX::SaveToTGAFile(

// Create file and write header
#ifdef _WIN32
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_WRITE, 0,
CREATE_ALWAYS, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(szFile,
GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)));
#endif
ScopedHandle hFile(safe_handle(CreateFile2(
szFile,
GENERIC_WRITE, 0, CREATE_ALWAYS,
nullptr)));
if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down
11 changes: 4 additions & 7 deletions ScreenGrab/ScreenGrab11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,10 @@ HRESULT DirectX::SaveDDSTextureToFile(
return hr;

// Create file
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(fileName,
GENERIC_WRITE | DELETE, 0, CREATE_ALWAYS, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(fileName,
GENERIC_WRITE | DELETE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)));
#endif
ScopedHandle hFile(safe_handle(CreateFile2(
fileName,
GENERIC_WRITE | DELETE, 0, CREATE_ALWAYS,
nullptr)));
if (!hFile)
return HRESULT_FROM_WIN32(GetLastError());

Expand Down
5 changes: 4 additions & 1 deletion ScreenGrab/ScreenGrab12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,10 @@ HRESULT DirectX::SaveDDSTextureToFile(

// Create file
#ifdef _WIN32
ScopedHandle hFile(safe_handle(CreateFile2(fileName, GENERIC_WRITE, 0, CREATE_ALWAYS, nullptr)));
ScopedHandle hFile(safe_handle(CreateFile2(
fileName,
GENERIC_WRITE, 0, CREATE_ALWAYS,
nullptr)));
if (!hFile)
return HRESULT_FROM_WIN32(GetLastError());

Expand Down
11 changes: 4 additions & 7 deletions ScreenGrab/ScreenGrab9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,13 +590,10 @@ HRESULT DirectX::SaveDDSTextureToFile(
}

// Create file
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(fileName,
GENERIC_WRITE | DELETE, 0, CREATE_ALWAYS, nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(fileName,
GENERIC_WRITE | DELETE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)));
#endif
ScopedHandle hFile(safe_handle(CreateFile2(
fileName,
GENERIC_WRITE | DELETE, 0, CREATE_ALWAYS,
nullptr)));
if (!hFile)
return HRESULT_FROM_WIN32(GetLastError());

Expand Down
Loading

0 comments on commit 64e154d

Please sign in to comment.