xref: /reactos/dll/cpl/intl/languages.c (revision ccef43f3)
1 #include "intl.h"
2 
3 #include <shellapi.h>
4 #include <shlobj.h>
5 #include <shlwapi.h>
6 #include <strsafe.h>
7 
8 /* What is the uninstallation command line of "ReactOS JPN Package"? */
9 BOOL GetJapaneseUninstallCmdLine(HWND hwnd, LPWSTR pszCmdLine, SIZE_T cchCmdLine)
10 {
11     HKEY hKey;
12     LONG error;
13     DWORD dwSize;
14 
15     pszCmdLine[0] = UNICODE_NULL;
16 
17     error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
18                           L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
19                           L"{80F03D6E-0549-4202-BE81-FF583F56A7A8}_is1",
20                           0,
21                           KEY_READ,
22                           &hKey);
23     if (error != ERROR_SUCCESS)
24         return FALSE;
25 
26     dwSize = cchCmdLine * sizeof(WCHAR);
27     error = RegQueryValueExW(hKey, L"UninstallString", NULL, NULL, (LPBYTE)pszCmdLine, &dwSize);
28     if (error != ERROR_SUCCESS)
29     {
30         RegCloseKey(hKey);
31         return FALSE;
32     }
33 
34     pszCmdLine[cchCmdLine - 1] = UNICODE_NULL;
35     RegCloseKey(hKey);
36     return TRUE;
37 }
38 
39 /* Is there any installed "ReactOS JPN Package"? */
40 BOOL HasJapanesePackage(HWND hwnd)
41 {
42     WCHAR szPath[MAX_PATH];
43     return GetJapaneseUninstallCmdLine(hwnd, szPath, _countof(szPath));
44 }
45 
46 /* Property page dialog callback */
47 INT_PTR CALLBACK
48 LanguagesPageProc(HWND hwndDlg,
49                   UINT uMsg,
50                   WPARAM wParam,
51                   LPARAM lParam)
52 {
53     SHELLEXECUTEINFOW shInputDll;
54     PGLOBALDATA pGlobalData;
55 
56     pGlobalData = (PGLOBALDATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
57 
58     switch (uMsg)
59     {
60         case WM_INITDIALOG:
61             pGlobalData = (PGLOBALDATA)((LPPROPSHEETPAGE)lParam)->lParam;
62             SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
63 
64             if (!pGlobalData->bIsUserAdmin)
65             {
66                 EnableWindow(GetDlgItem(hwndDlg, IDC_INST_FILES_FOR_RTOL_LANG), FALSE);
67                 EnableWindow(GetDlgItem(hwndDlg, IDC_INST_FILES_FOR_ASIAN), FALSE);
68             }
69 
70             /* EAST ASIAN specific */
71             switch (PRIMARYLANGID(GetUserDefaultLangID()))
72             {
73                 case LANG_JAPANESE:
74                     if (HasJapanesePackage(hwndDlg))
75                     {
76                         CheckDlgButton(hwndDlg, IDC_INST_FILES_FOR_ASIAN, BST_CHECKED);
77                     }
78                     break;
79 
80                 case LANG_CHINESE: /* Not supported yet */
81                 case LANG_KOREAN: /* Not supported yet */
82                 default:
83                     EnableWindow(GetDlgItem(hwndDlg, IDC_INST_FILES_FOR_ASIAN), FALSE);
84                     break;
85             }
86             break;
87 
88         case WM_COMMAND:
89             switch (LOWORD(wParam))
90             {
91                 /* If "detail" button pressed */
92                 case IDC_DETAIL_BUTTON:
93                     if (HIWORD(wParam) == BN_CLICKED)
94                     {
95                         memset(&shInputDll, 0x0, sizeof(SHELLEXECUTEINFOW));
96                         shInputDll.cbSize = sizeof(shInputDll);
97                         shInputDll.hwnd = hwndDlg;
98                         shInputDll.lpVerb = L"open";
99                         shInputDll.lpFile = L"RunDll32.exe";
100                         shInputDll.lpParameters = L"shell32.dll,Control_RunDLL input.dll";
101                         if (ShellExecuteExW(&shInputDll) == 0)
102                         {
103                             PrintErrorMsgBox(IDS_ERROR_INPUT_DLL);
104                         }
105                     }
106                     break;
107 
108                 case IDC_INST_FILES_FOR_ASIAN:
109                     PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
110                     break;
111             }
112             break;
113 
114         case WM_NOTIFY:
115             if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY) /* Apply changes */
116             {
117                 /* EAST ASIAN specific */
118                 switch (PRIMARYLANGID(GetUserDefaultLangID()))
119                 {
120                     case LANG_JAPANESE:
121                         if (IsDlgButtonChecked(hwndDlg, IDC_INST_FILES_FOR_ASIAN) == BST_CHECKED)
122                         {
123                             if (!HasJapanesePackage(hwndDlg))
124                             {
125                                 /* Install now */
126                                 ShellExecuteW(hwndDlg, NULL, L"rapps.exe", L"/INSTALL jpn-package",
127                                               NULL, SW_SHOWNORMAL);
128                             }
129                         }
130                         else
131                         {
132                             WCHAR szUninstall[MAX_PATH];
133                             if (GetJapaneseUninstallCmdLine(hwndDlg, szUninstall, _countof(szUninstall)))
134                             {
135                                 /* Go to arguments of command line */
136                                 PWCHAR pchArgs = PathGetArgsW(szUninstall);
137                                 if (pchArgs && *pchArgs)
138                                 {
139                                     --pchArgs;
140                                     /* pchArgs pointer is inside szUninstall,
141                                      * so we have to split both strings */
142                                     *pchArgs = UNICODE_NULL;
143                                     ++pchArgs;
144                                 }
145                                 PathUnquoteSpacesW(szUninstall);
146 
147                                 /* Uninstall now */
148                                 ShellExecuteW(hwndDlg, NULL, szUninstall, pchArgs, NULL, SW_SHOWNORMAL);
149                             }
150                         }
151                         break;
152 
153                     case LANG_CHINESE: /* Not supported yet */
154                     case LANG_KOREAN: /* Not supported yet */
155                     default:
156                         break;
157                 }
158 
159                 PropSheet_UnChanged(GetParent(hwndDlg), hwndDlg);
160             }
161             break;
162     }
163     return FALSE;
164 }
165 
166 /* EOF */
167