1 | /* $Id: conprop2.cpp,v 1.4 2000-02-16 14:25:33 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 Console API Translation for OS/2
|
---|
5 | *
|
---|
6 | * 1998/03/06 Patrick Haller (haller@zebra.fh-weingarten.de)
|
---|
7 | *
|
---|
8 | * @(#) conprop.cpp 1.0.0 1998/03/06 PH Start from scratch
|
---|
9 | */
|
---|
10 |
|
---|
11 |
|
---|
12 | /*****************************************************************************
|
---|
13 | * Remark *
|
---|
14 | *****************************************************************************
|
---|
15 |
|
---|
16 | - save / load properties from EAs
|
---|
17 |
|
---|
18 | */
|
---|
19 |
|
---|
20 |
|
---|
21 | /*****************************************************************************
|
---|
22 | * Includes *
|
---|
23 | *****************************************************************************/
|
---|
24 |
|
---|
25 | #include <odin.h>
|
---|
26 | #include <odinwrap.h>
|
---|
27 | #include <os2sel.h>
|
---|
28 |
|
---|
29 | #define INCL_GPI
|
---|
30 | #define INCL_WIN
|
---|
31 | #define INCL_DOSMEMMGR
|
---|
32 | #define INCL_DOSSEMAPHORES
|
---|
33 | #define INCL_DOSERRORS
|
---|
34 | #define INCL_DOSPROCESS
|
---|
35 | #define INCL_DOSMODULEMGR
|
---|
36 | #define INCL_VIO
|
---|
37 | #define INCL_AVIO
|
---|
38 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
39 | #include <builtin.h>
|
---|
40 |
|
---|
41 | #include <win32type.h>
|
---|
42 | #include <misc.h>
|
---|
43 | #include <stdio.h>
|
---|
44 |
|
---|
45 | #include "console.h"
|
---|
46 | #include "console2.h"
|
---|
47 | #include "conprop.h"
|
---|
48 |
|
---|
49 | #define DBG_LOCALLOG DBG_conprop2
|
---|
50 | #include "dbglocal.h"
|
---|
51 |
|
---|
52 |
|
---|
53 | ODINDEBUGCHANNEL(KERNEL32-CONPROP2)
|
---|
54 |
|
---|
55 | /*****************************************************************************
|
---|
56 | * Defines *
|
---|
57 | *****************************************************************************/
|
---|
58 |
|
---|
59 | #define ERROR_SUCCESS 0
|
---|
60 |
|
---|
61 | #define REG_NONE 0 /* no type */
|
---|
62 | #define REG_SZ 1 /* string type (ASCII) */
|
---|
63 | #define REG_EXPAND_SZ 2 /* string, includes %ENVVAR% (expanded by caller) (ASCII) */
|
---|
64 | #define REG_BINARY 3 /* binary format, callerspecific */
|
---|
65 | /* YES, REG_DWORD == REG_DWORD_LITTLE_ENDIAN */
|
---|
66 | #define REG_DWORD 4 /* DWORD in little endian format */
|
---|
67 | #define REG_DWORD_LITTLE_ENDIAN 4 /* DWORD in little endian format */
|
---|
68 | #define REG_DWORD_BIG_ENDIAN 5 /* DWORD in big endian format */
|
---|
69 | #define REG_LINK 6 /* symbolic link (UNICODE) */
|
---|
70 | #define REG_MULTI_SZ 7 /* multiple strings, delimited by \0, terminated by \0\0 (ASCII) */
|
---|
71 | #define REG_RESOURCE_LIST 8 /* resource list? huh? */
|
---|
72 | #define REG_FULL_RESOURCE_DESCRIPTOR 9 /* full resource descriptor? huh? */
|
---|
73 |
|
---|
74 | #define HKEY_LOCAL_MACHINE_O32 0xFFFFFFEFL
|
---|
75 | #define HKEY_CURRENT_USER_O32 0xFFFFFFEEL
|
---|
76 | #define HKEY_USERS_O32 0xFFFFFFEDL
|
---|
77 | #define HKEY_CLASSES_ROOT_O32 0xFFFFFFECL
|
---|
78 |
|
---|
79 | #define KEY_ALL_ACCESS 0x0000003f
|
---|
80 |
|
---|
81 | typedef unsigned long HKEY;
|
---|
82 | typedef HKEY* LPHKEY;
|
---|
83 | typedef DWORD REGSAM;
|
---|
84 |
|
---|
85 | LONG _System _O32_RegOpenKeyEx(HKEY,LPCSTR,DWORD,REGSAM,LPHKEY);
|
---|
86 | LONG _System _O32_RegCreateKeyEx(HKEY,LPCSTR,DWORD,LPSTR,DWORD,REGSAM,
|
---|
87 | LPSECURITY_ATTRIBUTES,LPHKEY,LPDWORD);
|
---|
88 | LONG _System _O32_RegQueryValueEx(HKEY,LPSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
|
---|
89 | LONG _System _O32_RegCloseKey(HKEY);
|
---|
90 | LONG _System _O32_RegSetValueEx( HKEY, LPCSTR, DWORD, DWORD, LPBYTE, DWORD );
|
---|
91 |
|
---|
92 | DWORD _System GetModuleFileNameA(HMODULE,LPSTR,DWORD);
|
---|
93 |
|
---|
94 |
|
---|
95 | /*****************************************************************************
|
---|
96 | * Name : iQueryModuleKeyName
|
---|
97 | * Funktion : determine name of key to store the console properties for
|
---|
98 | * this process
|
---|
99 | * Parameter :
|
---|
100 | * Variablen :
|
---|
101 | * Ergebnis :
|
---|
102 | * Bemerkung :
|
---|
103 | *
|
---|
104 | * Autor : Patrick Haller [1998/06/13 23:20]
|
---|
105 | *****************************************************************************/
|
---|
106 |
|
---|
107 | static DWORD iQueryModuleKeyName(LPSTR lpstrProcessName,
|
---|
108 | DWORD dwProcessNameLength)
|
---|
109 | {
|
---|
110 | // Note: one might want to scan the string and replace illegal characters
|
---|
111 | // or use a module name only instead of the fully qualified path!
|
---|
112 | return(GetModuleFileNameA(NULL,
|
---|
113 | lpstrProcessName,
|
---|
114 | dwProcessNameLength));
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | /*****************************************************************************
|
---|
119 | * Name : APIRET EXPENTRY ConsolePropertyDefault
|
---|
120 | * Funktion : load default options
|
---|
121 | * Parameter : PICONSOLEOPTIONS pConsoleOptions
|
---|
122 | * Variablen :
|
---|
123 | * Ergebnis : APIRET
|
---|
124 | * Bemerkung :
|
---|
125 | *
|
---|
126 | * Autor : Patrick Haller [1998/06/13 23:20]
|
---|
127 | *****************************************************************************/
|
---|
128 |
|
---|
129 | DWORD ConsolePropertyDefault(PICONSOLEOPTIONS pConsoleOptions)
|
---|
130 | {
|
---|
131 | /*************************************
|
---|
132 | * Initialize Console Window Options *
|
---|
133 | *************************************/
|
---|
134 |
|
---|
135 | pConsoleOptions->fTerminateAutomatically = FALSE;
|
---|
136 | pConsoleOptions->fSpeakerEnabled = TRUE;
|
---|
137 | pConsoleOptions->fSetWindowPosition = FALSE;
|
---|
138 | pConsoleOptions->coordDefaultPosition.X = 0;
|
---|
139 | pConsoleOptions->coordDefaultPosition.Y = 0;
|
---|
140 | pConsoleOptions->coordDefaultSize.X = 80;
|
---|
141 | pConsoleOptions->coordDefaultSize.Y = 25;
|
---|
142 | pConsoleOptions->fQuickInsert = FALSE;
|
---|
143 | pConsoleOptions->fInsertMode = FALSE;
|
---|
144 | pConsoleOptions->fMouseActions = FALSE;
|
---|
145 | pConsoleOptions->fToolbarActive = FALSE;
|
---|
146 | pConsoleOptions->ucDefaultAttribute = 0x0007; /* 07 = grey on black */
|
---|
147 | pConsoleOptions->ulTabSize = 8; /* tabulator size */
|
---|
148 | pConsoleOptions->ulUpdateLimit = 8; /* scroll max. n lines */
|
---|
149 |
|
---|
150 | /* priority settings for message thread */
|
---|
151 | pConsoleOptions->ulConsoleThreadPriorityClass = PRTYC_REGULAR;
|
---|
152 | pConsoleOptions->ulConsoleThreadPriorityDelta = +10;
|
---|
153 |
|
---|
154 | pConsoleOptions->ucCursorDivisor = 10; /* timer divisor for blinking */
|
---|
155 |
|
---|
156 | return NO_ERROR;
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | /*****************************************************************************
|
---|
161 | * Name : APIRET EXPENTRY ConsolePropertyLoad
|
---|
162 | * Funktion : load properties from registry
|
---|
163 | * Parameter : PICONSOLEOPTIONS pConsoleOptions
|
---|
164 | * Variablen :
|
---|
165 | * Ergebnis : APIRET
|
---|
166 | * Bemerkung :
|
---|
167 | *
|
---|
168 | * Autor : Patrick Haller [1998/06/13 23:20]
|
---|
169 | *****************************************************************************/
|
---|
170 |
|
---|
171 | DWORD ConsolePropertyLoad(PICONSOLEOPTIONS pConsoleOptions)
|
---|
172 | {
|
---|
173 | dprintf (("KERNEL32: Console:ConsolePropertyLoad(%08xh)\n",
|
---|
174 | pConsoleOptions));
|
---|
175 |
|
---|
176 | // HKEY_CURRENT_USER/SOFTWARE/ODIN/ConsoleProperties/<process name>/<option name>
|
---|
177 | LONG lRes = ERROR_SUCCESS;
|
---|
178 | HKEY hkConsole;
|
---|
179 | char szKey[256];
|
---|
180 | char szProcessName[256];
|
---|
181 | DWORD dwRes;
|
---|
182 | DWORD dwSize;
|
---|
183 | DWORD dwType;
|
---|
184 |
|
---|
185 | // query process's name
|
---|
186 | dwRes = iQueryModuleKeyName((LPSTR)&szProcessName,
|
---|
187 | sizeof(szProcessName));
|
---|
188 | if (dwRes == 0)
|
---|
189 | {
|
---|
190 | dprintf(("KERNEL32: ConProp: ConsolePropertyLoad: GetModuleFileName failed\n"));
|
---|
191 | lRes = ERROR_INVALID_PARAMETER;
|
---|
192 | }
|
---|
193 | else
|
---|
194 | {
|
---|
195 | // open process key
|
---|
196 | sprintf (szKey,
|
---|
197 | "Software\\ODIN\\ConsoleProperties\\%s",
|
---|
198 | szProcessName);
|
---|
199 |
|
---|
200 | lRes = _O32_RegOpenKeyEx(HKEY_CURRENT_USER_O32,
|
---|
201 | szKey,
|
---|
202 | 0,
|
---|
203 | KEY_ALL_ACCESS,
|
---|
204 | &hkConsole);
|
---|
205 | }
|
---|
206 |
|
---|
207 | // try to open DEFAULT
|
---|
208 | if (lRes != ERROR_SUCCESS)
|
---|
209 | lRes = _O32_RegOpenKeyEx(HKEY_CURRENT_USER_O32,
|
---|
210 | "Software\\ODIN\\ConsoleProperties\\DEFAULT",
|
---|
211 | 0,
|
---|
212 | KEY_ALL_ACCESS,
|
---|
213 | &hkConsole);
|
---|
214 |
|
---|
215 | // now it's time to retrieve information
|
---|
216 | if (lRes != ERROR_SUCCESS)
|
---|
217 | {
|
---|
218 | // load hardcoded defaults instead
|
---|
219 | ConsolePropertyDefault(pConsoleOptions);
|
---|
220 | return ERROR_INVALID_PARAMETER;
|
---|
221 | }
|
---|
222 |
|
---|
223 |
|
---|
224 | // OK, finally retrieve tokens
|
---|
225 | #define REGQUERYVALUE(name,var) \
|
---|
226 | dwSize = sizeof(pConsoleOptions->var); \
|
---|
227 | lRes = _O32_RegQueryValueEx(hkConsole, name, NULL, &dwType, \
|
---|
228 | (LPBYTE)&pConsoleOptions->var, &dwSize);
|
---|
229 |
|
---|
230 | REGQUERYVALUE("AutomaticTermination", fTerminateAutomatically)
|
---|
231 | REGQUERYVALUE("Speaker", fSpeakerEnabled)
|
---|
232 | REGQUERYVALUE("SpeakerDuration", ulSpeakerDuration)
|
---|
233 | REGQUERYVALUE("SpeakerFrequency", ulSpeakerFrequency)
|
---|
234 | REGQUERYVALUE("UpdateLimit", ulUpdateLimit)
|
---|
235 | REGQUERYVALUE("SetWindowPosition", fSetWindowPosition)
|
---|
236 | REGQUERYVALUE("DefaultPosition_x", coordDefaultPosition.X)
|
---|
237 | REGQUERYVALUE("DefaultPosition_y", coordDefaultPosition.Y)
|
---|
238 | REGQUERYVALUE("DefaultSize_x", coordDefaultSize.X)
|
---|
239 | REGQUERYVALUE("DefaultSize_y", coordDefaultSize.Y)
|
---|
240 | REGQUERYVALUE("BufferSize_x", coordBufferSize.X)
|
---|
241 | REGQUERYVALUE("BufferSize_y", coordBufferSize.Y)
|
---|
242 | REGQUERYVALUE("QuickInsert", fQuickInsert)
|
---|
243 | REGQUERYVALUE("InsertMode", fInsertMode)
|
---|
244 | REGQUERYVALUE("MouseActions", fMouseActions)
|
---|
245 | REGQUERYVALUE("Toolbar", fToolbarActive)
|
---|
246 | REGQUERYVALUE("TabSize", ulTabSize)
|
---|
247 | REGQUERYVALUE("DefaultAttribute", ucDefaultAttribute)
|
---|
248 | REGQUERYVALUE("CursorDivisor", ucCursorDivisor)
|
---|
249 | REGQUERYVALUE("ConsolePriorityClass", ulConsoleThreadPriorityClass)
|
---|
250 | REGQUERYVALUE("ConsolePriorityDelta", ulConsoleThreadPriorityDelta)
|
---|
251 | REGQUERYVALUE("ApplicationPriorityClass", ulAppThreadPriorityClass)
|
---|
252 | REGQUERYVALUE("ApplicationPriorityDelta", ulAppThreadPriorityDelta)
|
---|
253 | #undef REGQUERYVALUE
|
---|
254 |
|
---|
255 | _O32_RegCloseKey(hkConsole);
|
---|
256 |
|
---|
257 | return (NO_ERROR);
|
---|
258 | }
|
---|
259 |
|
---|
260 |
|
---|
261 |
|
---|
262 | /*****************************************************************************
|
---|
263 | * Name : APIRET EXPENTRY ConsolePropertySave
|
---|
264 | * Funktion : save properties from registry
|
---|
265 | * Parameter : PICONSOLEOPTIONS pConsoleOptions
|
---|
266 | * Variablen :
|
---|
267 | * Ergebnis : APIRET
|
---|
268 | * Bemerkung :
|
---|
269 | *
|
---|
270 | * Autor : Patrick Haller [1998/06/13 23:20]
|
---|
271 | *****************************************************************************/
|
---|
272 |
|
---|
273 | DWORD ConsolePropertySave(PICONSOLEOPTIONS pConsoleOptions)
|
---|
274 | {
|
---|
275 | dprintf (("KERNEL32: Console:ConsolePropertySave(%08xh)\n",
|
---|
276 | pConsoleOptions));
|
---|
277 |
|
---|
278 | // HKEY_CURRENT_USER/SOFTWARE/ODIN/ConsoleProperties/<process name>/<option name>
|
---|
279 | LONG lRes = ERROR_SUCCESS;
|
---|
280 | HKEY hkConsole;
|
---|
281 | char szKey[256];
|
---|
282 | char szProcessName[256];
|
---|
283 | DWORD dwRes;
|
---|
284 | DWORD dwSize;
|
---|
285 | DWORD dwType;
|
---|
286 | DWORD dwDisposition = 0;
|
---|
287 |
|
---|
288 | // query process's name
|
---|
289 | dwRes = iQueryModuleKeyName((LPSTR)&szProcessName,
|
---|
290 | sizeof(szProcessName));
|
---|
291 | if (dwRes == 0)
|
---|
292 | {
|
---|
293 | dprintf(("KERNEL32: ConProp: ConsolePropertyLoad: GetModuleFileName failed\n"));
|
---|
294 | lRes = ERROR_INVALID_PARAMETER;
|
---|
295 | }
|
---|
296 | else
|
---|
297 | {
|
---|
298 | // open process key
|
---|
299 | sprintf (szKey,
|
---|
300 | "Software\\ODIN\\ConsoleProperties\\%s",
|
---|
301 | szProcessName);
|
---|
302 |
|
---|
303 | lRes = _O32_RegCreateKeyEx(HKEY_CURRENT_USER_O32,
|
---|
304 | szKey,
|
---|
305 | 0,
|
---|
306 | "",
|
---|
307 | 0,
|
---|
308 | KEY_ALL_ACCESS,
|
---|
309 | NULL,
|
---|
310 | &hkConsole,
|
---|
311 | &dwDisposition);
|
---|
312 | if (lRes != ERROR_SUCCESS)
|
---|
313 | return lRes;
|
---|
314 | }
|
---|
315 |
|
---|
316 |
|
---|
317 | #define REGSAVEVALUE(name,var) \
|
---|
318 | lRes = _O32_RegSetValueEx(hkConsole, name, 0, REG_DWORD, \
|
---|
319 | (LPBYTE)&pConsoleOptions->var, sizeof(pConsoleOptions->var));
|
---|
320 |
|
---|
321 | REGSAVEVALUE("AutomaticTermination", fTerminateAutomatically)
|
---|
322 | REGSAVEVALUE("Speaker", fSpeakerEnabled)
|
---|
323 | REGSAVEVALUE("SpeakerDuration", ulSpeakerDuration)
|
---|
324 | REGSAVEVALUE("SpeakerFrequency", ulSpeakerFrequency)
|
---|
325 | REGSAVEVALUE("UpdateLimit", ulUpdateLimit)
|
---|
326 | REGSAVEVALUE("SetWindowPosition", fSetWindowPosition)
|
---|
327 | REGSAVEVALUE("DefaultPosition_x", coordDefaultPosition.X)
|
---|
328 | REGSAVEVALUE("DefaultPosition_y", coordDefaultPosition.Y)
|
---|
329 | REGSAVEVALUE("DefaultSize_x", coordDefaultSize.X)
|
---|
330 | REGSAVEVALUE("DefaultSize_y", coordDefaultSize.Y)
|
---|
331 | REGSAVEVALUE("BufferSize_x", coordBufferSize.X)
|
---|
332 | REGSAVEVALUE("BufferSize_y", coordBufferSize.Y)
|
---|
333 | REGSAVEVALUE("QuickInsert", fQuickInsert)
|
---|
334 | REGSAVEVALUE("InsertMode", fInsertMode)
|
---|
335 | REGSAVEVALUE("MouseActions", fMouseActions)
|
---|
336 | REGSAVEVALUE("Toolbar", fToolbarActive)
|
---|
337 | REGSAVEVALUE("TabSize", ulTabSize)
|
---|
338 | REGSAVEVALUE("DefaultAttribute", ucDefaultAttribute)
|
---|
339 | REGSAVEVALUE("CursorDivisor", ucCursorDivisor)
|
---|
340 | REGSAVEVALUE("ConsolePriorityClass", ulConsoleThreadPriorityClass)
|
---|
341 | REGSAVEVALUE("ConsolePriorityDelta", ulConsoleThreadPriorityDelta)
|
---|
342 | REGSAVEVALUE("ApplicationPriorityClass", ulAppThreadPriorityClass)
|
---|
343 | REGSAVEVALUE("ApplicationPriorityDelta", ulAppThreadPriorityDelta)
|
---|
344 | #undef REGSAVEVALUE
|
---|
345 |
|
---|
346 | _O32_RegCloseKey(hkConsole);
|
---|
347 |
|
---|
348 | return (NO_ERROR);
|
---|
349 |
|
---|
350 | }
|
---|
351 |
|
---|