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

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

Added force preload.

File size: 35.6 KB
Line 
1/* $Id: Win32kCC.c,v 1.12 2001-02-11 23:41:46 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"); - old default */
355 if (pThis->NewOptions.fPE == FLAGS_PE_MIXED)strcat(szArgs, " -P:mixed");
356 /* if (pThis->NewOptions.fPE == FLAGS_PE_PE) strcat(szArgs, " -P:pe"); - default */
357 if (pThis->NewOptions.fPE == FLAGS_PE_NOT) strcat(szArgs, " -P:not");
358 if (pThis->NewOptions.ulInfoLevel != 0) /* -W0 is default */
359 sprintf(szArgs + strlen(szArgs), " -W%d", pThis->NewOptions.ulInfoLevel); /* FIXME - to be changed */
360 if (pThis->NewOptions.fElf) strcat(szArgs, " -E:Y"); /* default is disabled */
361 if (!pThis->NewOptions.fUNIXScript) strcat(szArgs, " -Script:N");
362 if (!pThis->NewOptions.fREXXScript) strcat(szArgs, " -Rexx:N");
363 if (!pThis->NewOptions.fJava) strcat(szArgs, " -Java:N");
364 if (pThis->NewOptions.fNoLoader) strcat(szArgs, " -Noloader");
365 if (!pThis->NewOptions.fDllFixes) strcat(szArgs, " -DllFixes:D"); /* default is enabled */
366 if (!pThis->NewOptions.fForcePreload) strcat(szArgs, " -ForcePreload:Y"); /* default is disabled */
367 if (pThis->NewOptions.cbSwpHeapMax != CB_SWP_MAX)
368 sprintf(szArgs + strlen(szArgs), " -HeapMax:%d", pThis->NewOptions.cbSwpHeapMax); /* FIXME - to be changed */
369 if (pThis->NewOptions.cbResHeapMax != CB_RES_MAX)
370 sprintf(szArgs + strlen(szArgs), " -ResHeapMax:%d", pThis->NewOptions.cbResHeapMax); /* FIXME - to be changed */
371 strcat(szArgs, "\n");
372 cchArgs = strlen(szArgs);
373
374 /*
375 * Update Config.sys.
376 */
377 *pszConfigSys = (char)(ulBootDrv - 1 + 'A');
378 phConfigSys = fopen(pszConfigSys, "r+");
379 if (phConfigSys)
380 {
381 ULONG cbConfigSys;
382 if ( fseek(phConfigSys, 0, SEEK_END) == 0
383 && (cbConfigSys = ftell(phConfigSys)) > 0
384 && fseek(phConfigSys, 0, SEEK_SET) == 0
385 )
386 {
387 char * pszConfigSys;
388
389 pszConfigSys = (char*)calloc(1, 2 * (cbConfigSys + 256)); /* Paranoia... */
390 if (pszConfigSys)
391 {
392 char *pszCurrent = pszConfigSys;
393
394 /* Read and modify config.sys */
395 while (fgets(pszCurrent, cbConfigSys + pszCurrent - pszConfigSys, phConfigSys))
396 {
397 char *pszWin32k;
398 /* NB! This statment will not only update the "device=" statements!
399 * We'll call this a feature...
400 */
401 pszWin32k = stristr(pszCurrent, "win32k.sys");
402 if (pszWin32k)
403 {
404 int cch;
405 pszWin32k += 10; /* skip "win32k.sys" */
406 cch = strlen(pszWin32k);
407 strcpy(pszWin32k, szArgs);
408 if (cchArgs < cch)
409 { /* fix which stops us from shrinking the file.. */
410 memset(pszWin32k + cchArgs - 1, ' ', cch - cchArgs);
411 pszWin32k[cch - 1] = '\n';
412 pszWin32k[cch] = '\0';
413 }
414 }
415
416 /* next */
417 pszCurrent += strlen(pszCurrent);
418 }
419 if (pszCurrent[-1] != '\n')
420 *pszCurrent++ = '\n';
421
422 /* Write it back
423 * One big question, how do we shrink a file?
424 */
425 if ( fseek(phConfigSys, 0, SEEK_SET) == 0
426 && fwrite(pszConfigSys, 1, pszCurrent - pszConfigSys, phConfigSys))
427 {
428 ShowMessage(hwnd, IDM_CONFIGSYS_UPDATED, MB_OK);
429 }
430 else
431 Complain(hwnd, IDS_FWRITE_FAILED, pszConfigSys);
432 free(pszConfigSys);
433 }
434 else
435 Complain(hwnd, IDS_MALLOC_FAILED, cbConfigSys + 256);
436 }
437 else
438 Complain(hwnd, IDS_FSIZE_FAILED, pszConfigSys);
439 fclose(phConfigSys);
440 }
441 else
442 Complain(hwnd, IDS_ERR_FOPEN_FAILED, pszConfigSys);
443 break;
444 }
445 }
446 return NULL;
447
448
449 /*
450 * Close window. Typically sent when Alt-F4 pressed or system-menu-Close is selected.
451 */
452 case WM_CLOSE:
453 fNotExit = TRUE;
454 WinSendMsg(hwnd, WM_COMMAND,
455 MPFROMSHORT(DID_OK), MPFROM2SHORT(CMDSRC_MENU, FALSE));
456 break;
457
458
459 /*
460 * Window is destroyed (last message which ever should reach us!)
461 * -Free instance data
462 * -Set the instance data pointer to NULL (just in case).
463 */
464 case WM_DESTROY:
465 {
466 free(pThis);
467 WinSetWindowPtr(hwnd, QWL_USER, NULL);
468 break;
469 }
470
471
472 /*
473 * Gets data from win32k.
474 * Sets the controls according to the data from win32k.
475 *
476 * mr: reserved
477 * mp1: reserved
478 * mp2: reserved
479 */
480 case WM_SETCONTROLS:
481 {
482 APIRET rc;
483 CHAR szNumber[32];
484 CHAR szBuffer[100];
485
486
487 /*
488 * Call Win32k.sys to get options and statuses.
489 */
490 memset(&pThis->Options, 0, sizeof(K32OPTIONS));
491 pThis->Options.cb = sizeof(K32OPTIONS);
492 memset(&pThis->Status, 0, sizeof(K32STATUS));
493 pThis->Status.cb = sizeof(K32STATUS);
494 rc = libWin32kQueryOptionsStatus(&pThis->Options, &pThis->Status);
495 if (rc != NO_ERROR)
496 {
497 Complain(hwnd, IDS_ERR_QUERYOPTIONSTATUS, rc);
498 fNotExit = FALSE;
499 WinDismissDlg(hwnd, 0);
500 WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
501 return NULL;
502 }
503
504 /*
505 * Set the controls.
506 */
507 /* win32k */
508 sprintf(szBuffer, "%d.%d", 0, pThis->Status.ulVersion);
509 WinSetDlgItemText(hwnd, TX_W32K_VERSION_VAL, szBuffer);
510 sprintf(szBuffer, "%s %s", pThis->Status.szBuildTime, pThis->Status.szBuildDate);
511 WinSetDlgItemText(hwnd, TX_W32K_BUILD_DATETIME_VAL, szBuffer);
512 WinSetDlgItemText(hwnd, TX_W32K_SYMBOLFILE_VAL, pThis->Status.szSymFile);
513 sprintf(szBuffer, "%d - ", pThis->Status.ulBuild);
514 if (GetFixpackDesc(pThis->Status.ulBuild, pThis->Status.fKernel, szBuffer + strlen(szBuffer)))
515 sprintf(szBuffer, "%d", pThis->Status.ulBuild);
516 WinSetDlgItemText(hwnd, TX_W32K_KERNELBUILD_VAL, szBuffer);
517
518 /* logging */
519 WinSendDlgItemMsg(hwnd, CB_LOGGING_ENABLED, BM_SETCHECK, (MPARAM)(pThis->Options.fLogging), NULL);
520 WinSendDlgItemMsg(hwnd, RB_LOGGING_COM1, BM_SETCHECK, (MPARAM)(pThis->Options.usCom == 0x3f8), NULL);
521 WinSendDlgItemMsg(hwnd, RB_LOGGING_COM2, BM_SETCHECK, (MPARAM)(pThis->Options.usCom == 0x2f8), NULL);
522 WinSendDlgItemMsg(hwnd, RB_LOGGING_COM3, BM_SETCHECK, (MPARAM)(pThis->Options.usCom == 0x3e8), NULL);
523 WinSendDlgItemMsg(hwnd, RB_LOGGING_COM4, BM_SETCHECK, (MPARAM)(pThis->Options.usCom == 0x2e8), NULL);
524
525 /* loaders */
526 WinSendDlgItemMsg(hwnd, CB_LDR_DISABLE_ALL, BM_SETCHECK, (MPARAM)(pThis->Options.fNoLoader), NULL);
527 /* PE */
528 WinSendDlgItemMsg(hwnd, RB_LDR_PE_PURE, BM_SETCHECK, (MPARAM)(pThis->Options.fPE == FLAGS_PE_PE2LX), NULL);
529 WinSendDlgItemMsg(hwnd, RB_LDR_PE_MIXED, BM_SETCHECK, (MPARAM)(pThis->Options.fPE == FLAGS_PE_MIXED), NULL);
530 WinSendDlgItemMsg(hwnd, RB_LDR_PE_PE, BM_SETCHECK, (MPARAM)(pThis->Options.fPE == FLAGS_PE_PE), NULL);
531 WinSendDlgItemMsg(hwnd, RB_LDR_PE_NOT, BM_SETCHECK, (MPARAM)(pThis->Options.fPE == FLAGS_PE_NOT), NULL);
532 WinSendDlgItemMsg(hwnd, CK_LDR_PE_ONEOBJECT, BM_SETCHECK, (MPARAM)(pThis->Options.fPEOneObject), NULL);
533 WinSendDlgItemMsg(hwnd, SB_LDR_PE_INFOLEVEL, SPBM_SETCURRENTVALUE, (MPARAM)(pThis->Options.ulInfoLevel), NULL); /* FIXME to be changed */
534 sprintf(szNumber, "%d", pThis->Status.cPe2LxModules);
535 WinSetDlgItemText(hwnd, TX_LDR_PE_MODULES_VAL, szNumber);
536 /* Elf */
537 WinSendDlgItemMsg(hwnd, CB_LDR_ELF_ENABLED, BM_SETCHECK, (MPARAM)(pThis->Options.fElf), NULL);
538 WinSendDlgItemMsg(hwnd, SB_LDR_ELF_INFOLEVEL, SPBM_SETCURRENTVALUE, (MPARAM)(pThis->Options.ulInfoLevel), NULL); /* FIXME to be changed */
539 sprintf(szNumber, "%d", pThis->Status.cElf2LxModules);
540 WinSetDlgItemText(hwnd, TX_LDR_ELF_MODULES_VAL, szNumber);
541 /* UNIX Shell Scripts */
542 WinSendDlgItemMsg(hwnd, CB_LDR_SHELL_SCRIPTS, BM_SETCHECK, (MPARAM)(pThis->Options.fUNIXScript), NULL);
543 /* JAVA */
544 WinSendDlgItemMsg(hwnd, CB_LDR_JAVA, BM_SETCHECK, (MPARAM)(pThis->Options.fJava), NULL);
545 /* REXX Scripts */
546 WinSendDlgItemMsg(hwnd, CB_LDR_REXX, BM_SETCHECK, (MPARAM)(pThis->Options.fREXXScript), NULL);
547
548 /* OS/2 Loader Fixes */
549 WinSendDlgItemMsg(hwnd, CB_LDRFIX_DLLFIXES, BM_SETCHECK, (MPARAM)(pThis->Options.fDllFixes), NULL);
550 WinSendDlgItemMsg(hwnd, CB_LDRFIX_FORCEPRELOAD, BM_SETCHECK, (MPARAM)(pThis->Options.fForcePreload), NULL);
551
552 /* heaps */
553 /* Resident */
554 WinSendDlgItemMsg(hwnd, SB_HEAP_RES_MAX, SPBM_SETCURRENTVALUE, (MPARAM)(pThis->Options.cbResHeapMax / 1024), NULL);
555 sprintf(szNumber, "%d", pThis->Status.cbResHeapInit / 1024);
556 WinSetDlgItemText(hwnd, TX_HEAP_RES_INIT_VAL, szNumber);
557 sprintf(szNumber, "%d", pThis->Status.cbResHeapSize / 1024);
558 WinSetDlgItemText(hwnd, TX_HEAP_RES_SIZE_VAL, szNumber);
559 sprintf(szNumber, "%d", pThis->Status.cbResHeapUsed / 1024);
560 WinSetDlgItemText(hwnd, TX_HEAP_RES_USED_VAL, szNumber);
561 sprintf(szNumber, "%d", pThis->Status.cbResHeapFree / 1024);
562 WinSetDlgItemText(hwnd, TX_HEAP_RES_FREE_VAL, szNumber);
563 sprintf(szNumber, "%d", pThis->Status.cResBlocksUsed);
564 WinSetDlgItemText(hwnd, TX_HEAP_RES_USED_BLOCKS_VAL, szNumber);
565 sprintf(szNumber, "%d", pThis->Status.cResBlocksFree);
566 WinSetDlgItemText(hwnd, TX_HEAP_RES_FREE_BLOCKS_VAL, szNumber);
567 /* Swappable */
568 WinSendDlgItemMsg(hwnd, SB_HEAP_SWP_MAX, SPBM_SETCURRENTVALUE, (MPARAM)(pThis->Options.cbSwpHeapMax / 1024), NULL);
569 sprintf(szNumber, "%d", pThis->Status.cbSwpHeapInit / 1024);
570 WinSetDlgItemText(hwnd, TX_HEAP_SWP_INIT_VAL, szNumber);
571 sprintf(szNumber, "%d", pThis->Status.cbSwpHeapSize / 1024);
572 WinSetDlgItemText(hwnd, TX_HEAP_SWP_SIZE_VAL, szNumber);
573 sprintf(szNumber, "%d", pThis->Status.cbSwpHeapUsed / 1024);
574 WinSetDlgItemText(hwnd, TX_HEAP_SWP_USED_VAL, szNumber);
575 sprintf(szNumber, "%d", pThis->Status.cbSwpHeapFree / 1024);
576 WinSetDlgItemText(hwnd, TX_HEAP_SWP_FREE_VAL, szNumber);
577 sprintf(szNumber, "%d", pThis->Status.cSwpBlocksUsed);
578 WinSetDlgItemText(hwnd, TX_HEAP_SWP_USED_BLOCKS_VAL, szNumber);
579 sprintf(szNumber, "%d", pThis->Status.cSwpBlocksFree);
580 WinSetDlgItemText(hwnd, TX_HEAP_SWP_FREE_BLOCKS_VAL, szNumber);
581
582 pThis->fDirty = FALSE;
583 return NULL;
584 }
585
586
587 /*
588 * Validate data in the controls. Complains accoring to mp1.
589 * Put the data into the win32k option struct.
590 *
591 * mr: Valid indicator.
592 * TRUE: Valid data.
593 * FALSE: Not valid data.
594 * mp1: BOOL fComplain.
595 * TRUE: Do complain about errors. The pThis->Options struct
596 * is updated on successful return.
597 * FALSE: Do not complain about errors, and don't update the
598 * pThis->Options struct.
599 * mp2: reserved.
600 */
601 case WM_QUERYCONTROLS:
602 {
603 BOOL fComplain = (BOOL)mp1;
604 ULONG ul;
605
606 /*
607 * Init temporary option struct.
608 */
609 memset(&pThis->NewOptions, 0, sizeof(K32OPTIONS));
610 pThis->NewOptions.cb = sizeof(K32OPTIONS);
611
612 /*
613 * Logging.
614 */
615 pThis->NewOptions.fLogging = WinSendDlgItemMsg(hwnd, CB_LOGGING_ENABLED, BM_QUERYCHECK, NULL, NULL) != 0;
616 if (WinSendDlgItemMsg(hwnd, RB_LOGGING_COM1, BM_QUERYCHECK, NULL, NULL))
617 pThis->NewOptions.usCom = 0x3f8;
618 else if (WinSendDlgItemMsg(hwnd, RB_LOGGING_COM2, BM_QUERYCHECK, NULL, NULL))
619 pThis->NewOptions.usCom = 0x2f8;
620 else if (WinSendDlgItemMsg(hwnd, RB_LOGGING_COM3, BM_QUERYCHECK, NULL, NULL))
621 pThis->NewOptions.usCom = 0x3e8;
622 else if (WinSendDlgItemMsg(hwnd, RB_LOGGING_COM4, BM_QUERYCHECK, NULL, NULL))
623 pThis->NewOptions.usCom = 0x2e8;
624 else
625 {
626 if (fComplain)
627 Complain(hwnd, IDS_ERR_NO_COM_RADIOBUTTON);
628 return (MPARAM)FALSE;
629 }
630
631 /*
632 * Loaders
633 */
634 pThis->NewOptions.fNoLoader = WinSendDlgItemMsg(hwnd, CB_LDR_DISABLE_ALL, BM_QUERYCHECK, NULL, NULL) != 0;
635 /* PE */
636 if (WinSendDlgItemMsg(hwnd, RB_LDR_PE_PURE, BM_QUERYCHECK, NULL, NULL))
637 pThis->NewOptions.fPE = FLAGS_PE_PE2LX;
638 else if (WinSendDlgItemMsg(hwnd, RB_LDR_PE_MIXED, BM_QUERYCHECK, NULL, NULL))
639 pThis->NewOptions.fPE = FLAGS_PE_MIXED;
640 else if (WinSendDlgItemMsg(hwnd, RB_LDR_PE_PE, BM_QUERYCHECK, NULL, NULL))
641 pThis->NewOptions.fPE = FLAGS_PE_PE;
642 else if (WinSendDlgItemMsg(hwnd, RB_LDR_PE_NOT, BM_QUERYCHECK, NULL, NULL))
643 pThis->NewOptions.fPE = FLAGS_PE_NOT;
644 else
645 {
646 if (fComplain)
647 Complain(hwnd, IDS_ERR_NO_PE_RADIOBUTTON);
648 return (MPARAM)FALSE;
649 }
650 pThis->NewOptions.fPEOneObject = (ULONG)WinSendDlgItemMsg(hwnd, CK_LDR_PE_ONEOBJECT, BM_QUERYCHECK, NULL, NULL);
651 if (pThis->NewOptions.fPEOneObject > 2)
652 {
653 if (fComplain)
654 Complain(hwnd, IDS_ERR_NO_PE_RADIOBUTTON);
655 return (MPARAM)FALSE;
656 }
657 if (!WinSendDlgItemMsg(hwnd, SB_LDR_PE_INFOLEVEL, SPBM_QUERYVALUE, (MPARAM)&ul, MPFROM2SHORT(0, SPBQ_UPDATEIFVALID)))
658 {
659 if (fComplain)
660 {
661 Complain(hwnd, IDS_ERR_INVALID_INFOLEVEL);
662 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SB_LDR_PE_INFOLEVEL));
663 }
664 return (MPARAM)FALSE;
665 }
666 pThis->NewOptions.ulInfoLevel = ul; /* FIXME to be changed */
667
668 /* Elf */
669 pThis->NewOptions.fElf = WinSendDlgItemMsg(hwnd, CB_LDR_ELF_ENABLED, BM_QUERYCHECK, NULL, NULL) != 0;
670 if (!WinSendDlgItemMsg(hwnd, SB_LDR_ELF_INFOLEVEL, SPBM_QUERYVALUE, (MPARAM)&ul, MPFROM2SHORT(0, SPBQ_UPDATEIFVALID)))
671 {
672 if (fComplain)
673 {
674 Complain(hwnd, IDS_ERR_INVALID_INFOLEVEL);
675 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SB_LDR_ELF_INFOLEVEL));
676 }
677 return (MPARAM)FALSE;
678 }
679 //pThis->NewOptions.ulInfoLevel = ul; /* FIXME to be changed */
680 /* UNIX Shell Scripts */
681 pThis->NewOptions.fUNIXScript = WinSendDlgItemMsg(hwnd, CB_LDR_SHELL_SCRIPTS, BM_QUERYCHECK, NULL, NULL) != 0;
682 /* JAVA */
683 pThis->NewOptions.fJava = WinSendDlgItemMsg(hwnd, CB_LDR_JAVA, BM_QUERYCHECK, NULL, NULL) != 0;
684 /* REXX Scripts */
685 pThis->NewOptions.fREXXScript = WinSendDlgItemMsg(hwnd, CB_LDR_REXX, BM_QUERYCHECK, NULL, NULL) != 0;
686
687 /*
688 * OS/2 Loader Fixes.
689 */
690 pThis->NewOptions.fDllFixes = WinSendDlgItemMsg(hwnd, CB_LDRFIX_DLLFIXES, BM_QUERYCHECK, NULL, NULL) != 0;
691 pThis->NewOptions.fForcePreload = WinSendDlgItemMsg(hwnd, CB_LDRFIX_FORCEPRELOAD, BM_QUERYCHECK, NULL, NULL) != 0;
692
693 /*
694 * Heaps
695 */
696 /* Resident */
697 if (!WinSendDlgItemMsg(hwnd, SB_HEAP_RES_MAX, SPBM_QUERYVALUE, (MPARAM)&ul, MPFROM2SHORT(0, SPBQ_UPDATEIFVALID)))
698 {
699 if (fComplain)
700 {
701 Complain(hwnd, IDS_ERR_INVALID_MAXHEAPSIZE);
702 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SB_HEAP_RES_MAX));
703 }
704 return (MPARAM)FALSE;
705 }
706 pThis->NewOptions.cbResHeapMax = ul*1024;
707 /* Swappable */
708 if (!WinSendDlgItemMsg(hwnd, SB_HEAP_SWP_MAX, SPBM_QUERYVALUE, (MPARAM)&ul, MPFROM2SHORT(0, SPBQ_UPDATEIFVALID)))
709 {
710 if (fComplain)
711 {
712 Complain(hwnd, IDS_ERR_INVALID_MAXHEAPSIZE);
713 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, SB_HEAP_SWP_MAX));
714 }
715 return (MPARAM)FALSE;
716 }
717 pThis->NewOptions.cbSwpHeapMax = ul*1024;
718
719 /*
720 * Check if there is any change and set the fDirty flag accordingly.
721 */
722 pThis->fDirty = memcmp(&pThis->NewOptions, &pThis->Options, sizeof(K32OPTIONS)) != 0;
723 return (MPARAM)TRUE;
724 }
725
726
727 }
728
729 /*
730 * Return thru the default dialog procedure.
731 */
732 return WinDefDlgProc(hwnd, msg, mp1, mp2);
733}
734
735
736/**
737 * Pops up a message box displaying a message from the message table.
738 * @returns Return from WinMessageBox
739 * @param hwndOwner Handle to owner window.
740 * @param id Message table id of the message.
741 * @param flStyle Messagebox style.
742 * If 0 the apply default style.
743 */
744ULONG ShowMessage(HWND hwndOwner, int id, ULONG flStyle)
745{
746 return WinMessageBox(HWND_DESKTOP,
747 hwndOwner,
748 getMessage(id),
749 "Win32k Control Center", 0,
750 (flStyle == 0
751 ? MB_OK | MB_INFORMATION
752 : flStyle)
753 | MB_MOVEABLE
754 );
755}
756
757
758
759/**
760 * Pops up a message box displaying some complaint or error.
761 * @returns Success indicator.
762 * @param hwndOwner Handle of owner window.
763 * @param id String table id of the message.
764 * @param ... Arguments passed on to vsprintf to format the message.
765 */
766BOOL Complain(HWND hwndOwner, int id, ...)
767{
768 ULONG rc;
769 char szMsg[1024];
770 char szMsgOutput[4096];
771
772
773 /*
774 * Load the string and format it.
775 */
776 if (WinLoadString(WinQueryAnchorBlock(hwndOwner), 0, id, sizeof(szMsg), szMsg))
777 {
778 va_list args;
779 #pragma info(none)
780 va_start(args, id);
781 #pragma info(restore)
782 vsprintf(szMsgOutput, szMsg, args);
783 va_end(args);
784 }
785 else
786 sprintf(szMsgOutput, "Failed to load the message id %id.\n", id);
787
788
789 /*
790 * Show message.
791 */
792 rc = WinMessageBox(HWND_DESKTOP, hwndOwner,
793 szMsgOutput,
794 "Win32k Control Center - error",
795 0,
796 MB_APPLMODAL | MB_ICONHAND | MB_OK | MB_MOVEABLE);
797 if (rc == (ULONG)MBID_ERROR)
798 {
799 rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
800 szMsgOutput,
801 "Win32k Control Center - error",
802 0,
803 MB_ICONHAND | MB_OK | MB_MOVEABLE);
804 }
805
806
807 /*
808 * Return according to rc.
809 */
810 return rc != MBID_ERROR;
811}
812
813
814/**
815 * Gets the message string for the last error message.
816 * @returns Pointer to message string.
817 * @param hab Handle of application anchor block.
818 */
819PCSZ getLastErrorMsg(HAB hab)
820{
821 char *pszErrInfo;
822 PERRINFO pErrInfo = WinGetErrorInfo(hab);
823
824 if (pErrInfo != NULL && pErrInfo->cDetailLevel > 0)
825 {
826 pszErrInfo = (char*)(void*)pErrInfo;
827 pszErrInfo += ((PUSHORT)(void*)(pszErrInfo + pErrInfo->offaoffszMsg))[pErrInfo->cDetailLevel-1];
828 }
829 else
830 pszErrInfo = "<none>";
831
832 return pszErrInfo;
833}
834
835
836/**
837 * Gets a message from the executable resources.
838 * @returns Pointer to read-only string.
839 * NULL if not found/error.
840 * @param id String Id.
841 */
842PSZ getMessage(ULONG id)
843{
844 PSZ psz;
845
846 if (DosGetResource(NULLHANDLE, RT_MESSAGE, id / 16 + 1, (PPVOID)(void*)&psz) == NO_ERROR)
847 {
848 psz +=2;
849 id %= 16;
850 while (id-- > 0)
851 psz += 1 + *psz;
852 return psz+1;
853 }
854 else
855 psz = NULL;
856
857 return psz;
858}
859
860
861/**
862 * Determin the fixpack+kernel description from build no. and kernel flags.
863 * @returns 0 on success. Description i szBuffer.
864 * -1 on error.
865 * @param ulBuild Kernel build no.
866 * @param flKernel Win32k kernel flags.
867 * @param szBuffer Pointer to buffer
868 */
869int GetFixpackDesc(ULONG ulBuild, ULONG flKernel, PSZ pszBuffer)
870{
871
872 pszBuffer[0] = '\0';
873 if (ulBuild == 9023)
874 strcpy(pszBuffer, "Warp 4 GA");
875 else if (ulBuild > 9023 && ulBuild <= 9036)
876 sprintf(pszBuffer, "Warp 4 FP %d", ulBuild - 9024);
877 else if (ulBuild == 14039)
878 strcpy(pszBuffer, "WS4eB GA");
879 else if (ulBuild == 14040)
880 strcpy(pszBuffer, flKernel & KF_W4 ? "Warp 4 FP13" : "WS4eB FP1");
881 else if (ulBuild >= 14041 /*&& ulBuild <= 1406x*/)
882 strcpy(pszBuffer, "Warp 4 FP14");
883 /*
884 else if (ulBuild >= 14048)
885 {
886 if (flKernel & KF_W4)
887 sprintf(pszBuffer, "Warp 4 FP%d", ulBuild - 14049 + 15); //???
888 else
889 sprintf(pszBuffer, "WS4eB FP%d", ulBuild - 14048 + 2); //???
890 }
891 */
892 else if (ulBuild >= 8255 && ulBuild <= 8270)
893 sprintf(pszBuffer, "Warp 3 FP%d", ulBuild - 8255 + 32);
894 else
895 return -1;
896
897 /*
898 * Check type.
899 */
900 if (pszBuffer[0] != '\0')
901 {
902 char *pszAdd;
903
904 if (flKernel & KF_SMP)
905 pszAdd = "SMP ";
906 else
907 pszAdd = " ";
908 strcpy(pszBuffer + strlen(pszBuffer), pszAdd);
909
910 if (flKernel & KF_DEBUG)
911 {
912 if (flKernel & KF_HAS_DEBUGTYPE)
913 pszAdd = (flKernel & KF_ALLSTRICT) ? "(Allstrict)" : "(Halfstrict)";
914 else
915 pszAdd = "(Debug)";
916 }
917 else
918 pszAdd = "(Retail)";
919 strcpy(pszBuffer + strlen(pszBuffer), pszAdd);
920 }
921
922 return 0;
923}
924
925
926/**
927 * Upcases a char.
928 * @returns Upper case of the char given in ch.
929 * @param ch Char to capitalize.
930 */
931#define upcase(ch) ((ch) >= 'a' && (ch) <= 'z' ? (char)((ch) - ('a' - 'A')) : (ch))
932
933
934/**
935 * Searches for a substring in a string.
936 * @returns Pointer to start of substring when found, NULL when not found.
937 * @param pszStr String to be searched.
938 * @param pszSubStr String to be searched.
939 * @remark Depends on the upcase function.
940 */
941static char *stristr(const char *pszStr, const char *pszSubStr)
942{
943 int cchSubStr = strlen(pszSubStr);
944 int i = 0;
945
946 while (*pszStr != '\0' && i < cchSubStr)
947 {
948 i = 0;
949 while (i < cchSubStr && pszStr[i] != '\0' &&
950 (upcase(pszStr[i]) == upcase(pszSubStr[i])))
951 i++;
952 pszStr++;
953 }
954
955 return (char*)(*pszStr != '\0' ? (const char*)pszStr - 1 : (const char*)NULL);
956}
957
Note: See TracBrowser for help on using the repository browser.