source: trunk/src/win32k/utils/Win32kCC.c@ 4806

Last change on this file since 4806 was 4792, checked in by bird, 25 years ago

Correct description of last revision:
Don't add parameter for default -pe value. (-pe:mixed)
Corrected default value for -DllFixes parameter. This is now enabled by
default.

File size: 34.6 KB
Line 
1/* $Id: Win32kCC.c,v 1.9 2000-12-12 15:34:17 bird Exp $
2 *
3 * Win32CC - Win32k Control Center.
4 *
5 * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10
11
12/*******************************************************************************
13* Defined Constants And Macros *
14*******************************************************************************/
15
16/*
17 * Private Window Messages
18 */
19#define WM_SETCONTROLS (WM_USER + 10)
20#define WM_QUERYCONTROLS (WM_USER + 11)
21
22
23/*
24 * Include defines
25 */
26#define INCL_DOSERRORS
27#define INCL_DOSFILEMGR
28#define INCL_DOSRESOURCES
29#define INCL_WINERRORS
30#define INCL_WINDIALOGS
31#define INCL_WINMESSAGEMGR
32#define INCL_WINSTDSPIN
33#define INCL_WINBUTTONS
34#define INCL_WINWINDOWMGR
35#define INCL_DOSMISC
36
37/*******************************************************************************
38* Header Files *
39*******************************************************************************/
40#include <os2.h>
41
42#include <string.h>
43#include <stdio.h>
44#include <stdarg.h>
45#include <stdlib.h>
46#include <errno.h>
47
48#include <Win32k.h>
49#include <devSegDf.h> /* Win32k segment definitions. */
50#include <Options.h>
51
52#include "Win32kCC.h"
53
54
55
56/*******************************************************************************
57* Structures and Typedefs *
58*******************************************************************************/
59typedef struct _WIN32KCC
60{
61 HWND hwnd;
62 HAB hab;
63 BOOL fDirty;
64
65 K32OPTIONS Options;
66 K32OPTIONS NewOptions;
67 K32STATUS Status;
68
69} WIN32KCC, *PWIN32KCC;
70
71
72/*******************************************************************************
73* Global Variables *
74*******************************************************************************/
75BOOL fNotExit; /* Global variable used to stop WM_QUITS.
76 * As long as this is true the message
77 * loop will never exit, but ignore all
78 * WM_QUITs.
79 */
80
81
82/*******************************************************************************
83* Internal Functions *
84*******************************************************************************/
85MRESULT EXPENTRY Win32kCCDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
86ULONG ShowMessage(HWND hwndOwner, int id, ULONG flStyle);
87BOOL Complain(HWND hwndOwner, int id, ...);
88PCSZ getLastErrorMsg(HAB hab);
89PSZ getMessage(ULONG id);
90int GetFixpackDesc(ULONG ulBuild, ULONG flKernel, PSZ pszBuffer);
91char * stristr(const char *pszStr, const char *pszSubStr);
92
93
94
95/**
96 * Main function.
97 * (No parameters)
98 * @returns -1 WinInitialize failed.
99 * -2 Failed to create message queue.
100 * -3 Failed to load dialog.
101 * 0 Dialog was closed using cancel.
102 * 1 Dialog was close using ok.
103 */
104int main(void)
105{
106 HAB hab;
107 HMQ hmq;
108 ULONG rc = 0;
109 HWND hwnd;
110
111 /*
112 * Initialize PM.
113 */
114 hab = WinInitialize(0);
115 if (hab == NULLHANDLE)
116 {
117 return -1;
118 }
119
120 /*
121 * Create Message Queue.
122 */
123 hmq = WinCreateMsgQueue(hab, 0);
124 if (hmq == NULLHANDLE)
125 {
126 WinTerminate(hab);
127 return -2;
128 }
129
130 /*
131 * Init Win32k library.
132 */
133 rc = libWin32kInit();
134 if (rc != NO_ERROR)
135 {
136 switch (rc)
137 {
138 case ERROR_FILE_NOT_FOUND:
139 Complain(HWND_DESKTOP, IDS_ERR_WIN32K_NOT_LOADED);
140 break;
141
142 default:
143 Complain(HWND_DESKTOP, IDS_ERR_WIN32K_OPEN_FAILED, rc);
144 }
145 }
146
147 /*
148 * Load the dialog.
149 */
150 hwnd = WinLoadDlg(HWND_DESKTOP, HWND_DESKTOP,
151 Win32kCCDlgProc,
152 NULLHANDLE,
153 DL_WIN32KCC,
154 NULL);
155
156 /*
157 * Process the dialog.
158 */
159 if (hwnd != NULLHANDLE)
160 {
161 QMSG qmsg;
162 do
163 {
164 fNotExit = FALSE;
165 while(WinGetMsg(hab, &qmsg, NULLHANDLE, NULLHANDLE, NULLHANDLE))
166 WinDispatchMsg(hab, &qmsg);
167 } while (fNotExit);
168
169
170 }
171 else
172 {
173 Complain(HWND_DESKTOP,
174 IDS_ERR_DIALOGLOAD,
175 DL_WIN32KCC,
176 WinGetLastError(hab),
177 getLastErrorMsg(hab)
178 );
179 rc = -3;
180 }
181
182 /*
183 * Cleanup.
184 */
185 WinDestroyMsgQueue(hmq);
186 WinTerminate(hab);
187 libWin32kTerm();
188
189 return rc;
190}
191
192#pragma info(noord) /*remove annoying (and possible incorrect) messages on the MP* macros */
193
194/**
195 * Dialog procedure for the DL_WIN32KCC dialog.
196 * (See PMREF for the general specifications of this function.)
197 */
198MRESULT EXPENTRY Win32kCCDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
199{
200 PWIN32KCC pThis;
201
202
203 /*
204 * Get instance data pointer (pThis).
205 */
206 if (msg != WM_INITDLG)
207 {
208 pThis = (PWIN32KCC)WinQueryWindowPtr(hwnd, QWL_USER);
209 if (pThis == NULL)
210 return WinDefDlgProc(hwnd, msg, mp1, mp2);
211 }
212
213
214 /*
215 * Message switch.
216 */
217 switch (msg)
218 {
219 /*
220 * Sets the controls according to the data from win32k.
221 *
222 * mr: Focus changed or not.
223 * mp1: hwnd of dialog
224 * mp2: (user data) (NULL)
225 */
226 case WM_INITDLG:
227 {
228
229 /*
230 * Initiate controls (ie. behaviour not data).
231 * - Ranges of the info level spinbuttons.
232 * - Max length of the max heap size entry fields.
233 */
234 WinSendDlgItemMsg(hwnd, SB_LDR_PE_INFOLEVEL, SPBM_SETLIMITS, (MPARAM)4, (MPARAM)0);
235 WinSendDlgItemMsg(hwnd, SB_LDR_ELF_INFOLEVEL, SPBM_SETLIMITS, (MPARAM)4, (MPARAM)0);
236
237 WinSendDlgItemMsg(hwnd, SB_HEAP_RES_MAX, SPBM_SETLIMITS, (MPARAM)32678, (MPARAM)128);
238 WinSendDlgItemMsg(hwnd, SB_HEAP_SWP_MAX, SPBM_SETLIMITS, (MPARAM)32678, (MPARAM)128);
239
240
241 /*
242 * Init and set instance data.
243 */
244 pThis = malloc(sizeof(*pThis));
245 if (pThis == NULL)
246 {
247 /* complain, dismiss and return. */
248 Complain(hwnd, IDS_ERR_MALLOC_FAILED, __FILE__, __LINE__, __FUNCTION__);
249 WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
250 return FALSE;
251 }
252 pThis->hwnd = hwnd;
253 pThis->hab = WinQueryAnchorBlock(hwnd);
254 if (!WinSetWindowPtr(hwnd, QWL_USER, pThis))
255 {
256 /* complain, dismiss and return. */
257 Complain(hwnd, IDS_ERR_SET_INSTACEDATA,
258 WinGetLastError(pThis->hab),
259 getLastErrorMsg(pThis->hab));
260 WinDismissDlg(hwnd, 0);
261 WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
262 free(pThis);
263 return FALSE;
264 }
265
266 /*
267 * Send a set controls message which gets data from
268 * win32k and puts it into the controls.
269 */
270 WinSendMsg(hwnd, WM_SETCONTROLS, NULL, NULL);
271 break;
272 }
273
274
275 /*
276 * The user wants me to do something...
277 */
278 case WM_COMMAND:
279 switch (SHORT1FROMMP(mp1))
280 {
281 /*
282 * The user pushed the "Apply" button.
283 */
284 case PB_APPLY:
285 {
286 /* Check and get data from the dialog. */
287 if (WinSendMsg(hwnd, WM_QUERYCONTROLS, (MPARAM)TRUE, NULL)
288 && pThis->fDirty
289 )
290 {
291 APIRET rc;
292 rc = libWin32kSetOptions(&pThis->NewOptions);
293 if (rc != NO_ERROR)
294 Complain(hwnd, IDS_ERR_SETPOPTIONS, rc);
295 WinSendMsg(hwnd, WM_SETCONTROLS, NULL, NULL);
296 }
297 }
298 break;
299
300
301 /*
302 * User pushed the "Refresh" button.
303 */
304 case PB_REFRESH:
305 WinSendMsg(hwnd, WM_SETCONTROLS, NULL, NULL);
306 break;
307
308
309 /*
310 * The user pushed the "Close" button.
311 */
312 case DID_OK:
313 /* Check if data is dirty */
314 if (!WinSendMsg(hwnd, WM_QUERYCONTROLS, (MPARAM)FALSE, NULL) || pThis->fDirty)
315 {
316 if (ShowMessage(hwnd, IDM_INFO_DIRTY, MB_YESNO | MB_WARNING) != MBID_YES)
317 {
318 fNotExit = TRUE;
319 return NULL;
320 }
321 }
322 /* Close the dialog */
323 fNotExit = FALSE;
324 WinDismissDlg(hwnd, 0);
325 WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
326 break;
327
328 /*
329 * The use requested update of config.sys.
330 */
331 case PB_UPD_CONFIGSYS:
332 {
333 ULONG ulBootDrv;
334 FILE * phConfigSys;
335 char * pszConfigSys = "A:\\Config.sys";
336 char szArgs[120];
337 int cchArgs;
338
339 if (!WinSendMsg(hwnd, WM_QUERYCONTROLS, (MPARAM)TRUE, NULL))
340 break;
341 if (DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrv, sizeof(ulBootDrv)))
342 break;
343
344 /*
345 * Make argument list.
346 */
347 szArgs[0] = '\0';
348 if (pThis->NewOptions.fLogging) strcat(szArgs, " -L:Y");
349 if (pThis->NewOptions.usCom == 0x3f8) strcat(szArgs, " -C1");
350 /*if (pThis->NewOptions.usCom != 0x2f8) strcat(szArgs, " -C2"); - default */
351 if (pThis->NewOptions.usCom == 0x3e8) strcat(szArgs, " -C3");
352 if (pThis->NewOptions.usCom == 0x2e8) strcat(szArgs, " -C4");
353 if (pThis->NewOptions.fPE == FLAGS_PE_PE2LX)strcat(szArgs, " -P:pe2lx");
354 /*if (pThis->NewOptions.fPE == FLAGS_PE_MIXED)strcat(szArgs, " -P:mixed"); - default */
355 if (pThis->NewOptions.fPE == FLAGS_PE_PE) strcat(szArgs, " -P:pe");
356 if (pThis->NewOptions.fPE == FLAGS_PE_NOT) strcat(szArgs, " -P:not");
357 if (pThis->NewOptions.ulInfoLevel != 0) /* -W0 is default */
358 sprintf(szArgs + strlen(szArgs), " -W%d", pThis->NewOptions.ulInfoLevel); /* FIXME - to be changed */
359 if (pThis->NewOptions.fElf) strcat(szArgs, " -E:Y"); /* default is disabled */
360 if (!pThis->NewOptions.fUNIXScript) strcat(szArgs, " -Script:N");
361 if (!pThis->NewOptions.fREXXScript) strcat(szArgs, " -Rexx:N");
362 if (!pThis->NewOptions.fJava) strcat(szArgs, " -Java:N");
363 if (pThis->NewOptions.fNoLoader) strcat(szArgs, " -Noloader");
364 if (!pThis->NewOptions.fDllFixes) strcat(szArgs, " -DllFixes:D"); /* default is enabled */
365 if (pThis->NewOptions.cbSwpHeapMax != CB_SWP_MAX)
366 sprintf(szArgs + strlen(szArgs), " -HeapMax:%d", pThis->NewOptions.cbSwpHeapMax); /* FIXME - to be changed */
367 if (pThis->NewOptions.cbResHeapMax != CB_RES_MAX)
368 sprintf(szArgs + strlen(szArgs), " -ResHeapMax:%d", pThis->NewOptions.cbResHeapMax); /* FIXME - to be changed */
369 strcat(szArgs, "\n");
370 cchArgs = strlen(szArgs);
371
372 /*
373 * Update Config.sys.
374 */
375 *pszConfigSys = ulBootDrv - 1 + 'A';
376 phConfigSys = fopen(pszConfigSys, "r+");
377 if (phConfigSys)
378 {
379 ULONG cbConfigSys;
380 if ( fseek(phConfigSys, 0, SEEK_END) == 0
381 && (cbConfigSys = ftell(phConfigSys)) > 0
382 && fseek(phConfigSys, 0, SEEK_SET) == 0
383 )
384 {
385 char * pszConfigSys;
386
387 pszConfigSys = (char*)calloc(1, 2 * (cbConfigSys + 256)); /* Paranoia... */
388 if (pszConfigSys)
389 {
390 char *pszCurrent = pszConfigSys;
391
392 /* Read and modify config.sys */
393 while (fgets(pszCurrent, cbConfigSys + pszCurrent - pszConfigSys, phConfigSys))
394 {
395 char *pszWin32k;
396 /* NB! This statment will not only update the "device=" statements!
397 * We'll call this a feature...
398 */
399 pszWin32k = stristr(pszCurrent, "win32k.sys");
400 if (pszWin32k)
401 {
402 int cch;
403 pszWin32k += 10; /* skip "win32k.sys" */
404 cch = strlen(pszWin32k);
405 strcpy(pszWin32k, szArgs);
406 if (cchArgs < cch)
407 { /* fix which stops us from shrinking the file.. */
408 memset(pszWin32k + cchArgs - 1, ' ', cch - cchArgs);
409 pszWin32k[cch - 1] = '\n';
410 pszWin32k[cch] = '\0';
411 }
412 }
413
414 /* next */
415 pszCurrent += strlen(pszCurrent);
416 }
417 if (pszCurrent[-1] != '\n')
418 *pszCurrent++ = '\n';
419
420 /* Write it back
421 * One big question, how do we shrink a file?
422 */
423 if ( fseek(phConfigSys, 0, SEEK_SET) == 0
424 && fwrite(pszConfigSys, 1, pszCurrent - pszConfigSys, phConfigSys))
425 {
426 ShowMessage(hwnd, IDM_CONFIGSYS_UPDATED, MB_OK);
427 }
428 else
429 Complain(hwnd, IDS_FWRITE_FAILED, pszConfigSys);
430 free(pszConfigSys);
431 }
432 else
433 Complain(hwnd, IDS_MALLOC_FAILED, cbConfigSys + 256);
434 }
435 else
436 Complain(hwnd, IDS_FSIZE_FAILED, pszConfigSys);
437 fclose(phConfigSys);
438 }
439 else
440 Complain(hwnd, IDS_ERR_FOPEN_FAILED, pszConfigSys);
441 break;
442 }
443 }
444 return NULL;
445
446
447 /*
448 * Close window. Typically sent when Alt-F4 pressed or system-menu-Close is selected.
449 */
450 case WM_CLOSE:
451 fNotExit = TRUE;
452 WinSendMsg(hwnd, WM_COMMAND,
453 MPFROMSHORT(DID_OK), MPFROM2SHORT(CMDSRC_MENU, FALSE));
454 break;
455
456
457 /*
458 * Window is destroyed (last message which ever should reach us!)
459 * -Free instance data
460 * -Set the instance data pointer to NULL (just in case).
461 */
462 case WM_DESTROY:
463 {
464 free(pThis);
465 WinSetWindowPtr(hwnd, QWL_USER, NULL);
466 break;
467 }
468
469
470 /*
471 * Gets data from win32k.
472 * Sets the controls according to the data from win32k.
473 *
474 * mr: reserved
475 * mp1: reserved
476 * mp2: reserved
477 */
478 case WM_SETCONTROLS:
479 {
480 APIRET rc;
481 CHAR szNumber[32];
482 CHAR szBuffer[100];
483
484
485 /*
486 * Call Win32k.sys to get options and statuses.
487 */
488 memset(&pThis->Options, 0, sizeof(K32OPTIONS));
489 pThis->Options.cb = sizeof(K32OPTIONS);
490 memset(&pThis->Status, 0, sizeof(K32STATUS));
491 pThis->Status.cb = sizeof(K32STATUS);
492 rc = libWin32kQueryOptionsStatus(&pThis->Options, &pThis->Status);
493 if (rc != NO_ERROR)
494 {
495 Complain(hwnd, IDS_ERR_QUERYOPTIONSTATUS, rc);
496 fNotExit = FALSE;
497 WinDismissDlg(hwnd, 0);
498 WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
499 return NULL;
500 }
501
502 /*
503 * Set the controls.
504 */
505 /* win32k */
506 sprintf(szBuffer, "%d.%d", 0, pThis->Status.ulVersion);
507 WinSetDlgItemText(hwnd, TX_W32K_VERSION_VAL, szBuffer);
508 sprintf(szBuffer, "%s %s", pThis->Status.szBuildTime, pThis->Status.szBuildDate);
509 WinSetDlgItemText(hwnd, TX_W32K_BUILD_DATETIME_VAL, szBuffer);
510 WinSetDlgItemText(hwnd, TX_W32K_SYMBOLFILE_VAL, pThis->Status.szSymFile);
511 sprintf(szBuffer, "%d - ", pThis->Status.ulBuild);
512 if (GetFixpackDesc(pThis->Status.ulBuild, pThis->Status.fKernel, szBuffer + strlen(szBuffer)))
513 sprintf(szBuffer, "%d", pThis->Status.ulBuild);
514 WinSetDlgItemText(hwnd, TX_W32K_KERNELBUILD_VAL, szBuffer);
515
516 /* logging */
517 WinSendDlgItemMsg(hwnd, CB_LOGGING_ENABLED, BM_SETCHECK, (MPARAM)(pThis->Options.fLogging), NULL);
518 WinSendDlgItemMsg(hwnd, RB_LOGGING_COM1, BM_SETCHECK, (MPARAM)(pThis->Options.usCom == 0x3f8), NULL);
519 WinSendDlgItemMsg(hwnd, RB_LOGGING_COM2, BM_SETCHECK, (MPARAM)(pThis->Options.usCom == 0x2f8), NULL);
520 WinSendDlgItemMsg(hwnd, RB_LOGGING_COM3, BM_SETCHECK, (MPARAM)(pThis->Options.usCom == 0x3e8), NULL);
521 WinSendDlgItemMsg(hwnd, RB_LOGGING_COM4, BM_SETCHECK, (MPARAM)(pThis->Options.usCom == 0x2e8), NULL);
522
523 /* loaders */
524 WinSendDlgItemMsg(hwnd, CB_LDR_DISABLE_ALL, BM_SETCHECK, (MPARAM)(pThis->Options.fNoLoader), NULL);
525 /* PE */
526 WinSendDlgItemMsg(hwnd, RB_LDR_PE_PURE, BM_SETCHECK, (MPARAM)(pThis->Options.fPE == FLAGS_PE_PE2LX), NULL);
527 WinSendDlgItemMsg(hwnd, RB_LDR_PE_MIXED, BM_SETCHECK, (MPARAM)(pThis->Options.fPE == FLAGS_PE_MIXED), NULL);
528 WinSendDlgItemMsg(hwnd, RB_LDR_PE_PE, BM_SETCHECK, (MPARAM)(pThis->Options.fPE == FLAGS_PE_PE), NULL);
529 WinSendDlgItemMsg(hwnd, RB_LDR_PE_NOT, BM_SETCHECK, (MPARAM)(pThis->Options.fPE == FLAGS_PE_NOT), NULL);
530 WinSendDlgItemMsg(hwnd, SB_LDR_PE_INFOLEVEL, SPBM_SETCURRENTVALUE, (MPARAM)(pThis->Options.ulInfoLevel), NULL); /* FIXME to be changed */
531 sprintf(szNumber, "%d", pThis->Status.cPe2LxModules);
532 WinSetDlgItemText(hwnd, TX_LDR_PE_MODULES_VAL, szNumber);
533 /* Elf */
534 WinSendDlgItemMsg(hwnd, CB_LDR_ELF_ENABLED, BM_SETCHECK, (MPARAM)(pThis->Options.fElf), NULL);
535 WinSendDlgItemMsg(hwnd, SB_LDR_ELF_INFOLEVEL, SPBM_SETCURRENTVALUE, (MPARAM)(pThis->Options.ulInfoLevel), NULL); /* FIXME to be changed */
536 sprintf(szNumber, "%d", pThis->Status.cElf2LxModules);
537 WinSetDlgItemText(hwnd, TX_LDR_ELF_MODULES_VAL, szNumber);
538 /* UNIX Shell Scripts */
539 WinSendDlgItemMsg(hwnd, CB_LDR_SHELL_SCRIPTS, BM_SETCHECK, (MPARAM)(pThis->Options.fUNIXScript), NULL);
540 /* JAVA */
541 WinSendDlgItemMsg(hwnd, CB_LDR_JAVA, BM_SETCHECK, (MPARAM)(pThis->Options.fJava), NULL);
542 /* REXX Scripts */
543 WinSendDlgItemMsg(hwnd, CB_LDR_REXX, BM_SETCHECK, (MPARAM)(pThis->Options.fREXXScript), NULL);
544
545 /* OS/2 Loader Fixes */
546 WinSendDlgItemMsg(hwnd, CB_LDRFIX_DLLFIXES, BM_SETCHECK, (MPARAM)(pThis->Options.fDllFixes), NULL);
547
548 /* heaps */
549 /* Resident */
550 WinSendDlgItemMsg(hwnd, SB_HEAP_RES_MAX, SPBM_SETCURRENTVALUE, (MPARAM)(pThis->Options.cbResHeapMax / 1024), NULL);
551 sprintf(szNumber, "%d", pThis->Status.cbResHeapInit / 1024);
552 WinSetDlgItemText(hwnd, TX_HEAP_RES_INIT_VAL, szNumber);
553 sprintf(szNumber, "%d", pThis->Status.cbResHeapSize / 1024);
554 WinSetDlgItemText(hwnd, TX_HEAP_RES_SIZE_VAL, szNumber);
555 sprintf(szNumber, "%d", pThis->Status.cbResHeapUsed / 1024);
556 WinSetDlgItemText(hwnd, TX_HEAP_RES_USED_VAL, szNumber);
557 sprintf(szNumber, "%d", pThis->Status.cbResHeapFree / 1024);
558 WinSetDlgItemText(hwnd, TX_HEAP_RES_FREE_VAL, szNumber);
559 sprintf(szNumber, "%d", pThis->Status.cResBlocksUsed);
560 WinSetDlgItemText(hwnd, TX_HEAP_RES_USED_BLOCKS_VAL, szNumber);
561 sprintf(szNumber, "%d", pThis->Status.cResBlocksFree);
562 WinSetDlgItemText(hwnd, TX_HEAP_RES_FREE_BLOCKS_VAL, szNumber);
563 /* Swappable */
564 WinSendDlgItemMsg(hwnd, SB_HEAP_SWP_MAX, SPBM_SETCURRENTVALUE, (MPARAM)(pThis->Options.cbSwpHeapMax / 1024), NULL);
565 sprintf(szNumber, "%d", pThis->Status.cbSwpHeapInit / 1024);
566 WinSetDlgItemText(hwnd, TX_HEAP_SWP_INIT_VAL, szNumber);
567 sprintf(szNumber, "%d", pThis->Status.cbSwpHeapSize / 1024);
568 WinSetDlgItemText(hwnd, TX_HEAP_SWP_SIZE_VAL, szNumber);
569 sprintf(szNumber, "%d", pThis->Status.cbSwpHeapUsed / 1024);
570 WinSetDlgItemText(hwnd, TX_HEAP_SWP_USED_VAL, szNumber);
571 sprintf(szNumber, "%d", pThis->Status.cbSwpHeapFree / 1024);
572 WinSetDlgItemText(hwnd, TX_HEAP_SWP_FREE_VAL, szNumber);
573 sprintf(szNumber, "%d", pThis->Status.cSwpBlocksUsed);
574 WinSetDlgItemText(hwnd, TX_HEAP_SWP_USED_BLOCKS_VAL, szNumber);
575 sprintf(szNumber, "%d", pThis->Status.cSwpBlocksFree);
576 WinSetDlgItemText(hwnd, TX_HEAP_SWP_FREE_BLOCKS_VAL, szNumber);
577
578 pThis->fDirty = FALSE;
579 return NULL;
580 }
581
582
583 /*
584 * Validate data in the controls. Complains accoring to mp1.
585 * Put the data into the win32k option struct.
586 *
587 * mr: Valid indicator.
588 * TRUE: Valid data.
589 * FALSE: Not valid data.
590 * mp1: BOOL fComplain.
591 * TRUE: Do complain about errors. The pThis->Options struct
592 * is updated on successful return.
593 * FALSE: Do not complain about errors, and don't update the
594 * pThis->Options struct.
595 * mp2: reserved.
596 */
597 case WM_QUERYCONTROLS:
598 {
599 BOOL fComplain = (BOOL)mp1;
600 ULONG ul;
601
602 /*
603 * Init temporary option struct.
604 */
605 memset(&pThis->NewOptions, 0, sizeof(K32OPTIONS));
606 pThis->NewOptions.cb = sizeof(K32OPTIONS);
607
608 /*
609 * Logging.
610 */
611 pThis->NewOptions.fLogging = WinSendDlgItemMsg(hwnd, CB_LOGGING_ENABLED, BM_QUERYCHECK, NULL, NULL) != 0;
612 if (WinSendDlgItemMsg(hwnd, RB_LOGGING_COM1, BM_QUERYCHECK, NULL, NULL))
613 pThis->NewOptions.usCom = 0x3f8;
614 else if (WinSendDlgItemMsg(hwnd, RB_LOGGING_COM2, BM_QUERYCHECK, NULL, NULL))
615 pThis->NewOptions.usCom = 0x2f8;
616 else if (WinSendDlgItemMsg(hwnd, RB_LOGGING_COM3, BM_QUERYCHECK, NULL, NULL))
617 pThis->NewOptions.usCom = 0x3e8;
618 else if (WinSendDlgItemMsg(hwnd, RB_LOGGING_COM4, BM_QUERYCHECK, NULL, NULL))
619 pThis->NewOptions.usCom = 0x2e8;
620 else
621 {
622 if (fComplain)
623 Complain(hwnd, IDS_ERR_NO_COM_RADIOBUTTON);
624 return (MPARAM)FALSE;
625 }
626
627 /*
628 * Loaders
629 */
630 pThis->NewOptions.fNoLoader = WinSendDlgItemMsg(hwnd, CB_LDR_DISABLE_ALL, BM_QUERYCHECK, NULL, NULL) != 0;
631 /* PE */
632 if (WinSendDlgItemMsg(hwnd, RB_LDR_PE_PURE, BM_QUERYCHECK, NULL, NULL))
633 pThis->NewOptions.fPE = FLAGS_PE_PE2LX;
634 else if (WinSendDlgItemMsg(hwnd, RB_LDR_PE_MIXED, BM_QUERYCHECK, NULL, NULL))
635 pThis->NewOptions.fPE = FLAGS_PE_MIXED;
636 else if (WinSendDlgItemMsg(hwnd, RB_LDR_PE_PE, BM_QUERYCHECK, NULL, NULL))
637 pThis->NewOptions.fPE = FLAGS_PE_PE;
638 else if (WinSendDlgItemMsg(hwnd, RB_LDR_PE_NOT, BM_QUERYCHECK, NULL, NULL))
639 pThis->NewOptions.fPE = FLAGS_PE_NOT;
640 else
641 {
642 if (fComplain)
643 Complain(hwnd, IDS_ERR_NO_PE_RADIOBUTTON);
644 return (MPARAM)FALSE;
645 }
646 if (!WinSendDlgItemMsg(hwnd, SB_LDR_PE_INFOLEVEL, SPBM_QUERYVALUE, (MPARAM)&ul, MPFROM2SHORT(0, SPBQ_UPDATEIFVALID)))
647 {
648 if (fComplain)
649 {
650 Complain(hwnd, IDS_ERR_INVALID_INFOLEVEL);
651 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SB_LDR_PE_INFOLEVEL));
652 }
653 return (MPARAM)FALSE;
654 }
655 pThis->NewOptions.ulInfoLevel = ul; /* FIXME to be changed */
656
657 /* Elf */
658 pThis->NewOptions.fElf = WinSendDlgItemMsg(hwnd, CB_LDR_ELF_ENABLED, BM_QUERYCHECK, NULL, NULL) != 0;
659 if (!WinSendDlgItemMsg(hwnd, SB_LDR_ELF_INFOLEVEL, SPBM_QUERYVALUE, (MPARAM)&ul, MPFROM2SHORT(0, SPBQ_UPDATEIFVALID)))
660 {
661 if (fComplain)
662 {
663 Complain(hwnd, IDS_ERR_INVALID_INFOLEVEL);
664 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SB_LDR_ELF_INFOLEVEL));
665 }
666 return (MPARAM)FALSE;
667 }
668 //pThis->NewOptions.ulInfoLevel = ul; /* FIXME to be changed */
669 /* UNIX Shell Scripts */
670 pThis->NewOptions.fUNIXScript = WinSendDlgItemMsg(hwnd, CB_LDR_SHELL_SCRIPTS, BM_QUERYCHECK, NULL, NULL) != 0;
671 /* JAVA */
672 pThis->NewOptions.fJava = WinSendDlgItemMsg(hwnd, CB_LDR_JAVA, BM_QUERYCHECK, NULL, NULL) != 0;
673 /* REXX Scripts */
674 pThis->NewOptions.fREXXScript = WinSendDlgItemMsg(hwnd, CB_LDR_REXX, BM_QUERYCHECK, NULL, NULL) != 0;
675
676 /*
677 * OS/2 Loader Fixes.
678 */
679 pThis->NewOptions.fDllFixes = WinSendDlgItemMsg(hwnd, CB_LDRFIX_DLLFIXES, BM_QUERYCHECK, NULL, NULL) != 0;
680
681 /*
682 * Heaps
683 */
684 /* Resident */
685 if (!WinSendDlgItemMsg(hwnd, SB_HEAP_RES_MAX, SPBM_QUERYVALUE, (MPARAM)&ul, MPFROM2SHORT(0, SPBQ_UPDATEIFVALID)))
686 {
687 if (fComplain)
688 {
689 Complain(hwnd, IDS_ERR_INVALID_MAXHEAPSIZE);
690 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SB_HEAP_RES_MAX));
691 }
692 return (MPARAM)FALSE;
693 }
694 pThis->NewOptions.cbResHeapMax = ul*1024;
695 /* Swappable */
696 if (!WinSendDlgItemMsg(hwnd, SB_HEAP_SWP_MAX, SPBM_QUERYVALUE, (MPARAM)&ul, MPFROM2SHORT(0, SPBQ_UPDATEIFVALID)))
697 {
698 if (fComplain)
699 {
700 Complain(hwnd, IDS_ERR_INVALID_MAXHEAPSIZE);
701 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SB_HEAP_SWP_MAX));
702 }
703 return (MPARAM)FALSE;
704 }
705 pThis->NewOptions.cbSwpHeapMax = ul*1024;
706
707 /*
708 * Check if there is any change and set the fDirty flag accordingly.
709 */
710 pThis->fDirty = memcmp(&pThis->NewOptions, &pThis->Options, sizeof(K32OPTIONS)) != 0;
711 return (MPARAM)TRUE;
712 }
713
714
715 }
716
717 /*
718 * Return thru the default dialog procedure.
719 */
720 return WinDefDlgProc(hwnd, msg, mp1, mp2);
721}
722
723
724/**
725 * Pops up a message box displaying a message from the message table.
726 * @returns Return from WinMessageBox
727 * @param hwndOwner Handle to owner window.
728 * @param id Message table id of the message.
729 * @param flStyle Messagebox style.
730 * If 0 the apply default style.
731 */
732ULONG ShowMessage(HWND hwndOwner, int id, ULONG flStyle)
733{
734 return WinMessageBox(HWND_DESKTOP,
735 hwndOwner,
736 getMessage(id),
737 "Win32k Control Center", 0,
738 (flStyle == 0
739 ? MB_OK | MB_INFORMATION
740 : flStyle)
741 | MB_MOVEABLE
742 );
743}
744
745
746
747/**
748 * Pops up a message box displaying some complaint or error.
749 * @returns Success indicator.
750 * @param hwndOwner Handle of owner window.
751 * @param id String table id of the message.
752 * @param ... Arguments passed on to vsprintf to format the message.
753 */
754BOOL Complain(HWND hwndOwner, int id, ...)
755{
756 ULONG rc;
757 char szMsg[1024];
758 char szMsgOutput[4096];
759
760
761 /*
762 * Load the string and format it.
763 */
764 if (WinLoadString(WinQueryAnchorBlock(hwndOwner), 0, id, sizeof(szMsg), szMsg))
765 {
766 va_list args;
767 va_start(args, id);
768 vsprintf(szMsgOutput, szMsg, args);
769 va_end(args);
770 }
771 else
772 sprintf(szMsgOutput, "Failed to load the message id %id.\n", id);
773
774
775 /*
776 * Show message.
777 */
778 rc = WinMessageBox(HWND_DESKTOP, hwndOwner,
779 szMsgOutput,
780 "Win32k Control Center - error",
781 0,
782 MB_APPLMODAL | MB_ICONHAND | MB_OK | MB_MOVEABLE);
783 if (rc == (ULONG)MBID_ERROR)
784 {
785 rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
786 szMsgOutput,
787 "Win32k Control Center - error",
788 0,
789 MB_ICONHAND | MB_OK | MB_MOVEABLE);
790 }
791
792
793 /*
794 * Return according to rc.
795 */
796 return rc != MBID_ERROR;
797}
798
799
800/**
801 * Gets the message string for the last error message.
802 * @returns Pointer to message string.
803 * @param hab Handle of application anchor block.
804 */
805PCSZ getLastErrorMsg(HAB hab)
806{
807 char *pszErrInfo;
808 PERRINFO pErrInfo = WinGetErrorInfo(hab);
809
810 if (pErrInfo != NULL && pErrInfo->cDetailLevel > 0)
811 {
812 pszErrInfo = (char*)(void*)pErrInfo;
813 pszErrInfo += ((PUSHORT)(void*)(pszErrInfo + pErrInfo->offaoffszMsg))[pErrInfo->cDetailLevel-1];
814 }
815 else
816 pszErrInfo = "<none>";
817
818 return pszErrInfo;
819}
820
821
822/**
823 * Gets a message from the executable resources.
824 * @returns Pointer to read-only string.
825 * NULL if not found/error.
826 * @param id String Id.
827 */
828PSZ getMessage(ULONG id)
829{
830 PSZ psz;
831
832 if (DosGetResource(NULLHANDLE, RT_MESSAGE, id / 16 + 1, (PPVOID)(void*)&psz) == NO_ERROR)
833 {
834 psz +=2;
835 id %= 16;
836 while (id-- > 0)
837 psz += 1 + *psz;
838 return psz+1;
839 }
840 else
841 psz = NULL;
842
843 return psz;
844}
845
846
847/**
848 * Determin the fixpack+kernel description from build no. and kernel flags.
849 * @returns 0 on success. Description i szBuffer.
850 * -1 on error.
851 * @param ulBuild Kernel build no.
852 * @param flKernel Win32k kernel flags.
853 * @param szBuffer Pointer to buffer
854 */
855int GetFixpackDesc(ULONG ulBuild, ULONG flKernel, PSZ pszBuffer)
856{
857
858 pszBuffer[0] = '\0';
859 if (ulBuild == 9023)
860 strcpy(pszBuffer, "Warp 4 GA");
861 else if (ulBuild > 9023 && ulBuild <= 9036)
862 sprintf(pszBuffer, "Warp 4 FP %d", ulBuild - 9024);
863 else if (ulBuild == 14039)
864 strcpy(pszBuffer, "WS4eB GA");
865 else if (ulBuild == 14040)
866 strcpy(pszBuffer, flKernel & KF_W4 ? "Warp 4 FP13" : "WS4eB FP1");
867 else if (ulBuild >= 14041 /*&& ulBuild <= 1406x*/)
868 strcpy(pszBuffer, "Warp 4 FP14");
869 /*
870 else if (ulBuild >= 14048)
871 {
872 if (flKernel & KF_W4)
873 sprintf(pszBuffer, "Warp 4 FP%d", ulBuild - 14049 + 15); //???
874 else
875 sprintf(pszBuffer, "WS4eB FP%d", ulBuild - 14048 + 2); //???
876 }
877 */
878 else if (ulBuild >= 8255 && ulBuild <= 8270)
879 sprintf(pszBuffer, "Warp 3 FP%d", ulBuild - 8255 + 32);
880 else
881 return -1;
882
883 /*
884 * Check type.
885 */
886 if (pszBuffer[0] != '\0')
887 {
888 char *pszAdd;
889
890 if (flKernel & KF_SMP)
891 pszAdd = "SMP ";
892 else
893 pszAdd = " ";
894 strcpy(pszBuffer + strlen(pszBuffer), pszAdd);
895
896 if (flKernel & KF_DEBUG)
897 {
898 if (flKernel & KF_HAS_DEBUGTYPE)
899 pszAdd = (flKernel & KF_ALLSTRICT) ? "(Allstrict)" : "(Halfstrict)";
900 else
901 pszAdd = "(Debug)";
902 }
903 else
904 pszAdd = "(Retail)";
905 strcpy(pszBuffer + strlen(pszBuffer), pszAdd);
906 }
907
908 return 0;
909}
910
911
912/**
913 * Upcases a char.
914 * @returns Upper case of the char given in ch.
915 * @param ch Char to capitalize.
916 */
917#define upcase(ch) ((ch) >= 'a' && (ch) <= 'z' ? (char)((ch) - ('a' - 'A')) : (ch))
918
919
920/**
921 * Searches for a substring in a string.
922 * @returns Pointer to start of substring when found, NULL when not found.
923 * @param pszStr String to be searched.
924 * @param pszSubStr String to be searched.
925 * @remark Depends on the upcase function.
926 */
927static char *stristr(const char *pszStr, const char *pszSubStr)
928{
929 int cchSubStr = strlen(pszSubStr);
930 int i = 0;
931
932 while (*pszStr != '\0' && i < cchSubStr)
933 {
934 i = 0;
935 while (i < cchSubStr && pszStr[i] != '\0' &&
936 (upcase(pszStr[i]) == upcase(pszSubStr[i])))
937 i++;
938 pszStr++;
939 }
940
941 return (char*)(*pszStr != '\0' ? (char*)pszStr - 1 : NULL);
942}
943
Note: See TracBrowser for help on using the repository browser.