| 1 | /* $Id: conprop2.cpp,v 1.6 2000-03-03 11:15:57 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 <win32api.h>
|
|---|
| 43 | #include <misc.h>
|
|---|
| 44 | #include <stdio.h>
|
|---|
| 45 |
|
|---|
| 46 | #include "console.h"
|
|---|
| 47 | #include "console2.h"
|
|---|
| 48 | #include "conprop.h"
|
|---|
| 49 |
|
|---|
| 50 | #define DBG_LOCALLOG DBG_conprop2
|
|---|
| 51 | #include "dbglocal.h"
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 | ODINDEBUGCHANNEL(KERNEL32-CONPROP2)
|
|---|
| 55 |
|
|---|
| 56 | /*****************************************************************************
|
|---|
| 57 | * Defines *
|
|---|
| 58 | *****************************************************************************/
|
|---|
| 59 |
|
|---|
| 60 | /*****************************************************************************
|
|---|
| 61 | * Name : iQueryModuleKeyName
|
|---|
| 62 | * Funktion : determine name of key to store the console properties for
|
|---|
| 63 | * this process
|
|---|
| 64 | * Parameter :
|
|---|
| 65 | * Variablen :
|
|---|
| 66 | * Ergebnis :
|
|---|
| 67 | * Bemerkung :
|
|---|
| 68 | *
|
|---|
| 69 | * Autor : Patrick Haller [1998/06/13 23:20]
|
|---|
| 70 | *****************************************************************************/
|
|---|
| 71 |
|
|---|
| 72 | static DWORD iQueryModuleKeyName(LPSTR lpstrProcessName,
|
|---|
| 73 | DWORD dwProcessNameLength)
|
|---|
| 74 | {
|
|---|
| 75 | // Note: one might want to scan the string and replace illegal characters
|
|---|
| 76 | // or use a module name only instead of the fully qualified path!
|
|---|
| 77 | return(GetModuleFileNameA(NULL,
|
|---|
| 78 | lpstrProcessName,
|
|---|
| 79 | dwProcessNameLength));
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 | /*****************************************************************************
|
|---|
| 84 | * Name : APIRET EXPENTRY ConsolePropertyDefault
|
|---|
| 85 | * Funktion : load default options
|
|---|
| 86 | * Parameter : PICONSOLEOPTIONS pConsoleOptions
|
|---|
| 87 | * Variablen :
|
|---|
| 88 | * Ergebnis : APIRET
|
|---|
| 89 | * Bemerkung :
|
|---|
| 90 | *
|
|---|
| 91 | * Autor : Patrick Haller [1998/06/13 23:20]
|
|---|
| 92 | *****************************************************************************/
|
|---|
| 93 |
|
|---|
| 94 | DWORD ConsolePropertyDefault(PICONSOLEOPTIONS pConsoleOptions)
|
|---|
| 95 | {
|
|---|
| 96 | /*************************************
|
|---|
| 97 | * Initialize Console Window Options *
|
|---|
| 98 | *************************************/
|
|---|
| 99 |
|
|---|
| 100 | pConsoleOptions->fTerminateAutomatically = FALSE;
|
|---|
| 101 | pConsoleOptions->fSpeakerEnabled = TRUE;
|
|---|
| 102 | pConsoleOptions->fSetWindowPosition = FALSE;
|
|---|
| 103 | pConsoleOptions->coordDefaultPosition.X = 0;
|
|---|
| 104 | pConsoleOptions->coordDefaultPosition.Y = 0;
|
|---|
| 105 | pConsoleOptions->coordDefaultSize.X = 80;
|
|---|
| 106 | pConsoleOptions->coordDefaultSize.Y = 25;
|
|---|
| 107 | pConsoleOptions->fQuickInsert = FALSE;
|
|---|
| 108 | pConsoleOptions->fInsertMode = FALSE;
|
|---|
| 109 | pConsoleOptions->fMouseActions = FALSE;
|
|---|
| 110 | pConsoleOptions->fToolbarActive = FALSE;
|
|---|
| 111 | pConsoleOptions->ucDefaultAttribute = 0x0007; /* 07 = grey on black */
|
|---|
| 112 | pConsoleOptions->ulTabSize = 8; /* tabulator size */
|
|---|
| 113 | pConsoleOptions->ulUpdateLimit = 8; /* scroll max. n lines */
|
|---|
| 114 |
|
|---|
| 115 | /* priority settings for message thread */
|
|---|
| 116 | pConsoleOptions->ulConsoleThreadPriorityClass = PRTYC_REGULAR;
|
|---|
| 117 | pConsoleOptions->ulConsoleThreadPriorityDelta = +10;
|
|---|
| 118 |
|
|---|
| 119 | pConsoleOptions->ucCursorDivisor = 10; /* timer divisor for blinking */
|
|---|
| 120 |
|
|---|
| 121 | return NO_ERROR;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 | /*****************************************************************************
|
|---|
| 126 | * Name : APIRET EXPENTRY ConsolePropertyLoad
|
|---|
| 127 | * Funktion : load properties from registry
|
|---|
| 128 | * Parameter : PICONSOLEOPTIONS pConsoleOptions
|
|---|
| 129 | * Variablen :
|
|---|
| 130 | * Ergebnis : APIRET
|
|---|
| 131 | * Bemerkung :
|
|---|
| 132 | *
|
|---|
| 133 | * Autor : Patrick Haller [1998/06/13 23:20]
|
|---|
| 134 | *****************************************************************************/
|
|---|
| 135 |
|
|---|
| 136 | DWORD ConsolePropertyLoad(PICONSOLEOPTIONS pConsoleOptions)
|
|---|
| 137 | {
|
|---|
| 138 | dprintf (("KERNEL32: Console:ConsolePropertyLoad(%08xh)\n",
|
|---|
| 139 | pConsoleOptions));
|
|---|
| 140 |
|
|---|
| 141 | // HKEY_CURRENT_USER/SOFTWARE/ODIN/ConsoleProperties/<process name>/<option name>
|
|---|
| 142 | LONG lRes = ERROR_SUCCESS_W;
|
|---|
| 143 | HKEY hkConsole;
|
|---|
| 144 | char szKey[256];
|
|---|
| 145 | char szProcessName[256];
|
|---|
| 146 | DWORD dwRes;
|
|---|
| 147 | DWORD dwSize;
|
|---|
| 148 | DWORD dwType;
|
|---|
| 149 |
|
|---|
| 150 | // query process's name
|
|---|
| 151 | dwRes = iQueryModuleKeyName((LPSTR)&szProcessName,
|
|---|
| 152 | sizeof(szProcessName));
|
|---|
| 153 | if (dwRes == 0)
|
|---|
| 154 | {
|
|---|
| 155 | dprintf(("KERNEL32: ConProp: ConsolePropertyLoad: GetModuleFileName failed\n"));
|
|---|
| 156 | lRes = ERROR_INVALID_PARAMETER;
|
|---|
| 157 | }
|
|---|
| 158 | else
|
|---|
| 159 | {
|
|---|
| 160 | // open process key
|
|---|
| 161 | sprintf (szKey,
|
|---|
| 162 | "Software\\ODIN\\ConsoleProperties\\%s",
|
|---|
| 163 | szProcessName);
|
|---|
| 164 |
|
|---|
| 165 | lRes = RegOpenKeyExA(HKEY_CURRENT_USER,
|
|---|
| 166 | szKey,
|
|---|
| 167 | 0,
|
|---|
| 168 | KEY_ALL_ACCESS,
|
|---|
| 169 | &hkConsole);
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | // try to open DEFAULT
|
|---|
| 173 | if (lRes != ERROR_SUCCESS_W)
|
|---|
| 174 | lRes = RegOpenKeyExA(HKEY_CURRENT_USER,
|
|---|
| 175 | "Software\\ODIN\\ConsoleProperties\\DEFAULT",
|
|---|
| 176 | 0,
|
|---|
| 177 | KEY_ALL_ACCESS,
|
|---|
| 178 | &hkConsole);
|
|---|
| 179 |
|
|---|
| 180 | // now it's time to retrieve information
|
|---|
| 181 | if (lRes != ERROR_SUCCESS_W)
|
|---|
| 182 | {
|
|---|
| 183 | // load hardcoded defaults instead
|
|---|
| 184 | ConsolePropertyDefault(pConsoleOptions);
|
|---|
| 185 | return ERROR_INVALID_PARAMETER;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 | // OK, finally retrieve tokens
|
|---|
| 190 | #define REGQUERYVALUE(name,var) \
|
|---|
| 191 | dwSize = sizeof(pConsoleOptions->var); \
|
|---|
| 192 | lRes = RegQueryValueExA(hkConsole, name, NULL, &dwType, \
|
|---|
| 193 | (LPBYTE)&pConsoleOptions->var, &dwSize);
|
|---|
| 194 |
|
|---|
| 195 | REGQUERYVALUE("AutomaticTermination", fTerminateAutomatically)
|
|---|
| 196 | REGQUERYVALUE("Speaker", fSpeakerEnabled)
|
|---|
| 197 | REGQUERYVALUE("SpeakerDuration", ulSpeakerDuration)
|
|---|
| 198 | REGQUERYVALUE("SpeakerFrequency", ulSpeakerFrequency)
|
|---|
| 199 | REGQUERYVALUE("UpdateLimit", ulUpdateLimit)
|
|---|
| 200 | REGQUERYVALUE("SetWindowPosition", fSetWindowPosition)
|
|---|
| 201 | REGQUERYVALUE("DefaultPosition_x", coordDefaultPosition.X)
|
|---|
| 202 | REGQUERYVALUE("DefaultPosition_y", coordDefaultPosition.Y)
|
|---|
| 203 | REGQUERYVALUE("DefaultSize_x", coordDefaultSize.X)
|
|---|
| 204 | REGQUERYVALUE("DefaultSize_y", coordDefaultSize.Y)
|
|---|
| 205 | REGQUERYVALUE("BufferSize_x", coordBufferSize.X)
|
|---|
| 206 | REGQUERYVALUE("BufferSize_y", coordBufferSize.Y)
|
|---|
| 207 | REGQUERYVALUE("QuickInsert", fQuickInsert)
|
|---|
| 208 | REGQUERYVALUE("InsertMode", fInsertMode)
|
|---|
| 209 | REGQUERYVALUE("MouseActions", fMouseActions)
|
|---|
| 210 | REGQUERYVALUE("Toolbar", fToolbarActive)
|
|---|
| 211 | REGQUERYVALUE("TabSize", ulTabSize)
|
|---|
| 212 | REGQUERYVALUE("DefaultAttribute", ucDefaultAttribute)
|
|---|
| 213 | REGQUERYVALUE("CursorDivisor", ucCursorDivisor)
|
|---|
| 214 | REGQUERYVALUE("ConsolePriorityClass", ulConsoleThreadPriorityClass)
|
|---|
| 215 | REGQUERYVALUE("ConsolePriorityDelta", ulConsoleThreadPriorityDelta)
|
|---|
| 216 | REGQUERYVALUE("ApplicationPriorityClass", ulAppThreadPriorityClass)
|
|---|
| 217 | REGQUERYVALUE("ApplicationPriorityDelta", ulAppThreadPriorityDelta)
|
|---|
| 218 | #undef REGQUERYVALUE
|
|---|
| 219 |
|
|---|
| 220 | RegCloseKey(hkConsole);
|
|---|
| 221 |
|
|---|
| 222 | return (NO_ERROR);
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 | /*****************************************************************************
|
|---|
| 228 | * Name : APIRET EXPENTRY ConsolePropertySave
|
|---|
| 229 | * Funktion : save properties from registry
|
|---|
| 230 | * Parameter : PICONSOLEOPTIONS pConsoleOptions
|
|---|
| 231 | * Variablen :
|
|---|
| 232 | * Ergebnis : APIRET
|
|---|
| 233 | * Bemerkung :
|
|---|
| 234 | *
|
|---|
| 235 | * Autor : Patrick Haller [1998/06/13 23:20]
|
|---|
| 236 | *****************************************************************************/
|
|---|
| 237 |
|
|---|
| 238 | DWORD ConsolePropertySave(PICONSOLEOPTIONS pConsoleOptions)
|
|---|
| 239 | {
|
|---|
| 240 | dprintf (("KERNEL32: Console:ConsolePropertySave(%08xh)\n",
|
|---|
| 241 | pConsoleOptions));
|
|---|
| 242 |
|
|---|
| 243 | // HKEY_CURRENT_USER/SOFTWARE/ODIN/ConsoleProperties/<process name>/<option name>
|
|---|
| 244 | LONG lRes = ERROR_SUCCESS_W;
|
|---|
| 245 | HKEY hkConsole;
|
|---|
| 246 | char szKey[256];
|
|---|
| 247 | char szProcessName[256];
|
|---|
| 248 | DWORD dwRes;
|
|---|
| 249 | DWORD dwSize;
|
|---|
| 250 | DWORD dwType;
|
|---|
| 251 | DWORD dwDisposition = 0;
|
|---|
| 252 |
|
|---|
| 253 | // query process's name
|
|---|
| 254 | dwRes = iQueryModuleKeyName((LPSTR)&szProcessName,
|
|---|
| 255 | sizeof(szProcessName));
|
|---|
| 256 | if (dwRes == 0)
|
|---|
| 257 | {
|
|---|
| 258 | dprintf(("KERNEL32: ConProp: ConsolePropertyLoad: GetModuleFileName failed\n"));
|
|---|
| 259 | lRes = ERROR_INVALID_PARAMETER;
|
|---|
| 260 | }
|
|---|
| 261 | else
|
|---|
| 262 | {
|
|---|
| 263 | // open process key
|
|---|
| 264 | sprintf (szKey,
|
|---|
| 265 | "Software\\ODIN\\ConsoleProperties\\%s",
|
|---|
| 266 | szProcessName);
|
|---|
| 267 |
|
|---|
| 268 | lRes = RegCreateKeyExA(HKEY_CURRENT_USER,
|
|---|
| 269 | szKey,
|
|---|
| 270 | 0,
|
|---|
| 271 | "",
|
|---|
| 272 | 0,
|
|---|
| 273 | KEY_ALL_ACCESS,
|
|---|
| 274 | NULL,
|
|---|
| 275 | &hkConsole,
|
|---|
| 276 | &dwDisposition);
|
|---|
| 277 | if (lRes != ERROR_SUCCESS_W)
|
|---|
| 278 | return lRes;
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 | #define REGSAVEVALUE(name,var) \
|
|---|
| 283 | lRes = RegSetValueExA(hkConsole, name, 0, REG_DWORD, \
|
|---|
| 284 | (LPBYTE)&pConsoleOptions->var, sizeof(pConsoleOptions->var));
|
|---|
| 285 |
|
|---|
| 286 | REGSAVEVALUE("AutomaticTermination", fTerminateAutomatically)
|
|---|
| 287 | REGSAVEVALUE("Speaker", fSpeakerEnabled)
|
|---|
| 288 | REGSAVEVALUE("SpeakerDuration", ulSpeakerDuration)
|
|---|
| 289 | REGSAVEVALUE("SpeakerFrequency", ulSpeakerFrequency)
|
|---|
| 290 | REGSAVEVALUE("UpdateLimit", ulUpdateLimit)
|
|---|
| 291 | REGSAVEVALUE("SetWindowPosition", fSetWindowPosition)
|
|---|
| 292 | REGSAVEVALUE("DefaultPosition_x", coordDefaultPosition.X)
|
|---|
| 293 | REGSAVEVALUE("DefaultPosition_y", coordDefaultPosition.Y)
|
|---|
| 294 | REGSAVEVALUE("DefaultSize_x", coordDefaultSize.X)
|
|---|
| 295 | REGSAVEVALUE("DefaultSize_y", coordDefaultSize.Y)
|
|---|
| 296 | REGSAVEVALUE("BufferSize_x", coordBufferSize.X)
|
|---|
| 297 | REGSAVEVALUE("BufferSize_y", coordBufferSize.Y)
|
|---|
| 298 | REGSAVEVALUE("QuickInsert", fQuickInsert)
|
|---|
| 299 | REGSAVEVALUE("InsertMode", fInsertMode)
|
|---|
| 300 | REGSAVEVALUE("MouseActions", fMouseActions)
|
|---|
| 301 | REGSAVEVALUE("Toolbar", fToolbarActive)
|
|---|
| 302 | REGSAVEVALUE("TabSize", ulTabSize)
|
|---|
| 303 | REGSAVEVALUE("DefaultAttribute", ucDefaultAttribute)
|
|---|
| 304 | REGSAVEVALUE("CursorDivisor", ucCursorDivisor)
|
|---|
| 305 | REGSAVEVALUE("ConsolePriorityClass", ulConsoleThreadPriorityClass)
|
|---|
| 306 | REGSAVEVALUE("ConsolePriorityDelta", ulConsoleThreadPriorityDelta)
|
|---|
| 307 | REGSAVEVALUE("ApplicationPriorityClass", ulAppThreadPriorityClass)
|
|---|
| 308 | REGSAVEVALUE("ApplicationPriorityDelta", ulAppThreadPriorityDelta)
|
|---|
| 309 | #undef REGSAVEVALUE
|
|---|
| 310 |
|
|---|
| 311 | RegCloseKey(hkConsole);
|
|---|
| 312 |
|
|---|
| 313 | return (NO_ERROR);
|
|---|
| 314 |
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|