- Show localized error messages
[reactos.git] / reactos / base / setup / usetup / mui.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2008 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: subsys/system/usetup/mui.c
23 * PURPOSE: Text-mode setup
24 * PROGRAMMER:
25 */
26
27 #include "usetup.h"
28 #include "errorcode.h"
29 #include "mui.h"
30
31 #include "lang/en-US.h"
32 #include "lang/de-DE.h"
33 #include "lang/el-GR.h"
34 #include "lang/es-ES.h"
35 #include "lang/fr-FR.h"
36 #include "lang/it-IT.h"
37 #include "lang/ru-RU.h"
38 #include "lang/sv-SE.h"
39 #include "lang/uk-UA.h"
40
41 static MUI_LANGUAGE LanguageList[] =
42 {
43 {
44 L"00000409", /* The Language ID */
45 L"00000409", /* Default Keyboard Layout for this language */
46 L"English", /* Language Name , not used just to make things easier when updating this file */
47 enUSPages, /* Translated page strings */
48 enUSErrorEntries /* Translated error strings */
49 },
50 {
51 L"0000040C",
52 L"0000040C",
53 L"French",
54 frFRPages,
55 frFRErrorEntries
56 },
57 {
58 L"00000407",
59 L"00000407",
60 L"German",
61 deDEPages,
62 deDEErrorEntries
63 },
64 {
65 L"00000408",
66 L"00000409",
67 L"Greek",
68 elGRPages,
69 elGRErrorEntries
70 },
71 {
72 L"00000410",
73 L"00000410",
74 L"Italian",
75 itITPages,
76 itITErrorEntries
77 },
78 {
79 L"00000419",
80 L"00000419",
81 L"Russian",
82 ruRUPages,
83 ruRUErrorEntries
84 },
85 {
86 L"0000040A",
87 L"0000040A",
88 L"Spanish",
89 esESPages,
90 esESErrorEntries
91 },
92 {
93 L"0000041D",
94 L"0000041D",
95 L"Swedish",
96 svSEPages,
97 svSEErrorEntries
98 },
99 {
100 L"00000422",
101 L"00000422",
102 L"Ukrainian",
103 ukUAPages,
104 ukUAErrorEntries
105 },
106 {
107 NULL,
108 NULL,
109 NULL
110 }
111 };
112
113 extern
114 VOID
115 PopupError(PCHAR Text,
116 PCHAR Status,
117 PINPUT_RECORD Ir,
118 ULONG WaitEvent);
119
120 static
121 MUI_ENTRY *
122 FindMUIEntriesOfPage (ULONG PageNumber)
123 {
124 ULONG muiIndex = 0;
125 ULONG lngIndex = 0;
126 MUI_PAGE * Pages = NULL;
127
128 do
129 {
130 /* First we search the language list till we find current selected language messages */
131 if (_wcsicmp(LanguageList[lngIndex].LanguageID , SelectedLanguageId) == 0)
132 {
133 /* Get all available pages for this language */
134 Pages = LanguageList[lngIndex].MuiPages;
135
136 do
137 {
138 /* Get page messages */
139 if (Pages[muiIndex].Number == PageNumber)
140 return Pages[muiIndex].MuiEntry;
141
142 muiIndex++;
143 }
144 while (Pages[muiIndex].MuiEntry != NULL);
145 }
146
147 lngIndex++;
148 }
149 while (LanguageList[lngIndex].MuiPages != NULL);
150
151 return NULL;
152 }
153
154 static
155 MUI_ERROR *
156 FindMUIErrorEntries ()
157 {
158 ULONG lngIndex = 0;
159
160 do
161 {
162 /* First we search the language list till we find current selected language messages */
163 if (_wcsicmp(LanguageList[lngIndex].LanguageID , SelectedLanguageId) == 0)
164 {
165 /* Get all available error messages for this language */
166 return LanguageList[lngIndex].MuiErrors;
167 }
168
169 lngIndex++;
170 }
171 while (LanguageList[lngIndex].MuiPages != NULL);
172
173 return NULL;
174 }
175
176 VOID
177 MUIDisplayPage(ULONG page)
178 {
179 MUI_ENTRY * entry;
180 int index;
181 int flags;
182
183 entry = FindMUIEntriesOfPage (page);
184 if (!entry)
185 {
186 PopupError("Error: Failed to find translated page",
187 NULL,
188 NULL,
189 POPUP_WAIT_NONE);
190 return;
191 }
192
193 index = 0;
194 do
195 {
196 flags = entry[index].Flags;
197 switch(flags)
198 {
199 case TEXT_NORMAL:
200 CONSOLE_SetTextXY(entry[index].X, entry[index].Y, entry[index].Buffer);
201 break;
202 case TEXT_HIGHLIGHT:
203 CONSOLE_SetHighlightedTextXY(entry[index].X, entry[index].Y, entry[index].Buffer);
204 break;
205 case TEXT_UNDERLINE:
206 CONSOLE_SetUnderlinedTextXY(entry[index].X, entry[index].Y, entry[index].Buffer);
207 break;
208 case TEXT_STATUS:
209 CONSOLE_SetStatusText(entry[index].Buffer);
210 break;
211 default:
212 break;
213 }
214 index++;
215 }
216 while (entry[index].Buffer != NULL);
217 }
218
219 VOID
220 MUIDisplayError(ULONG ErrorNum, PINPUT_RECORD Ir, ULONG WaitEvent)
221 {
222 MUI_ERROR * entry;
223
224 if (ErrorNum >= ERROR_LAST_ERROR_CODE)
225 {
226 PopupError("Pnvalid error number provided",
227 "Press ENTER to continue",
228 Ir,
229 POPUP_WAIT_ENTER);
230
231 return;
232 }
233
234 entry = FindMUIErrorEntries ();
235 if (!entry)
236 {
237 PopupError("Error: Failed to find translated error message",
238 NULL,
239 NULL,
240 POPUP_WAIT_NONE);
241 return;
242 }
243
244 PopupError(entry[ErrorNum].ErrorText,
245 entry[ErrorNum].ErrorStatus,
246 Ir,
247 WaitEvent);
248 }
249
250 /* EOF */