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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "winecon_private.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(wineconsole);
30 static const WCHAR wszConsole[] = {'C','o','n','s','o','l','e',0};
31 static const WCHAR wszCursorSize[] = {'C','u','r','s','o','r','S','i','z','e',0};
32 static const WCHAR wszCursorVisible[] = {'C','u','r','s','o','r','V','i','s','i','b','l','e',0};
33 static const WCHAR wszEditionMode[] = {'E','d','i','t','i','o','n','M','o','d','e',0};
34 static const WCHAR wszExitOnDie[] = {'E','x','i','t','O','n','D','i','e',0};
35 static const WCHAR wszFaceName[] = {'F','a','c','e','N','a','m','e',0};
36 static const WCHAR wszFontSize[] = {'F','o','n','t','S','i','z','e',0};
37 static const WCHAR wszFontWeight[] = {'F','o','n','t','W','e','i','g','h','t',0};
38 static const WCHAR wszHistoryBufferSize[] = {'H','i','s','t','o','r','y','B','u','f','f','e','r','S','i','z','e',0};
39 static const WCHAR wszHistoryNoDup[] = {'H','i','s','t','o','r','y','N','o','D','u','p',0};
40 static const WCHAR wszMenuMask[] = {'M','e','n','u','M','a','s','k',0};
41 static const WCHAR wszQuickEdit[] = {'Q','u','i','c','k','E','d','i','t',0};
42 static const WCHAR wszScreenBufferSize[] = {'S','c','r','e','e','n','B','u','f','f','e','r','S','i','z','e',0};
43 static const WCHAR wszScreenColors[] = {'S','c','r','e','e','n','C','o','l','o','r','s',0};
44 static const WCHAR wszWindowSize[] = {'W','i','n','d','o','w','S','i','z','e',0};
46 void WINECON_DumpConfig(const char* pfx, const struct config_data* cfg)
48 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",
49 pfx, cfg->cell_width, cfg->cell_height, cfg->cursor_size, cfg->cursor_visible, cfg->def_attr,
50 wine_dbgstr_w(cfg->face_name), cfg->font_weight, cfg->history_size, cfg->history_nodup ? 1 : 2,
51 cfg->quick_edit ? 'Q' : 'q', cfg->exit_on_die ? 'X' : 'x',
52 cfg->menu_mask, cfg->sb_width, cfg->sb_height, cfg->win_pos.X, cfg->win_pos.Y, cfg->win_width, cfg->win_height,
54 wine_dbgstr_w(cfg->registry));
57 /******************************************************************
58 * WINECON_CreateKeyName
60 * Get a proper key name from an appname (mainly convert '\\' to '_')
62 static LPWSTR WINECON_CreateKeyName(LPCWSTR kn)
64 LPWSTR ret = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(kn) + 1) * sizeof(WCHAR));
67 if (!ptr) WINECON_Fatal("OOM");
71 *ptr++ = *kn == '\\' ? '_' : *kn;
76 /******************************************************************
77 * WINECON_RegLoadHelper
79 * Read the basic configuration from any console key or subkey
81 static void WINECON_RegLoadHelper(HKEY hConKey, struct config_data* cfg)
88 if (!RegQueryValueEx(hConKey, wszCursorSize, 0, &type, (char*)&val, &count))
89 cfg->cursor_size = val;
92 if (!RegQueryValueEx(hConKey, wszCursorVisible, 0, &type, (char*)&val, &count))
93 cfg->cursor_visible = val;
96 if (!RegQueryValueEx(hConKey, wszEditionMode, 0, &type, (char*)&val, &count))
97 cfg->edition_mode = val;
100 if (!RegQueryValueEx(hConKey, wszExitOnDie, 0, &type, (char*)&val, &count))
101 cfg->exit_on_die = val;
103 count = sizeof(cfg->face_name);
104 RegQueryValueEx(hConKey, wszFaceName, 0, &type, (char*)&cfg->face_name, &count);
107 if (!RegQueryValueEx(hConKey, wszFontSize, 0, &type, (char*)&val, &count))
109 cfg->cell_height = HIWORD(val);
110 cfg->cell_width = LOWORD(val);
114 if (!RegQueryValueEx(hConKey, wszFontWeight, 0, &type, (char*)&val, &count))
115 cfg->font_weight = val;
118 if (!RegQueryValueEx(hConKey, wszHistoryBufferSize, 0, &type, (char*)&val, &count))
119 cfg->history_size = val;
122 if (!RegQueryValueEx(hConKey, wszHistoryNoDup, 0, &type, (char*)&val, &count))
123 cfg->history_nodup = val;
126 if (!RegQueryValueEx(hConKey, wszMenuMask, 0, &type, (char*)&val, &count))
127 cfg->menu_mask = val;
130 if (!RegQueryValueEx(hConKey, wszQuickEdit, 0, &type, (char*)&val, &count))
131 cfg->quick_edit = val;
134 if (!RegQueryValueEx(hConKey, wszScreenBufferSize, 0, &type, (char*)&val, &count))
136 cfg->sb_height = HIWORD(val);
137 cfg->sb_width = LOWORD(val);
141 if (!RegQueryValueEx(hConKey, wszScreenColors, 0, &type, (char*)&val, &count))
145 if (!RegQueryValueEx(hConKey, wszWindowSize, 0, &type, (char*)&val, &count))
147 cfg->win_height = HIWORD(val);
148 cfg->win_width = LOWORD(val);
151 /* win_pos isn't read from registry */
154 /******************************************************************
159 void WINECON_RegLoad(const WCHAR* appname, struct config_data* cfg)
163 WINE_TRACE("loading %s registry settings.\n", appname ? wine_dbgstr_w(appname) : "default");
165 /* first set default values */
166 cfg->cursor_size = 25;
167 cfg->cursor_visible = 1;
168 cfg->exit_on_die = 1;
169 memset(cfg->face_name, 0, sizeof(cfg->face_name));
170 cfg->cell_height = 12;
172 cfg->font_weight = 0;
173 cfg->history_size = 50;
174 cfg->history_nodup = 0;
179 cfg->def_attr = 0x000F;
180 cfg->win_height = 25;
184 cfg->edition_mode = 0;
185 cfg->registry = NULL;
187 /* then read global settings */
188 if (!RegOpenKey(HKEY_CURRENT_USER, wszConsole, &hConKey))
190 WINECON_RegLoadHelper(hConKey, cfg);
191 /* if requested, load part related to console title */
196 cfg->registry = WINECON_CreateKeyName(appname);
197 if (!RegOpenKey(hConKey, cfg->registry, &hAppKey))
199 WINECON_RegLoadHelper(hAppKey, cfg);
200 RegCloseKey(hAppKey);
203 RegCloseKey(hConKey);
205 WINECON_DumpConfig("load", cfg);
208 /******************************************************************
209 * WINECON_RegSaveHelper
213 static void WINECON_RegSaveHelper(HKEY hConKey, const struct config_data* cfg)
217 WINECON_DumpConfig("save", cfg);
219 val = cfg->cursor_size;
220 RegSetValueEx(hConKey, wszCursorSize, 0, REG_DWORD, (char*)&val, sizeof(val));
222 val = cfg->cursor_visible;
223 RegSetValueEx(hConKey, wszCursorVisible, 0, REG_DWORD, (char*)&val, sizeof(val));
225 val = cfg->edition_mode;
226 RegSetValueEx(hConKey, wszEditionMode, 0, REG_DWORD, (char*)&val, sizeof(val));
228 val = cfg->exit_on_die;
229 RegSetValueEx(hConKey, wszExitOnDie, 0, REG_DWORD, (char*)&val, sizeof(val));
231 RegSetValueEx(hConKey, wszFaceName, 0, REG_SZ, (char*)&cfg->face_name, sizeof(cfg->face_name));
233 val = MAKELONG(cfg->cell_width, cfg->cell_height);
234 RegSetValueEx(hConKey, wszFontSize, 0, REG_DWORD, (char*)&val, sizeof(val));
236 val = cfg->font_weight;
237 RegSetValueEx(hConKey, wszFontWeight, 0, REG_DWORD, (char*)&val, sizeof(val));
239 val = cfg->history_size;
240 RegSetValueEx(hConKey, wszHistoryBufferSize, 0, REG_DWORD, (char*)&val, sizeof(val));
242 val = cfg->history_nodup;
243 RegSetValueEx(hConKey, wszHistoryNoDup, 0, REG_DWORD, (char*)&val, sizeof(val));
245 val = cfg->menu_mask;
246 RegSetValueEx(hConKey, wszMenuMask, 0, REG_DWORD, (char*)&val, sizeof(val));
248 val = cfg->quick_edit;
249 RegSetValueEx(hConKey, wszQuickEdit, 0, REG_DWORD, (char*)&val, sizeof(val));
251 val = MAKELONG(cfg->sb_width, cfg->sb_height);
252 RegSetValueEx(hConKey, wszScreenBufferSize, 0, REG_DWORD, (char*)&val, sizeof(val));
255 RegSetValueEx(hConKey, wszScreenColors, 0, REG_DWORD, (char*)&val, sizeof(val));
257 val = MAKELONG(cfg->win_width, cfg->win_height);
258 RegSetValueEx(hConKey, wszWindowSize, 0, REG_DWORD, (char*)&val, sizeof(val));
261 /******************************************************************
266 void WINECON_RegSave(const struct config_data* cfg)
270 WINE_TRACE("saving registry settings.\n");
271 if (RegCreateKey(HKEY_CURRENT_USER, wszConsole, &hConKey))
273 WINE_ERR("Can't open registry for saving\n");
281 if (RegCreateKey(hConKey, cfg->registry, &hAppKey))
283 WINE_ERR("Can't open registry for saving\n");
287 /* FIXME: maybe only save the values different from the default value ? */
288 WINECON_RegSaveHelper(hAppKey, cfg);
289 RegCloseKey(hAppKey);
292 else WINECON_RegSaveHelper(hConKey, cfg);
293 RegCloseKey(hConKey);