Files
totk-pc-recomp/installer/launcher/launcher.c
T
itaskaev2andClaude Opus 5.5 8427d8e006 The setup speaks German, French, Spanish, Italian, Dutch, Japanese and Korean, picked from the Windows display language, with every Chinese Windows on the Simplified Chinese setup and the game language starting as the window's where the game has it (the setup part of pull request #497; its in-game menu part stays out, as it covers about two thirds of today's menu)
Taken from #497: the seven catalogs, the language choice in installer/guilogic.py and the launcher, the launcher header and bundle check in the release scripts, the tests. Added here: the ids dev and this branch gained since (kit, PC prompts and display shapes steps, the locked exe and skipped plugins messages, the form sections and More details), and new translations of the ids whose English changed after #497 was translated (NSZ and XCZ input, the missing shared fonts warning, the PlayStation prompts). README gains a Languages table that shows the menu in four languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 19:45:37 +03:00

63 lines
3.4 KiB
C

/* TotK-Setup.exe: starts python\pythonw.exe -m installer.gui with this exe's folder as the working directory.
No console window. The two message strings come from the catalog (installer/text/<lang>.json, ids launcher.title and
launcher.python_missing); tools/make_release.py writes them into launcher_text.h before it compiles this file.
Build: llvm/bin/llvm-windres -I runtime -O coff launcher.rc -o launcher_rc.o, then
llvm/bin/clang -O2 -mwindows launcher.c launcher_rc.o -o TotK-Setup.exe
System DPI aware, like the window's Python process (installer/dpi.py): Windows draws the error box of fail() at the
display's scale instead of stretching it, which it would at 125% and above. */
#include <windows.h>
#include <wchar.h>
#include "launcher_text.h"
#define LANGID_PT_BR 0x0416 /* the whole LANGID: Portugal's Portuguese stays English */
#define PATH_CHARS (MAX_PATH * 2)
/* The language of the window (installer/guilogic.py ui_language_for_langid): Brazilian Portuguese by the whole LANGID,
the rest by the primary language (every Chinese gets Simplified Chinese), else English. */
static void fail(void)
{
static const struct { WORD primary; const wchar_t *title, *text; } by_primary[] = {
{ LANG_RUSSIAN, LAUNCHER_TITLE_RU, LAUNCHER_PYTHON_MISSING_RU },
{ LANG_GERMAN, LAUNCHER_TITLE_DE, LAUNCHER_PYTHON_MISSING_DE },
{ LANG_FRENCH, LAUNCHER_TITLE_FR, LAUNCHER_PYTHON_MISSING_FR },
{ LANG_SPANISH, LAUNCHER_TITLE_ES, LAUNCHER_PYTHON_MISSING_ES },
{ LANG_ITALIAN, LAUNCHER_TITLE_IT, LAUNCHER_PYTHON_MISSING_IT },
{ LANG_DUTCH, LAUNCHER_TITLE_NL, LAUNCHER_PYTHON_MISSING_NL },
{ LANG_JAPANESE, LAUNCHER_TITLE_JA, LAUNCHER_PYTHON_MISSING_JA },
{ LANG_KOREAN, LAUNCHER_TITLE_KO, LAUNCHER_PYTHON_MISSING_KO },
{ LANG_CHINESE, LAUNCHER_TITLE_ZH_HANS, LAUNCHER_PYTHON_MISSING_ZH_HANS },
};
LANGID ui = GetUserDefaultUILanguage();
const wchar_t *title = LAUNCHER_TITLE_EN, *text = LAUNCHER_PYTHON_MISSING_EN;
if (ui == LANGID_PT_BR) {
title = LAUNCHER_TITLE_PT_BR; text = LAUNCHER_PYTHON_MISSING_PT_BR;
} else {
for (size_t i = 0; i < sizeof by_primary / sizeof by_primary[0]; i++)
if (PRIMARYLANGID(ui) == by_primary[i].primary) { title = by_primary[i].title; text = by_primary[i].text; }
}
MessageBoxW(NULL, text, title, MB_OK | MB_ICONERROR);
}
int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR command_line, int show)
{
wchar_t folder[PATH_CHARS], python[PATH_CHARS], command[PATH_CHARS + 64];
DWORD n = GetModuleFileNameW(NULL, folder, PATH_CHARS);
STARTUPINFOW si = { sizeof si };
PROCESS_INFORMATION pi;
(void)instance; (void)previous; (void)command_line; (void)show;
SetProcessDPIAware(); /* before the message box exists; the call fails harmlessly when a manifest set it */
if (n == 0 || n >= PATH_CHARS) { fail(); return 1; }
while (n > 0 && folder[n - 1] != L'\\') n--;
folder[n > 0 ? n - 1 : 0] = 0;
if (swprintf(python, PATH_CHARS, L"%ls\\python\\pythonw.exe", folder) < 0 ||
GetFileAttributesW(python) == INVALID_FILE_ATTRIBUTES) { fail(); return 1; }
if (swprintf(command, PATH_CHARS + 64, L"\"%ls\" -m installer.gui", python) < 0) { fail(); return 1; }
if (!CreateProcessW(python, command, NULL, NULL, FALSE, 0, NULL, folder, &si, &pi)) { fail(); return 1; }
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return 0;
}