From 0ef3154e489eed1176e9ca3a2e5f244fc0c1cf0f Mon Sep 17 00:00:00 2001 From: fxliang Date: Thu, 17 Oct 2024 17:02:57 +0800 Subject: [PATCH] feat: WeaselSetup.exe parameter /userdir: to set user data directory in command line --- WeaselSetup/WeaselSetup.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/WeaselSetup/WeaselSetup.cpp b/WeaselSetup/WeaselSetup.cpp index e9a1e56e7..43286ecfb 100644 --- a/WeaselSetup/WeaselSetup.cpp +++ b/WeaselSetup/WeaselSetup.cpp @@ -136,6 +136,12 @@ static int CustomInstall(bool installing) { return 0; } +LPCTSTR GetParamByPrefix(LPCTSTR lpCmdLine, LPCTSTR prefix) { + return (wcsncmp(lpCmdLine, prefix, wcslen(prefix)) == 0) + ? (lpCmdLine + wcslen(prefix)) + : 0; +} + static int Run(LPTSTR lpCmdLine) { constexpr bool silent = true; constexpr bool old_ime_support = false; @@ -147,6 +153,11 @@ static int Run(LPTSTR lpCmdLine) { return RestartAsAdmin(lpCmdLine); } + if (auto res = GetParamByPrefix(lpCmdLine, L"/userdir:")) { + return SetRegKeyValue(HKEY_CURRENT_USER, L"Software\\Rime\\weasel", + L"RimeUserDir", res, REG_SZ); + } + if (!wcscmp(L"/ls", lpCmdLine)) { return SetRegKeyValue(HKEY_CURRENT_USER, L"Software\\Rime\\weasel", L"Language", L"chs", REG_SZ);