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 9
9
10
10
#include < AppModel.Identity.h>
11
11
12
+ #include " Helper.h"
13
+
12
14
namespace winrt ::Microsoft::Windows::ApplicationModel::Resources::implementation
13
15
{
14
16
hstring ApplicationLanguages::m_language;
@@ -20,7 +22,14 @@ namespace winrt::Microsoft::Windows::ApplicationModel::Resources::implementation
20
22
21
23
winrt::Windows::Foundation::Collections::IVectorView<hstring> ApplicationLanguages::ManifestLanguages ()
22
24
{
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
+ }
24
33
}
25
34
26
35
hstring ApplicationLanguages::PrimaryLanguageOverride ()
@@ -33,16 +42,18 @@ namespace winrt::Microsoft::Windows::ApplicationModel::Resources::implementation
33
42
34
43
void ApplicationLanguages::PrimaryLanguageOverride (hstring const & language)
35
44
{
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
+
36
54
if (AppModel::Identity::IsPackagedProcess ())
37
55
{
38
56
winrt::Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride (language);
39
57
}
40
- else
41
- {
42
- static wil::srwlock lock;
43
-
44
- auto criticalSection{ lock.lock_exclusive () };
45
- m_language = language;
46
- }
47
58
}
48
59
} // 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
25
25
struct ApplicationLanguages : ApplicationLanguagesT<ApplicationLanguages, implementation::ApplicationLanguages>
26
26
{
27
27
};
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)
86
86
bool isPackaged = (hr != HRESULT_FROM_WIN32 (APPMODEL_ERROR_NO_PACKAGE));
87
87
return GetDefaultPriFileForCurentModule (isPackaged, filePath);
88
88
}
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 4
4
#pragma once
5
5
bool IsResourceNotFound (HRESULT hr );
6
6
HRESULT GetDefaultPriFile (winrt ::hstring & path );
7
+ bool IsWellFormedLanguageTag (const wchar_t * languageTag );
You can’t perform that action at this time.
0 commit comments