source: trunk/dll/inis.c@ 1038

Last change on this file since 1038 was 1038, checked in by Gregg Young, 17 years ago

More fortify cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 75.4 KB
Line 
1
2/***********************************************************************
3
4 $Id: inis.c 1038 2008-07-04 20:33:59Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2004, 2008 Steven H. Levine
8
9 01 Aug 04 SHL Rework lstrip/rstrip usage
10 01 Aug 04 SHL Rework fixup usage
11 24 May 05 SHL Rework Win_Error usage
12 05 Jun 05 SHL Use QWL_USER
13 17 Jul 06 SHL Use Runtime_Error
14 03 Nov 06 SHL Renames
15 03 Nov 06 SHL Count thread usage
16 22 Mar 07 GKY Use QWL_USER
17 30 Mar 07 GKY Remove GetPString for window class names
18 06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
19 06 Apr 07 GKY Add some error checking in drag/drop
20 19 Apr 07 SHL Use FreeDragInfoData. Add more drag/drop error checks.
21 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
22 16 Nov 07 SHL Ensure fixup buffer sufficiently large
23 09 Jan 08 SHL Avoid closing INI more times than opened
24 09 Jan 08 SHL Add some missing error reporting
25 09 Jan 08 SHL Standardize PrfOpenProfile return checks
26 09 Jan 08 SHL Use CloseProfile to avoid spurious system INI closes
27 29 Feb 08 GKY Use xfree where appropriate
28
29***********************************************************************/
30
31#include <stdlib.h>
32#include <string.h>
33#include <ctype.h>
34#include <share.h>
35#include <process.h> // _beginthread
36
37#define INCL_DOS
38#define INCL_DOSERRORS
39#define INCL_WIN
40#define INCL_GPI
41#define INCL_LONGLONG // dircnrs.h
42
43#include "fm3dlg.h"
44#include "fm3str.h"
45#include "mle.h"
46#include "errutil.h" // Dos_Error...
47#include "strutil.h" // GetPString
48#include "fm3dll.h"
49#include "fortify.h"
50
51#pragma data_seg(DATA2)
52
53static PSZ pszSrcFile = __FILE__;
54
55typedef struct
56{
57 USHORT size;
58 CHAR ininame[CCHMAXPATH]; // Must be null string if user or system ini
59 HINI hini;
60 BOOL working;
61 BOOL edit;
62 BOOL confirm;
63 HWND hwndMenu;
64 CHAR applname[CCHMAXPATH];
65 CHAR keyname[CCHMAXPATH];
66 CHAR *data;
67 ULONG datalen;
68 SHORT appindex;
69 SHORT keyindex;
70 BOOL dontclose;
71 USHORT currid;
72 BOOL isbinary;
73 HWND hwndIni;
74 HWND hwndApp;
75 HWND hwndKey;
76 HWND hwndData;
77 HWND hwndPopup;
78 HWND hwndCurrent;
79}
80INIDATA;
81
82typedef struct
83{
84 USHORT size;
85 USHORT action;
86 CHAR filename1[CCHMAXPATH];
87 CHAR filename2[CCHMAXPATH];
88 CHAR app[CCHMAXPATH];
89 CHAR key[CCHMAXPATH];
90 CHAR app2[CCHMAXPATH];
91 CHAR key2[CCHMAXPATH];
92 HWND hwndDlg;
93 HWND hwndSource;
94 BOOL confirm;
95}
96INIREC;
97
98/**
99 * Close profile unless it is user or system INI
100 * @param hini is profile handle
101 * @param fSkipIfSystem bypasses close for system INIs
102 */
103
104static VOID CloseProfile(HINI hini, BOOL fSkipIfSystem)
105{
106 BOOL ok = fSkipIfSystem &&
107 (hini == HINI_USERPROFILE || hini == HINI_SYSTEMPROFILE);
108
109 if (!ok) {
110 ok = PrfCloseProfile(hini);
111 if (!ok) {
112 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
113 "PrfCloseProfile failed for handle 0x%x", hini);
114 }
115 }
116}
117
118VOID CopyIniThread(VOID * args)
119{
120 INIREC *inirec = (INIREC *) args;
121 HAB hab2;
122 HMQ hmq2;
123 HINI hiniFrom = NULLHANDLE;
124 HINI hiniTo = NULLHANDLE;
125 PRFPROFILE cprfp;
126 CHAR userini[CCHMAXPATH], sysini[CCHMAXPATH];
127
128 if (inirec) {
129# ifdef FORTIFY
130 Fortify_EnterScope();
131# endif
132 hab2 = WinInitialize(0);
133 if (hab2) {
134 hmq2 = WinCreateMsgQueue(hab2, 0);
135 if (hmq2) {
136 WinCancelShutdown(hmq2, TRUE);
137 IncrThreadUsage();
138 *userini = *sysini = 0;
139 memset(&cprfp, 0, sizeof(PRFPROFILE));
140 cprfp.cchUserName = CCHMAXPATH;
141 cprfp.cchSysName = CCHMAXPATH;
142 cprfp.pszUserName = (PSZ) userini;
143 cprfp.pszSysName = (PSZ) sysini;
144 if (PrfQueryProfile(hab2, &cprfp)) {
145 if (!stricmp(cprfp.pszUserName, inirec->filename1))
146 hiniFrom = HINI_USERPROFILE;
147 else if (!stricmp(cprfp.pszSysName, inirec->filename1))
148 hiniFrom = HINI_SYSTEMPROFILE;
149 if (!stricmp(cprfp.pszUserName, inirec->filename2))
150 hiniTo = HINI_USERPROFILE;
151 else if (!stricmp(cprfp.pszSysName, inirec->filename2))
152 hiniTo = HINI_SYSTEMPROFILE;
153 }
154 if (hiniFrom == NULLHANDLE) {
155 hiniFrom = PrfOpenProfile(hab2, inirec->filename1);
156 if (hiniFrom == NULLHANDLE) {
157 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
158 "PrfOpenProfile failed for %s", inirec->filename1);
159 }
160 }
161 if (hiniTo == NULLHANDLE) {
162 if (!stricmp(inirec->filename1, inirec->filename2))
163 hiniTo = hiniFrom;
164 else {
165 hiniTo = PrfOpenProfile(hab2, inirec->filename2);
166 if (hiniTo == NULLHANDLE) {
167 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
168 "PrfOpenProfile failed for %s", inirec->filename2);
169 }
170 }
171 }
172 if (hiniFrom && hiniTo && (*inirec->app2 || hiniFrom != hiniTo)) {
173
174 PVOID pDataK, pData;
175 PBYTE pCurrentK;
176 ULONG ulSize = 0L;
177
178 if (inirec->action == IDM_MOVE || inirec->action == IDM_COPY) {
179 if (!*inirec->key) {
180 if (inirec->confirm &&
181 PrfQueryProfileSize(hiniFrom, (PSZ) ((*inirec->app2) ?
182 inirec->app2 : inirec->
183 app), NULL,
184 (PULONG) & ulSize) && ulSize) {
185 if (saymsg
186 (MB_YESNOCANCEL, HWND_DESKTOP,
187 GetPString(IDS_CONFIRMTEXT),
188 GetPString(IDS_INIOVERAPPNAMETEXT),
189 ((*inirec->app2) ? inirec->app2 : inirec->app),
190 inirec->filename1) != MBID_YES)
191 goto Abort;
192 }
193 if (PrfQueryProfileSize(hiniTo,
194 (PSZ) inirec->app,
195 NULL, (PULONG) & ulSize) && ulSize) {
196 pDataK = xmalloc(ulSize, pszSrcFile, __LINE__); /* allocate space for keynames */
197 if (pDataK) {
198 /* get keynames */
199 if (PrfQueryProfileString(hiniTo,
200 (PSZ) inirec->app,
201 NULL, "\0", pDataK, ulSize)) {
202 pCurrentK = pDataK;
203 /* step through keynames */
204 while (*pCurrentK) {
205 if (PrfQueryProfileSize(hiniTo, inirec->app,
206 pCurrentK,
207 (PULONG) & ulSize) && ulSize) {
208 pData = xmalloc(ulSize, pszSrcFile, __LINE__);
209 if (pData) {
210 /* get data */
211 if (PrfQueryProfileData(hiniTo, inirec->app,
212 pCurrentK,
213 pData, (PULONG) & ulSize))
214 /* write data to new ini file */
215 PrfWriteProfileData(hiniFrom, ((*inirec->app2) ?
216 inirec->
217 app2 : inirec->app),
218 pCurrentK, pData, ulSize);
219 xfree(pData, pszSrcFile, __LINE__); /* free data */
220 }
221 }
222 while (*pCurrentK) /* next keyname */
223 pCurrentK++;
224 pCurrentK++;
225 }
226 }
227 xfree(pDataK, pszSrcFile, __LINE__); /* free keynames */
228 }
229 }
230 }
231 else {
232 if (inirec->confirm &&
233 PrfQueryProfileSize(hiniFrom, (PSZ) ((*inirec->app2) ?
234 inirec->app2 : inirec->
235 app),
236 ((*inirec->key2) ? inirec->
237 key2 : inirec->key), (PULONG) & ulSize)
238 && ulSize) {
239 if (saymsg
240 (MB_YESNOCANCEL, HWND_DESKTOP,
241 GetPString(IDS_CONFIRMTEXT),
242 GetPString(IDS_INIOVERAPPKEYNAMETEXT),
243 ((*inirec->app2) ? inirec->app2 : inirec->app),
244 ((*inirec->key2) ? inirec->key2 : inirec->key),
245 inirec->filename1) != MBID_YES)
246 goto Abort;
247 }
248 if (PrfQueryProfileSize(hiniTo, inirec->app,
249 inirec->key,
250 (PULONG) & ulSize) && ulSize) {
251 pData = xmalloc(ulSize, pszSrcFile, __LINE__);
252 if (pData) {
253 /* get data */
254 if (PrfQueryProfileData(hiniTo, inirec->app,
255 inirec->key,
256 pData, (PULONG) & ulSize))
257 /* write data to new ini file */
258 PrfWriteProfileData(hiniFrom, ((*inirec->app2) ?
259 inirec->app2 : inirec->app),
260 ((*inirec->key2) ?
261 inirec->key2 : inirec->key),
262 pData, ulSize);
263 xfree(pData, pszSrcFile, __LINE__); /* free data */
264 }
265 }
266 }
267 if (inirec->action == IDM_MOVE) {
268 if (inirec->confirm &&
269 saymsg(MB_YESNOCANCEL,
270 HWND_DESKTOP,
271 GetPString(IDS_CONFIRMTEXT),
272 GetPString(IDS_INIDELETEMOVEDTEXT),
273 inirec->filename2) != MBID_YES)
274 goto Abort;
275 PrfWriteProfileData(hiniTo,
276 inirec->app,
277 ((*inirec->key) ? inirec->key : NULL),
278 NULL, 0L);
279 }
280 }
281 }
282 Abort:
283 if (hiniFrom)
284 CloseProfile(hiniFrom, TRUE);
285 if (hiniTo && hiniTo != hiniFrom)
286 CloseProfile(hiniTo, FALSE);
287 WinDestroyMsgQueue(hmq2);
288 }
289 DecrThreadUsage();
290 WinTerminate(hab2);
291 }
292 PostMsg(inirec->hwndDlg, WM_COMMAND, MPFROM2SHORT(INI_REFRESH, 0),
293 MPVOID);
294 if (inirec->action == IDM_MOVE && inirec->hwndSource &&
295 inirec->hwndSource != inirec->hwndDlg)
296 PostMsg(inirec->hwndSource, WM_COMMAND, MPFROM2SHORT(INI_REFRESH, 0),
297 MPVOID);
298 xfree(inirec, pszSrcFile, __LINE__);
299# ifdef FORTIFY
300 Fortify_LeaveScope();
301# endif
302 }
303}
304
305static VOID CompareIniThread(VOID * args)
306{
307 INIREC *inirec = (INIREC *) args;
308 HAB hab2;
309 HMQ hmq2;
310
311 if (inirec) {
312 hab2 = WinInitialize(0);
313 if (hab2) {
314 hmq2 = WinCreateMsgQueue(hab2, 0);
315 if (hmq2) {
316 WinCancelShutdown(hmq2, TRUE);
317 IncrThreadUsage();
318
319 // fixme to do something?
320
321 WinDestroyMsgQueue(hmq2);
322 }
323 DecrThreadUsage();
324 WinTerminate(hab2);
325 }
326 xfree(inirec, pszSrcFile, __LINE__);
327 }
328}
329
330static VOID BackupIniThread(VOID * args)
331{
332 PPRFPROFILE prfp = (PPRFPROFILE)args;
333 HAB hab2;
334 HMQ hmq2;
335 HINI orig = NULLHANDLE;
336 HINI new;
337 PVOID pDataA, pDataK, pData;
338 PBYTE pCurrentA, pCurrentK;
339 ULONG ulSize;
340 PRFPROFILE cprfp;
341 CHAR userini[CCHMAXPATH], sysini[CCHMAXPATH];
342
343 if (prfp) {
344# ifdef FORTIFY
345 Fortify_EnterScope();
346# endif
347 hab2 = WinInitialize(0);
348 if (hab2) {
349 hmq2 = WinCreateMsgQueue(hab2, 0);
350 if (hmq2) {
351 WinCancelShutdown(hmq2, TRUE);
352 IncrThreadUsage();
353 *userini = *sysini = 0;
354 memset(&cprfp, 0, sizeof(PRFPROFILE));
355 cprfp.cchUserName = CCHMAXPATH;
356 cprfp.cchSysName = CCHMAXPATH;
357 cprfp.pszUserName = (PSZ) userini;
358 cprfp.pszSysName = (PSZ) sysini;
359 if (PrfQueryProfile(hab2, &cprfp)) {
360 if (!stricmp(cprfp.pszUserName, prfp->pszUserName))
361 orig = HINI_USERPROFILE;
362 else if (!stricmp(cprfp.pszSysName, prfp->pszUserName))
363 orig = HINI_SYSTEMPROFILE;
364 }
365 if (orig == NULLHANDLE)
366 orig = PrfOpenProfile(hab2, prfp->pszUserName);
367 if (orig == NULLHANDLE) {
368 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
369 "PrfOpenProfile failed for %s", prfp->pszUserName);
370 }
371 else {
372 new = PrfOpenProfile(hab2, prfp->pszSysName);
373 if (new == NULLHANDLE) {
374 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
375 "PrfOpenProfile failed for %s", prfp->pszSysName);
376 }
377 else {
378 ulSize = 0;
379 if (PrfQueryProfileSize(orig, NULL, NULL, (PULONG) & ulSize)
380 && ulSize) {
381 pDataA = xmalloc(ulSize, pszSrcFile, __LINE__); /* allocate space for applnames */
382 if (pDataA) {
383 /* get applnames */
384 if (PrfQueryProfileString
385 (orig, NULL, NULL, "\0", pDataA, ulSize)) {
386 pCurrentA = pDataA;
387 /* step through applnames */
388 while (*pCurrentA) {
389 /* now keynames for this applname */
390 if (PrfQueryProfileSize(orig, (PSZ) pCurrentA, NULL,
391 (PULONG) & ulSize) && ulSize) {
392 pDataK = xmalloc(ulSize, pszSrcFile, __LINE__); /* allocate space for keynames */
393 if (pDataK) {
394 /* get keynames */
395 if (PrfQueryProfileString(orig, (PSZ) pCurrentA, NULL,
396 "\0", pDataK, ulSize)) {
397 pCurrentK = pDataK;
398 /* step through keynames */
399 while (*pCurrentK) {
400 if (PrfQueryProfileSize(orig, pCurrentA,
401 pCurrentK,
402 (PULONG) & ulSize) &&
403 ulSize) {
404 pData = xmalloc(ulSize, pszSrcFile, __LINE__);
405 if (pData) {
406 /* get data */
407 if (PrfQueryProfileData(orig, pCurrentA,
408 pCurrentK,
409 pData,
410 (PULONG) & ulSize))
411 /* write data to new ini file */
412 PrfWriteProfileData(new, pCurrentA,
413 pCurrentK, pData,
414 ulSize);
415 xfree(pData, pszSrcFile, __LINE__); /* free data */
416 }
417 }
418 while (*pCurrentK) /* next keyname */
419 pCurrentK++;
420 pCurrentK++;
421 }
422 }
423 xfree(pDataK, pszSrcFile, __LINE__); /* free keynames */
424 }
425 }
426 while (*pCurrentA) /* next applname */
427 pCurrentA++;
428 pCurrentA++;
429 }
430 }
431 xfree(pDataA, pszSrcFile, __LINE__); /* free applnames */
432 }
433 }
434 CloseProfile(new, FALSE);
435 }
436 CloseProfile(orig, TRUE);
437 }
438 WinDestroyMsgQueue(hmq2);
439 }
440 DecrThreadUsage();
441 WinTerminate(hab2);
442 }
443 xfree(prfp->pszUserName, pszSrcFile, __LINE__);
444 xfree(prfp->pszSysName, pszSrcFile, __LINE__);
445 xfree(prfp, pszSrcFile, __LINE__);
446# ifdef FORTIFY
447 Fortify_LeaveScope();
448# endif
449 }
450}
451
452static VOID EnumAppNames(HWND hwndList, HINI hini)
453{
454 PVOID pData;
455 PBYTE pCurrent;
456 ULONG ulSize = 0;
457
458 WinSendMsg(hwndList, LM_DELETEALL, NULL, NULL);
459 if (!PrfQueryProfileSize(hini, NULL, NULL, (PULONG) & ulSize))
460 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
461 "PrfQueryProfileSize");
462 else if (!ulSize)
463 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
464 else {
465 pData = xmalloc(ulSize, pszSrcFile, __LINE__);
466 if (pData) {
467 if (PrfQueryProfileString(hini, NULL, NULL, "\0", pData, ulSize)) {
468 pCurrent = pData;
469 WinEnableWindowUpdate(hwndList, FALSE);
470 while (*pCurrent) {
471 WinSendMsg(hwndList, LM_INSERTITEM, MPFROMSHORT(LIT_SORTASCENDING),
472 MPFROMP(pCurrent));
473 while (*pCurrent)
474 pCurrent++;
475 pCurrent++;
476 }
477 WinSendMsg(hwndList, LM_SELECTITEM, MPFROMSHORT(0),
478 MPFROMSHORT(TRUE));
479 WinEnableWindowUpdate(hwndList, TRUE);
480 }
481 xfree(pData, pszSrcFile, __LINE__);
482 }
483 }
484}
485
486static CHAR *GetKeyData(HWND hwndList, HINI hini, PSZ pAppName,
487 PSZ pKeyName, PULONG datalen)
488{
489 ULONG ulKeySize = 0L;
490 PVOID pKeyData = NULL;
491
492 *datalen = 0L;
493 if (!PrfQueryProfileSize(hini, pAppName, pKeyName, (PULONG) & ulKeySize))
494 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
495 "PrfQueryProfileSize");
496 else {
497 pKeyData = xmalloc(ulKeySize + 1L, pszSrcFile, __LINE__);
498 if (pKeyData) {
499 if (!PrfQueryProfileData
500 (hini, pAppName, pKeyName, pKeyData, (PULONG) & ulKeySize))
501 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
502 "PrfQueryProfileData");
503 else {
504 HexDump(hwndList, pKeyData, ulKeySize);
505 {
506 CHAR s[81];
507
508 sprintf(s,
509 GetPString(IDS_INIBYTESTEXT),
510 ulKeySize, &"s"[ulKeySize == 1]);
511 WinSetDlgItemText(WinQueryWindow(hwndList, QW_PARENT),
512 INI_NUMDATA, s);
513 }
514 *datalen = ulKeySize;
515 return (CHAR *)pKeyData;
516 }
517 }
518 }
519 return NULL;
520}
521
522static BOOL EnumKeyNames(HWND hwndList, HINI hini, PSZ pAppName)
523{
524 PVOID pData;
525 PBYTE pCurrent;
526 ULONG ulSize = 0;
527
528 WinSendMsg(hwndList, LM_DELETEALL, NULL, NULL);
529 if (!PrfQueryProfileSize(hini, pAppName, NULL, (PULONG) & ulSize))
530 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
531 "PrfQueryProfileSize");
532 else {
533 if (!ulSize)
534 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
535 pData = xmalloc(ulSize + 1L, pszSrcFile, __LINE__);
536 if (pData) {
537 if (!PrfQueryProfileString(hini, pAppName, NULL, "\0", pData, ulSize)) {
538 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
539 "PrfQueryProfileString");
540 xfree(pData, pszSrcFile, __LINE__);
541 }
542 else {
543 pCurrent = pData;
544 WinEnableWindowUpdate(hwndList, FALSE);
545 while (*pCurrent) {
546 WinSendMsg(hwndList, LM_INSERTITEM, MPFROMSHORT(LIT_SORTASCENDING),
547 MPFROMP(pCurrent));
548 while (*pCurrent)
549 pCurrent++;
550 pCurrent++;
551 }
552 WinSendMsg(hwndList, LM_SELECTITEM, MPFROMSHORT(0),
553 MPFROMSHORT(TRUE));
554 WinEnableWindowUpdate(hwndList, TRUE);
555 xfree(pData, pszSrcFile, __LINE__);
556 return TRUE;
557 }
558 }
559 }
560 return FALSE;
561}
562
563#define hwndMLE WinWindowFromID(hwnd,IAF_MLE)
564
565MRESULT EXPENTRY FilterIniProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
566{
567 INIDATA *inidata;
568 static CHAR lasttext[8192] = "";
569
570 switch (msg) {
571 case WM_INITDLG:
572 WinSetWindowPtr(hwnd, QWL_USER, mp2);
573 inidata = (INIDATA *) mp2;
574 WinSendDlgItemMsg(hwnd, IAF_SAVENAME, EM_SETTEXTLIMIT,
575 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
576 MLEsetformat(hwndMLE, MLFIE_NOTRANS);
577 MLEsetlimit(hwndMLE, 8192);
578 WinSetWindowText(hwndMLE, lasttext);
579 {
580 FILEFINDBUF3 ffb;
581 ULONG nm;
582 HDIR hdir;
583
584 hdir = HDIR_CREATE;
585 nm = 1;
586 DosError(FERR_DISABLEHARDERR);
587 if (!DosFindFirst("*.IST",
588 &hdir,
589 FILE_NORMAL | FILE_ARCHIVED,
590 &ffb, sizeof(ffb), &nm, FIL_STANDARD)) {
591 do {
592 priority_bumped();
593 WinSendDlgItemMsg(hwnd, IAF_LISTBOX, LM_INSERTITEM,
594 MPFROMSHORT(LIT_SORTASCENDING),
595 MPFROMP(ffb.achName));
596 nm = 1;
597 } while (!DosFindNext(hdir, &ffb, sizeof(ffb), &nm));
598 DosFindClose(hdir);
599 priority_bumped();
600 }
601 }
602 break;
603
604 case WM_ADJUSTWINDOWPOS:
605 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
606 break;
607
608 case UM_SETDIR:
609 PaintRecessedWindow(WinWindowFromID(hwnd, IAF_HELP), (HPS) 0, FALSE,
610 TRUE);
611 PaintRecessedWindow(WinWindowFromID(hwnd, IAF_SAVENAME), (HPS) 0, FALSE,
612 FALSE);
613 PaintRecessedWindow(WinWindowFromID(hwnd, IAF_LISTBOX), (HPS) 0, FALSE,
614 FALSE);
615 PaintRecessedWindow(WinWindowFromID(hwnd, IAF_MLE), (HPS) 0, FALSE,
616 FALSE);
617 return 0;
618
619 case WM_CONTROL:
620 switch (SHORT1FROMMP(mp1)) {
621 case IAF_SAVENAME:
622 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
623 WinSetDlgItemText(hwnd, IAF_HELP, NullStr);
624 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
625 WinSetDlgItemText(hwnd,
626 IAF_HELP, GetPString(IDS_MASKLISTNAMEHELPTEXT));
627 break;
628
629 case IAF_LISTBOX:
630 if (SHORT2FROMMP(mp1) == LN_KILLFOCUS)
631 WinSetDlgItemText(hwnd, IAF_HELP, NullStr);
632 if (SHORT2FROMMP(mp1) == LN_SETFOCUS)
633 WinSetDlgItemText(hwnd,
634 IAF_HELP, GetPString(IDS_MASKLISTFILESHELPTEXT));
635 else if (SHORT2FROMMP(mp1) == LN_ENTER)
636 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IAF_LOAD, 0), MPVOID);
637 break;
638
639 case IAF_MLE:
640 if (SHORT2FROMMP(mp1) == MLN_KILLFOCUS)
641 WinSetDlgItemText(hwnd, IAF_HELP, NullStr);
642 if (SHORT2FROMMP(mp1) == MLN_SETFOCUS)
643 WinSetDlgItemText(hwnd,
644 IAF_HELP, GetPString(IDS_MASKLISTMASKSHELPTEXT));
645 break;
646 }
647 return 0;
648
649 case WM_COMMAND:
650 switch (SHORT1FROMMP(mp1)) {
651 case DID_OK:
652 inidata = INSTDATA(hwnd);
653 if (!inidata)
654 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
655 else {
656 CHAR s[8193], app[1024];
657 register CHAR *p;
658 SHORT sSelect, numitems;
659 BOOL match;
660
661 *s = 0;
662 WinQueryWindowText(hwndMLE, 8192, s);
663 if (!*s) {
664 DosBeep(250, 100);
665 break;
666 }
667 else {
668 strcpy(lasttext, s);
669 p = s;
670 while (*p) {
671 if (*p == '\r') {
672 memmove(p, p + 1, strlen(p));
673 continue;
674 }
675 if (*p == '\n')
676 *p = 0;
677 p++;
678 }
679 p++;
680 *p = 0;
681 }
682 numitems = (SHORT) WinSendMsg(inidata->hwndApp,
683 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
684 if (!numitems) {
685 DosBeep(250, 100);
686 break;
687 }
688 else {
689 WinSetPointer(HWND_DESKTOP, hptrBusy);
690 WinSetDlgItemText(hwnd, IAF_HELP, GetPString(IDS_FILTERINGTEXT));
691 sSelect = 0;
692 while (numitems) {
693 *app = 0;
694 WinSendMsg(inidata->hwndApp,
695 LM_QUERYITEMTEXT,
696 MPFROM2SHORT(sSelect, 1024), MPFROMP(app));
697 match = FALSE;
698 if (*app) {
699 p = s;
700 while (*p) {
701 if (*p != '/') {
702 if (wildcard(app, p, TRUE))
703 match = TRUE;
704 }
705 else if (wildcard(app, p + 1, TRUE)) {
706 match = FALSE;
707 break;
708 }
709 while (*p)
710 p++;
711 p++;
712 }
713 }
714 if (!match)
715 WinSendMsg(inidata->hwndApp, LM_DELETEITEM,
716 MPFROMSHORT(sSelect), MPVOID);
717 else
718 sSelect++;
719 numitems--;
720 }
721 WinSetPointer(HWND_DESKTOP, hptrArrow);
722 }
723 }
724 WinDismissDlg(hwnd, 1);
725 break;
726
727 case IAF_LOAD:
728 {
729 CHAR s[8193];
730 FILE *fp;
731 INT len;
732 SHORT sSelect;
733
734 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, IAF_LISTBOX,
735 LM_QUERYSELECTION,
736 MPFROM2SHORT(LIT_FIRST, 0),
737 MPVOID);
738 if (sSelect < 0)
739 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
740 else {
741 *s = 0;
742 WinSendDlgItemMsg(hwnd, IAF_LISTBOX, LM_QUERYITEMTEXT,
743 MPFROM2SHORT(sSelect, CCHMAXPATH), MPFROMP(s));
744 bstrip(s);
745 if (*s) {
746 fp = _fsopen(s, "r", SH_DENYWR);
747 if (fp) {
748 len = fread(s, 1, 8192, fp);
749 s[len] = 0;
750 WinSetWindowText(hwndMLE, s);
751 fclose(fp);
752 }
753 }
754 }
755 }
756 break;
757
758 case IAF_SAVE:
759 {
760 CHAR s[8193], filename[CCHMAXPATH], *p;
761 FILE *fp;
762
763 *filename = 0;
764 WinQueryDlgItemText(hwnd, IAF_SAVENAME, CCHMAXPATH, filename);
765 bstrip(filename);
766 if (*filename) {
767 p = strchr(filename, '.');
768 if (p) {
769 strcpy(p, ".IST");
770 WinSetDlgItemText(hwnd, IAF_SAVENAME, filename);
771 }
772 *s = 0;
773 WinQueryWindowText(hwndMLE, 8192, s);
774 if (!*s)
775 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
776 else {
777 fp = xfopen(filename, "w", pszSrcFile, __LINE__);
778 if (fp) {
779 fwrite(s, 1, strlen(s), fp);
780 fclose(fp);
781 WinSendDlgItemMsg(hwnd,
782 IAF_LISTBOX,
783 LM_INSERTITEM,
784 MPFROMSHORT(LIT_SORTASCENDING),
785 MPFROMP(filename));
786 }
787 }
788 }
789 }
790 break;
791
792 case IAF_DELETE:
793 {
794 CHAR s[CCHMAXPATH];
795 SHORT sSelect;
796
797 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, IAF_LISTBOX,
798 LM_QUERYSELECTION,
799 MPFROM2SHORT(LIT_FIRST, 0),
800 MPVOID);
801 if (sSelect >= 0) {
802 *s = 0;
803 WinSendDlgItemMsg(hwnd, IAF_LISTBOX, LM_QUERYITEMTEXT,
804 MPFROM2SHORT(sSelect, CCHMAXPATH), MPFROMP(s));
805 bstrip(s);
806 if (*s) {
807 unlinkf(s);
808 WinSendDlgItemMsg(hwnd, IAF_LISTBOX, LM_DELETEITEM,
809 MPFROMSHORT(sSelect), MPVOID);
810 }
811 }
812 }
813 break;
814
815 case DID_CANCEL:
816 WinDismissDlg(hwnd, 0);
817 break;
818
819 case IDM_HELP:
820 if (hwndHelp)
821 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
822 MPFROM2SHORT(HELP_FILTERINI, 0),
823 MPFROMSHORT(HM_RESOURCEID));
824 break;
825 }
826 return 0;
827 }
828 return WinDefDlgProc(hwnd, msg, mp1, mp2);
829}
830
831MRESULT EXPENTRY IntraIniProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
832{
833 INIREC *inirec;
834
835 switch (msg) {
836 case WM_INITDLG:
837 WinSetWindowPtr(hwnd, QWL_USER, mp2);
838 inirec = (INIREC *) mp2;
839 WinSendDlgItemMsg(hwnd,
840 INII_NEWAPP,
841 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
842 WinSendDlgItemMsg(hwnd,
843 INII_NEWKEY,
844 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
845 {
846 CHAR s[CCHMAXPATH + 34];
847
848 sprintf(s, GetPString(IDS_INIWASTEXT), inirec->app);
849 WinSetDlgItemText(hwnd, INII_OLDAPP, s);
850 }
851 if (!*inirec->key) {
852 WinEnableWindow(WinWindowFromID(hwnd, INII_NEWKEY), FALSE);
853 WinEnableWindow(WinWindowFromID(hwnd, INII_NEWKEYHDR), FALSE);
854 switch (inirec->action) {
855 case IDM_MOVE:
856 WinSetWindowText(hwnd, GetPString(IDS_INIRENAMEAPPTITLETEXT));
857 break;
858 case IDM_COPY:
859 WinSetWindowText(hwnd, GetPString(IDS_INICOPYAPPTITLETEXT));
860 break;
861 }
862 }
863 else {
864 {
865 CHAR s[CCHMAXPATH + 34];
866
867 sprintf(s, GetPString(IDS_INIWASTEXT), inirec->key);
868 WinSetDlgItemText(hwnd, INII_OLDKEY, s);
869 }
870 WinSetDlgItemText(hwnd, INII_NEWAPP, inirec->app);
871 WinSendDlgItemMsg(hwnd,
872 INII_NEWAPP,
873 EM_SETSEL, MPFROM2SHORT(0, CCHMAXPATH), MPVOID);
874 switch (inirec->action) {
875 case IDM_MOVE:
876 WinSetWindowText(hwnd, GetPString(IDS_INIRENAMEKEYTITLETEXT));
877 break;
878 case IDM_COPY:
879 WinSetWindowText(hwnd, GetPString(IDS_INICOPYKEYTITLETEXT));
880 break;
881 }
882 }
883 break;
884
885 case WM_COMMAND:
886 switch (SHORT1FROMMP(mp1)) {
887 case DID_OK:
888 inirec = (INIREC *) WinQueryWindowPtr(hwnd, QWL_USER);
889 if (inirec) {
890 WinQueryDlgItemText(hwnd, INII_NEWAPP, CCHMAXPATH, inirec->app2);
891 bstrip(inirec->app2);
892 if (!*inirec->app2) {
893 DosBeep(50, 100);
894 break;
895 }
896 if (*inirec->key) {
897 WinQueryDlgItemText(hwnd, INII_NEWKEY, CCHMAXPATH, inirec->key2);
898 bstrip(inirec->key2);
899 if (!*inirec->key2) {
900 DosBeep(50, 100);
901 break;
902 }
903 }
904 WinDismissDlg(hwnd, 1);
905 }
906 break;
907
908 case DID_CANCEL:
909 WinDismissDlg(hwnd, 0);
910 break;
911
912 case IDM_HELP:
913 if (hwndHelp)
914 WinSendMsg(hwndHelp,
915 HM_DISPLAY_HELP,
916 MPFROM2SHORT(HELP_INTRAINI, 0),
917 MPFROMSHORT(HM_RESOURCEID));
918 break;
919 }
920 return 0;
921 }
922 return WinDefDlgProc(hwnd, msg, mp1, mp2);
923}
924
925MRESULT EXPENTRY ChangeIniProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
926{
927 switch (msg) {
928 case WM_INITDLG:
929 WinSetWindowPtr(hwnd, QWL_USER, mp2);
930 WinSendDlgItemMsg(hwnd, INIR_USERPROFILE, EM_SETTEXTLIMIT,
931 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
932 WinSendDlgItemMsg(hwnd, INIR_SYSTEMPROFILE, EM_SETTEXTLIMIT,
933 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
934 break;
935
936 case WM_COMMAND:
937 switch (SHORT1FROMMP(mp1)) {
938 case INIR_FIND:
939 {
940 CHAR filename[CCHMAXPATH], *p, *ininame;
941 USHORT id = 0;
942 HWND hwndFocus;
943
944 hwndFocus = WinQueryFocus(HWND_DESKTOP);
945 if (hwndFocus)
946 id = WinQueryWindowUShort(hwndFocus, QWS_ID);
947 if (id != INIR_SYSTEMPROFILE)
948 id = INIR_USERPROFILE;
949 ininame = INSTDATA(hwnd);
950 if (ininame && *ininame) {
951 strcpy(filename, ininame);
952 p = filename;
953 while (*p) {
954 if (*p == '/')
955 *p = '\\';
956 p++;
957 }
958 p = strrchr(filename, '\\');
959 if (p) {
960 p++;
961 *p = 0;
962 }
963 else
964 *filename = 0;
965 }
966 else
967 *filename = 0;
968 strcat(filename, "*.INI");
969 if (insert_filename(hwnd, filename, TRUE, FALSE) && *filename)
970 WinSetDlgItemText(hwnd, id, filename);
971 }
972 break;
973
974 case DID_OK:
975 {
976 HINI testini;
977 PRFPROFILE prfp;
978 CHAR sysini[CCHMAXPATH];
979 CHAR userini[CCHMAXPATH];
980
981 WinQueryDlgItemText(hwnd, INIR_USERPROFILE, CCHMAXPATH, userini);
982 WinQueryDlgItemText(hwnd, INIR_SYSTEMPROFILE, CCHMAXPATH, sysini);
983 testini = PrfOpenProfile(WinQueryAnchorBlock(hwnd), userini);
984 if (testini == NULLHANDLE) {
985 saymsg(MB_CANCEL,
986 hwnd,
987 GetPString(IDS_ERRORTEXT),
988 GetPString(IDS_INICANTOPENUSERTEXT), userini);
989 break;
990 }
991 CloseProfile(testini, FALSE);
992 testini = PrfOpenProfile(WinQueryAnchorBlock(hwnd), sysini);
993 if (testini == NULLHANDLE) {
994 saymsg(MB_CANCEL,
995 hwnd,
996 GetPString(IDS_ERRORTEXT),
997 GetPString(IDS_INICANTOPENSYSTEXT), sysini);
998 break;
999 }
1000 CloseProfile(testini, FALSE);
1001 memset(&prfp, 0, sizeof(PRFPROFILE));
1002 prfp.cchUserName = strlen(sysini);
1003 prfp.cchSysName = strlen(userini);
1004 prfp.pszUserName = (PSZ) userini;
1005 prfp.pszSysName = (PSZ) sysini;
1006 if (!PrfReset(WinQueryAnchorBlock(hwnd), &prfp)) {
1007 Win_Error(hwnd, hwnd, __FILE__, __LINE__,
1008 GetPString(IDS_INIPRFRESETFAILEDTEXT));
1009 }
1010 else
1011 WinDismissDlg(hwnd, 1);
1012 }
1013 break;
1014
1015 case DID_CANCEL:
1016 WinDismissDlg(hwnd, 0);
1017 break;
1018
1019 case IDM_HELP:
1020 if (hwndHelp)
1021 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
1022 MPFROM2SHORT(HELP_CHANGEINI, 0),
1023 MPFROMSHORT(HM_RESOURCEID));
1024 break;
1025 }
1026 return 0;
1027 }
1028 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1029}
1030
1031MRESULT EXPENTRY SwapIniProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1032{
1033 switch (msg) {
1034 case WM_INITDLG:
1035 WinSetWindowPtr(hwnd, QWL_USER, mp2);
1036 WinSendDlgItemMsg(hwnd,
1037 INIR_USERPROFILE,
1038 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
1039 WinSendDlgItemMsg(hwnd,
1040 INIR_SYSTEMPROFILE,
1041 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
1042 WinSetWindowText(hwnd, GetPString(IDS_INISWAPOS2INISTITLETEXT));
1043 break;
1044
1045 case WM_COMMAND:
1046 switch (SHORT1FROMMP(mp1)) {
1047 case INIR_FIND:
1048 {
1049 CHAR filename[CCHMAXPATH], *p, *ininame;
1050 USHORT id = 0;
1051 HWND hwndFocus;
1052
1053 hwndFocus = WinQueryFocus(HWND_DESKTOP);
1054 if (hwndFocus)
1055 id = WinQueryWindowUShort(hwndFocus, QWS_ID);
1056 if (id != INIR_SYSTEMPROFILE)
1057 id = INIR_USERPROFILE;
1058 ininame = INSTDATA(hwnd);
1059 if (ininame && *ininame) {
1060 strcpy(filename, ininame);
1061 p = filename;
1062 while (*p) {
1063 if (*p == '/')
1064 *p = '\\';
1065 p++;
1066 }
1067 p = strrchr(filename, '\\');
1068 if (p) {
1069 p++;
1070 *p = 0;
1071 }
1072 else
1073 *filename = 0;
1074 }
1075 else
1076 *filename = 0;
1077 strcat(filename, "*.INI");
1078 if (insert_filename(hwnd, filename, TRUE, FALSE) && *filename)
1079 WinSetDlgItemText(hwnd, id, filename);
1080 }
1081 break;
1082
1083 case DID_OK:
1084 {
1085 HINI testini;
1086 PRFPROFILE prfp;
1087 CHAR sysini[CCHMAXPATH];
1088 CHAR userini[CCHMAXPATH];
1089 CHAR oldsysini[CCHMAXPATH];
1090 CHAR olduserini[CCHMAXPATH];
1091 CHAR tempsysini[CCHMAXPATH];
1092 CHAR tempuserini[CCHMAXPATH];
1093 CHAR tempsysini2[CCHMAXPATH];
1094 CHAR tempuserini2[CCHMAXPATH];
1095 CHAR *p;
1096 APIRET rc;
1097
1098 *tempuserini = 0;
1099 *tempsysini = 0;
1100 *tempuserini2 = 0;
1101 *tempsysini2 = 0;
1102 memset(&prfp, 0, sizeof(PRFPROFILE));
1103 prfp.cchUserName = CCHMAXPATH;
1104 prfp.cchSysName = CCHMAXPATH;
1105 prfp.pszUserName = (PSZ) olduserini;
1106 prfp.pszSysName = (PSZ) oldsysini;
1107 if (!PrfQueryProfile(WinQueryAnchorBlock(hwnd), &prfp)) {
1108 Win_Error(hwnd, hwnd, __FILE__, __LINE__,
1109 GetPString(IDS_INIQUERYPRFFAILEDTEXT));
1110 break;
1111 }
1112 WinQueryDlgItemText(hwnd, INIR_USERPROFILE, CCHMAXPATH, userini);
1113 WinQueryDlgItemText(hwnd, INIR_SYSTEMPROFILE, CCHMAXPATH, sysini);
1114 MakeFullName(userini);
1115 MakeFullName(sysini);
1116 testini = PrfOpenProfile(WinQueryAnchorBlock(hwnd), userini);
1117 if (testini == NULLHANDLE) {
1118 saymsg(MB_CANCEL,
1119 hwnd,
1120 GetPString(IDS_ERRORTEXT),
1121 GetPString(IDS_INICANTOPENUSERTEXT), userini);
1122 break;
1123 }
1124 CloseProfile(testini, FALSE);
1125 testini = PrfOpenProfile(WinQueryAnchorBlock(hwnd), sysini);
1126 if (testini == NULLHANDLE) {
1127 saymsg(MB_CANCEL,
1128 hwnd,
1129 GetPString(IDS_ERRORTEXT),
1130 GetPString(IDS_INICANTOPENSYSTEXT), sysini);
1131 break;
1132 }
1133 CloseProfile(testini, FALSE);
1134 /* make copies of new inis */
1135 *tempuserini = 0;
1136 *tempsysini = 0;
1137 save_dir2(tempuserini);
1138 if (tempuserini[strlen(tempuserini) - 1] != '\\')
1139 strcat(tempuserini, "\\");
1140 strcat(tempuserini, "TEMPUSER.INI");
1141 rc = DosCopy(userini, tempuserini, DCPY_EXISTING);
1142 if (rc) {
1143 Dos_Error(MB_CANCEL,
1144 rc,
1145 hwnd,
1146 __FILE__,
1147 __LINE__,
1148 GetPString(IDS_COMPCOPYFAILEDTEXT), userini, tempuserini);
1149 break;
1150 }
1151 save_dir2(tempsysini);
1152 if (tempsysini[strlen(tempsysini) - 1] != '\\')
1153 strcat(tempsysini, "\\");
1154 strcat(tempsysini, "TEMPSYS.INI");
1155 rc = DosCopy(sysini, tempsysini, DCPY_EXISTING);
1156 if (rc) {
1157 Dos_Error(MB_CANCEL,
1158 rc,
1159 hwnd,
1160 __FILE__,
1161 __LINE__,
1162 GetPString(IDS_COMPCOPYFAILEDTEXT), sysini, tempsysini);
1163 break;
1164 }
1165 memset(&prfp, 0, sizeof(PRFPROFILE));
1166 prfp.cchUserName = strlen(tempuserini);
1167 prfp.cchSysName = strlen(tempsysini);
1168 prfp.pszUserName = (PSZ) tempuserini;
1169 prfp.pszSysName = (PSZ) tempsysini;
1170 if (!PrfReset(WinQueryAnchorBlock(hwnd), &prfp)) {
1171 Win_Error(hwnd, hwnd, __FILE__, __LINE__,
1172 GetPString(IDS_INIPRFRESETFAILEDTEXT));
1173 }
1174 else {
1175 /* backup old inis */
1176 strcpy(tempuserini2, olduserini);
1177 p = strrchr(tempuserini2, '\\');
1178 if (!p)
1179 *tempuserini2 = 0;
1180 else {
1181 p++;
1182 *p = 0;
1183 }
1184 strcat(tempuserini2, "OS2INI.BAK");
1185 rc = DosCopy(olduserini, tempuserini2, DCPY_EXISTING);
1186 if (rc) {
1187 Dos_Error(MB_CANCEL,
1188 rc,
1189 hwnd,
1190 __FILE__,
1191 __LINE__,
1192 GetPString(IDS_COMPCOPYFAILEDTEXT),
1193 olduserini, tempuserini2);
1194 WinDismissDlg(hwnd, 1);
1195 break;
1196 }
1197 strcpy(tempsysini2, oldsysini);
1198 p = strrchr(tempsysini2, '\\');
1199 if (!p)
1200 *tempsysini2 = 0;
1201 else {
1202 p++;
1203 *p = 0;
1204 }
1205 strcat(tempsysini2, "OS2SYINI.BAK");
1206 rc = DosCopy(oldsysini, tempsysini2, DCPY_EXISTING);
1207 if (rc) {
1208 Dos_Error(MB_CANCEL,
1209 rc,
1210 hwnd,
1211 __FILE__,
1212 __LINE__,
1213 GetPString(IDS_COMPCOPYFAILEDTEXT),
1214 oldsysini, tempsysini2);
1215 WinDismissDlg(hwnd, 1);
1216 break;
1217 }
1218 /* copy new inis to old ini names */
1219 rc = DosCopy(userini, olduserini, DCPY_EXISTING);
1220 if (rc) {
1221 Dos_Error(MB_CANCEL,
1222 rc,
1223 hwnd,
1224 __FILE__,
1225 __LINE__,
1226 GetPString(IDS_COMPCOPYFAILEDTEXT),
1227 userini, olduserini);
1228 WinDismissDlg(hwnd, 1);
1229 break;
1230 }
1231 rc = DosCopy(sysini, oldsysini, DCPY_EXISTING);
1232 if (rc) {
1233 Dos_Error(MB_CANCEL,
1234 rc,
1235 hwnd,
1236 __FILE__,
1237 __LINE__,
1238 GetPString(IDS_COMPCOPYFAILEDTEXT),
1239 userini, olduserini);
1240 WinDismissDlg(hwnd, 1);
1241 break;
1242 }
1243 /* replace temp inis with new permanent inis */
1244 memset(&prfp, 0, sizeof(PRFPROFILE));
1245 prfp.cchUserName = strlen(oldsysini);
1246 prfp.cchSysName = strlen(olduserini);
1247 prfp.pszUserName = (PSZ) olduserini;
1248 prfp.pszSysName = (PSZ) oldsysini;
1249 if (!PrfReset(WinQueryAnchorBlock(hwnd), &prfp)) {
1250 Win_Error(hwnd, hwnd, __FILE__, __LINE__,
1251 GetPString(IDS_INIPRFRESETFAILEDTEXT));
1252 }
1253 else {
1254 Notify(GetPString(IDS_SUCCESSTEXT));
1255 unlinkf(tempuserini);
1256 unlinkf(tempsysini);
1257 }
1258 WinDismissDlg(hwnd, 1);
1259 }
1260 }
1261 break;
1262
1263 case DID_CANCEL:
1264 WinDismissDlg(hwnd, 0);
1265 break;
1266
1267 case IDM_HELP:
1268 if (hwndHelp)
1269 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
1270 MPFROM2SHORT(HELP_SWAPINI, 0), MPFROMSHORT(HM_RESOURCEID));
1271 break;
1272 }
1273 return 0;
1274 }
1275 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1276}
1277
1278MRESULT EXPENTRY AddIniProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1279{
1280 INIDATA *inidata = INSTDATA(hwnd);
1281 size_t l;
1282
1283 switch (msg) {
1284 case WM_INITDLG:
1285 if (!mp2) {
1286 WinDismissDlg(hwnd, 0);
1287 break;
1288 }
1289 inidata = (INIDATA *) mp2;
1290 if (inidata->edit)
1291 WinSetWindowText(hwnd, GetPString(IDS_INIEDITINITITLETEXT));
1292 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) mp2);
1293 WinSendDlgItemMsg(hwnd,
1294 IAD_APPNAME,
1295 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
1296 WinSendDlgItemMsg(hwnd,
1297 IAD_KEYNAME,
1298 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
1299 WinSendDlgItemMsg(hwnd,
1300 IAD_DATA,
1301 EM_SETTEXTLIMIT, MPFROM2SHORT(32767, 0), MPVOID);
1302 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
1303 WinSetDlgItemText(hwnd, IAD_APPNAME, inidata->applname);
1304 if (inidata->edit) {
1305 WinSetDlgItemText(hwnd, IAD_KEYNAME, inidata->keyname);
1306 if (inidata->data && inidata->datalen) {
1307
1308 CHAR *p;
1309
1310 inidata->isbinary = FALSE;
1311 p = inidata->data;
1312 while ((p - inidata->data) < inidata->datalen - 1) {
1313 if (*p < ' ' || !isprint(*p)) {
1314 inidata->isbinary = TRUE;
1315 break;
1316 }
1317 p++;
1318 }
1319 if (inidata->isbinary) {
1320 inidata->isbinary = TRUE;
1321 WinCheckButton(hwnd, IAD_ISBINARY, TRUE);
1322 if (saymsg(MB_ENTERCANCEL | MB_ICONEXCLAMATION,
1323 hwnd,
1324 GetPString(IDS_WARNINGTEXT),
1325 GetPString(IDS_INIBINARYDATASKIPTEXT)) == MBID_CANCEL)
1326 WinDismissDlg(hwnd, 0);
1327 l = inidata->datalen * 4 + 1;
1328 p = xmallocz(l, pszSrcFile, __LINE__);
1329 if (p) {
1330 fixup(inidata->data, p, l, inidata->datalen);
1331 WinSetDlgItemText(hwnd, IAD_DATA, p);
1332 xfree(p, pszSrcFile, __LINE__);
1333 }
1334 }
1335 else
1336 WinSetDlgItemText(hwnd, IAD_DATA, inidata->data);
1337 }
1338 PostMsg(hwnd, UM_SETDIR, MPFROMLONG(1L), MPVOID);
1339 }
1340 else
1341 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
1342 {
1343 CHAR s[32];
1344
1345 *s = 0;
1346 WinQueryDlgItemText(hwnd, IAD_DATA, 32, s);
1347 if (*s)
1348 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), TRUE);
1349 }
1350 WinSendDlgItemMsg(hwnd, IAD_APPNAME, EM_QUERYCHANGED, MPVOID, MPVOID);
1351 WinSendDlgItemMsg(hwnd, IAD_KEYNAME, EM_QUERYCHANGED, MPVOID, MPVOID);
1352 WinSendDlgItemMsg(hwnd, IAD_DATA, EM_QUERYCHANGED, MPVOID, MPVOID);
1353 break;
1354
1355 case UM_SETDIR:
1356 if (mp1)
1357 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, IAD_DATA));
1358 else
1359 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, IAD_KEYNAME));
1360 return 0;
1361
1362 case UM_SETUP:
1363 saymsg(MB_ENTER | MB_ICONASTERISK,
1364 hwnd,
1365 GetPString(IDS_WARNINGTEXT), GetPString(IDS_INIAPPKEYEXISTSTEXT));
1366 return 0;
1367
1368 case WM_CONTROL:
1369 switch (SHORT2FROMMP(mp1)) {
1370 case EN_KILLFOCUS:
1371 inidata = INSTDATA(hwnd);
1372 if (!inidata)
1373 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
1374 else {
1375 CHAR s[CCHMAXPATH], applname[CCHMAXPATH];
1376 BOOL appchanged = FALSE, keychanged = FALSE;
1377
1378 *applname = 0;
1379 WinQueryDlgItemText(hwnd, IAD_APPNAME, CCHMAXPATH, applname);
1380 bstrip(applname);
1381 if (*applname) {
1382 *s = 0;
1383 WinQueryDlgItemText(hwnd, IAD_KEYNAME, CCHMAXPATH, s);
1384 bstrip(s);
1385 if (*s) {
1386 appchanged = (BOOL) WinSendDlgItemMsg(hwnd, IAD_APPNAME,
1387 EM_QUERYCHANGED,
1388 MPVOID, MPVOID);
1389 keychanged = (BOOL) WinSendDlgItemMsg(hwnd, IAD_KEYNAME,
1390 EM_QUERYCHANGED,
1391 MPVOID, MPVOID);
1392 if (appchanged || keychanged) {
1393
1394 ULONG size = 0L;
1395
1396 if (PrfQueryProfileSize(inidata->hini, applname, s, &size))
1397 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
1398 }
1399 *s = 0;
1400 WinQueryDlgItemText(hwnd, IAD_DATA, CCHMAXPATH, s);
1401 bstrip(s);
1402 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), (*s != 0));
1403 }
1404 else
1405 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
1406 }
1407 else
1408 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
1409 }
1410 break;
1411 }
1412 return 0;
1413
1414 case WM_COMMAND:
1415 switch (SHORT1FROMMP(mp1)) {
1416 case DID_OK:
1417 {
1418 CHAR applname[CCHMAXPATH], keyname[CCHMAXPATH], data[CCHMAXPATH];
1419 INT len;
1420
1421 inidata = INSTDATA(hwnd);
1422 if (!inidata) {
1423 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
1424 break;
1425 }
1426 inidata->isbinary = WinQueryButtonCheckstate(hwnd, IAD_ISBINARY);
1427 *applname = 0;
1428 WinQueryDlgItemText(hwnd, IAD_APPNAME, CCHMAXPATH, applname);
1429 bstrip(applname);
1430 if (*applname) {
1431 *keyname = 0;
1432 WinQueryDlgItemText(hwnd, IAD_KEYNAME, CCHMAXPATH, keyname);
1433 bstrip(keyname);
1434 if (*keyname) {
1435 *data = 0;
1436 WinQueryDlgItemText(hwnd, IAD_DATA, CCHMAXPATH, data);
1437 if (*data) {
1438 if (inidata->isbinary)
1439 len = literal(data);
1440 else
1441 len = strlen(data) + 1;
1442 PrfWriteProfileData(inidata->hini, applname, keyname, data,
1443 (ULONG) len);
1444 WinSendMsg(inidata->hwndIni, UM_RESCAN,
1445 MPFROMP(applname), MPFROMP(keyname));
1446 WinDismissDlg(hwnd, 1);
1447 }
1448 }
1449 }
1450 }
1451 break;
1452
1453 case DID_CANCEL:
1454 WinDismissDlg(hwnd, 0);
1455 break;
1456
1457 case IDM_HELP:
1458 if (hwndHelp)
1459 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
1460 MPFROM2SHORT(HELP_INIADD, 0), MPFROMSHORT(HM_RESOURCEID));
1461 break;
1462 }
1463 return 0;
1464 }
1465 return WinDefDlgProc(hwnd, msg, mp1, mp2);
1466}
1467
1468static ULONG flFrameFlags = FCF_SYSMENU | FCF_SIZEBORDER | FCF_ICON |
1469 FCF_TITLEBAR | FCF_MINMAX | FCF_MENU | FCF_ACCELTABLE | FCF_NOBYTEALIGN;
1470
1471HWND StartIniEditor(HWND hwnd, CHAR * fname, INT flags)
1472{
1473 /*
1474 * create an ini editor window
1475 * bitmapped flags:
1476 * 2 = don't position window for non-desktop client
1477 * 4 = don't kill proc when closed
1478 */
1479
1480 HWND hwndFrame, hwndClient;
1481 HINI hINI;
1482 HAB useHab = (HAB) 0;
1483 CHAR *filename = NULL;
1484
1485 if (fExternalINIs || strcmp(realappname, FM3Str))
1486 hwnd = HWND_DESKTOP;
1487 if (hwnd != HWND_DESKTOP)
1488 useHab = WinQueryAnchorBlock(hwnd);
1489 if (fname && *fname) {
1490 filename = xstrdup(fname, pszSrcFile, __LINE__);
1491 if (!filename)
1492 return (HWND) 0;
1493 hINI = PrfOpenProfile(useHab, filename);
1494 if (hINI == NULLHANDLE) {
1495 xfree(filename, pszSrcFile, __LINE__);
1496 return (HWND) 0;
1497 }
1498 else
1499 CloseProfile(hINI, FALSE);
1500 }
1501
1502 if (ParentIsDesktop(hwnd, hwnd))
1503 flFrameFlags |= FCF_TASKLIST;
1504 hwndFrame = WinCreateStdWindow(hwnd,
1505 0,
1506 &flFrameFlags,
1507 WC_INIEDITOR,
1508 NullStr,
1509 fwsAnimate,
1510 FM3ModHandle, INI_FRAME, &hwndClient);
1511 if (hwndFrame) {
1512 WinSetWindowUShort(hwndFrame, QWS_ID, INI_FRAME);
1513 if (!ParentIsDesktop(hwndFrame, hwnd) && !(flags & 2)) {
1514
1515 SWP swp;
1516
1517 FillClient(hwnd, &swp, NULL, FALSE);
1518 WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
1519 SWP_SIZE | SWP_MOVE);
1520 }
1521 else if (ParentIsDesktop(hwndFrame, hwnd)) {
1522 if (!WinRestoreWindowPos(FM2Str, "INIWindowPos", hwndFrame)) {
1523
1524 ULONG fl = SWP_MOVE | SWP_SIZE;
1525 SWP swp;
1526
1527 WinQueryTaskSizePos(WinQueryAnchorBlock(hwndFrame), 0L, &swp);
1528 if (swp.fl & (SWP_MINIMIZE | SWP_HIDE))
1529 fl = swp.fl;
1530 else if (swp.fl & SWP_ACTIVATE)
1531 fl |= SWP_ACTIVATE;
1532 WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
1533 fl);
1534 }
1535 }
1536 PostMsg(hwndClient, UM_SELECT, MPVOID, MPVOID);
1537 PostMsg(hwndClient, UM_ACTION, MPVOID, MPVOID);
1538 if (!PostMsg(hwndClient, UM_LOADFILE, MPFROMP(((filename && *filename) ?
1539 filename : NULL)), MPVOID))
1540 WinSendMsg(hwndClient, UM_LOADFILE, MPFROMP(((filename && *filename) ?
1541 filename : NULL)), MPVOID);
1542 if (flags & 4)
1543 PostMsg(hwndClient, UM_INITIALSIZE, MPVOID, MPVOID);
1544 }
1545 else
1546 xfree(filename, pszSrcFile, __LINE__);
1547 return hwndFrame;
1548}
1549
1550MRESULT EXPENTRY IniLBSubProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1551{
1552 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
1553 static HWND hwndPopup = (HWND) 0;
1554
1555 switch (msg) {
1556 case WM_SETFOCUS:
1557 if (mp2)
1558 PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_FOCUSME, mp1, mp2);
1559 break;
1560
1561 case WM_MENUEND:
1562 if (hwndPopup == (HWND) mp2) {
1563 WinDestroyWindow(hwndPopup);
1564 hwndPopup = (HWND) 0;
1565 }
1566 break;
1567
1568 case WM_CONTEXTMENU:
1569 {
1570 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
1571
1572 switch (id) {
1573 case INI_APPLIST:
1574 id = INI_APPMENU;
1575 break;
1576 case INI_KEYLIST:
1577 id = INI_KEYMENU;
1578 break;
1579 default:
1580 id = 0;
1581 break;
1582 }
1583 if (id) {
1584 if (hwndPopup)
1585 WinDestroyWindow(hwndPopup);
1586 hwndPopup = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
1587 if (hwndPopup)
1588 WinPopupMenu(hwnd, WinQueryWindow(hwnd, QW_PARENT),
1589 hwndPopup, 8, 8, 0,
1590 PU_HCONSTRAIN | PU_VCONSTRAIN |
1591 PU_KEYBOARD | PU_MOUSEBUTTON1);
1592 }
1593 }
1594 break;
1595
1596 case WM_BEGINDRAG:
1597 {
1598 PDRAGINFO pDInfo;
1599 DRAGITEM DItem;
1600 DRAGIMAGE DIcon;
1601 INIDATA *inidata;
1602 HPOINTER hptrINI;
1603 USHORT id;
1604 HWND hDrop = 0;
1605
1606 id = WinQueryWindowUShort(hwnd, QWS_ID);
1607 inidata = WinQueryWindowPtr(WinQueryWindow(hwnd, QW_PARENT), QWL_USER);
1608 if (!inidata || !*inidata->ininame || !*inidata->applname ||
1609 !inidata->keyname) {
1610 DosBeep(50, 100);
1611 break;
1612 }
1613 hptrINI = WinLoadPointer(HWND_DESKTOP, FM3ModHandle, INI_FRAME);
1614 memset(&DItem, 0, sizeof(DItem));
1615 memset(&DIcon, 0, sizeof(DIcon));
1616 DIcon.cb = sizeof(DIcon);
1617 DIcon.cptl = 0;
1618 DIcon.hImage = hptrINI;
1619 DIcon.fl = DRG_ICON;
1620 DIcon.sizlStretch.cx = 32;
1621 DIcon.sizlStretch.cy = 32;
1622 DIcon.cxOffset = -16;
1623 DIcon.cyOffset = 0;
1624 DItem.hwndItem = hwnd;
1625 DItem.ulItemID = 0L;
1626 DItem.hstrType = DrgAddStrHandle(DRT_UNKNOWN);
1627 DItem.hstrRMF = DrgAddStrHandle("<DRM_FM2INIRECORD,DRF_FM2INI>");
1628 DItem.hstrContainerName = DrgAddStrHandle(inidata->ininame);
1629 DItem.hstrSourceName = DrgAddStrHandle(inidata->applname);
1630 if (id == INI_APPLIST)
1631 DItem.hstrTargetName = DrgAddStrHandle(NullStr);
1632 else
1633 DItem.hstrTargetName = DrgAddStrHandle(inidata->keyname);
1634 DItem.fsControl = 0;
1635 DItem.fsSupportedOps = DO_COPYABLE | DO_LINKABLE | DO_MOVEABLE;
1636 pDInfo = DrgAllocDraginfo(1L);
1637 DrgSetDragitem(pDInfo, &DItem, sizeof(DRAGITEM), 0L);
1638 hDrop = DrgDrag(hwnd, pDInfo, &DIcon, 1L, VK_ENDDRAG, (PVOID) NULL);
1639 if (hDrop == NULLHANDLE)
1640 FreeDragInfoData(hwnd, pDInfo);
1641 WinDestroyPointer(hptrINI);
1642 }
1643 break;
1644
1645 case DM_DRAGOVER:
1646 {
1647 PDRAGINFO pDInfo = (PDRAGINFO) mp1;
1648 PDRAGITEM pDItem;
1649
1650 if (!DrgAccessDraginfo(pDInfo)) {
1651 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
1652 "DrgAccessDraginfo");
1653 }
1654 else {
1655 pDItem = DrgQueryDragitemPtr(pDInfo,0);
1656 /* Check valid rendering mechanisms and data */
1657 if (DrgVerifyRMF(pDItem, DRM_OS2FILE, NULL)) {
1658 DrgFreeDraginfo(pDInfo);
1659 return (MRFROM2SHORT(DOR_DROP, DO_LINK)); /* OK to drop */
1660 }
1661 else if (DrgVerifyRMF(pDItem, DRM_FM2INIRECORD, DRF_FM2INI)) {
1662 if (WinQueryWindow(pDInfo->hwndSource, QW_PARENT) !=
1663 WinQueryWindow(hwnd, QW_PARENT))
1664 {
1665 DrgFreeDraginfo(pDInfo);
1666 return (MRFROM2SHORT(DOR_DROP, ((fCopyDefault) ? DO_COPY : DO_MOVE)));
1667 }
1668 }
1669 DrgFreeDraginfo(pDInfo);
1670 }
1671 }
1672 return MRFROM2SHORT(DOR_NEVERDROP, 0);
1673
1674 case DM_DRAGLEAVE:
1675
1676 break;
1677
1678 case DM_DROP:
1679 {
1680 PDRAGINFO pDInfo = (PDRAGINFO) mp1;
1681 PDRAGITEM pDItem; /* Pointer to DRAGITEM */
1682 ULONG numitems, curitem, len;
1683 USHORT action;
1684 CHAR szFrom[CCHMAXPATH + 2], szDir[CCHMAXPATH + 1],
1685 szTemp[CCHMAXPATH + 2];
1686 FILESTATUS3 fsa;
1687 INIREC inirec;
1688
1689 if (!DrgAccessDraginfo(pDInfo)) {
1690 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
1691 "DrgAccessDraginfo");
1692 return 0;
1693 }
1694 numitems = DrgQueryDragitemCount(pDInfo);
1695 for (curitem = 0; curitem < numitems; curitem++) {
1696 pDItem = DrgQueryDragitemPtr(pDInfo, curitem);
1697 if (DrgVerifyRMF(pDItem, DRM_OS2FILE, NULL)) {
1698 if (pDItem->fsControl & DC_PREPARE)
1699 DrgSendTransferMsg(pDItem->hwndItem,
1700 DM_ENDCONVERSATION,
1701 MPFROMLONG(pDItem->ulItemID),
1702 MPFROMLONG(DMFL_TARGETFAIL));
1703 else {
1704 if (FullDrgName(pDItem, szFrom, sizeof(szFrom)) &&
1705 !DosQueryPathInfo(szFrom, FIL_STANDARD, &fsa, sizeof(fsa)))
1706 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
1707 MPFROM2SHORT(IDM_COMPARE, 0), MPFROMP(szFrom));
1708 DrgSendTransferMsg(pDItem->hwndItem,
1709 DM_ENDCONVERSATION,
1710 MPFROMLONG(pDItem->ulItemID),
1711 MPFROMLONG(DMFL_TARGETFAIL));
1712 }
1713 }
1714 else if (DrgVerifyRMF(pDItem, DRM_FM2INIRECORD, DRF_FM2INI)) {
1715 *szDir = *szFrom = *szTemp = 0;
1716 len = DrgQueryStrName(pDItem->hstrContainerName, CCHMAXPATH, szDir);
1717 szDir[len] = 0;
1718 len = DrgQueryStrName(pDItem->hstrSourceName, CCHMAXPATH, szFrom);
1719 szFrom[len] = 0;
1720 len = DrgQueryStrName(pDItem->hstrTargetName, CCHMAXPATH, szTemp);
1721 szTemp[len] = 0;
1722 switch (pDInfo->usOperation) {
1723 case DO_MOVE:
1724 action = IDM_MOVE;
1725 break;
1726 case DO_COPY:
1727 action = IDM_COPY;
1728 break;
1729 default:
1730 action = IDM_INFO;
1731 break;
1732 }
1733 memset(&inirec, 0, sizeof(inirec));
1734 inirec.size = sizeof(inirec);
1735 strcpy(inirec.filename2, szDir);
1736 strcpy(inirec.app, szFrom);
1737 strcpy(inirec.key, szTemp);
1738 inirec.action = action;
1739 inirec.hwndSource = WinQueryWindow(pDInfo->hwndSource, QW_PARENT);
1740 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
1741 MPFROM2SHORT(action, 0), MPFROMP(&inirec));
1742 DrgSendTransferMsg(pDItem->hwndItem,
1743 DM_ENDCONVERSATION,
1744 MPFROMLONG(pDItem->ulItemID),
1745 MPFROMLONG(DMFL_TARGETFAIL));
1746 }
1747 } // for
1748 FreeDragInfoData(hwnd, pDInfo);
1749 }
1750 return 0;
1751
1752 case WM_DESTROY:
1753 if (hwndPopup)
1754 WinDestroyWindow(hwndPopup);
1755 hwndPopup = (HWND) 0;
1756 break;
1757 } // switch
1758 if (oldproc)
1759 return oldproc(hwnd, msg, mp1, mp2);
1760 return WinDefWindowProc(hwnd, msg, mp1, mp2);
1761}
1762
1763MRESULT EXPENTRY IniLBSubProc2(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1764{
1765 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
1766
1767 switch (msg) {
1768 case WM_SETFOCUS:
1769 if (mp2)
1770 PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_FOCUSME, mp1, mp2);
1771 break;
1772 }
1773 if (oldproc)
1774 return oldproc(hwnd, msg, mp1, mp2);
1775 return WinDefWindowProc(hwnd, msg, mp1, mp2);
1776}
1777
1778MRESULT EXPENTRY IniProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1779{
1780 INIDATA *inidata;
1781 SHORT sSel;
1782 PFNWP oldproc;
1783
1784 switch (msg) {
1785 case WM_CREATE:
1786 inidata = xmallocz(sizeof(INIDATA), pszSrcFile, __LINE__);
1787 if (!inidata) {
1788 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1789 break;
1790 }
1791 inidata->size = sizeof(INIDATA);
1792 inidata->confirm = TRUE;
1793 inidata->currid = INI_APPLIST;
1794 inidata->hwndMenu = WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1795 FID_MENU);
1796 inidata->hwndIni = hwnd;
1797 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) inidata);
1798 WinCheckMenuItem(inidata->hwndMenu, INI_CONFIRM, inidata->confirm);
1799
1800 if (!WinCreateWindow
1801 (hwnd, WC_LISTBOX, (PSZ) NULL,
1802 WS_VISIBLE | LS_HORZSCROLL | LS_NOADJUSTPOS, 0, 0, 0, 0, hwnd,
1803 HWND_TOP, INI_APPLIST, NULL, NULL)) {
1804 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
1805 }
1806 if (!WinCreateWindow
1807 (hwnd, WC_LISTBOX, (PSZ) NULL,
1808 WS_VISIBLE | LS_HORZSCROLL | LS_NOADJUSTPOS, 0, 0, 0, 0, hwnd,
1809 HWND_TOP, INI_KEYLIST, NULL, NULL)) {
1810 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
1811 }
1812 if (!WinCreateWindow
1813 (hwnd, WC_LISTBOX, (PSZ) NULL,
1814 WS_VISIBLE | LS_HORZSCROLL | LS_NOADJUSTPOS, 0, 0, 0, 0, hwnd,
1815 HWND_TOP, INI_DATALIST, NULL, NULL)) {
1816 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
1817 }
1818 if (!WinCreateWindow(hwnd, WC_STATIC, (PSZ) NULL, WS_VISIBLE | SS_TEXT |
1819 DT_CENTER | DT_VCENTER, 0, 0, 0, 0, hwnd, HWND_TOP,
1820 INI_NUMAPPS, NULL, NULL)) {
1821 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
1822 }
1823 if (!WinCreateWindow(hwnd, WC_STATIC, (PSZ) NULL, WS_VISIBLE | SS_TEXT |
1824 DT_CENTER | DT_VCENTER, 0, 0, 0, 0, hwnd, HWND_TOP,
1825 INI_NUMKEYS, NULL, NULL)) {
1826 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
1827 }
1828 if (!WinCreateWindow(hwnd, WC_STATIC, (PSZ) NULL, WS_VISIBLE | SS_TEXT |
1829 DT_CENTER | DT_VCENTER, 0, 0, 0, 0, hwnd, HWND_TOP,
1830 INI_NUMDATA, NULL, NULL)) {
1831 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
1832 }
1833 if (!WinCreateWindow(hwnd,
1834 WC_STATIC,
1835 GetPString(IDS_APPLICATIONSTITLETEXT),
1836 WS_VISIBLE | SS_TEXT |
1837 DT_CENTER | DT_VCENTER,
1838 0,
1839 0, 0, 0, hwnd, HWND_TOP, INI_APPHDR, NULL, NULL)) {
1840 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
1841 }
1842 if (!WinCreateWindow(hwnd,
1843 WC_STATIC,
1844 GetPString(IDS_KEYWORDSTITLETEXT),
1845 WS_VISIBLE | SS_TEXT |
1846 DT_CENTER | DT_VCENTER,
1847 0,
1848 0, 0, 0, hwnd, HWND_TOP, INI_KEYHDR, NULL, NULL)) {
1849 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
1850 }
1851 if (!WinCreateWindow(hwnd,
1852 WC_STATIC,
1853 GetPString(IDS_DATABYTESTITLETEXT),
1854 WS_VISIBLE | SS_TEXT |
1855 DT_CENTER | DT_VCENTER,
1856 0,
1857 0, 0, 0, hwnd, HWND_TOP, INI_DATAHDR, NULL, NULL)) {
1858 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
1859 }
1860
1861 inidata->hwndApp = WinWindowFromID(hwnd, INI_APPLIST);
1862 inidata->hwndKey = WinWindowFromID(hwnd, INI_KEYLIST);
1863 inidata->hwndData = WinWindowFromID(hwnd, INI_DATALIST);
1864
1865 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, INI_APPLIST),
1866 IniLBSubProc);
1867 WinSetWindowPtr(WinWindowFromID(hwnd, INI_APPLIST),
1868 QWL_USER, (PVOID) oldproc);
1869 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, INI_KEYLIST),
1870 IniLBSubProc);
1871 WinSetWindowPtr(WinWindowFromID(hwnd, INI_KEYLIST),
1872 QWL_USER, (PVOID) oldproc);
1873 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, INI_DATALIST),
1874 IniLBSubProc2);
1875 WinSetWindowPtr(WinWindowFromID(hwnd, INI_DATALIST),
1876 QWL_USER, (PVOID) oldproc);
1877 break;
1878
1879 case UM_FOCUSME:
1880 case WM_SETFOCUS:
1881 if (mp2) {
1882 if (hwndMain && fAutoView)
1883 PostMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
1884 inidata = INSTDATA(hwnd);
1885 if (!inidata)
1886 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
1887 else if (hwndStatus) {
1888 if (*inidata->ininame) {
1889 WinSetWindowText(hwndStatus, GetPString(IDS_INTERNALINIVIEWERTEXT));
1890 if (hwndStatus2)
1891 WinSetWindowText(hwndStatus2, inidata->ininame);
1892 }
1893 else
1894 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
1895 }
1896 }
1897 if (msg == WM_SETFOCUS)
1898 break;
1899 return 0;
1900
1901 case UM_SELECT:
1902 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, INI_APPLIST));
1903 break;
1904
1905 case UM_ACTION:
1906 SetPresParams(WinWindowFromID(hwnd, INI_APPHDR),
1907 &RGBGREY,
1908 &RGBBLACK, &RGBBLACK, GetPString(IDS_8HELVBOLDTEXT));
1909 SetPresParams(WinWindowFromID(hwnd, INI_KEYHDR),
1910 &RGBGREY,
1911 &RGBBLACK, &RGBBLACK, GetPString(IDS_8HELVBOLDTEXT));
1912 SetPresParams(WinWindowFromID(hwnd, INI_DATAHDR),
1913 &RGBGREY,
1914 &RGBBLACK, &RGBBLACK, GetPString(IDS_8HELVBOLDTEXT));
1915 SetPresParams(WinWindowFromID(hwnd, INI_NUMAPPS),
1916 &RGBGREY,
1917 &RGBBLACK, &RGBBLACK, GetPString(IDS_8HELVBOLDTEXT));
1918 SetPresParams(WinWindowFromID(hwnd, INI_NUMKEYS),
1919 &RGBGREY,
1920 &RGBBLACK, &RGBBLACK, GetPString(IDS_8HELVBOLDTEXT));
1921 SetPresParams(WinWindowFromID(hwnd, INI_NUMDATA),
1922 &RGBGREY,
1923 &RGBBLACK, &RGBBLACK, GetPString(IDS_8HELVBOLDTEXT));
1924 if (!WinSetPresParam(WinWindowFromID(hwnd, INI_DATALIST),
1925 PP_FONTNAMESIZE,
1926 (ULONG) strlen(GetPString(IDS_5SYSTEMVIOTEXT)) + 1,
1927 (PVOID) GetPString(IDS_5SYSTEMVIOTEXT)))
1928 WinSetPresParam(WinWindowFromID(hwnd, INI_DATALIST),
1929 PP_FONTNAMESIZE,
1930 (ULONG) strlen(GetPString(IDS_10SYSTEMMONOTEXT)) + 1,
1931 (PVOID) GetPString(IDS_10SYSTEMMONOTEXT));
1932 RestorePresParams(hwnd, "IniUtil");
1933 return 0;
1934
1935 case WM_PRESPARAMCHANGED:
1936 PresParamChanged(hwnd, "IniUtil", mp1, mp2);
1937 break;
1938
1939 case UM_RESCAN:
1940 inidata = INSTDATA(hwnd);
1941 if (!inidata)
1942 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
1943 else if (mp1) {
1944 SHORT sSelect;
1945 BOOL inprofile;
1946 ULONG size;
1947 SHORT numitems = (SHORT)WinSendDlgItemMsg(hwnd,
1948 INI_APPLIST,
1949 LM_QUERYITEMCOUNT,
1950 MPVOID, MPVOID);
1951 if (!numitems) {
1952 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(INI_REFRESH, 0), MPVOID);
1953 return 0;
1954 }
1955 size = 0;
1956 if (PrfQueryProfileSize(inidata->hini,
1957 (CHAR *)mp1, NULL, (PULONG) & size) && size)
1958 inprofile = TRUE;
1959 else
1960 inprofile = FALSE;
1961 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
1962 INI_APPLIST,
1963 LM_SEARCHSTRING,
1964 MPFROM2SHORT(LSS_CASESENSITIVE,
1965 LIT_FIRST),
1966 MPFROMP((CHAR *)mp1));
1967 if (sSelect >= 0) {
1968 if (!inprofile)
1969 WinSendDlgItemMsg(hwnd,
1970 INI_APPLIST,
1971 LM_DELETEITEM, MPFROMSHORT(sSelect), MPVOID);
1972 else if (!strcmp(inidata->applname, (CHAR *)mp1))
1973 PostMsg(hwnd,
1974 WM_CONTROL,
1975 MPFROM2SHORT(INI_APPLIST, LN_SELECT),
1976 MPFROMLONG(WinWindowFromID(hwnd, INI_APPLIST)));
1977 }
1978 else if (inprofile)
1979 WinSendDlgItemMsg(hwnd,
1980 INI_APPLIST,
1981 LM_INSERTITEM,
1982 MPFROM2SHORT(LIT_SORTASCENDING, 0),
1983 MPFROMP((CHAR *)mp1));
1984 if (mp2 && inidata->applname) {
1985 if (!EnumKeyNames(WinWindowFromID(hwnd, INI_KEYLIST),
1986 inidata->hini, inidata->applname))
1987 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(INI_REFRESH, 0), MPVOID);
1988 }
1989 }
1990 return 0;
1991
1992 case UM_INITIALSIZE: /* kludge */
1993 inidata = INSTDATA(hwnd);
1994 if (!inidata)
1995 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
1996 else
1997 inidata->dontclose = TRUE;
1998 return 0;
1999
2000 case WM_SIZE:
2001 {
2002 SHORT cx = SHORT1FROMMP(mp2);
2003 SHORT cy = SHORT2FROMMP(mp2);
2004
2005 WinSetWindowPos(WinWindowFromID(hwnd, INI_APPHDR), HWND_TOP,
2006 2, cy - 22, (cx / 4) - 4, 20, SWP_MOVE | SWP_SIZE);
2007 WinSetWindowPos(WinWindowFromID(hwnd, INI_NUMAPPS), HWND_TOP,
2008 (cx / 4) + 2, cy - 22, (cx / 4) - 4, 20,
2009 SWP_MOVE | SWP_SIZE);
2010 WinSetWindowPos(WinWindowFromID(hwnd, INI_APPLIST), HWND_TOP,
2011 2, (cy / 2) + 2, (cx / 2) - 4, (cy / 2) - 28,
2012 SWP_MOVE | SWP_SIZE);
2013 WinSetWindowPos(WinWindowFromID(hwnd, INI_KEYHDR), HWND_TOP,
2014 (cx / 2) + 2, cy - 22, (cx / 4) - 4, 20,
2015 SWP_MOVE | SWP_SIZE);
2016 WinSetWindowPos(WinWindowFromID(hwnd, INI_NUMKEYS), HWND_TOP,
2017 (cx - (cx / 4)) + 2, cy - 22, (cx / 4) - 4, 20,
2018 SWP_MOVE | SWP_SIZE);
2019 WinSetWindowPos(WinWindowFromID(hwnd, INI_KEYLIST), HWND_TOP,
2020 (cx / 2) + 2, (cy / 2) + 2, (cx / 2) - 4, (cy / 2) - 28,
2021 SWP_MOVE | SWP_SIZE);
2022 WinSetWindowPos(WinWindowFromID(hwnd, INI_DATAHDR), HWND_TOP,
2023 2, (cy / 2) - 22, (cx / 2) - 4, 20,
2024 SWP_MOVE | SWP_SIZE);
2025 WinSetWindowPos(WinWindowFromID(hwnd, INI_NUMDATA), HWND_TOP,
2026 (cx / 2) + 2, (cy / 2) - 22, (cx / 2) - 4, 20,
2027 SWP_MOVE | SWP_SIZE);
2028 WinSetWindowPos(WinWindowFromID(hwnd, INI_DATALIST), HWND_TOP,
2029 2, 2, cx - 4, (cy / 2) - 28, SWP_MOVE | SWP_SIZE);
2030 }
2031 break;
2032
2033 case UM_LOADFILE:
2034 /* load initial file */
2035 inidata = INSTDATA(hwnd);
2036 if (!inidata)
2037 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2038 else {
2039 if (mp1) {
2040 strcpy(inidata->ininame, (CHAR *)mp1);
2041 inidata->hini = PrfOpenProfile(WinQueryAnchorBlock(hwnd),
2042 inidata->ininame);
2043 xfree(mp1, pszSrcFile, __LINE__);
2044 }
2045 else
2046 inidata->hini = HINI_USERPROFILE;
2047 if (inidata->hini == NULLHANDLE) {
2048 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
2049 "PrfOpenProfile failed for %s", inidata->ininame);
2050 }
2051 else {
2052 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
2053 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2054 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
2055 HWND_TOP,
2056 0, 0, 0, 0, SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER);
2057 EnumAppNames(WinWindowFromID(hwnd, INI_APPLIST), inidata->hini);
2058 return 0;
2059 }
2060 }
2061 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2062 return 0;
2063
2064 case WM_ERASEBACKGROUND:
2065 WinFillRect((HPS) mp1, (PRECTL) mp2, 0x00d0d0d0);
2066 return 0;
2067
2068 case WM_PAINT:
2069 {
2070 HPS hps;
2071 RECTL rcl;
2072
2073 hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
2074 if (hps) {
2075 WinQueryWindowRect(hwnd, &rcl);
2076 WinFillRect(hps, &rcl, CLR_PALEGRAY);
2077 WinEndPaint(hps);
2078 /*
2079 * tell status window to paint its box
2080 */
2081 PaintRecessedWindow(WinWindowFromID(hwnd, INI_APPHDR),
2082 (HPS) 0, FALSE, FALSE);
2083 PaintRecessedWindow(WinWindowFromID(hwnd, INI_KEYHDR),
2084 (HPS) 0, FALSE, FALSE);
2085 PaintRecessedWindow(WinWindowFromID(hwnd, INI_DATAHDR),
2086 (HPS) 0, FALSE, FALSE);
2087 PaintRecessedWindow(WinWindowFromID(hwnd, INI_NUMAPPS),
2088 (HPS) 0, FALSE, FALSE);
2089 PaintRecessedWindow(WinWindowFromID(hwnd, INI_NUMKEYS),
2090 (HPS) 0, FALSE, FALSE);
2091 PaintRecessedWindow(WinWindowFromID(hwnd, INI_NUMDATA),
2092 (HPS) 0, FALSE, FALSE);
2093 inidata = INSTDATA(hwnd);
2094 if (!inidata)
2095 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2096 else if (inidata->hwndCurrent)
2097 BoxWindow(inidata->hwndCurrent, (HPS) 0, CLR_RED);
2098 }
2099 }
2100 break;
2101
2102 case WM_CONTROL:
2103 switch (SHORT1FROMMP(mp1)) {
2104 case INI_KEYLIST:
2105 case INI_APPLIST:
2106 case INI_DATALIST:
2107 switch (SHORT2FROMMP(mp1)) {
2108 case LN_SETFOCUS:
2109 inidata = INSTDATA(hwnd);
2110 if (!inidata)
2111 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2112 else {
2113 if (inidata->hwndCurrent)
2114 BoxWindow(inidata->hwndCurrent, (HPS) 0, CLR_PALEGRAY);
2115 inidata->hwndCurrent = WinWindowFromID(hwnd, SHORT1FROMMP(mp1));
2116 BoxWindow(WinWindowFromID(hwnd,
2117 SHORT1FROMMP(mp1)), (HPS) 0, CLR_RED);
2118 }
2119 break;
2120
2121 case LN_ENTER:
2122 case LN_SELECT:
2123 {
2124 CHAR applname[CCHMAXPATH], keyname[CCHMAXPATH];
2125 SHORT sSelect;
2126
2127 if (SHORT1FROMMP(mp1) == INI_DATALIST)
2128 break;
2129
2130 inidata = INSTDATA(hwnd);
2131 if (!inidata || !inidata->hini) {
2132 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2133 break;
2134 }
2135 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2136 inidata->keyindex = inidata->appindex = 0;
2137 *applname = *keyname = *inidata->applname = *inidata->keyname = 0;
2138 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
2139 INI_APPLIST,
2140 LM_QUERYSELECTION,
2141 MPFROM2SHORT(LIT_FIRST, 0),
2142 MPVOID);
2143 if (sSelect < 0)
2144 break;
2145 inidata->appindex = sSelect;
2146 WinSendDlgItemMsg(hwnd,
2147 INI_APPLIST,
2148 LM_QUERYITEMTEXT,
2149 MPFROM2SHORT(sSelect, CCHMAXPATH - 1),
2150 MPFROMP(applname));
2151 if (SHORT1FROMMP(mp1) == INI_APPLIST) {
2152 if (!EnumKeyNames(WinWindowFromID(hwnd, INI_KEYLIST),
2153 inidata->hini, applname))
2154 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(INI_REFRESH, 0), MPVOID);
2155 }
2156 else {
2157 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, INI_KEYLIST,
2158 LM_QUERYSELECTION,
2159 MPFROM2SHORT(LIT_FIRST, 0),
2160 MPVOID);
2161 if (sSelect < 0)
2162 break;
2163 inidata->keyindex = sSelect;
2164 WinSendDlgItemMsg(hwnd,
2165 INI_KEYLIST,
2166 LM_QUERYITEMTEXT,
2167 MPFROM2SHORT(sSelect, CCHMAXPATH - 1),
2168 MPFROMP(keyname));
2169 if (!*keyname || !*applname)
2170 break;
2171 strcpy(inidata->keyname, keyname);
2172 strcpy(inidata->applname, applname);
2173 xfree(inidata->data, pszSrcFile, __LINE__);
2174 inidata->data = GetKeyData(WinWindowFromID(hwnd,
2175 INI_DATALIST),
2176 inidata->hini,
2177 applname, keyname, &inidata->datalen);
2178 if (!inidata->data)
2179 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(INI_REFRESH, 0), MPVOID);
2180 }
2181 }
2182 break;
2183 }
2184 break;
2185 }
2186 return 0;
2187
2188 case UM_SETDIR:
2189 {
2190 SHORT num;
2191 CHAR s[81];
2192
2193 num = (SHORT) WinSendDlgItemMsg(hwnd,
2194 INI_APPLIST,
2195 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
2196 sprintf(s, "%u", num);
2197 WinSetDlgItemText(hwnd, INI_NUMAPPS, s);
2198 num = (SHORT) WinSendDlgItemMsg(hwnd,
2199 INI_KEYLIST,
2200 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
2201 sprintf(s, "%u", num);
2202 WinSetDlgItemText(hwnd, INI_NUMKEYS, s);
2203 WinSetDlgItemText(hwnd, INI_NUMDATA, "0");
2204 WinSendDlgItemMsg(hwnd, INI_DATALIST, LM_DELETEALL, MPVOID, MPVOID);
2205 // inidata = WinQueryWindowPtr(hwnd, QWL_USER); // 09 Jan 08 SHL
2206 }
2207 return 0;
2208
2209 case UM_SETUP:
2210 inidata = INSTDATA(hwnd);
2211 if (!inidata)
2212 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2213 else {
2214 PRFPROFILE prfp;
2215 CHAR sysini[CCHMAXPATH + 81];
2216 CHAR userini[CCHMAXPATH];
2217
2218 memset(&prfp, 0, sizeof(PRFPROFILE));
2219 prfp.cchUserName = CCHMAXPATH;
2220 prfp.cchSysName = CCHMAXPATH;
2221 prfp.pszUserName = (PSZ) userini;
2222 prfp.pszSysName = (PSZ) sysini;
2223 if (PrfQueryProfile(WinQueryAnchorBlock(hwnd), &prfp)) {
2224 if (inidata->hini == HINI_SYSTEMPROFILE)
2225 strcpy(inidata->ininame, sysini);
2226 else if (inidata->hini == HINI_USERPROFILE)
2227 strcpy(inidata->ininame, userini);
2228 sprintf(sysini, GetPString(IDS_INITITLETEXT), inidata->ininame);
2229 WinSetWindowText(WinQueryWindow(hwnd, QW_PARENT), sysini);
2230 if (WinQueryWindow(hwnd, QW_PARENT) ==
2231 WinQueryActiveWindow(WinQueryWindow
2232 (WinQueryWindow(hwnd, QW_PARENT),
2233 QW_PARENT))) {
2234 if (hwndStatus)
2235 WinSetWindowText(hwndStatus,
2236 GetPString(IDS_INTERNALINIVIEWERTEXT));
2237 if (hwndStatus2)
2238 WinSetWindowText(hwndStatus2, inidata->ininame);
2239 }
2240 }
2241 else
2242 WinSetWindowText(WinQueryWindow(hwnd, QW_PARENT),
2243 GetPString(IDS_INIQUERYPRFFAILEDTEXT));
2244 return 0;
2245 }
2246
2247 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2248 return 0;
2249
2250 case WM_CHAR:
2251 if (!(SHORT1FROMMP(mp1) & KC_KEYUP)) {
2252 if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
2253 switch (SHORT2FROMMP(mp2)) {
2254 case VK_DELETE:
2255 inidata = INSTDATA(hwnd);
2256 if (!inidata)
2257 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2258 else {
2259 SHORT cmd = inidata->hwndCurrent &&
2260 WinQueryWindowUShort(inidata->hwndCurrent, QWS_ID) ==
2261 INI_APPLIST ?
2262 INI_DELETEAPP :INI_DELETEKEY;
2263 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
2264 }
2265 break;
2266 }
2267 }
2268 }
2269 break;
2270
2271 case WM_COMMAND:
2272 switch (SHORT1FROMMP(mp1)) {
2273 case IDM_FINDNEXT:
2274 case IDM_FINDFIRST:
2275 inidata = INSTDATA(hwnd);
2276 if (!inidata)
2277 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2278 else if (inidata->hwndCurrent) {
2279 STRINGINPARMS sip;
2280 static CHAR tofind[258] = "";
2281 SHORT x, z;
2282
2283 if (SHORT1FROMMP(mp1) == IDM_FINDFIRST || !*tofind) {
2284 z = LIT_FIRST;
2285 memset(&sip, 0, sizeof(sip));
2286 sip.help = GetPString(IDS_INISEARCHHELPTEXT);
2287 sip.prompt = GetPString(IDS_INISEARCHPROMPTTEXT);
2288 sip.inputlen = 257;
2289 sip.ret = tofind;
2290 sip.title = GetPString(IDS_INISEARCHTITLETEXT);
2291 if (WinDlgBox(HWND_DESKTOP,
2292 hwnd,
2293 InputDlgProc, FM3ModHandle, STR_FRAME, &sip)) {
2294 rstrip(tofind);
2295 if (!*tofind) {
2296 DosBeep(50, 100);
2297 break;
2298 }
2299 }
2300 else
2301 break;
2302 }
2303 else {
2304 z = (SHORT) WinSendMsg(inidata->hwndCurrent,
2305 LM_QUERYSELECTION,
2306 MPFROM2SHORT(LIT_CURSOR, 0), MPVOID);
2307 if (z < 0)
2308 z = LIT_FIRST;
2309 }
2310 x = (SHORT) WinSendMsg(inidata->hwndCurrent,
2311 LM_SEARCHSTRING,
2312 MPFROM2SHORT(LSS_SUBSTRING, z),
2313 MPFROMP(tofind));
2314 if (x >= 0 && x > z) {
2315 WinSendMsg(inidata->hwndCurrent,
2316 LM_SETTOPINDEX, MPFROM2SHORT(x, 0), MPVOID);
2317 WinSendMsg(inidata->hwndCurrent,
2318 LM_SELECTITEM,
2319 MPFROM2SHORT(x, 0), MPFROM2SHORT(TRUE, 0));
2320 }
2321 else
2322 DosBeep(250, 100);
2323 }
2324 break;
2325
2326 case IDM_FILTER:
2327 inidata = INSTDATA(hwnd);
2328 if (!inidata)
2329 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2330 else {
2331 SHORT numitems = (SHORT)WinSendDlgItemMsg(hwnd,
2332 INI_APPLIST,
2333 LM_QUERYITEMCOUNT,
2334 MPVOID, MPVOID);
2335 if (numitems)
2336 WinDlgBox(HWND_DESKTOP,
2337 hwnd,
2338 FilterIniProc, FM3ModHandle, IAF_FRAME, (PVOID) inidata);
2339 else
2340 DosBeep(50, 100);
2341 }
2342 break;
2343
2344 case IDM_COPY:
2345 case IDM_INFO:
2346 case IDM_MOVE:
2347 inidata = INSTDATA(hwnd);
2348 if (!inidata || !*inidata->ininame)
2349 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2350 else if (mp2) {
2351 INIREC *inirec = xmallocz(sizeof(INIREC), pszSrcFile, __LINE__);
2352 if (inirec) {
2353 *inirec = *(INIREC *) mp2;
2354 inirec->hwndDlg = hwnd;
2355 inirec->confirm = inidata->confirm;
2356 strcpy(inirec->filename1, inidata->ininame);
2357 if (_beginthread(CopyIniThread, NULL, 122880, (PVOID) inirec) == -1) {
2358 Runtime_Error(pszSrcFile, __LINE__,
2359 GetPString(IDS_COULDNTSTARTTHREADTEXT));
2360 xfree(inirec, pszSrcFile, __LINE__);
2361 }
2362 }
2363 }
2364 break;
2365
2366 case IDM_COMPARE:
2367 inidata = INSTDATA(hwnd);
2368 if (!inidata || !*inidata->ininame)
2369 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2370 else if (mp2) {
2371 INIREC *inirec = xmalloc(sizeof(INIREC), pszSrcFile, __LINE__);
2372 if (inirec) {
2373 strcpy(inirec->filename2, (CHAR *)(mp2));
2374 strcpy(inirec->filename1, inidata->ininame);
2375 inirec->hwndDlg = hwnd;
2376 if (_beginthread(CompareIniThread, NULL, 122880, (PVOID) inirec) ==
2377 -1) {
2378 Runtime_Error(pszSrcFile, __LINE__,
2379 GetPString(IDS_COULDNTSTARTTHREADTEXT));
2380 xfree(inirec, pszSrcFile, __LINE__);
2381 }
2382 }
2383 }
2384 break;
2385
2386 case INI_COPYAPP:
2387 case INI_COPYKEY:
2388 case INI_RENAMEAPP:
2389 case INI_RENAMEKEY:
2390 inidata = INSTDATA(hwnd);
2391 if (!inidata) {
2392 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2393 break;
2394 }
2395 if (!*inidata->ininame ||
2396 !*inidata->applname ||
2397 (!*inidata->keyname &&
2398 (SHORT1FROMMP(mp1) == INI_RENAMEKEY ||
2399 SHORT1FROMMP(mp1) == INI_COPYKEY)))
2400 break;
2401 {
2402 INIREC *inirec = xmallocz(sizeof(INIREC), pszSrcFile, __LINE__);
2403 if (inirec) {
2404 inirec->size = sizeof(INIREC);
2405 inirec->hwndDlg = hwnd;
2406 inirec->confirm = inidata->confirm;
2407 inirec->action = (SHORT1FROMMP(mp1) == INI_COPYAPP ||
2408 SHORT1FROMMP(mp1) == INI_COPYKEY) ?
2409 IDM_COPY : IDM_MOVE;
2410 strcpy(inirec->filename1, inidata->ininame);
2411 strcpy(inirec->filename2, inidata->ininame);
2412 if (SHORT1FROMMP(mp1) == INI_COPYKEY ||
2413 SHORT1FROMMP(mp1) == INI_RENAMEKEY)
2414 strcpy(inirec->key, inidata->keyname);
2415 strcpy(inirec->app, inidata->applname);
2416 if (!WinDlgBox(HWND_DESKTOP,
2417 hwnd,
2418 IntraIniProc,
2419 FM3ModHandle, INII_FRAME, (PVOID) inirec)) {
2420 xfree(inirec, pszSrcFile, __LINE__);
2421 break;
2422 }
2423 if (_beginthread(CopyIniThread, NULL, 122880, (PVOID) inirec) == -1) {
2424 Runtime_Error(pszSrcFile, __LINE__,
2425 GetPString(IDS_COULDNTSTARTTHREADTEXT));
2426 xfree(inirec, pszSrcFile, __LINE__);
2427 }
2428 }
2429 }
2430 break;
2431
2432 case INI_BACKUPINI:
2433 inidata = INSTDATA(hwnd);
2434 if (!inidata)
2435 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2436 else if (*inidata->ininame) {
2437 // 09 Jan 08 SHL fixme to complain
2438 CHAR filename[CCHMAXPATH], *p;
2439
2440 strcpy(filename, inidata->ininame);
2441 p = filename;
2442 while (*p) {
2443 if (*p == '/')
2444 *p = '\\';
2445 p++;
2446 }
2447 p = strrchr(filename, '\\');
2448 if (p) {
2449 p++;
2450 *p = 0;
2451 }
2452 else
2453 *filename = 0;
2454 strcat(filename, "*.INI");
2455 if (export_filename(hwnd, filename, TRUE)) {
2456
2457 PPRFPROFILE prfp;
2458
2459 prfp = xmallocz(sizeof(PRFPROFILE), pszSrcFile, __LINE__);
2460 if (prfp) {
2461 prfp->pszUserName =
2462 xstrdup(inidata->ininame, pszSrcFile, __LINE__);
2463 if (!prfp->pszUserName)
2464 xfree(prfp, pszSrcFile, __LINE__);
2465 else {
2466 prfp->cchUserName = strlen(prfp->pszUserName);
2467 prfp->pszSysName = xstrdup(filename, pszSrcFile, __LINE__);
2468 if (!prfp->pszSysName) {
2469 xfree(prfp->pszUserName, pszSrcFile, __LINE__);
2470 xfree(prfp, pszSrcFile, __LINE__);
2471 }
2472 else {
2473 prfp->cchSysName = strlen(prfp->pszSysName);
2474 if (_beginthread(BackupIniThread, NULL, 122880, (PVOID) prfp)
2475 == -1) {
2476 Runtime_Error(pszSrcFile, __LINE__,
2477 GetPString(IDS_COULDNTSTARTTHREADTEXT));
2478 xfree(prfp->pszSysName, pszSrcFile, __LINE__);
2479 xfree(prfp->pszUserName, pszSrcFile, __LINE__);
2480 xfree(prfp, pszSrcFile, __LINE__);
2481 }
2482 else
2483 DosSleep(100); //05 Aug 07 GKY 250
2484 }
2485 }
2486 }
2487 }
2488 }
2489 break;
2490
2491 case INI_CHANGEINI:
2492 inidata = INSTDATA(hwnd);
2493 if (!inidata)
2494 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2495 else {
2496 if (WinDlgBox(HWND_DESKTOP,
2497 hwnd,
2498 ChangeIniProc,
2499 FM3ModHandle, INIR_FRAME, (PVOID) inidata->ininame)) {
2500 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
2501 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2502 EnumAppNames(WinWindowFromID(hwnd, INI_APPLIST), inidata->hini);
2503 }
2504 }
2505 break;
2506
2507 case INI_SWAPINI:
2508 inidata = INSTDATA(hwnd);
2509 if (!inidata)
2510 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2511 else {
2512 if (WinDlgBox(HWND_DESKTOP,
2513 hwnd,
2514 SwapIniProc,
2515 FM3ModHandle, INIR_FRAME, (PVOID) inidata->ininame)) {
2516 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
2517 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2518 EnumAppNames(WinWindowFromID(hwnd, INI_APPLIST), inidata->hini);
2519 }
2520 }
2521 break;
2522
2523 case IDM_NEXTWINDOW:
2524 inidata = INSTDATA(hwnd);
2525 if (!inidata)
2526 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2527 else {
2528 inidata->currid++;
2529 if (inidata->currid > INI_DATALIST)
2530 inidata->currid = INI_APPLIST;
2531 }
2532 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, inidata->currid));
2533 break;
2534
2535 case IDM_PREVWINDOW:
2536 inidata = INSTDATA(hwnd);
2537 if (!inidata)
2538 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2539 else {
2540 inidata->currid--;
2541 if (inidata->currid < INI_APPLIST)
2542 inidata->currid = INI_DATALIST;
2543 }
2544 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, inidata->currid));
2545 break;
2546
2547 case INI_CONFIRM:
2548 inidata = INSTDATA(hwnd);
2549 if (!inidata)
2550 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2551 else {
2552 inidata->confirm = (inidata->confirm) ? FALSE : TRUE;
2553 WinCheckMenuItem(inidata->hwndMenu, INI_CONFIRM, inidata->confirm);
2554
2555 }
2556 break;
2557
2558 case INI_EDITENTRY:
2559 case INI_ADDENTRY:
2560 inidata = INSTDATA(hwnd);
2561 if (!inidata)
2562 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2563 else {
2564 inidata->edit = (SHORT1FROMMP(mp1) == INI_EDITENTRY);
2565 WinDlgBox(HWND_DESKTOP,
2566 hwnd, AddIniProc, FM3ModHandle, IAD_FRAME, (PVOID) inidata);
2567 }
2568 break;
2569
2570 case INI_OTHERPROFILE:
2571 inidata = INSTDATA(hwnd);
2572 if (!inidata)
2573 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2574 else {
2575 CHAR filename[CCHMAXPATH + 81], *p;
2576 FILESTATUS3 fsa;
2577 HINI hINI;
2578
2579 strcpy(filename, inidata->ininame);
2580 p = filename;
2581 while (*p) {
2582 if (*p == '/')
2583 *p = '\\';
2584 p++;
2585 }
2586 p = strrchr(filename, '\\');
2587 if (p) {
2588 p++;
2589 *p = 0;
2590 }
2591 else
2592 *filename = 0;
2593 strcat(filename, "*.INI");
2594 if (insert_filename(hwnd,
2595 filename,
2596 TRUE,
2597 TRUE) &&
2598 *filename &&
2599 !DosQueryPathInfo(filename, FIL_STANDARD, &fsa, sizeof(fsa))) {
2600 hINI = PrfOpenProfile(WinQueryAnchorBlock(hwnd), filename);
2601 if (hINI == NULLHANDLE) {
2602 Win_Error(hwnd, hwnd, __FILE__, __LINE__,
2603 GetPString(IDS_INICANTOPENINITEXT), filename);
2604 }
2605 else {
2606 if (*inidata->ininame) {
2607 if (inidata->hini)
2608 CloseProfile(inidata->hini, FALSE);
2609 *inidata->ininame = 0;
2610 }
2611 inidata->hini = hINI;
2612 strcpy(inidata->ininame, filename);
2613 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
2614 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2615 EnumAppNames(WinWindowFromID(hwnd, INI_APPLIST), inidata->hini);
2616 }
2617 }
2618 }
2619 break;
2620
2621 case INI_USERPROFILE:
2622 inidata = INSTDATA(hwnd);
2623 if (!inidata)
2624 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2625 else {
2626 if (inidata->hini && *inidata->ininame)
2627 CloseProfile(inidata->hini, FALSE);
2628 *inidata->ininame = 0;
2629 inidata->hini = HINI_USERPROFILE;
2630 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
2631 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2632 EnumAppNames(WinWindowFromID(hwnd, INI_APPLIST), inidata->hini);
2633 }
2634 break;
2635
2636 case INI_SYSTEMPROFILE:
2637 inidata = INSTDATA(hwnd);
2638 if (!inidata)
2639 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2640 else {
2641 if (inidata->hini && *inidata->ininame)
2642 CloseProfile(inidata->hini, FALSE);
2643 *inidata->ininame = 0;
2644 inidata->hini = HINI_SYSTEMPROFILE;
2645 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
2646 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2647 EnumAppNames(WinWindowFromID(hwnd, INI_APPLIST), inidata->hini);
2648 }
2649 break;
2650
2651 case INI_REFRESH:
2652 inidata = INSTDATA(hwnd);
2653 if (!inidata)
2654 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2655 else {
2656 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2657 EnumAppNames(WinWindowFromID(hwnd, INI_APPLIST), inidata->hini);
2658 }
2659 break;
2660
2661 case INI_DELETEKEY:
2662 inidata = INSTDATA(hwnd);
2663 if (!inidata)
2664 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2665 else if (*inidata->applname && *inidata->keyname) {
2666
2667 SHORT keyindex = inidata->keyindex;
2668
2669 if (inidata->confirm && saymsg(MB_YESNO,
2670 hwnd,
2671 GetPString(IDS_CONFIRMTEXT),
2672 GetPString(IDS_INIDELETEKEYTEXT),
2673 inidata->keyname) == MBID_NO)
2674 break;
2675 PrfWriteProfileData(inidata->hini,
2676 inidata->applname, inidata->keyname, NULL, 0L);
2677 *inidata->keyname = 0;
2678 WinSendDlgItemMsg(hwnd,
2679 INI_KEYLIST,
2680 LM_DELETEITEM, MPFROM2SHORT(keyindex, 0), MPVOID);
2681 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2682 sSel = (SHORT) WinSendDlgItemMsg(hwnd,
2683 INI_KEYLIST,
2684 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
2685 if (!sSel)
2686 WinSendMsg(hwnd, INI_DELETEAPP, MPVOID, MPVOID);
2687 else {
2688 sSel = min(keyindex, sSel - 1);
2689 WinSendDlgItemMsg(hwnd,
2690 INI_KEYLIST,
2691 LM_SELECTITEM,
2692 MPFROMSHORT(sSel), MPFROMSHORT(TRUE));
2693 }
2694 }
2695 break;
2696
2697 case INI_DELETEAPP:
2698 inidata = INSTDATA(hwnd);
2699 if (!inidata)
2700 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2701 // 09 Jan 08 SHL fixme to complain?
2702 else if (*inidata->applname) {
2703
2704 SHORT appindex = inidata->appindex;
2705
2706 if (inidata->confirm && saymsg(MB_YESNO,
2707 hwnd,
2708 GetPString(IDS_CONFIRMTEXT),
2709 GetPString(IDS_INIDELETEAPPTEXT),
2710 inidata->applname) == MBID_NO)
2711 break;
2712 PrfWriteProfileData(inidata->hini, inidata->applname, NULL, NULL, 0L);
2713 *inidata->applname = *inidata->keyname = 0;
2714 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2715 WinSendDlgItemMsg(hwnd, INI_KEYLIST, LM_DELETEALL, MPVOID, MPVOID);
2716 WinSendDlgItemMsg(hwnd,
2717 INI_APPLIST,
2718 LM_DELETEITEM, MPFROM2SHORT(appindex, 0), MPVOID);
2719 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2720 sSel = (SHORT) WinSendDlgItemMsg(hwnd,
2721 INI_APPLIST,
2722 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
2723 if (sSel) {
2724 sSel = min(appindex, sSel - 1);
2725 WinSendDlgItemMsg(hwnd,
2726 INI_APPLIST,
2727 LM_SELECTITEM,
2728 MPFROMSHORT(sSel), MPFROMSHORT(TRUE));
2729 }
2730 }
2731 break;
2732
2733 case DID_OK:
2734 case DID_CANCEL:
2735 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2736 break;
2737
2738 case IDM_HELP:
2739 if (hwndHelp)
2740 WinSendMsg(hwndHelp,
2741 HM_DISPLAY_HELP,
2742 MPFROM2SHORT(HELP_INI, 0), MPFROMSHORT(HM_RESOURCEID));
2743 break;
2744
2745 case IDM_ABOUT:
2746 saymsg(MB_ENTER | MB_ICONASTERISK,
2747 hwnd,
2748 GetPString(IDS_VIEWABOUTTITLETEXT),
2749 GetPString(IDS_INIABOUTTEXT));
2750 break;
2751 }
2752 return 0;
2753
2754 case WM_CLOSE:
2755 if (ParentIsDesktop(WinQueryWindow(hwnd, QW_PARENT), (HWND) 0)) {
2756
2757 SWP swp;
2758
2759 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
2760 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE)))
2761 WinStoreWindowPos(FM2Str,
2762 "INIWindowPos", WinQueryWindow(hwnd, QW_PARENT));
2763 // inidata = WinQueryWindowPtr(hwnd, QWL_USER); // 09 Jan 08 SHL
2764 }
2765 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
2766 return 0;
2767
2768 case WM_DESTROY:
2769 {
2770 BOOL dontclose = FALSE;
2771
2772 inidata = INSTDATA(hwnd);
2773 if (!inidata)
2774 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2775 else {
2776 dontclose = inidata->dontclose;
2777 if (inidata->hini != NULLHANDLE && *inidata->ininame)
2778 CloseProfile(inidata->hini, FALSE);
2779 xfree(inidata->data, pszSrcFile, __LINE__);
2780 if (inidata->hwndPopup)
2781 WinDestroyWindow(inidata->hwndPopup);
2782 xfree(inidata, pszSrcFile, __LINE__);
2783 }
2784 if (!dontclose &&
2785 ParentIsDesktop(hwnd, WinQueryWindow(WinQueryWindow(hwnd,
2786 QW_PARENT),
2787 QW_PARENT))) {
2788 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
2789 DosExit(EXIT_PROCESS, 1);
2790 }
2791 }
2792 break;
2793 }
2794 return WinDefWindowProc(hwnd, msg, mp1, mp2);
2795}
2796
2797#pragma alloc_text(INIS,EnumAppNames,GetKeyData,EnumKeyNames,AddIniProc,IniProc,BackupIniThread)
2798#pragma alloc_text(INIS,ChangeIniProc,SwapIniProc,IniLBSubProc,IniLBSubProc2,CopyIniThread)
2799#pragma alloc_text(INIS,IntraIniProc,FilterIniProc)
2800#pragma alloc_text(STARTUP,StartIniEditor)
Note: See TracBrowser for help on using the repository browser.