From e8490c6f13695fc14532950defe343049f0cd213 Mon Sep 17 00:00:00 2001 From: David Fields <18537467+dfields-msft@users.noreply.github.com> Date: Tue, 10 May 2022 16:06:12 -0700 Subject: [PATCH 1/2] Test whether SDKManifest.xml exists before attempting to read it. --- cppwinrt/cmd_reader.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cppwinrt/cmd_reader.h b/cppwinrt/cmd_reader.h index e50f66036..050acb6c0 100644 --- a/cppwinrt/cmd_reader.h +++ b/cppwinrt/cmd_reader.h @@ -474,7 +474,11 @@ namespace cppwinrt xml_path = item.path() / sdk_version; xml_path /= L"SDKManifest.xml"; - add_files_from_xml(files, sdk_version, xml_path, sdk_path); + // Not all Extension SDKs include an SDKManifest.xml file; ignore those which do not (e.g. WindowsIoT). + if (std::filesystem::is_regular_file(xml_path)) + { + add_files_from_xml(files, sdk_version, xml_path, sdk_path); + } } continue; From 74e640c23ddc5735074b7ea2cab98868b260a8b3 Mon Sep 17 00:00:00 2001 From: David Fields <18537467+dfields-msft@users.noreply.github.com> Date: Wed, 11 May 2022 10:26:50 -0700 Subject: [PATCH 2/2] Check for and conditionally ignore failure from SHCreateStreamOnFileW instead of pre-emptively avoiding the call. --- cppwinrt/cmd_reader.h | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/cppwinrt/cmd_reader.h b/cppwinrt/cmd_reader.h index 050acb6c0..c86cfdcc6 100644 --- a/cppwinrt/cmd_reader.h +++ b/cppwinrt/cmd_reader.h @@ -71,17 +71,31 @@ namespace cppwinrt } } + enum class xml_requirement + { + required = 0, + optional + }; + inline void add_files_from_xml( std::set& files, std::string const& sdk_version, std::filesystem::path const& xml_path, - std::filesystem::path const& sdk_path) + std::filesystem::path const& sdk_path, + xml_requirement xml_path_requirement) { com_ptr stream; - check_xml(SHCreateStreamOnFileW( + auto streamResult = SHCreateStreamOnFileW( xml_path.c_str(), - STGM_READ, &stream.ptr)); + STGM_READ, &stream.ptr); + if (xml_path_requirement == xml_requirement::optional && + (streamResult == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || + streamResult == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND))) + { + return; + } + check_xml(streamResult); com_ptr reader; @@ -462,7 +476,7 @@ namespace cppwinrt xml_path /= sdk_version; xml_path /= L"Platform.xml"; - add_files_from_xml(files, sdk_version, xml_path, sdk_path); + add_files_from_xml(files, sdk_version, xml_path, sdk_path, xml_requirement::required); if (path.back() != '+') { @@ -475,10 +489,7 @@ namespace cppwinrt xml_path /= L"SDKManifest.xml"; // Not all Extension SDKs include an SDKManifest.xml file; ignore those which do not (e.g. WindowsIoT). - if (std::filesystem::is_regular_file(xml_path)) - { - add_files_from_xml(files, sdk_version, xml_path, sdk_path); - } + add_files_from_xml(files, sdk_version, xml_path, sdk_path, xml_requirement::optional); } continue;