From b0e354ed116aa89e7a64cd932737fdb4a9369858 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Sat, 24 Oct 2026 09:15:16 +0300 Subject: [PATCH] Add the TotK-Setup.exe launcher: a no-console C program that starts the bundled pythonw with installer.gui and shows a message when python is missing Co-Authored-By: Claude Opus 5.5 --- installer/launcher/launcher.c | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 installer/launcher/launcher.c diff --git a/installer/launcher/launcher.c b/installer/launcher/launcher.c new file mode 100644 index 00000000..0644234b --- /dev/null +++ b/installer/launcher/launcher.c @@ -0,0 +1,38 @@ +/* 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/.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/clang -O2 -mwindows launcher.c -o TotK-Setup.exe */ +#include +#include + +#include "launcher_text.h" + +#define LANGID_RUSSIAN 0x19 +#define PATH_CHARS (MAX_PATH * 2) + +static void fail(void) +{ + int russian = (GetUserDefaultUILanguage() & 0x3ff) == LANGID_RUSSIAN; + MessageBoxW(NULL, russian ? LAUNCHER_PYTHON_MISSING_RU : LAUNCHER_PYTHON_MISSING_EN, + russian ? LAUNCHER_TITLE_RU : LAUNCHER_TITLE_EN, 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; + 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; +}