ResolveHostLanguage takes the host locales in order of preference from a source
and the console language of the first one that is recognised. When none is
(or the source returns none), it reports one notice line that names the
detected locale and the English (United States) fallback and returns it, so
auto never fails. Source and notice are injectable so tests do not depend on
the host.
The macOS locale source calls CFLocaleCopyPreferredLanguages. The header is
inline, so every target that resolves the language needs the framework: an
interface target carries it on macOS and nothing elsewhere, and the system
service library, the trophy library and the locale test link it.
MacHostLocales returns the user's preferred languages in order from
CFLocaleCopyPreferredLanguages, BCP-47 tags such as en-US, zh-Hans-CN or
pt-BR, which the process environment of a macOS desktop session does not
carry. Only built on macOS.
WindowsHostLocales returns the user default locale name from
GetUserDefaultLocaleName, a BCP-47 tag such as en-US, zh-Hans-CN or pt-BR. It
reads the regional-format locale of the user, not the list of preferred
display languages, because that is one documented call with a fixed buffer.
A name with a non-ASCII character is treated as no locale. Only built on
Windows.
PosixHostLocales takes an injectable environment reader and returns the locales
in order of preference: LC_ALL, then LC_MESSAGES, then LANG, the first one that
is set and not empty, as the C library chooses the locale of the messages
category. When that locale is a real one (not C, POSIX or unset) the entries of
LANGUAGE, the GNU preference list, come before it, as gettext ignores LANGUAGE
under the C locale.
MatchLocale returns the console language of a locale and whether the locale was
recognised. An empty, C, POSIX, malformed or unlisted locale is not
recognised and gives English (United States), the language the console answers
when ANYPS5_LANGUAGE is unset, so resolving a host locale cannot fail. A
recognised language with no row for its region already takes the language's
main row.
Each has a single console language, so every region maps to it. The legacy
code in for Indonesian, still used by some POSIX and Java hosts, is accepted
as well as id.
Russian, Ukrainian, Polish, Czech, Finnish, Swedish and Danish map to their
console language. Norwegian is the console's one Norwegian language, so no,
nb (Bokmal) and nn (Nynorsk) all map to it. Lithuanian, Latvian, Estonian and
the other Slavic languages the console has no entry for stay unrecognised.
A script decides first (zh-Hant is Traditional, zh-Hans Simplified, also
against a contradicting region such as zh-Hans-TW), then the region (TW, HK and
MO are Traditional), and a bare zh is Simplified. Mandarin (cmn) follows the
same rules and Cantonese (yue) is Traditional unless it names Hans.
The console has Spanish (Spain) and Spanish (Latin America), and Portuguese
(Portugal) and Portuguese (Brazil). A bare es is Spain, and the Latin American
countries, the es-419 region and es-US are Latin America. A bare pt is Brazil,
the language's larger variant, and Portugal and the African and Asian
territories that follow the European standard (AO, MZ, CV, GW, ST, TL, MO) are
Portugal.
ConsoleLanguageForTag picks, among the rows of the tag's language whose script
and region are empty or equal to the tag's, the one that names the most
(script outranks region), so a regional row wins over the language's main row
and a language with no row for the tag's region falls back to its main row.
The first group of rows covers the Latin-script European languages that have
no regional split but a few: English (United Kingdom for GB, IE, AU and NZ,
English (United States) otherwise), French and French (Canada), German,
Italian, Dutch and Romanian.
ParseLocale normalises the text as a POSIX name first, which leaves a BCP-47
tag unchanged except for underscores, and then parses the result, so the
caller handles en-US and en_US.UTF-8 alike. C, POSIX and an empty text report
no locale and leave the output tag as it was.
POSIX hosts name their locale language[_territory][.codeset][@modifier], such
as en_GB.UTF-8@euro, and use C and POSIX for no locale at all. NormalizePosixLocale
drops the codeset and the modifier, turns underscores into hyphens, maps the
@latin and @cyrillic modifiers to the Latn and Cyrl scripts where the name has
no script, and returns an empty string for C, POSIX and an empty name so the
caller sees "no locale" instead of a language called C.
Adds a host-only test, system_service_language_locale, for ParseTag: case
normalisation of the language, script and region subtags, the three-digit
region of es-419, variants and extensions that are ignored, and the inputs it
must reject (empty and oversized subtags, one-letter and long languages, the
POSIX underscore and codeset forms) without touching the output tag.
ANYPS5_LANGUAGE can only name a console language number. Taking the language
from the host needs the host's locale, which arrives as a BCP-47 tag such as
en-US, pt-BR or zh-Hant-TW. ParseTag reads the language, script and region
subtags, normalises their case, ignores variants and extensions, and rejects
empty subtags, subtags over 8 characters and languages that are not 2 or 3
letters.
The sceSystemServiceUsbStorage* exports jump straight into the USB storage
module, so call the matching libSceUsbStorage export instead of throwing.
RequestMapWSB keeps its marker while its two declarations disagree on the
fourth argument and the output type.
BunnyFl ran firmware 13.42's libSceSystemService.sprx in an emulator and
recorded the checks these calls make before they pass a request on. A
null title ID or one whose length isn't 9 makes sceSystemServiceGetAppId
and sceLncUtilGetAppId return -1 and sceLncUtilIsAppLaunched return
0x80940005. A null output, list, count or user returns 0x80940005 from
the LncUtil and SystemService calls and 0x80e30003 from
sceShellCoreUtilGetUserFocus, before the app ID is looked at, and a null
sceLncUtilLoadExec path returns 0x80940005.
What the module passes on as a request still throws: another
9-character title ID, another app ID, a list capacity of 0 and an empty
sceLncUtilLoadExec path.
sceLncUtilLoadExec takes the same path and null-terminated argument
list, which the SystemService call passes on to it on the console. It
returns sceSystemServiceLoadExec's result: the same parameter errors,
the same refusals for paths it cannot start, and "exit" ends the title
in the same way.
sceLncUtilIsAppSuspended, sceSystemServiceIsAppSuspended and
sceLncUtilIsSpeculativeLaunch write false for the running title's app
ID. The title that calls them is running and has no shell to suspend
it. It was started from the host rather than by sceLncUtilLaunchApp,
so no LncLaunchParam asked for a speculative launch. Another app ID
and a null output still throw.
sceLncUtilGetAppLaunchedUser, sceSystemServiceGetAppLaunchedUser and
sceShellCoreUtilGetUserFocus write the initial user for the running
title's app ID. That is the user sceUserServiceGetInitialUser and
sceUserServiceGetForegroundUser report. Another app ID and a null user
pointer still throw.
sceLncUtilGetAppId and sceLncUtilIsAppLaunched accept the running
title's ID as sceSystemServiceGetAppId does, and
sceLncUtilGetAppIdOfRunningBigApp returns what
sceSystemServiceGetAppIdOfRunningBigApp returns. Both big-app lists
write the running title's app ID as their only entry, because AnyPS5
runs one title. Another title ID, a null pointer and a list capacity of
0 still throw.