Skip to content

Commit d5afea6

Browse files
yeelam-gordonCopilotCopilot
authored
Fix sparse-packaged apps unable to discover module-specific PRI files (#6376)
* Fix sparse-packaged apps unable to discover module-specific PRI files Sparse-packaged apps have package identity (via AddPackageByUriAsync) but deploy resources as loose files next to the executable. GetDefaultPriFile() determines isPackaged=true for these apps (since they have identity), causing GetDefaultPriFileForCurentModule to pass "resources.pri" to MrmGetFilePathFromName — which only searches for that exact filename, skipping the [modulename].pri fallback that unpackaged apps receive. When the "resources.pri" search fails for apps with identity, fall back to the unpackaged discovery path (pass nullptr to MrmGetFilePathFromName) which triggers the broader search including "[modulename].pri" derived via PathCchRenameExtension from the process executable name. If the fallback also fails, return the original HRESULT from the "resources.pri" search so callers that check for specific errors (e.g., ERROR_FILE_NOT_FOUND) are not broken. Existing test coverage: - DefaultResourceManagerWithExePri validates the nullptr fallback mechanism - DefaultResourceManager validates error behavior when no PRI exists - DefaultResourceManagerWithResourcePri validates the normal packaged path A full sparse-app integration test requires actual sparse package registration (AddPackageByUriAsync) which is beyond unit test scope. Fixes: microsoft/microsoft-ui-xaml#10856 Co-authored-by: Copilot <[email protected]> * Address PR review: simplify flow, shorten comment, gate on file-not-found * Add backward-compatibility comment on return hr * Move backward-compat comment to fallback block for clarity * Keep comment sentences on single lines * Use existing IsResourceNotFound() helper instead of manual HRESULT checks * Merge two-line comment into single line Agent-Logs-Url: https://github.com/microsoft/WindowsAppSDK/sessions/ed36cfc6-52ad-414b-8e1a-dc16f413a97e Co-authored-by: yeelam-gordon <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
1 parent 7c324df commit d5afea6

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

  • dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src

dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/Helper.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,19 @@ HRESULT GetDefaultPriFile(winrt::hstring& filePath)
8484
// GetDefaultPriFileForCurrentPackage will not handle the new case where
8585
// resources.pri is in the parent folder.
8686
bool isPackaged = (hr != HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE));
87-
return GetDefaultPriFileForCurentModule(isPackaged, filePath);
87+
hr = GetDefaultPriFileForCurentModule(isPackaged, filePath);
88+
89+
// Sparse-packaged apps have identity but deploy PRI files as loose files; fall back to unpackaged discovery which also searches for "[modulename].pri".
90+
if (isPackaged && IsResourceNotFound(hr))
91+
{
92+
HRESULT hrFallback = GetDefaultPriFileForCurentModule(false, filePath);
93+
if (SUCCEEDED(hrFallback))
94+
{
95+
hr = hrFallback;
96+
}
97+
// If the fallback also fails, preserve the original HRESULT (not the fallback's)
98+
// for backward compatibility so callers checking for specific errors (e.g., ERROR_FILE_NOT_FOUND) are not broken.
99+
}
100+
101+
return hr;
88102
}

0 commit comments

Comments
 (0)