source: trunk/dll/inis.c@ 1082

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

Changes so FM2 will use TMP/TEMP directory for all temp files; Replaced save_dir2 with global variable so BldFullPathName could easily replace code that performed the same function; Added #ifdef FORTIFY to free_ function that are only used when fortified.

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