https://git.reactos.org/?p=reactos.git;a=commitdiff;h=87f2950e1a51447399fdcf3186c0b908c600b194

commit 87f2950e1a51447399fdcf3186c0b908c600b194
Author:     Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com>
AuthorDate: Fri Sep 16 08:26:22 2022 +0900
Commit:     Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com>
CommitDate: Fri Sep 16 08:26:22 2022 +0900

    [INPUT] Follow-up of #4666 (596f04b)
    
    Reboot is still needed for IME settings.
    CORE-11700, CORE-18364
---
 dll/cpl/input/settings_page.c | 64 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)

diff --git a/dll/cpl/input/settings_page.c b/dll/cpl/input/settings_page.c
index aeed2ad7e2c..a42de1399d6 100644
--- a/dll/cpl/input/settings_page.c
+++ b/dll/cpl/input/settings_page.c
@@ -352,6 +352,53 @@ OnCommandSettingsPage(HWND hwndDlg, WPARAM wParam)
     }
 }
 
+static BOOL IsRebootNeeded(VOID)
+{
+    INPUT_LIST_NODE *pNode;
+
+    for (pNode = InputList_GetFirst(); pNode != NULL; pNode = pNode->pNext)
+    {
+        if (IS_IME_HKL(pNode->hkl)) /* IME? */
+        {
+            if (pNode->wFlags & (INPUT_LIST_NODE_FLAG_ADDED |
+                                 INPUT_LIST_NODE_FLAG_EDITED |
+                                 INPUT_LIST_NODE_FLAG_DEFAULT))
+            {
+                return TRUE;
+            }
+        }
+    }
+
+    return FALSE;
+}
+
+BOOL EnableProcessPrivileges(LPCWSTR lpPrivilegeName, BOOL bEnable)
+{
+    HANDLE hToken;
+    LUID luid;
+    TOKEN_PRIVILEGES tokenPrivileges;
+    BOOL Ret;
+
+    Ret = OpenProcessToken(GetCurrentProcess(),
+                           TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
+                           &hToken);
+    if (!Ret)
+        return Ret;     // failure
+
+    Ret = LookupPrivilegeValueW(NULL, lpPrivilegeName, &luid);
+    if (Ret)
+    {
+        tokenPrivileges.PrivilegeCount = 1;
+        tokenPrivileges.Privileges[0].Luid = luid;
+        tokenPrivileges.Privileges[0].Attributes = bEnable ? 
SE_PRIVILEGE_ENABLED : 0;
+
+        Ret = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, 0, 0, 0);
+    }
+
+    CloseHandle(hToken);
+    return Ret;
+}
+
 static VOID
 OnNotifySettingsPage(HWND hwndDlg, LPARAM lParam)
 {
@@ -370,8 +417,23 @@ OnNotifySettingsPage(HWND hwndDlg, LPARAM lParam)
 
         case PSN_APPLY:
         {
+            BOOL bRebootNeeded = IsRebootNeeded();
+
             /* Write Input Methods list to registry */
-            InputList_Process();
+            if (InputList_Process() && bRebootNeeded)
+            {
+                /* Needs reboot */
+                WCHAR szNeedsReboot[128], szLanguage[64];
+                LoadStringW(hApplet, IDS_REBOOT_NOW, szNeedsReboot, 
_countof(szNeedsReboot));
+                LoadStringW(hApplet, IDS_LANGUAGE, szLanguage, 
_countof(szLanguage));
+
+                if (MessageBoxW(hwndDlg, szNeedsReboot, szLanguage,
+                                MB_ICONINFORMATION | MB_YESNOCANCEL) == IDYES)
+                {
+                    EnableProcessPrivileges(SE_SHUTDOWN_NAME, TRUE);
+                    ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0);
+                }
+            }
         }
         break;
     }

Reply via email to