diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c024b2..92212dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -477,7 +477,8 @@ if(BUILD_TOOLS AND BUILD_DX11 AND WIN32) add_executable(texenvmap Texenvmap/texenvmap.cpp Texenvmap/texenvmap.rc - Texenvmap/settings.manifest + Common/CmdLineHelpers.h + Common/settings.manifest ${COMPILED_SHADERS}/Texenvmap_VSBasic.inc) target_compile_features(texenvmap PRIVATE cxx_std_17) target_include_directories(texenvmap PRIVATE ${COMPILED_SHADERS}) diff --git a/Texenvmap/Texenvmap_Desktop_2019.vcxproj b/Texenvmap/Texenvmap_Desktop_2019.vcxproj index 39b80d1..6f99b0b 100644 --- a/Texenvmap/Texenvmap_Desktop_2019.vcxproj +++ b/Texenvmap/Texenvmap_Desktop_2019.vcxproj @@ -134,7 +134,7 @@ MultiThreadedDebugDLL Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) true true @@ -159,7 +159,7 @@ Disabled MultiThreadedDebugDLL Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) true true @@ -183,7 +183,7 @@ MaxSpeed Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) Guard true @@ -210,7 +210,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) Guard true @@ -237,7 +237,7 @@ MaxSpeed Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) true true @@ -264,7 +264,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) true true @@ -297,10 +297,13 @@ - + - + + + + diff --git a/Texenvmap/Texenvmap_Desktop_2019.vcxproj.filters b/Texenvmap/Texenvmap_Desktop_2019.vcxproj.filters index 4658588..92e57ed 100644 --- a/Texenvmap/Texenvmap_Desktop_2019.vcxproj.filters +++ b/Texenvmap/Texenvmap_Desktop_2019.vcxproj.filters @@ -15,11 +15,14 @@ - + + + + + + + Resource Files - - - \ No newline at end of file diff --git a/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj b/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj index 2c44329..4734792 100644 --- a/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj +++ b/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj @@ -191,7 +191,7 @@ MultiThreadedDebugDLL Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -216,7 +216,7 @@ Disabled MultiThreadedDebugDLL Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -240,7 +240,7 @@ Disabled MultiThreadedDebugDLL Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -263,7 +263,7 @@ MaxSpeed Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) Guard true @@ -290,7 +290,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) Guard true @@ -316,7 +316,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) Guard true @@ -342,7 +342,7 @@ MaxSpeed Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -369,7 +369,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -395,7 +395,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -427,10 +427,13 @@ - + - + + + + diff --git a/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj.filters b/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj.filters index 4658588..9f03f10 100644 --- a/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj.filters +++ b/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj.filters @@ -15,11 +15,14 @@ - + + + + Resource Files - + \ No newline at end of file diff --git a/Texenvmap/Texenvmap_Desktop_2022.vcxproj b/Texenvmap/Texenvmap_Desktop_2022.vcxproj index 3031d7f..284cc64 100644 --- a/Texenvmap/Texenvmap_Desktop_2022.vcxproj +++ b/Texenvmap/Texenvmap_Desktop_2022.vcxproj @@ -134,7 +134,7 @@ MultiThreadedDebugDLL Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) true true @@ -159,7 +159,7 @@ Disabled MultiThreadedDebugDLL Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) true true @@ -183,7 +183,7 @@ MaxSpeed Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) Guard true @@ -210,7 +210,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) Guard true @@ -237,7 +237,7 @@ MaxSpeed Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) true true @@ -264,7 +264,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) true true @@ -297,10 +297,13 @@ - + - + + + + diff --git a/Texenvmap/Texenvmap_Desktop_2022.vcxproj.filters b/Texenvmap/Texenvmap_Desktop_2022.vcxproj.filters index 4658588..9f03f10 100644 --- a/Texenvmap/Texenvmap_Desktop_2022.vcxproj.filters +++ b/Texenvmap/Texenvmap_Desktop_2022.vcxproj.filters @@ -15,11 +15,14 @@ - + + + + Resource Files - + \ No newline at end of file diff --git a/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj b/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj index 01ffc00..0616d04 100644 --- a/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj +++ b/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj @@ -191,7 +191,7 @@ MultiThreadedDebugDLL Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -216,7 +216,7 @@ Disabled MultiThreadedDebugDLL Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -240,7 +240,7 @@ Disabled MultiThreadedDebugDLL Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -263,7 +263,7 @@ MaxSpeed Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) Guard true @@ -290,7 +290,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) Guard true @@ -316,7 +316,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) Guard true @@ -342,7 +342,7 @@ MaxSpeed Fast StreamingSIMDExtensions2 - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -369,7 +369,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -395,7 +395,7 @@ Level4 MaxSpeed Fast - $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\DirectXTex;%(AdditionalIncludeDirectories) + $(ProjectDir);$(ProjectDir)Shaders\Compiled;..\Common;..\DirectXTex;%(AdditionalIncludeDirectories) WIN32;NDEBUG;PROFILE;_CONSOLE;_WIN32_WINNT=0x0A00;%(PreprocessorDefinitions) true true @@ -427,10 +427,13 @@ - + - + + + + diff --git a/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj.filters b/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj.filters index 4658588..9f03f10 100644 --- a/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj.filters +++ b/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj.filters @@ -15,11 +15,14 @@ - + + + + Resource Files - + \ No newline at end of file diff --git a/Texenvmap/directx.ico b/Texenvmap/directx.ico deleted file mode 100644 index bc43c1b..0000000 Binary files a/Texenvmap/directx.ico and /dev/null differ diff --git a/Texenvmap/settings.manifest b/Texenvmap/settings.manifest deleted file mode 100644 index 544e45d..0000000 --- a/Texenvmap/settings.manifest +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - true - - - diff --git a/Texenvmap/texenvmap.cpp b/Texenvmap/texenvmap.cpp index 7428166..0b5598d 100644 --- a/Texenvmap/texenvmap.cpp +++ b/Texenvmap/texenvmap.cpp @@ -44,7 +44,6 @@ #include #include #include -#include #include #include #include @@ -77,11 +76,18 @@ #include "DirectXTexPNG.h" #endif +#define TOOL_VERSION DIRECTX_TEX_VERSION +#include "CmdLineHelpers.h" + +using namespace Helpers; using namespace DirectX; using Microsoft::WRL::ComPtr; namespace { + const wchar_t* g_ToolName = L"texenvmap"; + const wchar_t* g_Description = L"Microsoft (R) DirectX Environment Map Tool [DirectXTex]"; + enum COMMANDS : uint32_t { CMD_CUBIC = 1, @@ -117,22 +123,11 @@ namespace static_assert(OPT_MAX <= 32, "dwOptions is a unsigned int bitfield"); - struct SConversion - { - std::wstring szSrc; - }; - - struct SValue - { - const wchar_t* name; - uint32_t value; - }; - ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - const SValue g_pCommands[] = + const SValue g_pCommands[] = { { L"cubic", CMD_CUBIC }, { L"sphere", CMD_SPHERE }, @@ -140,7 +135,7 @@ namespace { nullptr, 0 } }; - const SValue g_pOptions[] = + const SValue g_pOptions[] = { { L"r", OPT_RECURSIVE }, { L"flist", OPT_FILELIST }, @@ -165,9 +160,9 @@ namespace { nullptr, 0 } }; -#define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt } + #define DEFFMT(fmt) { L## #fmt, DXGI_FORMAT_ ## fmt } - const SValue g_pFormats[] = + const SValue g_pFormats[] = { // List only includes render target supported formats DEFFMT(R32G32B32A32_FLOAT), @@ -197,7 +192,9 @@ namespace { nullptr, DXGI_FORMAT_UNKNOWN } }; - const SValue g_pFormatAliases[] = + #undef DEFFMT + + const SValue g_pFormatAliases[] = { { L"RGBA", DXGI_FORMAT_R8G8B8A8_UNORM }, { L"BGRA", DXGI_FORMAT_B8G8R8A8_UNORM }, @@ -209,7 +206,7 @@ namespace { nullptr, DXGI_FORMAT_UNKNOWN } }; - const SValue g_pFilters[] = + const SValue g_pFilters[] = { { L"POINT", TEX_FILTER_POINT }, { L"LINEAR", TEX_FILTER_LINEAR }, @@ -246,7 +243,7 @@ namespace #define CODEC_PNG 0xFFFF0008 #endif - const SValue g_pExtFileTypes[] = + const SValue g_pExtFileTypes[] = { { L".BMP", WIC_CODEC_BMP }, #ifdef USE_LIBJPEG @@ -293,183 +290,6 @@ namespace namespace { - inline HANDLE safe_handle(HANDLE h) noexcept { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; } - - struct find_closer { void operator()(HANDLE h) noexcept { assert(h != INVALID_HANDLE_VALUE); if (h) FindClose(h); } }; - - using ScopedFindHandle = std::unique_ptr; - -#ifdef _PREFAST_ -#pragma prefast(disable : 26018, "Only used with static internal arrays") -#endif - - uint32_t LookupByName(const wchar_t *pName, const SValue *pArray) - { - while (pArray->name) - { - if (!_wcsicmp(pName, pArray->name)) - return pArray->value; - - pArray++; - } - - return 0; - } - - void SearchForFiles(const std::filesystem::path& path, std::list& files, bool recursive) - { - // Process files - WIN32_FIND_DATAW findData = {}; - ScopedFindHandle hFile(safe_handle(FindFirstFileExW(path.c_str(), - FindExInfoBasic, &findData, - FindExSearchNameMatch, nullptr, - FIND_FIRST_EX_LARGE_FETCH))); - if (hFile) - { - for (;;) - { - if (!(findData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY))) - { - SConversion conv = {}; - conv.szSrc = path.parent_path().append(findData.cFileName).native(); - files.push_back(conv); - } - - if (!FindNextFileW(hFile.get(), &findData)) - break; - } - } - - // Process directories - if (recursive) - { - auto searchDir = path.parent_path().append(L"*"); - - hFile.reset(safe_handle(FindFirstFileExW(searchDir.c_str(), - FindExInfoBasic, &findData, - FindExSearchLimitToDirectories, nullptr, - FIND_FIRST_EX_LARGE_FETCH))); - if (!hFile) - return; - - for (;;) - { - if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - { - if (findData.cFileName[0] != L'.') - { - auto subdir = path.parent_path().append(findData.cFileName).append(path.filename().c_str()); - - SearchForFiles(subdir, files, recursive); - } - } - - if (!FindNextFileW(hFile.get(), &findData)) - break; - } - } - } - - void ProcessFileList(std::wifstream& inFile, std::list& files) - { - std::list flist; - std::set excludes; - - for (;;) - { - std::wstring fname; - std::getline(inFile, fname); - if (!inFile) - break; - - if (fname[0] == L'#') - { - // Comment - } - else if (fname[0] == L'-') - { - if (flist.empty()) - { - wprintf(L"WARNING: Ignoring the line '%ls' in -flist\n", fname.c_str()); - } - else - { - std::filesystem::path path(fname.c_str() + 1); - auto& npath = path.make_preferred(); - if (wcspbrk(fname.c_str(), L"?*") != nullptr) - { - std::list removeFiles; - SearchForFiles(npath, removeFiles, false); - - for (auto& it : removeFiles) - { - std::wstring name = it.szSrc; - std::transform(name.begin(), name.end(), name.begin(), towlower); - excludes.insert(name); - } - } - else - { - std::wstring name = npath.c_str(); - std::transform(name.begin(), name.end(), name.begin(), towlower); - excludes.insert(name); - } - } - } - else if (wcspbrk(fname.c_str(), L"?*") != nullptr) - { - std::filesystem::path path(fname.c_str()); - SearchForFiles(path.make_preferred(), flist, false); - } - else - { - SConversion conv = {}; - std::filesystem::path path(fname.c_str()); - conv.szSrc = path.make_preferred().native(); - flist.push_back(conv); - } - } - - inFile.close(); - - if (!excludes.empty()) - { - // Remove any excluded files - for (auto it = flist.begin(); it != flist.end();) - { - std::wstring name = it->szSrc; - std::transform(name.begin(), name.end(), name.begin(), towlower); - auto item = it; - ++it; - if (excludes.find(name) != excludes.end()) - { - flist.erase(item); - } - } - } - - if (flist.empty()) - { - wprintf(L"WARNING: No file names found in -flist\n"); - } - else - { - files.splice(files.end(), flist); - } - } - - void PrintFormat(DXGI_FORMAT Format) - { - for (auto pFormat = g_pFormats; pFormat->name; pFormat++) - { - if (static_cast(pFormat->value) == Format) - { - wprintf(L"%ls", pFormat->name); - break; - } - } - } - void PrintInfo(const TexMetadata& info) { wprintf(L" (%zux%zu", info.width, info.height); @@ -484,7 +304,7 @@ namespace wprintf(L",%zu", info.arraySize); wprintf(L" "); - PrintFormat(info.format); + PrintFormat(info.format, g_pFormats); switch (info.dimension) { @@ -529,106 +349,6 @@ namespace wprintf(L")"); } - void PrintList(size_t cch, const SValue *pValue) - { - while (pValue->name) - { - const size_t cchName = wcslen(pValue->name); - - if (cch + cchName + 2 >= 80) - { - wprintf(L"\n "); - cch = 6; - } - - wprintf(L"%ls ", pValue->name); - cch += cchName + 2; - pValue++; - } - - wprintf(L"\n"); - } - - void PrintLogo(bool versionOnly) - { - wchar_t version[32] = {}; - - wchar_t appName[_MAX_PATH] = {}; - if (GetModuleFileNameW(nullptr, appName, _MAX_PATH)) - { - const DWORD size = GetFileVersionInfoSizeW(appName, nullptr); - if (size > 0) - { - auto verInfo = std::make_unique(size); - if (GetFileVersionInfoW(appName, 0, size, verInfo.get())) - { - LPVOID lpstr = nullptr; - UINT strLen = 0; - if (VerQueryValueW(verInfo.get(), L"\\StringFileInfo\\040904B0\\ProductVersion", &lpstr, &strLen)) - { - wcsncpy_s(version, reinterpret_cast(lpstr), strLen); - } - } - } - } - - if (!*version || wcscmp(version, L"1.0.0.0") == 0) - { - swprintf_s(version, L"%03d (library)", DIRECTX_TEX_VERSION); - } - - if (versionOnly) - { - wprintf(L"texenvmap version %ls\n", version); - } - else - { - wprintf(L"Microsoft (R) DirectX Environment Map Tool [DirectXTex] Version %ls\n", version); - wprintf(L"Copyright (C) Microsoft Corp.\n"); - #ifdef _DEBUG - wprintf(L"*** Debug build ***\n"); - #endif - wprintf(L"\n"); - } - } - - const wchar_t* GetErrorDesc(HRESULT hr) - { - static wchar_t desc[1024] = {}; - - LPWSTR errorText = nullptr; - - const DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER, - nullptr, static_cast(hr), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast(&errorText), 0, nullptr); - - *desc = 0; - - if (result > 0 && errorText) - { - swprintf_s(desc, L": %ls", errorText); - - size_t len = wcslen(desc); - if (len >= 1) - { - desc[len - 1] = 0; - } - - if (errorText) - LocalFree(errorText); - - for (wchar_t* ptr = desc; *ptr != 0; ++ptr) - { - if (*ptr == L'\r' || *ptr == L'\n') - { - *ptr = L' '; - } - } - } - - return desc; - } - _Success_(return != false) bool GetDXGIFactory(_Outptr_ IDXGIFactory1** pFactory) noexcept { @@ -655,10 +375,9 @@ namespace return SUCCEEDED(s_CreateDXGIFactory1(IID_PPV_ARGS(pFactory))); } - void PrintUsage() { - PrintLogo(false); + PrintLogo(false, g_ToolName, g_Description); static const wchar_t* const s_usage = L"Usage: texenvmap [--] \n\n" @@ -714,7 +433,6 @@ namespace } } - _Success_(return != false) bool CreateDevice(int adapter, _Outptr_ ID3D11Device** pDevice) noexcept { @@ -1329,9 +1047,6 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) // Set locale for output since GetErrorDesc can get localized strings. std::locale::global(std::locale("")); - // Set locale for output since GetErrorDesc can get localized strings. - std::locale::global(std::locale("")); - // Initialize COM (needed for WIC) HRESULT hr = hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); if (FAILED(hr)) @@ -1347,6 +1062,20 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 0; } + if (('-' == argv[1][0]) && ('-' == argv[1][1])) + { + if (!_wcsicmp(argv[1], L"--version")) + { + PrintLogo(true, g_ToolName, g_Description); + return 0; + } + else if (!_wcsicmp(argv[1], L"--help")) + { + PrintUsage(); + return 0; + } + } + const uint32_t dwCommand = LookupByName(argv[1], g_pCommands); switch (dwCommand) { @@ -1379,7 +1108,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } else if (!_wcsicmp(pArg, L"--version")) { - PrintLogo(true); + PrintLogo(true, g_ToolName, g_Description); return 0; } else if (!_wcsicmp(pArg, L"--help")) @@ -1574,7 +1303,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { const size_t count = conversion.size(); std::filesystem::path path(pArg); - SearchForFiles(path.make_preferred(), conversion, (dwOptions & (1 << OPT_RECURSIVE)) != 0); + SearchForFiles(path.make_preferred(), conversion, (dwOptions & (1 << OPT_RECURSIVE)) != 0, nullptr); if (conversion.size() <= count) { wprintf(L"No matching files found for %ls\n", pArg); @@ -1597,7 +1326,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } if (~dwOptions & (1 << OPT_NOLOGO)) - PrintLogo(false); + PrintLogo(false, g_ToolName, g_Description); ComPtr pDevice; if (!CreateDevice(adapter, pDevice.GetAddressOf())) @@ -1641,7 +1370,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) if (FAILED(hr) || ((support & required) != required)) { wprintf(L"\nERROR: Direct3D device does not support format as a render target (DXGI_FORMAT_"); - PrintFormat(format); + PrintFormat(format, g_pFormats); wprintf(L")\n"); return 1; } diff --git a/Texenvmap/texenvmap.rc b/Texenvmap/texenvmap.rc index 31e6500..d12b573 100644 --- a/Texenvmap/texenvmap.rc +++ b/Texenvmap/texenvmap.rc @@ -28,7 +28,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. -IDI_MAIN_ICON ICON "directx.ico" +IDI_MAIN_ICON ICON "..\\Common\\directx.ico" #ifdef APSTUDIO_INVOKED