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

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

Corrected fixpack number code.

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