source: trunk/dll/sysinfo.c@ 1570

Last change on this file since 1570 was 1554, checked in by Gregg Young, 15 years ago

Check that pTmpDir IsValid and recreate if not found; Fixes hangs caused by temp file creation failures. (Ticket 440)

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