Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
system_utils.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/shell/platform/windows/system_utils.h"
6
7#include <Windows.h>
8
9#include <sstream>
10
11#include "flutter/fml/platform/win/wstring_conversion.h"
12
13namespace flutter {
14
15std::vector<LanguageInfo> GetPreferredLanguageInfo(
16 const WindowsProcTable& windows_proc_table) {
17 std::vector<std::wstring> languages =
18 GetPreferredLanguages(windows_proc_table);
19 std::vector<LanguageInfo> language_info;
20 language_info.reserve(languages.size());
21
22 for (auto language : languages) {
23 language_info.push_back(ParseLanguageName(language));
24 }
25 return language_info;
26}
27
29 const WindowsProcTable& windows_proc_table) {
31 ULONG count = 0;
32 DWORD flags = MUI_LANGUAGE_NAME | MUI_UI_FALLBACK;
33 if (!windows_proc_table.GetThreadPreferredUILanguages(flags, &count, nullptr,
34 &buffer_size)) {
35 return std::wstring();
36 }
37 std::wstring buffer(buffer_size, '\0');
38 if (!windows_proc_table.GetThreadPreferredUILanguages(
39 flags, &count, buffer.data(), &buffer_size)) {
40 return std::wstring();
41 }
42 return buffer;
43}
44
45std::vector<std::wstring> GetPreferredLanguages(
46 const WindowsProcTable& windows_proc_table) {
47 std::vector<std::wstring> languages;
48
49 // Initialize the buffer
50 std::wstring buffer = GetPreferredLanguagesFromMUI(windows_proc_table);
51
52 // Extract the individual languages from the buffer.
53 size_t start = 0;
54 while (true) {
55 // The buffer is terminated by an empty string (i.e., a double null).
56 if (buffer[start] == L'\0') {
57 break;
58 }
59 // Read the next null-terminated language.
60 std::wstring language(buffer.c_str() + start);
61 if (language.empty()) {
62 break;
63 }
64 languages.push_back(language);
65 // Skip past that language and its terminating null in the buffer.
66 start += language.size() + 1;
67 }
68 return languages;
69}
70
71LanguageInfo ParseLanguageName(std::wstring language_name) {
73
74 // Split by '-', discarding any suplemental language info (-x-foo).
75 std::vector<std::string> components;
76 std::istringstream stream(fml::WideStringToUtf8(language_name));
77 std::string component;
78 while (getline(stream, component, '-')) {
79 if (component == "x") {
80 break;
81 }
82 components.push_back(component);
83 }
84
85 // Determine which components are which.
86 info.language = components[0];
87 if (components.size() == 3) {
88 info.script = components[1];
89 info.region = components[2];
90 } else if (components.size() == 2) {
91 // A script code will always be four characters long.
92 if (components[1].size() == 4) {
93 info.script = components[1];
94 } else {
95 info.region = components[1];
96 }
97 }
98 return info;
99}
100
101std::wstring GetUserTimeFormat() {
102 // Rather than do the call-allocate-call-free dance, just use a sufficiently
103 // large buffer to handle any reasonable time format string.
104 const int kBufferSize = 100;
105 wchar_t buffer[kBufferSize];
106 if (::GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_STIMEFORMAT, buffer,
107 kBufferSize) == 0) {
108 return std::wstring();
109 }
110 return std::wstring(buffer, kBufferSize);
111}
112
113bool Prefer24HourTime(std::wstring time_format) {
114 return time_format.find(L"H") != std::wstring::npos;
115}
116
117} // namespace flutter
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
int count
static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment)
static const size_t kBufferSize
Definition SkString.cpp:27
virtual LRESULT GetThreadPreferredUILanguages(DWORD flags, PULONG count, PZZWSTR languages, PULONG length) const
FlutterSemanticsFlag flags
std::wstring GetUserTimeFormat()
std::vector< std::wstring > GetPreferredLanguages(const WindowsProcTable &windows_proc_table)
std::wstring GetPreferredLanguagesFromMUI(const WindowsProcTable &windows_proc_table)
std::vector< LanguageInfo > GetPreferredLanguageInfo()
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
LanguageInfo ParseLanguageName(std::wstring language_name)
bool Prefer24HourTime(std::wstring time_format)
std::string WideStringToUtf8(const std::wstring_view str)
DWORD ULONG
unsigned long DWORD