2 * an application for displaying Win32 console
3 * registry and init functions
5 * Copyright 2001 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "winecon_private.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wineconsole
);
33 static const WCHAR wszConsole
[] = {'C','o','n','s','o','l','e',0};
34 static const WCHAR wszCursorSize
[] = {'C','u','r','s','o','r','S','i','z','e',0};
35 static const WCHAR wszCursorVisible
[] = {'C','u','r','s','o','r','V','i','s','i','b','l','e',0};
36 static const WCHAR wszEditionMode
[] = {'E','d','i','t','i','o','n','M','o','d','e',0};
37 static const WCHAR wszExitOnDie
[] = {'E','x','i','t','O','n','D','i','e',0};
38 static const WCHAR wszFaceName
[] = {'F','a','c','e','N','a','m','e',0};
39 static const WCHAR wszFontSize
[] = {'F','o','n','t','S','i','z','e',0};
40 static const WCHAR wszFontWeight
[] = {'F','o','n','t','W','e','i','g','h','t',0};
41 static const WCHAR wszHistoryBufferSize
[] = {'H','i','s','t','o','r','y','B','u','f','f','e','r','S','i','z','e',0};
42 static const WCHAR wszHistoryNoDup
[] = {'H','i','s','t','o','r','y','N','o','D','u','p',0};
43 static const WCHAR wszMenuMask
[] = {'M','e','n','u','M','a','s','k',0};
44 static const WCHAR wszQuickEdit
[] = {'Q','u','i','c','k','E','d','i','t',0};
45 static const WCHAR wszScreenBufferSize
[] = {'S','c','r','e','e','n','B','u','f','f','e','r','S','i','z','e',0};
46 static const WCHAR wszScreenColors
[] = {'S','c','r','e','e','n','C','o','l','o','r','s',0};
47 static const WCHAR wszWindowSize
[] = {'W','i','n','d','o','w','S','i','z','e',0};
49 void WINECON_DumpConfig(const char* pfx
, const struct config_data
* cfg
)
51 WINE_TRACE("%s cell=(%u,%u) cursor=(%d,%d) attr=%02lx font=%s/%lu hist=%lu/%d flags=%c%c msk=%08lx sb=(%u,%u) win=(%u,%u)x(%u,%u) edit=%u registry=%s\n",
52 pfx
, cfg
->cell_width
, cfg
->cell_height
, cfg
->cursor_size
, cfg
->cursor_visible
, cfg
->def_attr
,
53 wine_dbgstr_w(cfg
->face_name
), cfg
->font_weight
, cfg
->history_size
, cfg
->history_nodup
? 1 : 2,
54 cfg
->quick_edit
? 'Q' : 'q', cfg
->exit_on_die
? 'X' : 'x',
55 cfg
->menu_mask
, cfg
->sb_width
, cfg
->sb_height
, cfg
->win_pos
.X
, cfg
->win_pos
.Y
, cfg
->win_width
, cfg
->win_height
,
57 wine_dbgstr_w(cfg
->registry
));
60 /******************************************************************
61 * WINECON_CreateKeyName
63 * Get a proper key name from an appname (mainly convert '\\' to '_')
65 static LPWSTR
WINECON_CreateKeyName(LPCWSTR kn
)
67 LPWSTR ret
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(kn
) + 1) * sizeof(WCHAR
));
70 if (!ptr
) WINECON_Fatal("OOM");
74 *ptr
++ = *kn
== '\\' ? '_' : *kn
;
79 /******************************************************************
80 * WINECON_RegLoadHelper
82 * Read the basic configuration from any console key or subkey
84 static void WINECON_RegLoadHelper(HKEY hConKey
, struct config_data
* cfg
)
91 if (!RegQueryValueEx(hConKey
, wszCursorSize
, 0, &type
, (LPBYTE
)&val
, &count
))
92 cfg
->cursor_size
= val
;
95 if (!RegQueryValueEx(hConKey
, wszCursorVisible
, 0, &type
, (LPBYTE
)&val
, &count
))
96 cfg
->cursor_visible
= val
;
99 if (!RegQueryValueEx(hConKey
, wszEditionMode
, 0, &type
, (LPBYTE
)&val
, &count
))
100 cfg
->edition_mode
= val
;
103 if (!RegQueryValueEx(hConKey
, wszExitOnDie
, 0, &type
, (LPBYTE
)&val
, &count
))
104 cfg
->exit_on_die
= val
;
106 count
= sizeof(cfg
->face_name
);
107 RegQueryValueEx(hConKey
, wszFaceName
, 0, &type
, (LPBYTE
)&cfg
->face_name
, &count
);
110 if (!RegQueryValueEx(hConKey
, wszFontSize
, 0, &type
, (LPBYTE
)&val
, &count
))
112 cfg
->cell_height
= HIWORD(val
);
113 cfg
->cell_width
= LOWORD(val
);
117 if (!RegQueryValueEx(hConKey
, wszFontWeight
, 0, &type
, (LPBYTE
)&val
, &count
))
118 cfg
->font_weight
= val
;
121 if (!RegQueryValueEx(hConKey
, wszHistoryBufferSize
, 0, &type
, (LPBYTE
)&val
, &count
))
122 cfg
->history_size
= val
;
125 if (!RegQueryValueEx(hConKey
, wszHistoryNoDup
, 0, &type
, (LPBYTE
)&val
, &count
))
126 cfg
->history_nodup
= val
;
129 if (!RegQueryValueEx(hConKey
, wszMenuMask
, 0, &type
, (LPBYTE
)&val
, &count
))
130 cfg
->menu_mask
= val
;
133 if (!RegQueryValueEx(hConKey
, wszQuickEdit
, 0, &type
, (LPBYTE
)&val
, &count
))
134 cfg
->quick_edit
= val
;
137 if (!RegQueryValueEx(hConKey
, wszScreenBufferSize
, 0, &type
, (LPBYTE
)&val
, &count
))
139 cfg
->sb_height
= HIWORD(val
);
140 cfg
->sb_width
= LOWORD(val
);
144 if (!RegQueryValueEx(hConKey
, wszScreenColors
, 0, &type
, (LPBYTE
)&val
, &count
))
148 if (!RegQueryValueEx(hConKey
, wszWindowSize
, 0, &type
, (LPBYTE
)&val
, &count
))
150 cfg
->win_height
= HIWORD(val
);
151 cfg
->win_width
= LOWORD(val
);
154 /* win_pos isn't read from registry */
157 /******************************************************************
162 void WINECON_RegLoad(const WCHAR
* appname
, struct config_data
* cfg
)
166 WINE_TRACE("loading %s registry settings.\n", appname
? wine_dbgstr_w(appname
) : "default");
168 /* first set default values */
169 cfg
->cursor_size
= 25;
170 cfg
->cursor_visible
= 1;
171 cfg
->exit_on_die
= 1;
172 memset(cfg
->face_name
, 0, sizeof(cfg
->face_name
));
173 cfg
->cell_height
= 12;
175 cfg
->font_weight
= 0;
176 cfg
->history_size
= 50;
177 cfg
->history_nodup
= 0;
182 cfg
->def_attr
= 0x000F;
183 cfg
->win_height
= 25;
187 cfg
->edition_mode
= 0;
188 cfg
->registry
= NULL
;
190 /* then read global settings */
191 if (!RegOpenKey(HKEY_CURRENT_USER
, wszConsole
, &hConKey
))
193 WINECON_RegLoadHelper(hConKey
, cfg
);
194 /* if requested, load part related to console title */
199 cfg
->registry
= WINECON_CreateKeyName(appname
);
200 if (!RegOpenKey(hConKey
, cfg
->registry
, &hAppKey
))
202 WINECON_RegLoadHelper(hAppKey
, cfg
);
203 RegCloseKey(hAppKey
);
206 RegCloseKey(hConKey
);
208 WINECON_DumpConfig("load", cfg
);
211 /******************************************************************
212 * WINECON_RegSaveHelper
216 static void WINECON_RegSaveHelper(HKEY hConKey
, const struct config_data
* cfg
)
220 WINECON_DumpConfig("save", cfg
);
222 val
= cfg
->cursor_size
;
223 RegSetValueEx(hConKey
, wszCursorSize
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
225 val
= cfg
->cursor_visible
;
226 RegSetValueEx(hConKey
, wszCursorVisible
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
228 val
= cfg
->edition_mode
;
229 RegSetValueEx(hConKey
, wszEditionMode
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
231 val
= cfg
->exit_on_die
;
232 RegSetValueEx(hConKey
, wszExitOnDie
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
234 RegSetValueEx(hConKey
, wszFaceName
, 0, REG_SZ
, (LPBYTE
)&cfg
->face_name
, sizeof(cfg
->face_name
));
236 val
= MAKELONG(cfg
->cell_width
, cfg
->cell_height
);
237 RegSetValueEx(hConKey
, wszFontSize
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
239 val
= cfg
->font_weight
;
240 RegSetValueEx(hConKey
, wszFontWeight
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
242 val
= cfg
->history_size
;
243 RegSetValueEx(hConKey
, wszHistoryBufferSize
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
245 val
= cfg
->history_nodup
;
246 RegSetValueEx(hConKey
, wszHistoryNoDup
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
248 val
= cfg
->menu_mask
;
249 RegSetValueEx(hConKey
, wszMenuMask
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
251 val
= cfg
->quick_edit
;
252 RegSetValueEx(hConKey
, wszQuickEdit
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
254 val
= MAKELONG(cfg
->sb_width
, cfg
->sb_height
);
255 RegSetValueEx(hConKey
, wszScreenBufferSize
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
258 RegSetValueEx(hConKey
, wszScreenColors
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
260 val
= MAKELONG(cfg
->win_width
, cfg
->win_height
);
261 RegSetValueEx(hConKey
, wszWindowSize
, 0, REG_DWORD
, (LPBYTE
)&val
, sizeof(val
));
264 /******************************************************************
269 void WINECON_RegSave(const struct config_data
* cfg
)
273 WINE_TRACE("saving registry settings.\n");
274 if (RegCreateKey(HKEY_CURRENT_USER
, wszConsole
, &hConKey
))
276 WINE_ERR("Can't open registry for saving\n");
284 if (RegCreateKey(hConKey
, cfg
->registry
, &hAppKey
))
286 WINE_ERR("Can't open registry for saving\n");
290 /* FIXME: maybe only save the values different from the default value ? */
291 WINECON_RegSaveHelper(hAppKey
, cfg
);
292 RegCloseKey(hAppKey
);
295 else WINECON_RegSaveHelper(hConKey
, cfg
);
296 RegCloseKey(hConKey
);