source: trunk/dll/sysinfo.c@ 1846

Last change on this file since 1846 was 1846, checked in by John Small, 10 years ago

Ticket #524: Ensure no "highmem-unsafe" functions are called directly
Calls to unsafe Dos... functions have been changed to call the wrapped xDos... functions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 KB
Line 
1
2/***********************************************************************
3
4 $Id: sysinfo.c 1846 2015-08-12 20:31:54Z jbs $
5
6 System Info Display
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2002, 2008 Steven H.Levine
10
11 16 Oct 02 SHL Baseline
12 08 Feb 03 SHL Enable display
13 01 Aug 04 SHL RunRmview: avoid buffer overflow
14 26 Jul 06 SHL Report open errors
15 29 Jul 06 SHL Use xfgets
16 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
17 16 JUL 08 GKY Use TMP directory for temp files
18 08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used)
19 20 Nov 10 GKY Check that pTmpDir IsValid and recreate if not found; Fixes hangs caused
20 by temp file creation failures.
21 12 Aug 15 JBS Ticket #524: Ensure no "highmem-unsafe" functions are called directly
22 Calls to unsafe Dos... functions have been changed to call the wrapped xDos... functions
23
24***********************************************************************/
25
26#include <string.h>
27
28#define INCL_DOS
29#define INCL_WIN
30#define INCL_LONGLONG
31
32#include "fm3dll.h"
33#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
34#include "sysinfo.h"
35#include "printer.h" // Data declaration(s)
36#include "init.h" // Data declaration(s)
37#include "mainwnd.h" // Data declaration(s)
38#include "fm3dlg.h"
39#include "pathutil.h" // BldFullPathName
40#include "copyf.h" // unlinkf
41#include "wrappers.h" // xfgets
42#include "systemf.h" // runemf2
43#include "misc.h" // PostMsg
44#include "strips.h" // bstrip
45#include "valid.h" // IsValidDir
46
47#pragma data_seg(DATA1)
48
49static PSZ pszSrcFile = __FILE__;
50
51VOID RunRmview(VOID * arg)
52{
53 HWND hwnd = (HWND) arg;
54 CHAR s[2048], *p, szTempFile[CCHMAXPATH];
55 HAB thab;
56 HMQ thmq;
57 FILE *fp;
58 HFILE oldstdout, newstdout;
59 CHAR *mode = "w";
60
61 DosError(FERR_DISABLEHARDERR);
62
63 thab = WinInitialize(0);
64 thmq = WinCreateMsgQueue(thab, 0);
65 WinCancelShutdown(thmq, TRUE);
66 if (thab && thmq) {
67 if (!WinIsWindow(thab, hwnd))
68 goto Abort;
69 if (pTmpDir && !IsValidDir(pTmpDir))
70 DosCreateDir(pTmpDir, 0);
71 BldFullPathName(szTempFile, pTmpDir, "$RMVIEW.#$#");
72 unlinkf(szTempFile);
73 fp = xfopen(szTempFile, mode, pszSrcFile, __LINE__, FALSE);
74 if (!fp)
75 goto Abort;
76 else {
77 newstdout = -1;
78 if (xDosDupHandle(fileno(stdout), &newstdout)) {
79 fclose(fp);
80 goto Abort;
81 }
82 oldstdout = fileno(stdout);
83 xDosDupHandle(fileno(fp), &oldstdout);
84 runemf2(SEPARATE | INVISIBLE | FULLSCREEN | BACKGROUND | WAIT,
85 hwnd, pszSrcFile, __LINE__,
86 NULL, NULL, "%s", szTempFile);
87 oldstdout = fileno(stdout);
88 xDosDupHandle(newstdout, &oldstdout);
89 DosClose(newstdout);
90 fclose(fp);
91 }
92 if (!WinIsWindow(thab, hwnd))
93 goto Abort;
94 mode = "r";
95 fp = xfopen(szTempFile, mode, pszSrcFile, __LINE__, FALSE);
96 if (fp) {
97 xfgets(s, sizeof(s), fp, pszSrcFile, __LINE__);
98 xfgets(s, sizeof(s), fp, pszSrcFile, __LINE__);
99 if (!feof(fp) && WinIsWindow(thab, hwnd))
100 WinSendDlgItemMsg(hwnd, SYS_LISTBOX, LM_INSERTITEM,
101 MPFROM2SHORT(LIT_END, 0),
102 MPFROMP(" -= RMView Physical Info =-"));
103 while (!feof(fp)) {
104 strset(s, 0);
105 if (!xfgets(s, sizeof(s), fp, pszSrcFile, __LINE__))
106 break;
107 stripcr(s);
108 rstrip(s);
109 p = s;
110 while (*p == '\r' || *p == '\n')
111 p++;
112 if (!WinIsWindow(thab, hwnd))
113 break;
114 WinSendDlgItemMsg(hwnd, SYS_LISTBOX, LM_INSERTITEM,
115 MPFROM2SHORT(LIT_END, 0), MPFROMP(p));
116 }
117 fclose(fp);
118 }
119 Abort:
120 WinDestroyMsgQueue(thmq);
121 WinTerminate(thab);
122 }
123 if (szTempFile)
124 xDosForceDelete(szTempFile);
125}
126
127MRESULT EXPENTRY SysInfoDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
128{
129 static HWND me = (HWND) 0;
130 static LONG ypos = 0;
131 static HPOINTER hptrIcon = (HPOINTER) 0;
132
133 switch (msg) {
134 case WM_INITDLG:
135 if (me) {
136 WinSetWindowPos(me, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE |
137 SWP_SHOW | SWP_RESTORE | SWP_ZORDER);
138 WinDismissDlg(hwnd, 0);
139 break;
140 }
141 hptrIcon = WinLoadPointer(HWND_DESKTOP, FM3ModHandle, SYS_FRAME);
142 WinDefDlgProc(hwnd, WM_SETICON, MPFROMLONG(hptrIcon), MPVOID);
143 {
144 static CHAR *names[] = { "Max. Path Length", // 1
145 "Max. Text Sessions", // 2
146 "Max. PM Sessions", // 3
147 "Max. VDM Sessions", // 4
148 "Boot Drive", // 5
149 "Dynamic Priority", // 6
150 "Max. Wait", // 7
151 "Min. Timeslice", // 8
152 "Max. Timeslice", // 9
153 "Page Size", // 10
154 "Version Major", // 11
155 "Version Minor", // 12
156 "Version Revision", // 13
157 "Millisecs Up", // 14
158 "Unixtime Low", // 15
159 "Unixtime High", // 16
160 "Physical Memory", // 17
161 "Resident Memory", // 18
162 "Total Available Memory", // 19
163 "Max. Private Memory", // 20
164 "Max. Shared Memory", // 21
165 "Timer Interval", // 22
166 "Max. Path Comp. Length", // 23
167 "Foreground FS Session ID"// 24
168 "Foreground Process PID", // 25
169 NULL
170 };
171 static CHAR *pnames[] = { "Swap button",
172 "Dblclk time",
173 "CX dblclk",
174 "CY dblclk",
175 "CX sizeborder",
176 "CY sizeborder",
177 "Alarm",
178 "",
179 "",
180 "Cursor rate",
181 "First scroll rate",
182 "Scroll rate",
183 "Numbered lists",
184 "Warning freq",
185 "Note freq",
186 "Error freq",
187 "Warning duration",
188 "Note duration",
189 "Error duration",
190 "",
191 "CX screen",
192 "CY screen",
193 "CX vscroll",
194 "CY hscroll",
195 "CY vscroll arrow",
196 "CX hscroll arrow",
197 "CX border",
198 "CY border",
199 "CX dlgframe",
200 "CY dlgframe",
201 "CY titlebar",
202 "CY vslider",
203 "CX hslider",
204 "CX minmaxbutton",
205 "CY minmaxbutton",
206 "CY menu",
207 "CX fullscreen",
208 "CY fullscreen",
209 "CX icon",
210 "CY icon",
211 "CX pointer",
212 "CY pointer",
213 "Debug",
214 "# Mouse buttons",
215 "Pointer level",
216 "Cursor level",
217 "Track rect level",
218 "# timers",
219 "Mouse present",
220 "CX bytealign",
221 "CY bytealign",
222 "",
223 "",
224 "",
225 "",
226 "",
227 "Not reserved",
228 "Extra key beep",
229 "Set lights",
230 "Insert mode",
231 "",
232 "",
233 "",
234 "",
235 "Menu rolldown delay",
236 "Menu rollup delay",
237 "Alt mnemonic",
238 "Tasklist mouse access",
239 "CX icon text width",
240 "# Icon text lines",
241 "Chord time",
242 "CX chord",
243 "CY chord",
244 "CX motion",
245 "CY motion",
246 "Begin drag",
247 "End drag",
248 "Single select",
249 "Open",
250 "Context menu",
251 "Context help",
252 "Text edit",
253 "Begin select",
254 "End select",
255 "Begin drag kb",
256 "End drag kb",
257 "Select kb",
258 "Open kb",
259 "Context menu kb",
260 "Context help kb",
261 "Text edit kb",
262 "Begin select kb",
263 "End select kb",
264 "Animation",
265 "Animation speed",
266 "Mono icons",
267 "Kbd id",
268 "Print screen",
269 NULL
270 };
271 static CHAR *dnames[] = { "# printers",
272 "# RS232 ports",
273 "# diskette drives",
274 "Coprocessor present",
275 "PC submodel",
276 "PC model",
277 "Display",
278 NULL
279 };
280 ULONG vals[26], val, x;
281 CHAR s[134], dev;
282
283 if (DosQuerySysInfo(QSV_MAX_PATH_LENGTH, QSV_MAX_COMP_LENGTH + 2,
284 (PVOID) vals, (ULONG) sizeof(vals))) {
285 WinDismissDlg(hwnd, 0);
286 break;
287 }
288 me = hwnd;
289 WinSendDlgItemMsg(hwnd, SYS_LISTBOX, LM_INSERTITEM,
290 MPFROMLONG(LIT_END), MPFROMP(" -= Base OS Info =-"));
291 for (x = 0; names[x]; x++) {
292 switch (x) {
293 case 0:
294 case 9:
295 case 22:
296 sprintf(s, "%-28.28s%lu bytes", names[x], vals[x]);
297 break;
298 case 16:
299 case 17:
300 case 18:
301 case 19:
302 case 20:
303 sprintf(s, "%-28.28s%lu bytes (%lu mb)", names[x], vals[x],
304 vals[x] / (1024 * 1024));
305 break;
306 case 4:
307 sprintf(s, "%-28.28s%c:", names[x], (CHAR) vals[x] + '@');
308 break;
309 case 5:
310 sprintf(s, "%-28.28s%s", names[x], (vals[x]) ? "On" : "Off");
311 break;
312 case 6:
313 sprintf(s, "%-28.28s%lu seconds", names[x], vals[x]);
314 break;
315 case 7:
316 case 8:
317 sprintf(s, "%-28.28s%lu milliseconds", names[x], vals[x]);
318 break;
319 case 13:
320 {
321 ULONG numdays, nummins;
322
323 sprintf(s, "%-28.28s%lu (", names[x], vals[x]);
324 vals[x] /= 60000;
325 numdays = vals[x] / (60 * 24);
326 if (numdays)
327 sprintf(s + strlen(s), "%lu day%s, ", numdays,
328 &"s"[numdays == 1]);
329 nummins = vals[x] % (60 * 24);
330 sprintf(s + strlen(s), "%luh:%02lum)", nummins / 60,
331 nummins % 60);
332 }
333 break;
334 case 21:
335 sprintf(s, "%-28.28s%lu.%01lu milliseconds", names[x],
336 vals[x] / 10, vals[x] % 10);
337 break;
338 default:
339 sprintf(s, "%-28.28s%lu", names[x], vals[x]);
340 break;
341 }
342 if (*s)
343 WinSendDlgItemMsg(hwnd, SYS_LISTBOX, LM_INSERTITEM,
344 MPFROMLONG(LIT_END), MPFROMP(s));
345 }
346 WinSendDlgItemMsg(hwnd, SYS_LISTBOX, LM_INSERTITEM,
347 MPFROMLONG(LIT_END), MPFROMP(" -= PM Info =-"));
348 for (x = 0; pnames[x]; x++) {
349 if (*pnames[x]) {
350 val = WinQuerySysValue(HWND_DESKTOP, x);
351 switch (x) {
352 case SV_CXBYTEALIGN:
353 case SV_CYBYTEALIGN:
354 case SV_CYMOTIONSTART:
355 case SV_CXMOTIONSTART:
356 case SV_CYDBLCLK:
357 case SV_CXDBLCLK:
358 case SV_CYPOINTER:
359 case SV_CXPOINTER:
360 case SV_CYICON:
361 case SV_CXICON:
362 case SV_CXFULLSCREEN:
363 case SV_CYFULLSCREEN:
364 case SV_CYMENU:
365 case SV_CYMINMAXBUTTON:
366 case SV_CXMINMAXBUTTON:
367 case SV_CXHSLIDER:
368 case SV_CYVSLIDER:
369 case SV_CXDLGFRAME:
370 case SV_CYDLGFRAME:
371 case SV_CXSIZEBORDER:
372 case SV_CYSIZEBORDER:
373 case SV_CXBORDER:
374 case SV_CYBORDER:
375 case SV_CYTITLEBAR:
376 case SV_CXHSCROLLARROW:
377 case SV_CYVSCROLLARROW:
378 case SV_CXVSCROLL:
379 case SV_CYHSCROLL:
380 case SV_CYSCREEN:
381 case SV_CXSCREEN:
382 case SV_CXICONTEXTWIDTH:
383 case SV_CXCHORD:
384 case SV_CYCHORD:
385 sprintf(s, "%-28.28s%lu pels", pnames[x], val);
386 break;
387 case SV_CONTEXTMENU:
388 case SV_OPEN:
389 case SV_TEXTEDIT:
390 case SV_BEGINSELECT:
391 case SV_ENDSELECT:
392 case SV_BEGINDRAG:
393 case SV_ENDDRAG:
394 case SV_CONTEXTHELP:
395 case SV_SINGLESELECT:
396 sprintf(s, "%-28.28sWM: %04xh KC: %04xh", pnames[x],
397 LOUSHORT(val), HIUSHORT(val));
398 break;
399 case SV_TASKLISTMOUSEACCESS:
400 sprintf(s, "%-28.28sWM: %04xh", pnames[x], LOUSHORT(val));
401 break;
402 case SV_CONTEXTMENUKB:
403 case SV_TEXTEDITKB:
404 case SV_BEGINDRAGKB:
405 case SV_ENDDRAGKB:
406 case SV_SELECTKB:
407 case SV_OPENKB:
408 case SV_CONTEXTHELPKB:
409 case SV_BEGINSELECTKB:
410 case SV_ENDSELECTKB:
411 sprintf(s, "%-28.28sVK: %04xh KC: %04xh", pnames[x],
412 LOUSHORT(val), HIUSHORT(val));
413 break;
414 case SV_CHORDTIME:
415 case SV_DBLCLKTIME:
416 case SV_CURSORRATE:
417 case SV_FIRSTSCROLLRATE:
418 case SV_SCROLLRATE:
419 case SV_MENUROLLDOWNDELAY:
420 case SV_MENUROLLUPDELAY:
421 case SV_ANIMATIONSPEED:
422 case SV_WARNINGDURATION:
423 case SV_NOTEDURATION:
424 case SV_ERRORDURATION:
425 sprintf(s, "%-28.28s%lu milliseconds", pnames[x], val);
426 break;
427 case SV_MOUSEPRESENT:
428 sprintf(s, "%-28.28s%s", pnames[x], (val) ? "True" : "False");
429 break;
430 case SV_ALARM:
431 case SV_ANIMATION:
432 case SV_MONOICONS:
433 case SV_PRINTSCREEN:
434 case SV_SETLIGHTS:
435 case SV_INSERTMODE:
436 case SV_SWAPBUTTON:
437 case SV_DEBUG:
438 sprintf(s, "%-28.28s%s", pnames[x], (val) ? "On" : "Off");
439 break;
440 default:
441 sprintf(s, "%-28.28s%lu", pnames[x], val);
442 break;
443 }
444 WinSendDlgItemMsg(hwnd, SYS_LISTBOX, LM_INSERTITEM,
445 MPFROMLONG(LIT_END), MPFROMP(s));
446 }
447 }
448 WinSendDlgItemMsg(hwnd, SYS_LISTBOX, LM_INSERTITEM,
449 MPFROMLONG(LIT_END), MPFROMP(" -= Hardware info =-"));
450 for (x = 0; dnames[x]; x++) {
451 if (*dnames[x]) {
452 if (!DosDevConfig(&dev, x)) {
453 switch (x) {
454 case DEVINFO_COPROCESSOR:
455 sprintf(s, "%-28.28s%s", dnames[x], (dev) ? "True" : "False");
456 break;
457 case DEVINFO_ADAPTER:
458 sprintf(s, "%-28.28s%sMonochrome or printer", dnames[x],
459 (dev) ? "Not " : NullStr);
460 break;
461 default:
462 sprintf(s, "%-28.28s%lu", dnames[x], dev);
463 break;
464 }
465 }
466 WinSendDlgItemMsg(hwnd, SYS_LISTBOX, LM_INSERTITEM,
467 MPFROMLONG(LIT_END), MPFROMP(s));
468 }
469 }
470 }
471 break;
472
473 case WM_ADJUSTWINDOWPOS:
474 PostMsg(hwnd, UM_STRETCH, MPVOID, MPVOID);
475 break;
476
477 case UM_STRETCH:
478 {
479 SWP swpC, swp;
480
481 WinQueryWindowPos(hwnd, &swp);
482 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE))) {
483 WinQueryWindowPos(WinWindowFromID(hwnd, SYS_LISTBOX), &swpC);
484 if (!ypos)
485 ypos = swpC.y;
486 WinSetWindowPos(WinWindowFromID(hwnd, SYS_LISTBOX), HWND_TOP,
487 SysVal(SV_CXSIZEBORDER),
488 ypos,
489 swp.cx - (SysVal(SV_CXSIZEBORDER) * 2),
490 (swp.cy - ypos) - (SysVal(SV_CYTITLEBAR) +
491 SysVal(SV_CYSIZEBORDER)),
492 SWP_MOVE | SWP_SIZE);
493 }
494 }
495 return 0;
496
497 case WM_COMMAND:
498 WinDismissDlg(hwnd, 0);
499 return 0;
500
501 case WM_DESTROY:
502 if (me == hwnd) {
503 me = (HWND) 0;
504 if (hptrIcon)
505 WinDestroyPointer(hptrIcon);
506 hptrIcon = (HPOINTER) 0;
507 }
508 break;
509 }
510
511 return WinDefDlgProc(hwnd, msg, mp1, mp2);
512}
513
514#pragma alloc_text(SYSINFO,SysInfoDlgProc,RunRmview)
Note: See TracBrowser for help on using the repository browser.