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