Skip to content

Commit

Permalink
Cherry pick #4389 to 1.7 (#4401)
Browse files Browse the repository at this point in the history
#4389 
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/winget-cli/pull/4401)

Co-authored-by: JohnMcPMS <johnmcp@microsoft.com>
  • Loading branch information
msftrubengu and JohnMcPMS authored Apr 23, 2024
1 parent 3aa9723 commit 36cf71e
Showing 1 changed file with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ namespace UndockedRegFreeWinRT

const UINT32 filter = PACKAGE_FILTER_HEAD | PACKAGE_FILTER_DIRECT | PACKAGE_FILTER_IS_IN_RELATED_SET;
hr = HRESULT_FROM_WIN32(GetCurrentPackageInfo(filter, &dwBufferLength, nullptr, &dwPackagesCount));
// Only find the type if the it is a unpacakged app. Packaged apps can have their exe on their package graph,
// which will allow type resolution against adjacent WinMDs.
// Only find the type next to the exe if the it is an unpackaged app. Packaged apps can have their exe on
// their package graph, which will allow type resolution against adjacent WinMDs.
if (hr == HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE))
{
PCWSTR exeDir = nullptr; // Never freed; owned by process global.
Expand All @@ -498,31 +498,38 @@ namespace UndockedRegFreeWinRT

if (hr == RO_E_METADATA_NAME_NOT_FOUND)
{
PCWSTR dllDir = nullptr; // Never freed; owned by process global.
RETURN_IF_FAILED(GetProcessDllDir(&dllDir));

hr = FindTypeInDirectoryWithNormalization(
pMetaDataDispenser,
pszFullName,
dllDir,
phstrMetaDataFilePath,
ppMetaDataImport,
pmdTypeDef);

if (hr == RO_E_METADATA_NAME_NOT_FOUND)
{
// For compatibility purposes, if we fail to find the type in the unpackaged location, we should return
// HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE) instead of a "not found" error. This preserves the
// behavior that existed before unpackaged type resolution was implemented.
hr = HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE);
}
// For compatibility purposes, if we fail to find the type in the unpackaged location, we should return
// HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE) instead of a "not found" error. This preserves the
// behavior that existed before unpackaged type resolution was implemented.
hr = HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE);
}
return hr;
}
else
{
return RO_E_METADATA_NAME_NOT_FOUND;
}
hr = RO_E_METADATA_NAME_NOT_FOUND;
}

// If not successful looking next to an unpackaged exe, try looking next to our DLL.
if (FAILED(hr))
{
PCWSTR dllDir = nullptr; // Never freed; owned by process global.
RETURN_IF_FAILED(GetProcessDllDir(&dllDir));

HRESULT dllHR = FindTypeInDirectoryWithNormalization(
pMetaDataDispenser,
pszFullName,
dllDir,
phstrMetaDataFilePath,
ppMetaDataImport,
pmdTypeDef);

if (SUCCEEDED(dllHR))
{
hr = dllHR;
}
}

return hr;
}

//
Expand Down

0 comments on commit 36cf71e

Please sign in to comment.