https://git.reactos.org/?p=reactos.git;a=commitdiff;h=94c8f271c98a793ea4f5a5e166e65215b93a9982

commit 94c8f271c98a793ea4f5a5e166e65215b93a9982
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Fri Nov 4 21:48:07 2022 +0900
Commit:     GitHub <[email protected]>
CommitDate: Fri Nov 4 21:48:07 2022 +0900

    [CPL:INTL] Use Japanese package for Far-East files (#4834)
    
    Implement IDC_INST_FILES_FOR_ASIAN checkbox action. It will 
install/uninstall "ReactOS JPN Package" in Japanese ReactOS.
    JIRA issue: CORE-12748
---
 dll/cpl/intl/CMakeLists.txt |   2 +-
 dll/cpl/intl/languages.c    | 100 ++++++++++++++++++++++++++++++++------------
 2 files changed, 74 insertions(+), 28 deletions(-)

diff --git a/dll/cpl/intl/CMakeLists.txt b/dll/cpl/intl/CMakeLists.txt
index a2b6723e250..e2b1c3f3077 100644
--- a/dll/cpl/intl/CMakeLists.txt
+++ b/dll/cpl/intl/CMakeLists.txt
@@ -24,6 +24,6 @@ add_library(intl MODULE
     ${CMAKE_CURRENT_BINARY_DIR}/intl.def)
 
 set_module_type(intl cpl UNICODE)
-add_importlibs(intl user32 comctl32 advapi32 setupapi shell32 msvcrt kernel32 
ntdll)
+add_importlibs(intl user32 comctl32 advapi32 setupapi shlwapi shell32 msvcrt 
kernel32 ntdll)
 add_pch(intl intl.h SOURCE)
 add_cd_file(TARGET intl DESTINATION reactos/system32 FOR all)
diff --git a/dll/cpl/intl/languages.c b/dll/cpl/intl/languages.c
index c4507b75643..548ad727370 100644
--- a/dll/cpl/intl/languages.c
+++ b/dll/cpl/intl/languages.c
@@ -1,15 +1,46 @@
 #include "intl.h"
 
 #include <shellapi.h>
+#include <shlobj.h>
+#include <shlwapi.h>
 #include <strsafe.h>
 
-/* Is there any Japanese input method? */
-BOOL HasJapaneseIME(VOID)
+/* What is the uninstallation command line of "ReactOS JPN Package"? */
+BOOL GetJapaneseUninstallCmdLine(HWND hwnd, LPWSTR pszCmdLine, SIZE_T 
cchCmdLine)
 {
-    WCHAR szImePath[MAX_PATH];
-    GetSystemDirectoryW(szImePath, _countof(szImePath));
-    StringCchCatW(szImePath, _countof(szImePath), L"\\mzimeja.ime");
-    return GetFileAttributesW(szImePath) != INVALID_FILE_ATTRIBUTES;
+    HKEY hKey;
+    LONG error;
+    DWORD dwSize;
+
+    pszCmdLine[0] = UNICODE_NULL;
+
+    error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+                          
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
+                          L"{80F03D6E-0549-4202-BE81-FF583F56A7A8}_is1",
+                          0,
+                          KEY_READ,
+                          &hKey);
+    if (error != ERROR_SUCCESS)
+        return FALSE;
+
+    dwSize = cchCmdLine * sizeof(WCHAR);
+    error = RegQueryValueExW(hKey, L"UninstallString", NULL, NULL, 
(LPBYTE)pszCmdLine, &dwSize);
+    if (error != ERROR_SUCCESS)
+    {
+        RegCloseKey(hKey);
+        return FALSE;
+    }
+
+    pszCmdLine[cchCmdLine - 1] = UNICODE_NULL;
+    RegCloseKey(hKey);
+    return TRUE;
+}
+
+/* Is there any installed "ReactOS JPN Package"? */
+BOOL HasJapanesePackage(HWND hwnd)
+{
+    WCHAR szPath[MAX_PATH];
+    return GetJapaneseUninstallCmdLine(hwnd, szPath, _countof(szPath));
 }
 
 /* Property page dialog callback */
@@ -40,9 +71,8 @@ LanguagesPageProc(HWND hwndDlg,
             switch (PRIMARYLANGID(GetUserDefaultLangID()))
             {
                 case LANG_JAPANESE:
-                    if (HasJapaneseIME())
+                    if (HasJapanesePackage(hwndDlg))
                     {
-                        EnableWindow(GetDlgItem(hwndDlg, 
IDC_INST_FILES_FOR_ASIAN), FALSE);
                         CheckDlgButton(hwndDlg, IDC_INST_FILES_FOR_ASIAN, 
BST_CHECKED);
                     }
                     break;
@@ -82,32 +112,48 @@ LanguagesPageProc(HWND hwndDlg,
             break;
 
         case WM_NOTIFY:
-            if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY)
+            if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY) /* Apply changes */
             {
-                /* Apply changes */
-                if (IsDlgButtonChecked(hwndDlg, IDC_INST_FILES_FOR_ASIAN) == 
BST_CHECKED)
+                /* EAST ASIAN specific */
+                switch (PRIMARYLANGID(GetUserDefaultLangID()))
                 {
-                    /* EAST ASIAN specific */
-                    switch (PRIMARYLANGID(GetUserDefaultLangID()))
-                    {
-                        case LANG_JAPANESE:
-                            if (HasJapaneseIME())
+                    case LANG_JAPANESE:
+                        if (IsDlgButtonChecked(hwndDlg, 
IDC_INST_FILES_FOR_ASIAN) == BST_CHECKED)
+                        {
+                            if (!HasJapanesePackage(hwndDlg))
                             {
-                                EnableWindow(GetDlgItem(hwndDlg, 
IDC_INST_FILES_FOR_ASIAN), FALSE);
-                                CheckDlgButton(hwndDlg, 
IDC_INST_FILES_FOR_ASIAN, BST_CHECKED);
+                                /* Install now */
+                                ShellExecuteW(hwndDlg, NULL, L"rapps.exe", 
L"/INSTALL jpn-package",
+                                              NULL, SW_SHOWNORMAL);
                             }
-                            else
+                        }
+                        else
+                        {
+                            WCHAR szUninstall[MAX_PATH];
+                            if (GetJapaneseUninstallCmdLine(hwndDlg, 
szUninstall, _countof(szUninstall)))
                             {
-                                ShellExecuteW(hwndDlg, NULL, L"rapps.exe", 
L"/INSTALL mzimeja",
-                                              NULL, SW_SHOWNORMAL);
+                                /* Go to arguments of command line */
+                                PWCHAR pchArgs = PathGetArgsW(szUninstall);
+                                if (pchArgs && *pchArgs)
+                                {
+                                    --pchArgs;
+                                    /* pchArgs pointer is inside szUninstall,
+                                     * so we have to split both strings */
+                                    *pchArgs = UNICODE_NULL;
+                                    ++pchArgs;
+                                }
+                                PathUnquoteSpacesW(szUninstall);
+
+                                /* Uninstall now */
+                                ShellExecuteW(hwndDlg, NULL, szUninstall, 
pchArgs, NULL, SW_SHOWNORMAL);
                             }
-                            break;
+                        }
+                        break;
 
-                        case LANG_CHINESE: /* Not supported yet */
-                        case LANG_KOREAN: /* Not supported yet */
-                        default:
-                            break;
-                    }
+                    case LANG_CHINESE: /* Not supported yet */
+                    case LANG_KOREAN: /* Not supported yet */
+                    default:
+                        break;
                 }
 
                 PropSheet_UnChanged(GetParent(hwndDlg), hwndDlg);

Reply via email to