Skip to content

[Fix] Locating Microsoft.WindowsAppRuntime.pri in framework usage #5582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions dev/Interop/StoragePickers/PickerLocalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,47 @@
#include "PickerLocalization.h"
#include <winrt\base.h>
#include <winrt\Microsoft.Windows.ApplicationModel.Resources.h>
#include <iostream>
#include <array>


const winrt::hstring priFileName = L"Microsoft.WindowsAppRuntime.pri";
winrt::hstring GetPriFilePath()
{
HMODULE hModule = nullptr;
// use GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, the module handle does not need to be released
// GetPriFilePath should only be called once to initialize the static priFilePath variable, thus thread safe
if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCWSTR>(&GetPriFilePath), &hModule))
{
std::array<wchar_t, MAX_PATH + 1> buffer;
auto pathLength = GetModuleFileName(hModule, buffer.data(), MAX_PATH + 1);
if (pathLength > 0)
{
auto dllPathString = std::wstring(buffer.data(), pathLength);
std::filesystem::path dllPath(dllPathString);
if (!std::filesystem::is_regular_file(dllPath))
{
return priFileName;
}
std::filesystem::path parentDir = dllPath.parent_path();
auto priFilePath = parentDir / std::wstring{ priFileName };
if (std::filesystem::exists(priFilePath))
{
return winrt::hstring{ priFilePath.wstring() };
}
}
}
return priFileName;
}

namespace PickerLocalization {
const winrt::hstring priPath = L"Microsoft.WindowsAppRuntime.pri";

winrt::hstring GetStoragePickersLocalizationText(winrt::hstring key)
{
static winrt::hstring priPath = GetPriFilePath();
auto manager = winrt::Microsoft::Windows::ApplicationModel::Resources::ResourceManager(priPath);
return manager.MainResourceMap().GetValue(key).ValueAsString();
}
}


15 changes: 1 addition & 14 deletions dev/Interop/StoragePickers/StoragePickers.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,6 @@
<Midl Include="$(MSBuildThisFileDirectory)Microsoft.Windows.Storage.Pickers.idl" />
</ItemGroup>
<ItemGroup>
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\cs-CZ\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\de-DE\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\en-US\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\es-ES\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\fr-FR\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\it-IT\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\ja-JP\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\ko-KR\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\pl-PL\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\pt-BR\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\ru-RU\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\tr-TR\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\zh-CN\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\zh-TW\StoragePickers.resw" />
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\*\*.resw" />
</ItemGroup>
</Project>
Loading