Pass correct instance in keyboard_hook setup.
[wine/multimedia.git] / programs / wineconsole / registry.c
blob4d650627b32a6118c780b39ed5bb46e8969ef84d
1 /*
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
22 #include "winbase.h"
23 #include "winreg.h"
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 wszExitOnDie[] = {'E','x','i','t','O','n','D','i','e',0};
34 static const WCHAR wszFaceName[] = {'F','a','c','e','N','a','m','e',0};
35 static const WCHAR wszFontSize[] = {'F','o','n','t','S','i','z','e',0};
36 static const WCHAR wszFontWeight[] = {'F','o','n','t','W','e','i','g','h','t',0};
37 static const WCHAR wszHistoryBufferSize[] = {'H','i','s','t','o','r','y','B','u','f','f','e','r','S','i','z','e',0};
38 static const WCHAR wszHistoryNoDup[] = {'H','i','s','t','o','r','y','N','o','D','u','p',0};
39 static const WCHAR wszMenuMask[] = {'M','e','n','u','M','a','s','k',0};
40 static const WCHAR wszQuickEdit[] = {'Q','u','i','c','k','E','d','i','t',0};
41 static const WCHAR wszScreenBufferSize[] = {'S','c','r','e','e','n','B','u','f','f','e','r','S','i','z','e',0};
42 static const WCHAR wszScreenColors[] = {'S','c','r','e','e','n','C','o','l','o','r','s',0};
43 static const WCHAR wszWindowSize[] = {'W','i','n','d','o','w','S','i','z','e',0};
45 void WINECON_DumpConfig(const char* pfx, const struct config_data* cfg)
47 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) registry=%s\n",
48 pfx, cfg->cell_width, cfg->cell_height, cfg->cursor_size, cfg->cursor_visible, cfg->def_attr,
49 wine_dbgstr_w(cfg->face_name), cfg->font_weight, cfg->history_size, cfg->history_nodup ? 1 : 2,
50 cfg->quick_edit ? 'Q' : 'q', cfg->exit_on_die ? 'X' : 'x',
51 cfg->menu_mask, cfg->sb_width, cfg->sb_height, cfg->win_pos.X, cfg->win_pos.Y, cfg->win_width, cfg->win_height,
52 wine_dbgstr_w(cfg->registry));
55 /******************************************************************
56 * WINECON_CreateKeyName
58 * Get a proper key name from an appname (mainly convert '\\' to '_')
60 static LPWSTR WINECON_CreateKeyName(LPCWSTR kn)
62 LPWSTR ret = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(kn) + 1) * sizeof(WCHAR));
63 LPWSTR ptr = ret;
65 if (!ptr) WINECON_Fatal("OOM");
69 *ptr++ = *kn == '\\' ? '_' : *kn;
70 } while (*kn++ != 0);
71 return ret;
74 /******************************************************************
75 * WINECON_RegLoadHelper
77 * Read the basic configuration from any console key or subkey
79 static void WINECON_RegLoadHelper(HKEY hConKey, struct config_data* cfg)
81 DWORD type;
82 DWORD count;
83 DWORD val;
85 count = sizeof(val);
86 if (!RegQueryValueEx(hConKey, wszCursorSize, 0, &type, (char*)&val, &count))
87 cfg->cursor_size = val;
89 count = sizeof(val);
90 if (!RegQueryValueEx(hConKey, wszCursorVisible, 0, &type, (char*)&val, &count))
91 cfg->cursor_visible = val;
93 count = sizeof(val);
94 if (!RegQueryValueEx(hConKey, wszExitOnDie, 0, &type, (char*)&val, &count))
95 cfg->exit_on_die = val;
97 count = sizeof(cfg->face_name);
98 RegQueryValueEx(hConKey, wszFaceName, 0, &type, (char*)&cfg->face_name, &count);
100 count = sizeof(val);
101 if (!RegQueryValueEx(hConKey, wszFontSize, 0, &type, (char*)&val, &count))
103 cfg->cell_height = HIWORD(val);
104 cfg->cell_width = LOWORD(val);
107 count = sizeof(val);
108 if (!RegQueryValueEx(hConKey, wszFontWeight, 0, &type, (char*)&val, &count))
109 cfg->font_weight = val;
111 count = sizeof(val);
112 if (!RegQueryValueEx(hConKey, wszHistoryBufferSize, 0, &type, (char*)&val, &count))
113 cfg->history_size = val;
115 count = sizeof(val);
116 if (!RegQueryValueEx(hConKey, wszHistoryNoDup, 0, &type, (char*)&val, &count))
117 cfg->history_nodup = val;
119 count = sizeof(val);
120 if (!RegQueryValueEx(hConKey, wszMenuMask, 0, &type, (char*)&val, &count))
121 cfg->menu_mask = val;
123 count = sizeof(val);
124 if (!RegQueryValueEx(hConKey, wszQuickEdit, 0, &type, (char*)&val, &count))
125 cfg->quick_edit = val;
127 count = sizeof(val);
128 if (!RegQueryValueEx(hConKey, wszScreenBufferSize, 0, &type, (char*)&val, &count))
130 cfg->sb_height = HIWORD(val);
131 cfg->sb_width = LOWORD(val);
134 count = sizeof(val);
135 if (!RegQueryValueEx(hConKey, wszScreenColors, 0, &type, (char*)&val, &count))
136 cfg->def_attr = val;
138 count = sizeof(val);
139 if (!RegQueryValueEx(hConKey, wszWindowSize, 0, &type, (char*)&val, &count))
141 cfg->win_height = HIWORD(val);
142 cfg->win_width = LOWORD(val);
145 /* win_pos isn't read from registry */
148 /******************************************************************
149 * WINECON_RegLoad
153 void WINECON_RegLoad(const WCHAR* appname, struct config_data* cfg)
155 HKEY hConKey;
157 WINE_TRACE("loading %s registry settings.\n", appname ? wine_dbgstr_w(appname) : "default");
159 /* first set default values */
160 cfg->cursor_size = 25;
161 cfg->cursor_visible = 1;
162 cfg->exit_on_die = 1;
163 cfg->face_name[0] = 0;
164 cfg->cell_height = 12;
165 cfg->cell_width = 8;
166 cfg->font_weight = 0;
167 cfg->history_size = 0;
168 cfg->history_nodup = 0;
169 cfg->menu_mask = 0;
170 cfg->quick_edit = 0;
171 cfg->sb_height = 25;
172 cfg->sb_width = 80;
173 cfg->def_attr = 0x000F;
174 cfg->win_height = 25;
175 cfg->win_width = 80;
176 cfg->registry = NULL;
178 /* then read global settings */
179 if (!RegOpenKey(HKEY_CURRENT_USER, wszConsole, &hConKey))
181 WINECON_RegLoadHelper(hConKey, cfg);
182 /* if requested, load part related to console title */
183 if (appname)
185 HKEY hAppKey;
187 cfg->registry = WINECON_CreateKeyName(appname);
188 if (!RegOpenKey(hConKey, cfg->registry, &hAppKey))
190 WINECON_RegLoadHelper(hAppKey, cfg);
191 RegCloseKey(hAppKey);
194 RegCloseKey(hConKey);
196 WINECON_DumpConfig("load", cfg);
199 /******************************************************************
200 * WINECON_RegSaveHelper
204 static void WINECON_RegSaveHelper(HKEY hConKey, const struct config_data* cfg)
206 DWORD val;
208 WINECON_DumpConfig("save", cfg);
210 val = cfg->cursor_size;
211 RegSetValueEx(hConKey, wszCursorSize, 0, REG_DWORD, (char*)&val, sizeof(val));
213 val = cfg->cursor_visible;
214 RegSetValueEx(hConKey, wszCursorVisible, 0, REG_DWORD, (char*)&val, sizeof(val));
216 val = cfg->exit_on_die;
217 RegSetValueEx(hConKey, wszExitOnDie, 0, REG_DWORD, (char*)&val, sizeof(val));
219 RegSetValueEx(hConKey, wszFaceName, 0, REG_SZ, (char*)&cfg->face_name, sizeof(cfg->face_name));
221 val = MAKELONG(cfg->cell_width, cfg->cell_height);
222 RegSetValueEx(hConKey, wszFontSize, 0, REG_DWORD, (char*)&val, sizeof(val));
224 val = cfg->font_weight;
225 RegSetValueEx(hConKey, wszFontWeight, 0, REG_DWORD, (char*)&val, sizeof(val));
227 val = cfg->history_size;
228 RegSetValueEx(hConKey, wszHistoryBufferSize, 0, REG_DWORD, (char*)&val, sizeof(val));
230 val = cfg->history_nodup;
231 RegSetValueEx(hConKey, wszHistoryNoDup, 0, REG_DWORD, (char*)&val, sizeof(val));
233 val = cfg->menu_mask;
234 RegSetValueEx(hConKey, wszMenuMask, 0, REG_DWORD, (char*)&val, sizeof(val));
236 val = cfg->quick_edit;
237 RegSetValueEx(hConKey, wszQuickEdit, 0, REG_DWORD, (char*)&val, sizeof(val));
239 val = MAKELONG(cfg->sb_width, cfg->sb_height);
240 RegSetValueEx(hConKey, wszScreenBufferSize, 0, REG_DWORD, (char*)&val, sizeof(val));
242 val = cfg->def_attr;
243 RegSetValueEx(hConKey, wszScreenColors, 0, REG_DWORD, (char*)&val, sizeof(val));
245 val = MAKELONG(cfg->win_width, cfg->win_height);
246 RegSetValueEx(hConKey, wszWindowSize, 0, REG_DWORD, (char*)&val, sizeof(val));
249 /******************************************************************
250 * WINECON_RegSave
254 void WINECON_RegSave(const struct config_data* cfg)
256 HKEY hConKey;
258 WINE_TRACE("saving registry settings.\n");
259 if (RegCreateKey(HKEY_CURRENT_USER, wszConsole, &hConKey))
261 WINE_ERR("Can't open registry for saving\n");
263 else
265 if (cfg->registry)
267 HKEY hAppKey;
269 if (RegCreateKey(hConKey, cfg->registry, &hAppKey))
271 WINE_ERR("Can't open registry for saving\n");
273 else
275 /* FIXME: maybe only save the values different from the default value ? */
276 WINECON_RegSaveHelper(hAppKey, cfg);
277 RegCloseKey(hAppKey);
280 else WINECON_RegSaveHelper(hConKey, cfg);
281 RegCloseKey(hConKey);