ReactOS  0.4.15-dev-489-g75a0787
mui.c
Go to the documentation of this file.
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 /*
20  * COPYRIGHT: See COPYING in the top level directory
21  * PROJECT: ReactOS text-mode setup
22  * FILE: base/setup/usetup/mui.c
23  * PURPOSE: Text-mode setup
24  * PROGRAMMER:
25  */
26 
27 #include "usetup.h"
28 #include "muilanguages.h"
29 
30 #define NDEBUG
31 #include <debug.h>
32 
33 static
34 ULONG
36 {
37  ULONG lngIndex = 0;
38 
39  if (SelectedLanguageId == NULL)
40  {
41  /* Default to en-US */
42  return 0; // FIXME!!
43  // SelectedLanguageId = L"00000409";
44  }
45 
46  while (ResourceList[lngIndex].MuiPages != NULL)
47  {
48  if (_wcsicmp(ResourceList[lngIndex].LanguageID, SelectedLanguageId) == 0)
49  {
50  return lngIndex;
51  }
52 
53  lngIndex++;
54  }
55 
56  return 0;
57 }
58 
59 
60 #if 0
61 BOOLEAN
63  PWCHAR LanguageId)
64 {
65  ULONG lngIndex = 0;
66 
67  while (ResourceList[lngIndex].MuiPages != NULL)
68  {
69  if (_wcsicmp(ResourceList[lngIndex].LanguageID, LanguageId) == 0)
70  return TRUE;
71 
72  lngIndex++;
73  }
74 
75  return FALSE;
76 }
77 #endif
78 
79 
80 static
81 const MUI_ENTRY *
83  IN ULONG PageNumber)
84 {
85  ULONG muiIndex = 0;
86  ULONG lngIndex;
87  const MUI_PAGE * Pages = NULL;
88 
89  lngIndex = max(FindLanguageIndex(), 0);
90  Pages = ResourceList[lngIndex].MuiPages;
91 
92  while (Pages[muiIndex].MuiEntry != NULL)
93  {
94  if (Pages[muiIndex].Number == PageNumber)
95  return Pages[muiIndex].MuiEntry;
96 
97  muiIndex++;
98  }
99 
100  return NULL;
101 }
102 
103 static
104 const MUI_ERROR *
106 {
107  ULONG lngIndex = max(FindLanguageIndex(), 0);
108  return ResourceList[lngIndex].MuiErrors;
109 }
110 
111 static
112 const MUI_STRING *
114 {
115  ULONG lngIndex = max(FindLanguageIndex(), 0);
116  return ResourceList[lngIndex].MuiStrings;
117 }
118 
119 
120 VOID
122  IN ULONG page)
123 {
124  const MUI_ENTRY * entry;
125  ULONG index;
126 
128  if (!entry)
129  {
130  PopupError("Error: Failed to find translated page",
131  NULL,
132  NULL,
134  return;
135  }
136 
137  index = 0;
138  while (entry[index].Buffer != NULL)
139  {
141  entry[index].Y,
142  entry[index].Flags,
144  index++;
145  }
146 }
147 
148 VOID
150  IN ULONG page)
151 {
152  const MUI_ENTRY * entry;
153  ULONG index;
154 
156  if (!entry)
157  {
158  PopupError("Error: Failed to find translated page",
159  NULL,
160  NULL,
162  return;
163  }
164 
165  index = 0;
166  while (entry[index].Buffer != NULL)
167  {
169  entry[index].Y,
170  entry[index].Flags,
171  entry[index].Buffer);
172 
173  index++;
174  }
175 }
176 
177 VOID
179  IN ULONG ErrorNum,
180  OUT PINPUT_RECORD Ir,
181  IN ULONG WaitEvent,
182  IN va_list args)
183 {
184  const MUI_ERROR* entry;
185  CHAR Buffer[2048];
186 
187  if (ErrorNum >= ERROR_LAST_ERROR_CODE)
188  {
189  PopupError("Invalid error number provided",
190  "Press ENTER to continue",
191  Ir,
193  return;
194  }
195 
197  if (!entry)
198  {
199  PopupError("Error: Failed to find translated error message",
200  NULL,
201  NULL,
203  return;
204  }
205 
206  vsprintf(Buffer, entry[ErrorNum].ErrorText, args);
207 
209  entry[ErrorNum].ErrorStatus,
210  Ir,
211  WaitEvent);
212 }
213 
214 VOID
215 __cdecl
217  IN ULONG ErrorNum,
218  OUT PINPUT_RECORD Ir,
219  IN ULONG WaitEvent,
220  ...)
221 {
222  va_list arg_ptr;
223 
224  va_start(arg_ptr, WaitEvent);
225  MUIDisplayErrorV(ErrorNum, Ir, WaitEvent, arg_ptr);
226  va_end(arg_ptr);
227 }
228 
229 LPSTR
231  ULONG Number)
232 {
233  ULONG i;
234  const MUI_STRING * entry;
235  CHAR szErr[128];
236 
238  if (entry)
239  {
240  for (i = 0; entry[i].Number != 0; i++)
241  {
242  if (entry[i].Number == Number)
243  {
244  return entry[i].String;
245  }
246  }
247  }
248 
249  sprintf(szErr, "Error: failed find string id %lu for language index %lu\n", Number, FindLanguageIndex());
250 
252  NULL,
253  NULL,
255 
256  return "<nostring>";
257 }
258 
275 const MUI_ENTRY *
277  IN ULONG Page,
278  IN INT TextID)
279 {
280  const MUI_ENTRY * entry;
281  ULONG index;
282 
283  /* Retrieve the entries of a MUI page */
284  entry = FindMUIEntriesOfPage(Page);
285  if (!entry)
286  {
287  DPRINT("MUIGetEntryData(): Failed to get the translated entry page!\n");
288  return NULL;
289  }
290 
291  /* Loop over the ID entries and check if it matches with one of them */
292  for (index = 0; entry[index].Buffer != NULL; index++)
293  {
294  if (entry[index].TextID == TextID)
295  {
296  /* They match so return the MUI entry */
297  return &entry[index];
298  }
299  }
300 
301  /* Page number or ID are incorrect so in this case bail out */
302  DPRINT("Couldn't get the MUI entry field from the page!\n");
303  return NULL;
304 }
305 
322 VOID
324  IN ULONG Page,
325  IN INT TextID)
326 {
327  const MUI_ENTRY * entry;
328 
329  /* Get the MUI entry */
330  entry = MUIGetEntry(Page, TextID);
331 
332  if (!entry)
333  return;
334 
335  /* Remove the text by using CONSOLE_ClearTextXY() */
337  entry->X,
338  entry->Y,
339  (ULONG)strlen(entry->Buffer));
340 }
341 
362 VOID
364  IN ULONG Page,
365  IN INT TextID,
366  IN INT Flags)
367 {
368  const MUI_ENTRY * entry;
369 
370  /* Get the MUI entry */
371  entry = MUIGetEntry(Page, TextID);
372 
373  if (!entry)
374  return;
375 
376  /* Now, begin removing the text by calling CONSOLE_ClearStyledText() */
378  entry->X,
379  entry->Y,
380  Flags,
381  (ULONG)strlen(entry->Buffer));
382 }
383 
400 VOID
402  IN ULONG Page,
403  IN INT TextID)
404 {
405  const MUI_ENTRY * entry;
406 
407  /* Get the MUI entry */
408  entry = MUIGetEntry(Page, TextID);
409 
410  if (!entry)
411  return;
412 
413  /* Print the text to the console output by calling CONSOLE_SetTextXY() */
414  CONSOLE_SetTextXY(entry->X, entry->Y, entry->Buffer);
415 }
416 
437 VOID
439  IN ULONG Page,
440  IN INT TextID,
441  IN INT Flags)
442 {
443  const MUI_ENTRY * entry;
444 
445  /* Get the MUI entry */
446  entry = MUIGetEntry(Page, TextID);
447 
448  if (!entry)
449  return;
450 
451  /* Print the text to the console output by calling CONSOLE_SetStyledText() */
452  CONSOLE_SetStyledText(entry->X, entry->Y, Flags, entry->Buffer);
453 }
454 
455 VOID
457 {
458  UINT wCodePage;
459 
460 #if 0
461  ULONG lngIndex = 0;
462 
463  while (ResourceList[lngIndex].MuiPages != NULL)
464  {
465  if (_wcsicmp(ResourceList[lngIndex].LanguageID, SelectedLanguageId) == 0)
466  {
467  wCodePage = (UINT) wcstoul(ResourceList[lngIndex].OEMCPage, NULL, 10);
468  SetConsoleOutputCP(wCodePage);
469  return;
470  }
471 
472  lngIndex++;
473  }
474 #else
476  SetConsoleOutputCP(wCodePage);
477 #endif
478 }
479 
480 /* EOF */
#define IN
Definition: typedefs.h:39
BOOL WINAPI SetConsoleOutputCP(IN UINT wCodepage)
Definition: console.c:692
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
#define POPUP_WAIT_NONE
Definition: usetup.h:124
VOID CONSOLE_SetTextXY(IN SHORT x, IN SHORT y, IN LPCSTR Text)
Definition: consup.c:305
#define Y(I)
#define __cdecl
Definition: accygwin.h:79
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
VOID CONSOLE_ClearTextXY(IN SHORT x, IN SHORT y, IN SHORT Length)
Definition: consup.c:325
VOID MUIDisplayPage(IN ULONG page)
Definition: mui.c:149
char CHAR
Definition: xmlstorage.h:175
VOID PopupError(PCCH Text, PCCH Status, PINPUT_RECORD Ir, ULONG WaitEvent)
Definition: usetup.c:256
Definition: mui.h:18
uint16_t * PWCHAR
Definition: typedefs.h:55
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
char * LPSTR
Definition: xmlstorage.h:182
const MUI_ERROR * MuiErrors
Definition: mui.h:35
static const MUI_STRING * FindMUIStringEntries(VOID)
Definition: mui.c:113
Definition: match.c:390
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
int32_t INT
Definition: typedefs.h:57
PCWSTR MUIGetOEMCodePage(IN PCWSTR LanguageId)
Definition: mui.c:96
VOID MUISetStyledText(IN ULONG Page, IN INT TextID, IN INT Flags)
Definition: mui.c:438
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define va_end(ap)
Definition: acmsvcex.h:90
const MUI_PAGE * MuiPages
Definition: mui.h:34
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
VOID MUIClearStyledText(IN ULONG Page, IN INT TextID, IN INT Flags)
Definition: mui.c:363
char * va_list
Definition: acmsvcex.h:78
void DPRINT(...)
Definition: polytest.cpp:61
Definition: module.h:566
Definition: bufpool.h:45
GLuint index
Definition: glext.h:6031
const MUI_STRING * MuiStrings
Definition: mui.h:36
Definition: mui.h:24
static const MUI_ERROR * FindMUIErrorEntries(VOID)
Definition: mui.c:105
VOID MUIClearPage(IN ULONG page)
Definition: mui.c:121
VOID CONSOLE_SetStyledText(IN SHORT x, IN SHORT y, IN INT Flags, IN LPCSTR Text)
Definition: consup.c:669
PCWSTR SelectedLanguageId
Definition: usetup.c:66
#define index(s, c)
Definition: various.h:29
uint32_t entry
Definition: isohybrid.c:63
LPSTR MUIGetString(ULONG Number)
Definition: mui.c:230
VOID __cdecl MUIDisplayError(IN ULONG ErrorNum, OUT PINPUT_RECORD Ir, IN ULONG WaitEvent,...)
Definition: mui.c:216
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
Definition: mui.h:3
static ULONG FindLanguageIndex(VOID)
Definition: mui.c:35
#define POPUP_WAIT_ENTER
Definition: usetup.h:126
Definition: mui.h:12
VOID MUIClearText(IN ULONG Page, IN INT TextID)
Definition: mui.c:323
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define va_start(ap, A)
Definition: acmsvcex.h:91
unsigned int UINT
Definition: ndis.h:50
BOOLEAN IsLanguageAvailable(IN PCWSTR LanguageId)
Definition: mui.c:70
VOID MUIDisplayErrorV(IN ULONG ErrorNum, OUT PINPUT_RECORD Ir, IN ULONG WaitEvent, IN va_list args)
Definition: mui.c:178
TCHAR szErr[256]
Definition: service.c:38
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
const MUI_ENTRY * MUIGetEntry(IN ULONG Page, IN INT TextID)
Definition: mui.c:276
VOID CONSOLE_ClearStyledText(IN SHORT x, IN SHORT y, IN INT Flags, IN SHORT Length)
Definition: consup.c:754
static const MUI_ENTRY * FindMUIEntriesOfPage(IN ULONG PageNumber)
Definition: mui.c:82
VOID MUISetText(IN ULONG Page, IN INT TextID)
Definition: mui.c:401
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
VOID SetConsoleCodePage(VOID)
Definition: mui.c:456
MUI_ENTRY * MuiEntry
Definition: mui.h:21