File tree Expand file tree Collapse file tree 4 files changed +49
-9
lines changed
dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src Expand file tree Collapse file tree 4 files changed +49
-9
lines changed Original file line number Diff line number Diff line change 99
1010#include < AppModel.Identity.h>
1111
12+ #include " Helper.h"
13+
1214namespace winrt ::Microsoft::Windows::ApplicationModel::Resources::implementation
1315{
1416 hstring ApplicationLanguages::m_language;
@@ -20,7 +22,14 @@ namespace winrt::Microsoft::Windows::ApplicationModel::Resources::implementation
2022
2123 winrt::Windows::Foundation::Collections::IVectorView<hstring> ApplicationLanguages::ManifestLanguages ()
2224 {
23- return winrt::Windows::Globalization::ApplicationLanguages::ManifestLanguages ();
25+ if (AppModel::Identity::IsPackagedProcess ())
26+ {
27+ return winrt::Windows::Globalization::ApplicationLanguages::ManifestLanguages ();
28+ }
29+ else
30+ {
31+ return {};
32+ }
2433 }
2534
2635 hstring ApplicationLanguages::PrimaryLanguageOverride ()
@@ -33,16 +42,18 @@ namespace winrt::Microsoft::Windows::ApplicationModel::Resources::implementation
3342
3443 void ApplicationLanguages::PrimaryLanguageOverride (hstring const & language)
3544 {
45+ bool isValidLanguageTag = IsWellFormedLanguageTag (language.c_str ());
46+
47+ THROW_HR_IF_MSG (E_INVALIDARG, isValidLanguageTag, " The parameter is incorrect" );
48+
49+ static wil::srwlock lock;
50+
51+ auto criticalSection {lock.lock_exclusive ()};
52+ m_language = language;
53+
3654 if (AppModel::Identity::IsPackagedProcess ())
3755 {
3856 winrt::Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride (language);
3957 }
40- else
41- {
42- static wil::srwlock lock;
43-
44- auto criticalSection{ lock.lock_exclusive () };
45- m_language = language;
46- }
4758 }
4859} // namespace winrt::Microsoft::Windows::ApplicationModel::Resources::implementation
Original file line number Diff line number Diff line change @@ -25,4 +25,4 @@ namespace winrt::Microsoft::Windows::ApplicationModel::Resources::factory_implem
2525 struct ApplicationLanguages : ApplicationLanguagesT<ApplicationLanguages, implementation::ApplicationLanguages>
2626 {
2727 };
28- } // winrt::Microsoft::Windows::ApplicationModel::Resources::factory_implementation
28+ } // namespace winrt::Microsoft::Windows::ApplicationModel::Resources::factory_implementation
Original file line number Diff line number Diff line change @@ -86,3 +86,31 @@ HRESULT GetDefaultPriFile(winrt::hstring& filePath)
8686 bool isPackaged = (hr != HRESULT_FROM_WIN32 (APPMODEL_ERROR_NO_PACKAGE));
8787 return GetDefaultPriFileForCurentModule (isPackaged, filePath);
8888}
89+
90+ bool IsWellFormedLanguageTag (const wchar_t * languageTag)
91+ {
92+ // Implementation taken from Platform.h, without accepting semi-colon, as it must be a single language tag
93+ if (languageTag == nullptr || *languageTag == L' \0 ' )
94+ {
95+ return FALSE ;
96+ }
97+
98+ BOOLEAN ok = TRUE ;
99+ PCWSTR test = languageTag;
100+
101+ while (ok && (*test != L' \0 ' ))
102+ {
103+ // we accept letters, numbers, dash and semi-colon (as list separator)
104+ if (((*test >= L' 0' ) && (*test <= L' 9' )) || ((*test >= L' a' ) && (*test <= L' z' )) || ((*test >= L' A' ) && (*test <= L' Z' )) ||
105+ (*test == L' -' ))
106+ {
107+ test++;
108+ }
109+ else
110+ {
111+ ok = FALSE ;
112+ }
113+ }
114+
115+ return ok && ((test - languageTag) >= 2 );
116+ }
Original file line number Diff line number Diff line change 44#pragma once
55bool IsResourceNotFound (HRESULT hr );
66HRESULT GetDefaultPriFile (winrt ::hstring & path );
7+ bool IsWellFormedLanguageTag (const wchar_t * languageTag );
You can’t perform that action at this time.
0 commit comments