Skip to content

Commit

Permalink
Test whether SDKManifest.xml exists before attempting to read it (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfields-msft authored May 20, 2022
1 parent 959ae02 commit 0058881
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cppwinrt/cmd_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,31 @@ namespace cppwinrt
}
}

enum class xml_requirement
{
required = 0,
optional
};

inline void add_files_from_xml(
std::set<std::string>& 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<IStream> 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<IXmlReader> reader;

Expand Down Expand Up @@ -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() != '+')
{
Expand All @@ -474,7 +488,8 @@ 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).
add_files_from_xml(files, sdk_version, xml_path, sdk_path, xml_requirement::optional);
}

continue;
Expand Down

0 comments on commit 0058881

Please sign in to comment.