Skip to content

Commit

Permalink
xwbtool updates for some POSIX like support (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn authored Mar 27, 2023
1 parent 355806d commit 1c6c988
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Audio/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ namespace
bool mFirst;
Microsoft::WRL::Wrappers::HStringReference mString;

~PropertyIterator() = default;
~PropertyIterator() override = default;
};

class PropertyList : public Microsoft::WRL::RuntimeClass<ABI::Windows::Foundation::Collections::IIterable<HSTRING>>
Expand All @@ -1567,7 +1567,7 @@ namespace
}

private:
~PropertyList() = default;
~PropertyList() override = default;
};

void GetDeviceOutputFormat(const wchar_t* deviceId, WAVEFORMATEX& wfx)
Expand Down
98 changes: 75 additions & 23 deletions XWBTool/xwbtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@

#include <Windows.h>

#if __cplusplus < 201703L
#error Requires C++17 (and /Zc:__cplusplus with MSVC)
#endif

#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cwchar>
#include <cwctype>
#include <filesystem>
#include <fstream>
#include <iterator>
#include <list>
Expand Down Expand Up @@ -986,33 +991,37 @@ namespace
}
else
{
std::filesystem::path path(fname + 1);
auto& npath = path.make_preferred();
if (wcspbrk(fname, L"?*") != nullptr)
{
std::list<SConversion> removeFiles;
SearchForFiles(&fname[1], removeFiles, false);
SearchForFiles(npath.c_str(), removeFiles, false);

for (auto it : removeFiles)
for (auto& it : removeFiles)
{
_wcslwr_s(it.szSrc);
excludes.insert(it.szSrc);
}
}
else
{
std::wstring name = (fname + 1);
std::wstring name = npath.c_str();
std::transform(name.begin(), name.end(), name.begin(), towlower);
excludes.insert(name);
}
}
}
else if (wcspbrk(fname, L"?*") != nullptr)
{
SearchForFiles(fname, flist, false);
std::filesystem::path path(fname);
SearchForFiles(path.make_preferred().c_str(), flist, false);
}
else
{
SConversion conv = {};
wcscpy_s(conv.szSrc, MAX_PATH, fname);
std::filesystem::path path(fname);
wcscpy_s(conv.szSrc, path.make_preferred().c_str());
flist.push_back(conv);
}

Expand Down Expand Up @@ -1047,7 +1056,7 @@ namespace
}
}

void PrintLogo()
void PrintLogo(bool versionOnly)
{
wchar_t version[32] = {};

Expand Down Expand Up @@ -1075,20 +1084,27 @@ namespace
wcscpy_s(version, L"MISSING");
}

wprintf(L"Microsoft (R) XACT-style Wave Bank Tool [DirectXTK] Version %ls\n", version);
wprintf(L"Copyright (C) Microsoft Corp.\n");
#ifdef _DEBUG
wprintf(L"*** Debug build ***\n");
#endif
wprintf(L"\n");
if (versionOnly)
{
wprintf(L"xwbtool version %ls\n", version);
}
else
{
wprintf(L"Microsoft (R) XACT-style Wave Bank Tool [DirectXTK] Version %ls\n", version);
wprintf(L"Copyright (C) Microsoft Corp.\n");
#ifdef _DEBUG
wprintf(L"*** Debug build ***\n");
#endif
wprintf(L"\n");
}
}

void PrintUsage()
{
PrintLogo();
PrintLogo(false);

static const wchar_t* const s_usage =
L"Usage: xwbtool <options> <wav-files>\n"
L"Usage: xwbtool <options> [--] <wav-files>\n"
L"\n"
L" -r wildcard filename search is recursive\n"
L" -s creates a streaming wave bank,\n"
Expand All @@ -1103,7 +1119,9 @@ namespace
L" -nc force creation of non-compact wavebank\n"
L" -f include entry friendly names\n"
L" -nologo suppress copyright message\n"
L" -flist <filename> use text file with a list of input files (one per line)\n";
L" -flist <filename> use text file with a list of input files (one per line)\n"
L"\n"
L" '-- ' is needed if any input filepath starts with the '-' or '/' character\n";

wprintf(L"%ls", s_usage);
}
Expand Down Expand Up @@ -1214,12 +1232,38 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
// Process command line
uint32_t dwOptions = 0;
std::list<SConversion> conversion;
bool allowOpts = true;

for (int iArg = 1; iArg < argc; iArg++)
{
PWSTR pArg = argv[iArg];

if (('-' == pArg[0]) || ('/' == pArg[0]))
if (allowOpts
&& ('-' == pArg[0]) && ('-' == pArg[1]))
{
if (pArg[2] == 0)
{
// "-- " is the POSIX standard for "end of options" marking to escape the '-' and '/' characters at the start of filepaths.
allowOpts = false;
}
else if (!_wcsicmp(pArg, L"--version"))
{
PrintLogo(true);
return 0;
}
else if (!_wcsicmp(pArg, L"--help"))
{
PrintUsage();
return 0;
}
else
{
wprintf(L"Unknown option: %ls\n", pArg);
return 1;
}
}
else if (allowOpts
&& (('-' == pArg[0]) || ('/' == pArg[0])))
{
pArg++;
PWSTR pValue;
Expand Down Expand Up @@ -1262,11 +1306,17 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
switch (dwOption)
{
case OPT_OUTPUTFILE:
wcscpy_s(szOutputFile, MAX_PATH, pValue);
{
std::filesystem::path path(pValue);
wcscpy_s(szOutputFile, path.make_preferred().c_str());
}
break;

case OPT_OUTPUTHEADER:
wcscpy_s(szHeaderFile, MAX_PATH, pValue);
{
std::filesystem::path path(pValue);
wcscpy_s(szHeaderFile, path.make_preferred().c_str());
}
break;

case OPT_ADVANCED_FORMAT:
Expand Down Expand Up @@ -1302,7 +1352,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])

case OPT_FILELIST:
{
std::wifstream inFile(pValue);
std::filesystem::path path(pValue);
std::wifstream inFile(path.make_preferred().c_str());
if (!inFile)
{
wprintf(L"Error opening -flist file %ls\n", pValue);
Expand All @@ -1319,7 +1370,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
else if (wcspbrk(pArg, L"?*") != nullptr)
{
size_t count = conversion.size();
SearchForFiles(pArg, conversion, (dwOptions & (1 << OPT_RECURSIVE)) != 0);
std::filesystem::path path(pArg);
SearchForFiles(path.make_preferred().c_str(), conversion, (dwOptions & (1 << OPT_RECURSIVE)) != 0);
if (conversion.size() <= count)
{
wprintf(L"No matching files found for %ls\n", pArg);
Expand All @@ -1329,8 +1381,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
else
{
SConversion conv = {};
wcscpy_s(conv.szSrc, MAX_PATH, pArg);

std::filesystem::path path(pArg);
wcscpy_s(conv.szSrc, path.make_preferred().c_str());
conversion.push_back(conv);
}
}
Expand All @@ -1343,7 +1395,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}

if (~dwOptions & (1 << OPT_NOLOGO))
PrintLogo();
PrintLogo(false);

// Determine output file name
if (!*szOutputFile)
Expand Down
6 changes: 6 additions & 0 deletions XWBTool/xwbtool_Desktop_2019.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -154,6 +155,7 @@
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -172,6 +174,7 @@
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -190,6 +193,7 @@
<ConformanceMode>false</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -211,6 +215,7 @@
<ConformanceMode>false</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -231,6 +236,7 @@
<ConformanceMode>false</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
6 changes: 6 additions & 0 deletions XWBTool/xwbtool_Desktop_2022.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -155,6 +156,7 @@
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -174,6 +176,7 @@
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -192,6 +195,7 @@
<ConformanceMode>false</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -214,6 +218,7 @@
<ConformanceMode>false</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -235,6 +240,7 @@
<ConformanceMode>false</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus /ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down

0 comments on commit 1c6c988

Please sign in to comment.