source: trunk/dll/inis.c@ 1009

Last change on this file since 1009 was 1009, checked in by Steven Levine, 17 years ago

Add xfree xstrdup Fortify support
Add MT capable Fortify scope logic

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