2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2013 Free Software Foundation, Inc.
5
* GRUB 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 3 of the License, or
8
* (at your option) any later version.
10
* GRUB 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.
15
* You should have received a copy of the GNU General Public License
16
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20
#include <config-util.h>
21
#include <grub/util/misc.h>
22
#include <grub/osdep/hostfile.h>
23
#include <grub/util/windows.h>
24
#include <grub/emu/config.h>
29
#include <grub/util/misc.h>
33
struct grub_windows_console_font_infoex {
39
WCHAR FaceName[LF_FACESIZE];
43
check_is_raster (HMODULE kernel32, HANDLE hnd)
45
CONSOLE_FONT_INFO console_font_info;
46
BOOL (WINAPI * func_GetCurrentConsoleFont) (HANDLE, BOOL,
49
func_GetCurrentConsoleFont = (void *)
50
GetProcAddress (kernel32, "GetCurrentConsoleFont");
52
if (!func_GetCurrentConsoleFont)
55
if (!func_GetCurrentConsoleFont (hnd, FALSE, &console_font_info))
57
return console_font_info.nFont < 12;
61
set_console_unicode_font (void)
63
BOOL (WINAPI * func_SetCurrentConsoleFontEx) (HANDLE, BOOL,
64
struct grub_windows_console_font_infoex *);
65
BOOL (WINAPI * func_SetConsoleFont)(HANDLE, DWORD);
67
HANDLE out_handle = GetStdHandle (STD_OUTPUT_HANDLE);
68
HANDLE err_handle = GetStdHandle (STD_ERROR_HANDLE);
69
int out_raster, err_raster;
71
kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
75
out_raster = check_is_raster (kernel32, out_handle);
76
err_raster = check_is_raster (kernel32, err_handle);
78
if (!out_raster && !err_raster)
81
func_SetCurrentConsoleFontEx = (void *) GetProcAddress (kernel32, "SetCurrentConsoleFontEx");
83
/* Newer windows versions. */
84
if (func_SetCurrentConsoleFontEx)
86
struct grub_windows_console_font_infoex new_console_font_info;
87
new_console_font_info.cbSize = sizeof (new_console_font_info);
88
new_console_font_info.nFont = 12;
89
new_console_font_info.dwFontSize.X = 7;
90
new_console_font_info.dwFontSize.Y = 12;
91
new_console_font_info.FontFamily = FF_DONTCARE;
92
new_console_font_info.FontWeight = 400;
93
memcpy (new_console_font_info.FaceName, TEXT("Lucida Console"),
94
sizeof (TEXT("Lucida Console")));
96
func_SetCurrentConsoleFontEx (out_handle, FALSE,
97
&new_console_font_info);
99
func_SetCurrentConsoleFontEx (err_handle, FALSE,
100
&new_console_font_info);
104
/* Fallback for older versions. */
105
func_SetConsoleFont = (void *) GetProcAddress (kernel32, "SetConsoleFont");
106
if (func_SetConsoleFont)
109
func_SetConsoleFont (out_handle, 12);
111
func_SetConsoleFont (err_handle, 12);
115
static char *grub_util_base_directory;
116
static char *locale_dir;
119
grub_util_get_config_filename (void)
121
static char *value = NULL;
123
value = grub_util_path_concat (2, grub_util_base_directory, "grub.cfg");
128
grub_util_get_pkgdatadir (void)
130
return grub_util_base_directory;
134
grub_util_get_localedir (void)
140
grub_util_get_pkglibdir (void)
142
return grub_util_base_directory;
146
grub_util_host_init (int *argc __attribute__ ((unused)),
151
SetConsoleOutputCP (CP_UTF8);
152
SetConsoleCP (CP_UTF8);
154
set_console_unicode_font ();
156
#if SIZEOF_TCHAR == 1
158
#elif SIZEOF_TCHAR == 2
159
LPWSTR tcmdline = GetCommandLineW ();
163
targv = CommandLineToArgvW (tcmdline, argc);
164
*argv = xmalloc ((*argc + 1) * sizeof (argv[0]));
166
for (i = 0; i < *argc; i++)
167
(*argv)[i] = grub_util_tchar_to_utf8 (targv[i]);
170
#error "Unsupported TCHAR size"
173
grub_util_base_directory = canonicalize_file_name ((*argv)[0]);
174
if (!grub_util_base_directory)
175
grub_util_base_directory = xstrdup ((*argv)[0]);
176
for (ptr = grub_util_base_directory + strlen (grub_util_base_directory) - 1;
177
ptr >= grub_util_base_directory && *ptr != '/' && *ptr != '\\'; ptr--);
178
if (ptr >= grub_util_base_directory)
181
locale_dir = grub_util_path_concat (2, grub_util_base_directory, "locale");
183
set_program_name ((*argv)[0]);
185
#if (defined (GRUB_UTIL) && defined(ENABLE_NLS) && ENABLE_NLS)
186
setlocale (LC_ALL, "");
187
bindtextdomain (PACKAGE, locale_dir);
188
textdomain (PACKAGE);
189
#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */