source: trunk/dll/arccnrs.c@ 1268

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

Added a thread to monitor completion of unarchive to send message to open viewer fix memory allocate/free issues. It appears that it fixes ticket 58

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 103.4 KB
Line 
1
2/***********************************************************************
3
4 $Id: arccnrs.c 1268 2008-10-31 03:19:47Z gyoung $
5
6 Archive containers
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001, 2008 Steven H. Levine
10
11 11 Jun 02 SHL Ensure archive name not garbage
12 22 May 03 SHL ArcObjWndProc: fix UM_RESCAN now that we understand it
13 01 Aug 04 SHL Rework lstrip/rstrip usage
14 23 May 05 SHL Use QWL_USER
15 25 May 05 SHL Rename comnam to szCommonName and fix typo
16 25 May 05 SHL Use ULONGLONG and CommaFmtULL
17 05 Jun 05 SHL Drop obsolete, localize
18 05 Jun 05 SHL Correct last sort logic
19 05 Jun 05 SHL Use QWL_USER
20 22 Jun 05 SHL ArcSort: correct typo in last sort fix
21 13 Aug 05 SHL FillArcCnr: optimize
22 08 Dec 05 SHL FillArcCnr: allow list start and end markers to be empty (i.e. tar)
23 08 Dec 05 SHL ArcCnrWndProc: suppress IDM_EXTRACT if no simple extract (i.e. tar)
24 30 Dec 05 SHL ArcCnrWndProc: correct date/time column display setup
25 29 May 06 SHL Comments
26 14 Jul 06 SHL Use Runtime_Error
27 26 Jul 06 SHL Correct SelectAll usage
28 29 Jul 06 SHL Use xfgets_bstripcr
29 31 Jul 06 SHL Lower priority for archives with more than 1000 entries
30 02 Aug 06 SHL Add logic to stop processing large archives
31 23 Aug 06 SHL Integrate John Small's switch list title logic
32 03 Nov 06 SHL Renames
33 14 Mar 07 SHL ArcObjWndProc/UM_ENTER: delay before starting viewer
34 30 Mar 07 GKY Remove GetPString for window class names
35 06 Apr 07 GKY Work around PM DragInfo and DrgFreeISH limit
36 06 Apr 07 GKY Add some error checking in drag/drop
37 20 Apr 07 SHL Sync with NumItemsToUnhilite mods
38 21 Apr 07 GKY Find FM2Utils by path or utils directory
39 12 May 07 SHL Use dcd->ulItemsToUnHilite; sync with UnHilite arg mods
40 10 Jun 07 GKY Add CheckPmDrgLimit including IsFm2Window as part of work around PM drag limit
41 16 Jun 07 SHL Use DosQueryAppType not DosQAppType
42 02 Aug 07 SHL Sync with ARCITEM mods
43 06 Aug 07 SHL Use BldFullPathName and BldQuotedFileName
44 06 Aug 07 SHL Move BldQuotedFileName and BldQuotedFullPathNamehere
45 to be near primary caller
46 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
47 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
48 26 Aug 07 GKY DosSleep(1) in loops changed to (0)
49 22 Nov 07 GKY Use CopyPresParams to fix presparam inconsistencies in menus
50 30 Dec 07 GKY Use TestCDates for sort by date
51 10 Jan 08 SHL Sync with CfgDlgProc mods
52 10 Feb 08 GKY Implement bubble help for bitmap menu items
53 15 Feb 08 SHL Sync with settings menu rework
54 29 Feb 08 GKY Use xfree where appropriate
55 14 Jul 08 JBS Ticket 126: Add support for WPS open default & open settings in arccnrs
56 16 Jul 08 GKY Fix trap on viewing multiple files from an archive (misplaced free)
57 16 Jul 08 GKY Use TMP directory for temp files if present. Use MakeTempName
58 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory
59 25 Aug 08 GKY Check TMP directory space warn if lee than 5 MiB prevent archiver from opening if
60 less than 10 KiB (It hangs and can't be closed)
61
62***********************************************************************/
63
64#include <stdlib.h> // free..
65#include <string.h>
66#include <ctype.h>
67#include <direct.h> // rmdir
68#include <share.h> // SH_DENYWR
69#include <limits.h> // ULONG_MAX
70#include <process.h> // _beginthread
71
72#if 0
73#include <malloc.h> // _heapchk
74#endif
75
76#define INCL_DOS
77#define INCL_DOSERRORS
78#define INCL_WIN
79#define INCL_LONGLONG
80
81#include "fm3dll.h"
82#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
83#include "arccnrs.h"
84#include "makelist.h" // Typedef
85#include "colors.h" // Typedef
86#include "mainwnd2.h" // Data declaration(s)
87#include "grep.h" // Data declaration(s)
88#include "dircnrs.h" // Data declaration(s)
89#include "info.h" // Data declaration(s)
90#include "init.h" // Data declaration(s)
91#include "fm3dlg.h"
92#include "fm3str.h"
93#include "mle.h"
94#include "pathutil.h" // BldFullPathName
95#include "filldir.h" // EmptyCnr...
96#include "errutil.h" // Dos_Error...
97#include "strutil.h" // GetPString
98#include "notebook.h" // CfgDlgProc
99#include "worker.h" // Action, MassAction
100#include "avv.h" // ArcReviewDlgProc, rewrite_archiverbb2
101#include "chklist.h" // CenterOverWindow, CheckListProc
102#include "common.h" // CommonCreateTextChildren, CommonFrameWndProc, CommonTextPaint
103 // CommonTextButton
104#include "draglist.h" // DoFileDrag, DragOne
105#include "valid.h" // GetDesktopName, TestCDates
106#include "mainwnd.h" // GetNextWindowPos, MakeBubble, TopWindowName
107#include "objwin.h" // MakeObjWin
108#include "shadow.h" // MakeShadows
109#include "objcnr.h" // ObjCnrDlgProc
110#include "printer.h" // PrintListThread
111#include "srchpath.h" // RunFM2Util
112#include "misc.h" // Broadcast, CheckMenu, CurrentRecord, SayFilter, SaySort
113 // DrawTargetEmphasis, IsFm2Window
114#include "select.h" // SelectAll, SelectList
115#include "findrec.h" // ShowCnrRecord
116#include "walkem.h" // WalkExtractDlgProc
117#include "droplist.h" // AcceptOneDrop, CheckPmDrgLimit, DropHelp, GetOneDrop
118#include "archive.h" // ArchiveDlgProc
119#include "common.h" // CommonTextProc
120#include "presparm.h" // CopyPresParams
121#include "defview.h" // DefaultViewKeys
122#include "systemf.h" // ExecOnList
123#include "filter.h" // PickMaskDlgProc
124#include "avl.h" // SBoxDlgProc
125#include "mkdir.h" // SetDir
126#include "collect.h" // StartCollector
127#include "viewer.h" // StartMLEEditor
128#include "newview.h" // StartViewer
129#include "commafmt.h" // commafmt
130#include "copyf.h" // unlinkf
131#include "literal.h" // wildcard
132#include "wrappers.h" // xrealloc
133#include "misc.h" // AdjustCnrColVis, QuickPopup, SetSortChecks, SwitchCommand
134#include "select.h" // DeselectAll, InvertAll
135#include "strips.h" // bstrip
136#include "dirs.h" // save_dir2
137#include "fortify.h"
138
139#define ARCFLAGS_REALDIR 0x00000001
140#define ARCFLAGS_PSEUDODIR 0x00000002
141#define CON_COLS 6
142#define EXTRA_ARCRECORD_BYTES (sizeof(ARCITEM) - sizeof(MINIRECORDCORE))
143
144
145#pragma data_seg(DATA1)
146static INT DefArcSortFlags;
147
148// Data definitions
149static PSZ pszSrcFile = __FILE__;
150#pragma data_seg(GLOBAL1)
151HWND ArcCnrMenu;
152HWND ArcMenu;
153CHAR ArcTempRoot[CCHMAXPATH];
154BOOL fArcStuffVisible;
155
156#pragma data_seg(GLOBAL2)
157CHAR lastextractpath[CCHMAXPATH];
158ULONGLONG ullDATFileSpaceNeeded;
159
160typedef struct {
161
162 CHAR filename[CCHMAXPATH];
163 HWND hwndCnr;
164}
165WAITCHILD;
166
167VOID WaitChildThread(VOID * arg)
168{
169 WAITCHILD *WaitChild;
170 ULONG clPosted;
171 HAB thab;
172 CHAR *filename;
173
174 DosError(FERR_DISABLEHARDERR);
175
176# ifdef FORTIFY
177 Fortify_EnterScope();
178# endif
179
180 WaitChild = (WAITCHILD *) arg;
181 if (WaitChild) {
182 filename = xstrdup(WaitChild->filename, pszSrcFile, __LINE__);
183 thab = WinInitialize(0);
184 if (thab) {
185 IncrThreadUsage();
186 priority_normal();
187 DosWaitEventSem(hWaitChildSem, SEM_INDEFINITE_WAIT);
188 priority_bumped();
189 DosResetEventSem(hWaitChildSem, &clPosted);
190 if (IsFile(WaitChild->filename) == 1)
191 PostMsg(WaitChild->hwndCnr, UM_ENTER, MPFROMP(filename), MPVOID);
192 DecrThreadUsage();
193 WinTerminate(thab);
194 }
195 free(WaitChild);
196 } // if WaitChild
197# ifdef FORTIFY
198 Fortify_LeaveScope();
199# endif
200 _endthread();
201}
202
203static MRESULT EXPENTRY ArcErrProc(HWND hwnd, ULONG msg, MPARAM mp1,
204 MPARAM mp2)
205{
206 ARCDUMP *ad;
207 CHAR szQuotedArcName[CCHMAXPATH];
208
209 switch (msg) {
210 case WM_INITDLG:
211 if (!mp2)
212 WinDismissDlg(hwnd, 0);
213 else {
214 ad = (ARCDUMP *) mp2;
215 WinSetWindowPtr(hwnd, QWL_USER, ad);
216 if (ad->errmsg)
217 WinSetDlgItemText(hwnd, ARCERR_TEXT, ad->errmsg);
218 if (!ad->info->test)
219 WinEnableWindow(WinWindowFromID(hwnd, ARCERR_TEST), FALSE);
220 if (ad->listname) {
221 MLEsetlimit(WinWindowFromID(hwnd, ARCERR_MLE), -1L);
222 MLEsetformat(WinWindowFromID(hwnd, ARCERR_MLE), MLFIE_NOTRANS);
223 MLEsetcurpos(WinWindowFromID(hwnd, ARCERR_MLE),
224 MLEgetlen(WinWindowFromID(hwnd, ARCERR_MLE)));
225 MLEinsert(WinWindowFromID(hwnd, ARCERR_MLE),
226 GetPString(IDS_ARCHIVERREPORTTEXT));
227 MLEinsertfile(WinWindowFromID(hwnd, ARCERR_MLE), ad->listname);
228 }
229 }
230 break;
231
232 case WM_COMMAND:
233 switch (SHORT1FROMMP(mp1)) {
234 case DID_CANCEL:
235 WinDismissDlg(hwnd, 0);
236 break;
237
238 case IDM_HELP:
239 if (hwndHelp) {
240 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
241 MPFROM2SHORT(HELP_ARCERR, 0), MPFROMSHORT(HM_RESOURCEID));
242 }
243 break;
244
245 case DID_OK:
246 ad = WinQueryWindowPtr(hwnd, QWL_USER);
247 WinDlgBox(HWND_DESKTOP, hwnd, ArcReviewDlgProc, FM3ModHandle,
248 AD_FRAME, MPFROMP(ad));
249 WinDismissDlg(hwnd, 0);
250 break;
251
252 case ARCERR_VIEW:
253 ad = WinQueryWindowPtr(hwnd, QWL_USER);
254 {
255 CHAR *list[2];
256
257 list[0] = ad->arcname;
258 list[1] = NULL;
259 if (TestBinary(ad->arcname)) {
260 if (*binview)
261 ExecOnList((HWND) 0, binview, WINDOWED | SEPARATE, NULL, list,
262 NULL, pszSrcFile, __LINE__);
263 else
264 StartMLEEditor(HWND_DESKTOP, 16 + 4 + 1, ad->arcname, hwnd);
265 }
266 else {
267 if (*viewer) {
268 ExecOnList((HWND) 0, viewer, WINDOWED | SEPARATE |
269 (fViewChild ? CHILD : 0),
270 NULL, list, NULL, pszSrcFile, __LINE__);
271 }
272 else
273 StartMLEEditor(HWND_DESKTOP, 8 + 4 + 1, ad->arcname, hwnd);
274 }
275 }
276 break;
277
278 case ARCERR_TEST:
279 ad = WinQueryWindowPtr(hwnd, QWL_USER);
280 runemf2(SEPARATEKEEP | WINDOWED | MAXIMIZED,
281 hwnd, pszSrcFile, __LINE__, NULL, NULL,
282 "%s %s",
283 ad->info->test,
284 BldQuotedFileName(szQuotedArcName, ad->arcname));
285 break;
286 }
287 return 0;
288 }
289 return WinDefDlgProc(hwnd, msg, mp1, mp2);
290}
291
292static SHORT APIENTRY ArcSort(PMINIRECORDCORE pmrc1, PMINIRECORDCORE pmrc2,
293 PVOID pStorage)
294{
295 PARCITEM pai1 = (PARCITEM) pmrc1;
296 PARCITEM pai2 = (PARCITEM) pmrc2;
297 DIRCNRDATA *pdcd = (DIRCNRDATA *) pStorage;
298 SHORT ret = 0;
299 CHAR *pext, *ppext;
300 INT sortFlags;
301
302 if (!pdcd) {
303 HWND hwndCnr = pai1->hwndCnr;
304
305 pdcd = WinQueryWindowPtr(hwndCnr, QWL_USER);
306 if (!pdcd) {
307 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
308 return ret;
309 }
310 }
311
312 sortFlags = pdcd->sortFlags; // Optimize
313
314 if (sortFlags) {
315 switch (sortFlags & (~SORT_REVERSE)) {
316 case SORT_FIRSTEXTENSION:
317 pext = strchr(pai1->pszFileName, '.');
318 ppext = strchr(pai2->pszFileName, '.');
319 if (!pext)
320 pext = NullStr;
321 if (!ppext)
322 ppext = NullStr;
323 ret = stricmp(pext, ppext);
324 break;
325
326 case SORT_LASTEXTENSION:
327 pext = strrchr(pai1->pszFileName, '.');
328 ppext = strrchr(pai2->pszFileName, '.');
329 if (!pext)
330 pext = NullStr;
331 if (!ppext)
332 ppext = NullStr;
333 ret = stricmp(pext, ppext);
334 break;
335
336 case SORT_LWDATE:
337 ret = TestCDates(&pai1->date, &pai1->time,
338 &pai2->date, &pai2->time);
339 /*(pai1->date.year < pai2->date.year) ? 1 :
340 (pai1->date.year > pai2->date.year) ? -1 :
341 (pai1->date.month < pai2->date.month) ? 1 :
342 (pai1->date.month > pai2->date.month) ? -1 :
343 (pai1->date.day < pai2->date.day) ? 1 :
344 (pai1->date.day > pai2->date.day) ? -1 :
345 (pai1->time.hours < pai2->time.hours) ? 1 :
346 (pai1->time.hours > pai2->time.hours) ? -1 :
347 (pai1->time.minutes < pai2->time.minutes) ? 1 :
348 (pai1->time.minutes > pai2->time.minutes) ? -1 :
349 (pai1->time.seconds < pai2->time.seconds) ? 1 :
350 (pai1->time.seconds > pai2->time.seconds) ? -1 : 0;*/
351 break;
352
353 case SORT_SIZE:
354 ret =
355 (pai1->cbFile < pai2->cbFile) ? 1 : (pai1->cbFile ==
356 pai2->cbFile) ? 0 : -1;
357 if (!ret)
358 ret =
359 (pai1->cbComp < pai2->cbComp) ? 1 : (pai1->cbComp ==
360 pai2->cbComp) ? 0 : -1;
361 break;
362
363 case SORT_EASIZE:
364 ret =
365 (pai1->cbComp < pai2->cbComp) ? 1 : (pai1->cbComp ==
366 pai2->cbComp) ? 0 : -1;
367 if (!ret)
368 ret =
369 (pai1->cbFile < pai2->cbFile) ? 1 : (pai1->cbFile ==
370 pai2->cbFile) ? 0 : -1;
371 break;
372 }
373 if (!ret)
374 ret = (SHORT) stricmp(pai1->pszFileName, pai2->pszFileName);
375 if (ret && (sortFlags & SORT_REVERSE))
376 ret = ret > 0 ? -1 : 1;
377 return ret;
378 }
379 return (SHORT) stricmp(pai1->pszFileName, pai2->pszFileName);
380}
381
382static INT APIENTRY ArcFilter(PMINIRECORDCORE rmini, PVOID arg)
383{
384 DIRCNRDATA *dcd = (DIRCNRDATA *) arg;
385 PARCITEM r;
386 register INT x;
387 INT ret = FALSE;
388
389 if (dcd && *dcd->mask.szMask) {
390 r = (PARCITEM) rmini;
391 if (dcd->mask.pszMasks[1]) {
392 for (x = 0; dcd->mask.pszMasks[x]; x++) {
393 if (*dcd->mask.pszMasks[x]) {
394 if (*dcd->mask.pszMasks[x] != '/') {
395 if (wildcard(r->pszFileName, dcd->mask.pszMasks[x], FALSE))
396 ret = TRUE;
397 }
398 else {
399 if (wildcard(r->pszFileName, dcd->mask.pszMasks[x] + 1, FALSE)) {
400 ret = FALSE;
401 break;
402 }
403 }
404 }
405 }
406 }
407 else {
408 if (wildcard(r->pszFileName, dcd->mask.szMask, FALSE))
409 ret = TRUE;
410 }
411 }
412 else
413 ret = TRUE;
414 return ret;
415}
416
417static MRESULT EXPENTRY ArcFrameWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
418 MPARAM mp2)
419{
420 return CommonFrameWndProc(ARC_CNR, hwnd, msg, mp1, mp2);
421}
422
423static BOOL IsArcThere(HWND hwnd, CHAR * arcname)
424{
425 if (arcname) {
426 if (IsFile(arcname) != 1) {
427 saymsg(MB_CANCEL, hwnd,
428 GetPString(IDS_SAYWHATTEXT),
429 GetPString(IDS_ARCNOTTHERETEXT), arcname);
430 return FALSE;
431 }
432 return TRUE;
433 }
434 return FALSE;
435}
436
437/**
438 * Free storage associated with archive container item
439 * Caller is responsible for correcting pointers
440 */
441
442static VOID FreeArcItemData(PARCITEM pai)
443{
444 // DbgMsg(pszSrcFile, __LINE__, "FreeArcItemData %p", pai);
445 PSZ psz;
446
447 if (pai->pszFileName && pai->pszFileName != NullStr) {
448 psz = pai->pszFileName;
449 pai->pszFileName = NULL; // 08 Jul 08 SHL was NulStr
450 free(psz);
451 }
452}
453
454/**
455 * Remove item(s) from archive container and free associated storage if requested
456 * @param paiFirst points to first item to remove or NULL to remove all
457 * @param usCnt is remove count or 0 to remove all
458 */
459
460static VOID RemoveArcItems(HWND hwnd, PARCITEM paiFirst, USHORT usCnt, USHORT usFlags)
461{
462 INT remaining = usCnt;
463 PARCITEM pai;
464
465 if ((usCnt && !paiFirst) || (!usCnt && paiFirst))
466 Runtime_Error(pszSrcFile, __LINE__, "paiFirst %p usCnt %u mismatch", paiFirst, usCnt);
467 else {
468 // Free our buffers if free requested
469 if (usFlags & CMA_FREE) {
470 if (paiFirst)
471 pai = paiFirst;
472 else {
473 pai = (PARCITEM)WinSendMsg(hwnd, CM_QUERYRECORD, MPVOID,
474 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
475 if ((INT)pai == -1) {
476 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_QUERYRECORD");
477 remaining = -1;
478 pai = NULL;
479 }
480 }
481 while (pai) {
482 FreeArcItemData(pai);
483 pai = (PARCITEM)pai->rc.preccNextRecord;
484 if (remaining && --remaining == 0)
485 break;
486 }
487 }
488 }
489
490 // DbgMsg(pszSrcFile, __LINE__, "RemoveArcItems %p %u %s", pai, usCnt, pai->pszFileName);
491
492 if (remaining != - 1) {
493 remaining = (INT)WinSendMsg(hwnd, CM_REMOVERECORD, MPFROMP(&paiFirst), MPFROM2SHORT(usCnt, usFlags));
494 if (remaining == -1) {
495 // Win_Error2(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,IDS_CMREMOVEERRTEXT);
496 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_REMOVERECORD hwnd %x pai %p cnt %u", hwnd, paiFirst, usCnt);
497 }
498 }
499}
500
501/**
502 * Empty all records from an archive container and
503 * free associated storage and free up field infos
504 */
505
506static VOID EmptyArcCnr(HWND hwnd)
507{
508#if 0 // fixme to be gone or to be configurable
509 {
510 int state = _heapchk();
511 if (state != _HEAPOK)
512 Runtime_Error(pszSrcFile, __LINE__, "heap corrupted %d", state);
513 else
514 DbgMsg(pszSrcFile, __LINE__, "_memavl %u", _memavl());
515 }
516#endif
517
518 // Remove all ARCITEM records
519 RemoveArcItems(hwnd, NULL, 0, CMA_FREE);
520
521 // Use common code to remove rest
522 EmptyCnr(hwnd);
523}
524
525//== FillArcCnr() generate archive content list and fill container window ==
526
527static INT FillArcCnr(HWND hwndCnr, CHAR * arcname, ARC_TYPE ** arcinfo,
528 ULONGLONG * pullTotalBytes, volatile PCHAR pStopFlag)
529{
530 FILE *fp;
531 HFILE oldstdout;
532 HFILE newstdout;
533 CHAR s[CCHMAXPATH * 2], lonename[CCHMAXPATH + 2],
534 *nsize, *osize, *fdate, *fname, *p, *pp, *arctemp;
535 BOOL gotstart;
536 BOOL gotend;
537 BOOL wasquote;
538 BOOL nomove = FALSE; // fixme to be gone?
539 INT highest = 0, x, counter = 0, numarcfiles = 0;
540 PARCITEM lastpai;
541 ARC_TYPE *info;
542 ARC_TYPE *tinfo;
543 ULONG apptype;
544 APIRET rc;
545
546 if (!arcname || !arcinfo)
547 return 0;
548
549 info = *arcinfo;
550 if (!info)
551 info = find_type(arcname, NULL);
552 arctemp = xmallocz(CCHMAXPATH, pszSrcFile, __LINE__);
553 if (CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) == 1)
554 saymsg(MB_OK,
555 HWND_DESKTOP,
556 NullStr,
557 GetPString(IDS_ARCTMPDRIVESPACELIMITED),
558 ArcTempRoot);
559 MakeTempName(arctemp, ArcTempRoot, 2);
560
561
562ReTry:
563
564 tinfo = NULL;
565 numarcfiles = counter = highest = 0;
566 gotstart = gotend = FALSE;
567 lastpai = NULL;
568 *pullTotalBytes = 0;
569 if (!info || !info->list)
570 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
571 else {
572 RemoveArcItems(hwndCnr, NULL, 0, CMA_FREE | CMA_INVALIDATE | CMA_ERASE);
573 *arcinfo = info;
574 highest = info->osizepos;
575 if (info->nsizepos > highest)
576 highest = info->nsizepos;
577 if (info->fdpos > highest)
578 highest = info->fdpos;
579 if (info->fnpos > highest)
580 highest = info->fnpos;
581 if (highest > 50) {
582 saymsg(MB_ENTER | MB_ICONEXCLAMATION, HWND_DESKTOP,
583 GetPString(IDS_SHAMETEXT), "%s", GetPString(IDS_BUNGEDUPTEXT));
584 }
585 if (info->fnpos == -1)
586 highest = 32767;
587
588 DosError(FERR_DISABLEHARDERR);
589 DosForceDelete(arctemp);
590 DosError(FERR_DISABLEHARDERR);
591
592 strcpy(s, info->list);
593 p = strchr(s, ' ');
594 if (p)
595 *p = 0;
596 DosError(FERR_DISABLEHARDERR);
597 if (!DosQueryAppType(s, &apptype) &&
598 (apptype & FAPPTYP_DOS ||
599 apptype & FAPPTYP_WINDOWSREAL ||
600 apptype & FAPPTYP_WINDOWSPROT ||
601 apptype & FAPPTYP_WINDOWSPROT31)) {
602 p = GetCmdSpec(TRUE);
603 runemf2(SEPARATE | INVISIBLE | MINIMIZED | BACKGROUND | WAIT,
604 hwndCnr, pszSrcFile, __LINE__, NULL, "DOS_BACKGROUND_EXECUTION=1",
605 "%s /C %s %s >%s",
606 p, // shell
607 info->list, // list command
608 BldQuotedFileName(s, arcname),
609 arctemp);
610 }
611 else {
612 fp = xfopen(arctemp, "w", pszSrcFile, __LINE__);
613 if (!fp) {
614 xfree(arctemp, pszSrcFile, __LINE__);
615 return 0;
616 }
617 else {
618 newstdout = -1;
619 DosError(FERR_DISABLEHARDERR);
620 rc = DosDupHandle(fileno(stdout), &newstdout);
621 if (rc) {
622 Dos_Error(MB_CANCEL, rc, hwndCnr, pszSrcFile, __LINE__,
623 "DosDupHandle");
624 xfree(arctemp, pszSrcFile, __LINE__);
625 return 0;
626 }
627 else {
628 oldstdout = fileno(stdout);
629 DosError(FERR_DISABLEHARDERR);
630 rc = DosDupHandle(fileno(fp), &oldstdout);
631 if (rc) {
632 Dos_Error(MB_CANCEL, rc, hwndCnr, pszSrcFile, __LINE__,
633 "DosDupHandle");
634 xfree(arctemp, pszSrcFile, __LINE__);
635 return 0;
636 }
637 else {
638 runemf2(SEPARATE | INVISIBLE | MINIMIZED | BACKGROUND | WAIT,
639 hwndCnr, pszSrcFile, __LINE__, NULL, NULL,
640 "%s %s",
641 info->list,
642 BldQuotedFileName(s, arcname));
643 oldstdout = fileno(stdout);
644 DosError(FERR_DISABLEHARDERR);
645 DosDupHandle(newstdout, &oldstdout);
646 DosClose(newstdout);
647 fclose(fp);
648 }
649 }
650 }
651 }
652
653 DosError(FERR_DISABLEHARDERR);
654 fp = _fsopen(arctemp, "r", SH_DENYWR);
655
656 if (fp) {
657 gotstart = !info->startlist || !*info->startlist; // If list has no start marker
658
659 while (!feof(fp) && !gotend && !*pStopFlag) {
660 if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__))
661 break;
662 if (!gotstart) {
663 if (!strcmp(s, info->startlist))
664 gotstart = TRUE;
665 }
666 else if (info->endlist && !strcmp(s, info->endlist))
667 gotend = TRUE;
668 else {
669 /* add to container */
670 fname = NULL;
671 bstrip(s);
672 if (info->nameisfirst) {
673 strncpy(lonename, s, CCHMAXPATH + 2);
674 lonename[CCHMAXPATH + 1] = 0;
675 fname = lonename;
676 if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__))
677 break;
678 if (*fname == '\"') {
679 memmove(fname, fname + 1, strlen(fname) + 1);
680 p = strchr(fname, '\"');
681 if (p)
682 *p = 0;
683 }
684 }
685 nsize = NULL;
686 osize = fdate = NullStr;
687 p = s;
688 for (x = 0; x <= highest; x++) {
689 pp = p;
690 while (*pp && (*pp == ' ' || *pp == '\t')) /* skip leading */
691 pp++;
692 if (!*pp)
693 break;
694 wasquote = FALSE;
695 p = pp;
696 while (*p && (wasquote ||
697 ((x != info->fnpos || !info->nameislast) ?
698 (*p != ' ' && *p != '\t') : TRUE))) {
699 if (*p == '\"') {
700 if (!wasquote) {
701 wasquote = TRUE;
702 memmove(p, p + 1, strlen(p));
703 while (*p == ' ' || *p == '\t')
704 p++;
705 }
706 else {
707 memmove(p, p + 1, strlen(p));
708 break;
709 }
710 }
711 else if (*p)
712 p++;
713 }
714 if (*p) {
715 *p = 0;
716 p++;
717 }
718 if (x == info->nsizepos)
719 nsize = pp;
720 else if (x == info->osizepos)
721 osize = pp;
722 else if (x == info->fdpos) {
723 fdate = pp;
724 if (info->fdflds > 1 && info->fdflds < 24) {
725 INT y;
726
727 if (*p) {
728 p--;
729 *p = ' ';
730 for (y = 0; y < info->fdflds - 1; y++) {
731 while (*p && (*p == ' ' || *p == '\t'))
732 p++;
733 while (*p && (*p != ' ' && *p != '\t'))
734 p++;
735 x++;
736 }
737 if (*p) {
738 *p = 0;
739 p++;
740 }
741 }
742 }
743 }
744 else if (x == info->fnpos) {
745 fname = pp;
746 if (pp && *pp == '*' && !*(pp + 1)) /* workaround for LH.EXE */
747 fname = NULL;
748 if (info->nameislast)
749 break;
750 }
751 else if ((!p || !*p) && info->fnpos == -1) {
752 fname = pp;
753 break;
754 }
755 }
756 if (info->nameisnext) {
757 if (!xfgets_bstripcr
758 (lonename, sizeof(lonename), fp, pszSrcFile, __LINE__))
759 break;
760 fname = lonename;
761 }
762 // fixme to complain?
763 if (fname && *fname) {
764
765 RECORDINSERT ri;
766 PARCITEM pai;
767
768 pai = WinSendMsg(hwndCnr,
769 CM_ALLOCRECORD,
770 MPFROMLONG(EXTRA_ARCRECORD_BYTES),
771 MPFROMLONG(1L));
772 if (!pai) {
773 Runtime_Error(pszSrcFile, __LINE__, "CM_ALLOCRECORD");
774 break;
775 }
776 else {
777 memset(pai, 0, sizeof(ARCITEM));
778 pai->hwndCnr = hwndCnr;
779 if (*fname == '*') {
780 fname++;
781 pai->flags = ARCFLAGS_REALDIR;
782 }
783 if (fname[strlen(fname) - 1] == '\\' ||
784 fname[strlen(fname) - 1] == '/')
785 pai->flags = ARCFLAGS_REALDIR;
786 pai->pszFileName = xstrdup(fname,pszSrcFile, __LINE__);
787 pai->pszDisplayName = pai->pszFileName;
788 pai->rc.pszIcon = pai->pszDisplayName;
789 if (fdate)
790 strcpy(pai->szDate, fdate);
791 // pai->pszFileName = pai->pszFileName;
792 pai->rc.pszIcon = pai->pszFileName;
793 pai->rc.hptrIcon = (pai->flags & ARCFLAGS_REALDIR) != 0 ?
794 hptrDir : hptrFile;
795 pai->pszDate = pai->szDate;
796 if (osize)
797 pai->cbFile = atol(osize);
798 if (nsize)
799 pai->cbComp = atol(nsize);
800 if (info->datetype && fdate && *fdate)
801 ArcDateTime(fdate, info->datetype, &pai->date, &pai->time);
802 memset(&ri, 0, sizeof(RECORDINSERT));
803 ri.cb = sizeof(RECORDINSERT);
804 ri.pRecordOrder = (PRECORDCORE) CMA_END;
805 ri.pRecordParent = (PRECORDCORE) NULL;
806 ri.zOrder = (USHORT) CMA_TOP;
807 ri.cRecordsInsert = 1L;
808 ri.fInvalidateRecord = FALSE;
809 if (WinSendMsg(hwndCnr,
810 CM_INSERTRECORD, MPFROMP(pai), MPFROMP(&ri))) {
811 *pullTotalBytes += pai->cbFile;
812 }
813 numarcfiles++;
814 if (!(++counter % 50)) {
815 if (!lastpai)
816 lastpai = pai;
817 WinSendMsg(hwndCnr,
818 CM_INVALIDATERECORD,
819 lastpai,
820 MPFROM2SHORT(10, CMA_ERASE | CMA_REPOSITION));
821 lastpai = pai;
822 }
823 // Avoid hogging system for large archive
824 if (numarcfiles == 100)
825 priority_idle();
826 }
827 }
828 }
829 } // while !eof
830
831 fclose(fp);
832
833 if (*pStopFlag)
834 numarcfiles = 0; // Request close
835 else if (!numarcfiles || !gotstart
836 || (!gotend && info->endlist && *info->endlist)) {
837 // Oops
838 ARCDUMP ad;
839 CHAR errstr[CCHMAXPATH + 256];
840
841 // Try for alternate archiver
842 tinfo = info;
843 do {
844 tinfo = tinfo->next;
845 if (tinfo)
846 tinfo = find_type(arcname, tinfo);
847 if (tinfo) {
848 DosError(FERR_DISABLEHARDERR);
849 DosForceDelete(arctemp);
850 info = tinfo;
851 goto ReTry;
852 }
853 } while (tinfo);
854 DosBeep(750, 50); // wake up user
855 sprintf(errstr, GetPString(IDS_ARCERRORINFOTEXT),
856 arcname,
857 !gotstart ? GetPString(IDS_NOGOTSTARTTEXT) : NullStr,
858 !numarcfiles ? GetPString(IDS_NOARCFILESFOUNDTEXT) :
859 NullStr,
860 !gotend ? GetPString(IDS_NOENDOFLISTTEXT) : NullStr);
861 memset(&ad, 0, sizeof(ARCDUMP));
862 ad.info = info;
863 strcpy(ad.listname, arctemp);
864 strcpy(ad.arcname, arcname);
865 ad.errmsg = errstr;
866 WinDlgBox(HWND_DESKTOP,
867 hwndCnr,
868 ArcErrProc, FM3ModHandle, ARCERR_FRAME, MPFROMP(&ad));
869 }
870 else if (!nomove && tinfo) {
871 /* if we got a false hit, move working hit to top */
872 tinfo = info->next;
873 info->next = arcsighead;
874 arcsighead->prev = info;
875 if (tinfo)
876 tinfo->next->prev = info->prev;
877 info->prev->next = tinfo;
878 info->prev = NULL;
879 arcsighead = info;
880 rewrite_archiverbb2(NULL); // Rewrite with warning
881 }
882 } // if opened
883
884 DosError(FERR_DISABLEHARDERR);
885 DosForceDelete(arctemp);
886 xfree(arctemp, pszSrcFile, __LINE__);
887 }
888
889 if (numarcfiles)
890 priority_normal();
891
892 return numarcfiles;
893}
894
895MRESULT EXPENTRY ArcTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
896{
897 static BOOL emphasized = FALSE;
898 static HWND hwndButtonPopup = (HWND) 0;
899 static ULONG timestamp = ULONG_MAX;
900 static USHORT lastid = 0;
901
902 switch (msg) {
903 case WM_CREATE:
904 return CommonTextProc(hwnd, msg, mp1, mp2);
905
906 case WM_COMMAND:
907 return WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
908 ARC_CNR), msg, mp1, mp2);
909
910 case UM_CONTEXTMENU:
911 case WM_CONTEXTMENU:
912 {
913 USHORT id;
914
915 id = WinQueryWindowUShort(hwnd, QWS_ID);
916 switch (id) {
917 case DIR_SELECTED:
918 case DIR_VIEW:
919 case DIR_SORT:
920 {
921 POINTL ptl = { 0, 0 };
922 SWP swp;
923 DIRCNRDATA *dcd;
924
925 if (hwndButtonPopup)
926 WinDestroyWindow(hwndButtonPopup);
927 if (id == DIR_SELECTED)
928 id = DIR_RESTORE;
929 if (id == lastid) {
930
931 ULONG check;
932
933 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &check,
934 sizeof(check));
935 if (check < timestamp + 500) {
936 lastid = 0;
937 goto MenuAbort;
938 }
939 }
940 hwndButtonPopup = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
941 if (hwndButtonPopup) {
942 WinSetWindowUShort(hwndButtonPopup, QWS_ID, id);
943 dcd = WinQueryWindowPtr(WinWindowFromID(WinQueryWindow(hwnd,
944 QW_PARENT),
945 ARC_CNR), QWL_USER);
946 if (id == DIR_SORT) {
947 if (dcd)
948 SetSortChecks(hwndButtonPopup, dcd->sortFlags);
949 WinSendMsg(hwndButtonPopup,
950 MM_DELETEITEM,
951 MPFROM2SHORT(IDM_SORTNONE, FALSE), MPVOID);
952 WinSendMsg(hwndButtonPopup,
953 MM_DELETEITEM,
954 MPFROM2SHORT(IDM_SORTNAME, FALSE), MPVOID);
955 WinSendMsg(hwndButtonPopup,
956 MM_DELETEITEM,
957 MPFROM2SHORT(IDM_SORTLADATE, FALSE), MPVOID);
958 WinSendMsg(hwndButtonPopup,
959 MM_DELETEITEM,
960 MPFROM2SHORT(IDM_SORTCRDATE, FALSE), MPVOID);
961 WinSendMsg(hwndButtonPopup,
962 MM_DELETEITEM,
963 MPFROM2SHORT(IDM_SORTDIRSFIRST, FALSE), MPVOID);
964 WinSendMsg(hwndButtonPopup,
965 MM_DELETEITEM,
966 MPFROM2SHORT(IDM_SORTDIRSLAST, FALSE), MPVOID);
967 WinSendMsg(hwndButtonPopup,
968 MM_DELETEITEM,
969 MPFROM2SHORT(IDM_SORTSUBJECT, FALSE), MPVOID);
970 WinSendMsg(hwndButtonPopup,
971 MM_SETITEMTEXT,
972 MPFROM2SHORT(IDM_SORTEASIZE, 0),
973 MPFROMP(GetPString(IDS_COMPRESSEDSIZEMENUTEXT)));
974 WinSendMsg(hwndButtonPopup,
975 MM_SETITEMTEXT,
976 MPFROM2SHORT(IDM_SORTLWDATE, 0),
977 MPFROMP(GetPString(IDS_DATEMENUTEXT)));
978 }
979 ptl.x = 0;
980 if (WinPopupMenu(HWND_OBJECT,
981 HWND_OBJECT,
982 hwndButtonPopup, -32767, -32767, 0, 0)) {
983 WinQueryWindowPos(hwndButtonPopup, &swp);
984 ptl.y = -(swp.cy + 2);
985 }
986 else {
987 WinQueryWindowPos(hwnd, &swp);
988 ptl.y = swp.cy + 2;
989 }
990 if (WinPopupMenu(hwnd,
991 hwnd,
992 hwndButtonPopup,
993 ptl.x,
994 ptl.y,
995 0,
996 PU_HCONSTRAIN | PU_VCONSTRAIN |
997 PU_KEYBOARD | PU_MOUSEBUTTON1)) {
998 CenterOverWindow(hwndButtonPopup);
999 PaintRecessedWindow(hwnd, (HPS) 0, FALSE, FALSE);
1000 }
1001 }
1002 }
1003 break;
1004 default:
1005 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1006 ARC_CNR),
1007 WM_CONTROL, MPFROM2SHORT(ARC_CNR, CN_CONTEXTMENU), MPVOID);
1008 break;
1009 }
1010 }
1011 MenuAbort:
1012 if (msg == UM_CONTEXTMENU)
1013 return 0;
1014 break;
1015
1016 case WM_MENUEND:
1017 if (hwndButtonPopup == (HWND) mp2) {
1018 lastid = WinQueryWindowUShort((HWND) mp2, QWS_ID);
1019 WinDestroyWindow(hwndButtonPopup);
1020 hwndButtonPopup = (HWND) 0;
1021 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &timestamp,
1022 sizeof(timestamp));
1023 switch (lastid) {
1024 case DIR_VIEW:
1025 case DIR_SORT:
1026 case DIR_RESTORE:
1027 case DIR_SELECTED:
1028 PaintRecessedWindow(hwnd, (HPS) 0, TRUE, FALSE);
1029 break;
1030 }
1031 }
1032 break;
1033
1034 case WM_MOUSEMOVE:
1035 {
1036 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
1037 char *s = NULL;
1038
1039 if (fOtherHelp) {
1040 if ((!hwndBubble ||
1041 WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd) &&
1042 !WinQueryCapture(HWND_DESKTOP)) {
1043 switch (id) {
1044 case DIR_TOTALS:
1045 s = GetPString(IDS_ARCCNRTOTALSHELPTEXT);
1046 break;
1047 case DIR_SELECTED:
1048 s = GetPString(IDS_ARCCNRSELECTEDHELPTEXT);
1049 break;
1050 case DIR_VIEW:
1051 s = GetPString(IDS_ARCCNRVIEWHELPTEXT);
1052 break;
1053 case DIR_SORT:
1054 s = GetPString(IDS_DIRCNRSORTHELP);
1055 break;
1056 case DIR_FILTER:
1057 s = GetPString(IDS_DIRCNRFILTERHELP);
1058 break;
1059 case DIR_FOLDERICON:
1060 s = GetPString(IDS_ARCCNRFOLDERHELPTEXT);
1061 break;
1062 default:
1063 break;
1064 }
1065 if (s)
1066 MakeBubble(hwnd, TRUE, s);
1067 else if (hwndBubble)
1068 WinDestroyWindow(hwndBubble);
1069 }
1070 }
1071 switch (id) {
1072 case DIR_FILTER:
1073 case DIR_SORT:
1074 case DIR_VIEW:
1075 case DIR_SELECTED:
1076 case DIR_FOLDERICON:
1077 return CommonTextButton(hwnd, msg, mp1, mp2);
1078 }
1079 }
1080 break;
1081
1082 case WM_BUTTON3UP:
1083 case WM_BUTTON1UP:
1084 case WM_BUTTON1DOWN:
1085 case WM_BUTTON3DOWN:
1086 {
1087 USHORT id;
1088
1089 id = WinQueryWindowUShort(hwnd, QWS_ID);
1090 switch (id) {
1091 case DIR_FILTER:
1092 case DIR_SORT:
1093 case DIR_VIEW:
1094 case DIR_SELECTED:
1095 case DIR_FOLDERICON:
1096 return CommonTextButton(hwnd, msg, mp1, mp2);
1097 }
1098 }
1099 break;
1100
1101 case UM_CLICKED:
1102 case UM_CLICKED3:
1103 {
1104 USHORT id, cmd = 0;
1105
1106 id = WinQueryWindowUShort(hwnd, QWS_ID);
1107 switch (id) {
1108 case DIR_FOLDERICON:
1109 switch (msg) {
1110 case WM_BUTTON3CLICK:
1111 case WM_CHORD:
1112 cmd = IDM_RESCAN;
1113 break;
1114 default:
1115 if ((SHORT2FROMMP(mp2) & KC_ALT) != 0)
1116 cmd = IDM_WINDOWDLG;
1117 else
1118 cmd = IDM_WALKDIR;
1119 break;
1120 }
1121 break;
1122 case DIR_VIEW:
1123 case DIR_SORT:
1124 case DIR_SELECTED:
1125 PostMsg(hwnd, UM_CONTEXTMENU, MPVOID, MPVOID);
1126 break;
1127 case DIR_FILTER:
1128 cmd = IDM_FILTER;
1129 break;
1130 default:
1131 break;
1132 }
1133 if (cmd)
1134 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1135 ARC_CNR),
1136 WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
1137 }
1138 return 0;
1139
1140 case WM_BEGINDRAG:
1141 case DM_DROP:
1142 case DM_DRAGOVER:
1143 case DM_DRAGLEAVE:
1144 case DM_DROPHELP:
1145 if (msg == DM_DRAGOVER) {
1146 if (!emphasized) {
1147 emphasized = TRUE;
1148 DrawTargetEmphasis(hwnd, emphasized);
1149 }
1150 }
1151 else if (msg != WM_BEGINDRAG) {
1152 if (emphasized) {
1153 emphasized = FALSE;
1154 DrawTargetEmphasis(hwnd, emphasized);
1155 }
1156 }
1157 switch (WinQueryWindowUShort(hwnd, QWS_ID)) {
1158 case DIR_FOLDERICON:
1159 switch (msg) {
1160 case DM_DRAGOVER:
1161 if (AcceptOneDrop(hwnd, mp1, mp2))
1162 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
1163 return MRFROM2SHORT(DOR_NODROP, 0); /* Drop not valid */
1164 case DM_DROPHELP:
1165 DropHelp(mp1, mp2, hwnd, GetPString(IDS_ARCCNRFOLDERDROPHELPTEXT));
1166 return 0;
1167 case DM_DROP:
1168 {
1169 char szFrom[CCHMAXPATH + 2];
1170
1171 if (emphasized) {
1172 emphasized = FALSE;
1173 DrawTargetEmphasis(hwnd, emphasized);
1174 }
1175 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
1176 WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1177 ARC_CNR),
1178 WM_COMMAND,
1179 MPFROM2SHORT(IDM_SWITCH, 0), MPFROMP(szFrom));
1180 }
1181 return 0;
1182 default:
1183 return PFNWPStatic(hwnd, msg, mp1, mp2);
1184 }
1185 default:
1186 {
1187 CNRDRAGINFO cnd;
1188 USHORT dcmd;
1189
1190 switch (msg) {
1191 case DM_DROP:
1192 dcmd = CN_DROP;
1193 break;
1194 case DM_DRAGOVER:
1195 dcmd = CN_DRAGOVER;
1196 break;
1197 case DM_DRAGLEAVE:
1198 dcmd = CN_DRAGLEAVE;
1199 break;
1200 case DM_DROPHELP:
1201 dcmd = CN_DROPHELP;
1202 break;
1203 case WM_BEGINDRAG:
1204 dcmd = CN_INITDRAG;
1205 break;
1206 }
1207 cnd.pDragInfo = (PDRAGINFO) mp1;
1208 cnd.pRecord = NULL;
1209 return WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
1210 WM_CONTROL,
1211 MPFROM2SHORT(ARC_CNR, dcmd), MPFROMP(&cnd));
1212 }
1213 }
1214 }
1215 return PFNWPStatic(hwnd, msg, mp1, mp2);
1216}
1217
1218MRESULT EXPENTRY ArcClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
1219 MPARAM mp2)
1220{
1221
1222 switch (msg) {
1223 case UM_CONTAINERHWND:
1224 return MRFROMLONG(WinWindowFromID(hwnd, ARC_CNR));
1225
1226 case UM_VIEWSMENU:
1227 // fixme to disble menu items as needed
1228 return MRFROMLONG(CheckMenu(hwnd, &ArcCnrMenu, ARCCNR_POPUP));
1229
1230 case UM_FILESMENU:
1231 // fixme to disble menu items as needed
1232 return MRFROMLONG(CheckMenu(hwnd, &ArcMenu, ARC_POPUP));
1233
1234 case MM_PORTHOLEINIT:
1235 case WM_INITMENU:
1236 case UM_INITMENU:
1237 case UM_COMMAND:
1238 case UM_LOADFILE:
1239 case UM_UPDATERECORD:
1240 case UM_UPDATERECORDLIST:
1241 case WM_COMMAND:
1242 case WM_CONTROL:
1243 case WM_CLOSE:
1244 return WinSendMsg(WinWindowFromID(hwnd, ARC_CNR), msg, mp1, mp2);
1245
1246 case WM_PSETFOCUS:
1247 case WM_SETFOCUS:
1248 if (mp2)
1249 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
1250 break;
1251
1252 case UM_FOCUSME:
1253 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ARC_CNR));
1254 break;
1255
1256 case WM_PAINT:
1257 {
1258 HPS hps;
1259 RECTL rcl;
1260
1261 hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
1262 if (hps) {
1263 WinQueryWindowRect(hwnd, &rcl);
1264 WinFillRect(hps, &rcl, CLR_PALEGRAY);
1265 CommonTextPaint(hwnd, hps);
1266 WinEndPaint(hps);
1267 }
1268 }
1269 break;
1270
1271 case UM_SIZE:
1272 case WM_SIZE:
1273 if (msg == UM_SIZE) {
1274
1275 SWP swp;
1276
1277 WinQueryWindowPos(hwnd, &swp);
1278 mp1 = MPFROM2SHORT(swp.cx, swp.cy);
1279 mp2 = MPFROM2SHORT(swp.cx, swp.cy);
1280 }
1281 {
1282 USHORT cx, cy, bx;
1283
1284 cx = SHORT1FROMMP(mp2);
1285 cy = SHORT2FROMMP(mp2);
1286 WinSetWindowPos(WinWindowFromID(hwnd, ARC_CNR), HWND_TOP,
1287 0,
1288 22, cx, cy - (24 + 22), SWP_SHOW | SWP_MOVE | SWP_SIZE);
1289 WinSetWindowPos(WinWindowFromID(hwnd, ARC_EXTRACTDIR), HWND_TOP,
1290 0, 0, cx, 22, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1291 WinSetWindowPos(WinWindowFromID(hwnd, DIR_FOLDERICON), HWND_TOP,
1292 2, cy - 22, 24, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1293 WinSetWindowPos(WinWindowFromID(hwnd, DIR_TOTALS), HWND_TOP,
1294 29,
1295 cy - 22,
1296 (cx / 3) - 2, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1297 WinSetWindowPos(WinWindowFromID(hwnd, DIR_SELECTED), HWND_TOP,
1298 29 + (cx / 3) + 2,
1299 cy - 22,
1300 (cx / 3) - 2, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1301 bx = (cx - (29 + (((cx / 3) + 2) * 2))) / 3;
1302 WinSetWindowPos(WinWindowFromID(hwnd, DIR_VIEW), HWND_TOP,
1303 29 + (((cx / 3) + 2) * 2),
1304 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1305 WinSetWindowPos(WinWindowFromID(hwnd, DIR_SORT), HWND_TOP,
1306 29 + (((cx / 3) + 2) * 2) + bx,
1307 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1308 WinSetWindowPos(WinWindowFromID(hwnd, DIR_FILTER), HWND_TOP,
1309 29 + (((cx / 3) + 2) * 2) + (bx * 2),
1310 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1311 }
1312 CommonTextPaint(hwnd, (HPS) 0);
1313 if (msg == UM_SIZE) {
1314 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP, 0, 0, 0, 0,
1315 SWP_SHOW | SWP_ZORDER | SWP_ACTIVATE);
1316 return 0;
1317 }
1318 break;
1319 }
1320 return WinDefWindowProc(hwnd, msg, mp1, mp2);
1321}
1322
1323MRESULT EXPENTRY ArcObjWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1324{
1325 DIRCNRDATA *dcd;
1326 PSZ psz;
1327 CHAR szQuotedArcName[CCHMAXPATH];
1328 CHAR szQuotedMemberName[CCHMAXPATH];
1329
1330 switch (msg) {
1331 case WM_CREATE:
1332 DbgMsg(pszSrcFile, __LINE__, "WM_CREATE mp1 %p mp2 %p", mp1, mp2); // 18 Jul 08 SHL fixme
1333 break;
1334
1335 case DM_PRINTOBJECT:
1336 case DM_DISCARDOBJECT:
1337 dcd = INSTDATA(hwnd);
1338 if (dcd) {
1339
1340 LISTINFO *li;
1341 CNRDRAGINFO cni;
1342
1343 cni.pRecord = NULL;
1344 cni.pDragInfo = (PDRAGINFO) mp1;
1345 li = DoFileDrop(dcd->hwndCnr,
1346 dcd->directory, FALSE, MPVOID, MPFROMP(&cni));
1347 CheckPmDrgLimit(cni.pDragInfo);
1348 if (li) {
1349 li->type = (msg == DM_DISCARDOBJECT) ? IDM_DELETE : IDM_PRINT;
1350 if (!li->list ||
1351 !li->list[0] || !PostMsg(hwnd, UM_ACTION, MPFROMP(li), MPVOID))
1352 FreeListInfo(li);
1353 else
1354 return MRFROMLONG(DRR_SOURCE);
1355 }
1356 }
1357 return MRFROMLONG(DRR_TARGET);
1358
1359 case DM_RENDERPREPARE:
1360 return (MRESULT) TRUE;
1361
1362 case DM_RENDER:
1363 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1364 if (dcd && dcd->info && dcd->info->extract && dcd->arcname) {
1365
1366 PDRAGTRANSFER pdt = (PDRAGTRANSFER) mp1;
1367 CHAR filename[CCHMAXPATH];
1368 ULONG len;
1369
1370 if (pdt->hwndClient && pdt->pditem && pdt->hstrSelectedRMF &&
1371 pdt->hstrRenderToName) {
1372 if (pdt->usOperation == DO_COPY || pdt->usOperation == DO_MOVE) {
1373 *filename = 0;
1374 len = DrgQueryStrName(pdt->hstrSelectedRMF, CCHMAXPATH, filename);
1375 filename[len] = 0;
1376 if (!strnicmp(filename, "OS2FILE,", 8)) {
1377 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"RMF = \"%s\"",filename);
1378 }
1379 else {
1380 *filename = 0;
1381 len =
1382 DrgQueryStrName(pdt->hstrRenderToName, CCHMAXPATH, filename);
1383 filename[len] = 0;
1384 if (len && *filename) {
1385 psz = xstrdup(filename, pszSrcFile, __LINE__);
1386 if (psz) {
1387 PostMsg(hwnd, UM_RENDER, MPFROMP(pdt), MPFROMP(psz));
1388 return (MRESULT) TRUE;
1389 }
1390 }
1391 else {
1392 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"No render-to name given.");
1393 }
1394 }
1395 }
1396 pdt->fsReply = DMFL_RENDERRETRY;
1397 }
1398 }
1399 return (MRESULT) FALSE;
1400
1401 case UM_RENDER:
1402 {
1403 PDRAGTRANSFER pdt = (PDRAGTRANSFER) mp1;
1404 USHORT usRes = DMFL_RENDERFAIL;
1405
1406 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1407 if (dcd && dcd->info && dcd->info->extract && dcd->arcname) {
1408
1409 CHAR *filename = (CHAR *) mp2, *p;
1410 ULONG len;
1411 CHAR membername[CCHMAXPATH], construct[CCHMAXPATH * 2];
1412
1413 *membername = 0;
1414 len = DrgQueryStrName(pdt->pditem->hstrSourceName,
1415 CCHMAXPATH, membername);
1416 membername[len] = 0;
1417 if (*membername && len && filename) {
1418 unlinkf("%s", filename);
1419 strcpy(construct, filename);
1420 p = strrchr(filename, '\\');
1421 if (!p)
1422 *construct = 0;
1423 else {
1424 if (p == filename || *(p - 1) == ':')
1425 p++;
1426 *p = 0;
1427 }
1428 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"%s %s %s\r[%s]",dcd->info->extract,dcd->arcname,membername,construct);
1429 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS | WAIT |
1430 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1431 dcd->hwndClient, pszSrcFile, __LINE__, construct, NULL,
1432 "%s %s %s",
1433 dcd->info->extract,
1434 BldQuotedFileName(szQuotedArcName, dcd->arcname),
1435 BldQuotedFileName(szQuotedMemberName, membername));
1436 BldFullPathName(construct, construct, membername);
1437 if (IsFile(construct) != -1) {
1438 rename(construct, filename);
1439 unlinkf("%s", construct);
1440 if (IsFile(filename) != -1)
1441 usRes = DMFL_RENDEROK;
1442 }
1443 }
1444 }
1445 xfree((CHAR *)mp2, pszSrcFile, __LINE__);
1446 PostMsg(pdt->hwndClient, DM_RENDERCOMPLETE, MPFROMP(pdt),
1447 MPFROM2SHORT(usRes, 0));
1448 }
1449 return 0;
1450
1451 case UM_SETUP:
1452# ifdef FORTIFY
1453 Fortify_EnterScope();
1454# endif
1455 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1456 if (!dcd) {
1457 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
1458 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1459 }
1460 else {
1461# ifdef FORTIFY
1462 Fortify_BecomeOwner(dcd);
1463# endif
1464 /* set unique id */
1465 WinSetWindowUShort(hwnd, QWS_ID, ARCOBJ_FRAME + (ARC_FRAME - dcd->id));
1466 dcd->hwndObject = hwnd; // pass back hwnd
1467 if (ParentIsDesktop(hwnd, dcd->hwndParent))
1468 DosSleep(100); //05 Aug 07 GKY 250 // Avoid race?
1469 }
1470 return 0;
1471
1472 case UM_RESCAN:
1473 /*
1474 * populate container
1475 */
1476 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1477 if (dcd) {
1478 if (mp1)
1479 strcpy(dcd->arcname, (CHAR *) mp1); // Update name on request
1480 dcd->ullTotalBytes = dcd->totalfiles =
1481 dcd->selectedfiles = dcd->selectedbytes = 0;
1482 WinSetDlgItemText(dcd->hwndClient, DIR_TOTALS, "0");
1483 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, "0 / 0k");
1484 dcd->totalfiles = FillArcCnr(dcd->hwndCnr,
1485 dcd->arcname,
1486 &dcd->info,
1487 &dcd->ullTotalBytes, &dcd->stopflag);
1488 if (!dcd->totalfiles)
1489 PostMsg(dcd->hwndCnr, WM_CLOSE, MPVOID, MPVOID);
1490 else {
1491 dcd->arcfilled = TRUE;
1492 if (!PostMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID))
1493 WinSendMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID);
1494 PostMsg(dcd->hwndCnr, UM_SETUP2, MPVOID, MPVOID);
1495 WinSendMsg(dcd->hwndCnr,
1496 CM_INVALIDATERECORD,
1497 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
1498 }
1499 }
1500 return 0;
1501
1502 case UM_SELECT:
1503 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1504 if (dcd) {
1505 switch (SHORT1FROMMP(mp1)) {
1506 case IDM_SELECTALL:
1507 case IDM_SELECTALLFILES:
1508 SelectAll(dcd->hwndCnr, TRUE, TRUE, NULL, NULL, TRUE);
1509 break;
1510 case IDM_DESELECTALL:
1511 case IDM_DESELECTALLFILES:
1512 DeselectAll(dcd->hwndCnr, TRUE, TRUE, NULL, NULL, TRUE);
1513 break;
1514 case IDM_DESELECTMASK:
1515 case IDM_SELECTMASK:
1516 {
1517 MASK mask;
1518 PARCITEM pci = (PARCITEM) mp2;
1519
1520 memset(&mask, 0, sizeof(MASK));
1521 mask.fNoAttribs = TRUE;
1522 mask.fNoDirs = TRUE;
1523 strcpy(mask.prompt,
1524 GetPString((SHORT1FROMMP(mp1) == IDM_SELECTMASK) ?
1525 IDS_SELECTFILTERTEXT : IDS_DESELECTFILTERTEXT));
1526 if (pci && (INT) pci != -1)
1527 strcpy(mask.szMask, pci->pszFileName);
1528 if (WinDlgBox(HWND_DESKTOP, dcd->hwndCnr, PickMaskDlgProc,
1529 FM3ModHandle, MSK_FRAME, MPFROMP(&mask))) {
1530 if (SHORT1FROMMP(mp1) == IDM_SELECTMASK)
1531 SelectAll(dcd->hwndCnr, TRUE, TRUE, mask.szMask, NULL, FALSE);
1532 else
1533 DeselectAll(dcd->hwndCnr, TRUE, TRUE, mask.szMask, NULL, FALSE);
1534 }
1535 }
1536
1537 case IDM_INVERT:
1538 InvertAll(dcd->hwndCnr);
1539 break;
1540 }
1541 }
1542 return 0;
1543
1544 case UM_ENTER:
1545 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1546 if (dcd) {
1547
1548 CHAR *s = (CHAR *) mp1, *p, *pp; // filename[CCHMAXPATH];
1549 WAITCHILD *WaitChild;
1550 APIRET rc;
1551
1552 WaitChild = xmallocz(sizeof(WAITCHILD), pszSrcFile, __LINE__);
1553 if (!WaitChild)
1554 return 0;
1555 if (s) {
1556 if (!dcd->info->extract) {
1557 Runtime_Error(pszSrcFile, __LINE__, "no extract");
1558 free(s);
1559 return 0;
1560 }
1561 runemf2(SEPARATE | ASYNCHRONOUS | WAIT |
1562 (fArcStuffVisible ? 0 : BACKGROUND),
1563 dcd->hwndClient, pszSrcFile, __LINE__, dcd->workdir, NULL,
1564 "%s %s %s",
1565 dcd->info->exwdirs ? dcd->info->exwdirs :
1566 dcd->info->extract,
1567 BldQuotedFileName(szQuotedArcName, dcd->arcname),
1568 BldQuotedFileName(szQuotedMemberName, s));
1569 if (!dcd->info->exwdirs) {
1570 p = s;
1571 p = strrchr(s, '\\');
1572 pp = strrchr(s, '/');
1573 if (p && pp)
1574 p = max(p, pp);
1575 else if (!p)
1576 p = pp;
1577 if (p)
1578 memmove(s, p + 1, strlen(p + 1));
1579 }
1580 sprintf(WaitChild->filename, "%s\\%s", dcd->workdir, s);
1581 p = WaitChild->filename;
1582 while (*p) {
1583 if (*p == '/')
1584 *p = '\\';
1585 p++;
1586 }
1587 //printf("%s %d UM_ENTER %s %x\n",__FILE__, __LINE__,WaitChild->filename, dcd->hwndCnr); fflush(stdout); // 10 Mar 07 SHL hang
1588 free(s);
1589 WaitChild->hwndCnr = dcd->hwndCnr;
1590 rc = _beginthread(WaitChildThread, NULL, 65536, WaitChild);
1591 if (rc == -1)
1592 Runtime_Error(pszSrcFile, __LINE__,
1593 GetPString(IDS_COULDNTSTARTTHREADTEXT));
1594 //if (IsFile(filename) == 1) {
1595#if 0 // 06 Oct 07 SHL fixme to be gone - set to 0 for ticket #58 testing
1596 if (fViewChild && fArcStuffVisible)
1597 DosSleep(100); // Allow unzip session to finish closing 14 Mar 07 SHL
1598#endif
1599 //DosWaitEventSem(hWaitChildSem, SEM_INDEFINITE_WAIT);
1600 //WinSendMsg(WaitChild->hwndCnr, UM_ENTER, MPFROMP(WaitChild->filename), MPVOID);
1601
1602 }
1603 }
1604 return 0;
1605
1606 case UM_COMMAND:
1607 if (mp1) {
1608 if (PostMsg(hwnd, UM_ACTION, mp1, mp2))
1609 return (MRESULT) TRUE;
1610 }
1611 return 0;
1612
1613 case UM_ACTION:
1614 DosError(FERR_DISABLEHARDERR);
1615 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1616 if (dcd) {
1617
1618 LISTINFO *li = (LISTINFO *) mp1;
1619 register INT x;
1620
1621 if (li && li->list && li->list[0]) {
1622 printf("%x/r", li->type); fflush(stdout);
1623 switch (li->type) {
1624 case IDM_ARCHIVE:
1625 case IDM_ARCHIVEM:
1626 {
1627 DIRCNRDATA ad;
1628 CHAR szBuffer[1025], *p;
1629
1630 if (!li->list[1] && !stricmp(li->list[0], dcd->arcname)) {
1631 Runtime_Error(pszSrcFile, __LINE__, "arc to self");
1632 break;
1633 }
1634 ad = *dcd;
1635 ad.namecanchange = 0;
1636 ad.fmoving = (li->type == IDM_ARCHIVEM);
1637 if (!WinDlgBox(HWND_DESKTOP, dcd->hwndClient, ArchiveDlgProc, FM3ModHandle, ARCH_FRAME, (PVOID) & ad) || !*ad.arcname || !*ad.command) /* we blew it */
1638 break;
1639 /* build the sucker */
1640 strcpy(szBuffer, ad.command);
1641 strcat(szBuffer, " ");
1642
1643 BldQuotedFileName(szBuffer + strlen(szBuffer), ad.arcname);
1644
1645 p = &szBuffer[strlen(szBuffer)]; // Remeber where archiver name ends
1646
1647 if (ad.mask.szMask) {
1648 strcat(szBuffer, " ");
1649
1650 BldQuotedFileName(szBuffer + strlen(szBuffer), ad.mask.szMask);
1651 }
1652 strcat(szBuffer, " ");
1653 x = 0;
1654
1655 // Run commands avoiding command line overflow
1656 while (li->list[x]) {
1657
1658 if (IsFile(li->list[x]))
1659 BldQuotedFileName(szBuffer + strlen(szBuffer), li->list[x]);
1660 else
1661 BldQuotedFullPathName(szBuffer + strlen(szBuffer), li->list[x], "*");
1662
1663 x++;
1664 if (!li->list[x] || strlen(szBuffer) +
1665 strlen(li->list[x]) + 5 > MaxComLineStrg) {
1666 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
1667 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1668 hwnd, pszSrcFile, __LINE__,
1669 NULL, NULL, "%s", szBuffer);
1670 *p = 0;
1671 }
1672 strcat(szBuffer, " ");
1673 } // while
1674
1675 PostMsg(dcd->hwndCnr, UM_RESCAN, MPFROMSHORT(1), MPVOID);
1676 Broadcast(WinQueryAnchorBlock(hwnd),
1677 hwndMain, UM_UPDATERECORD, MPFROMP(ad.arcname), MPVOID);
1678 Broadcast(WinQueryAnchorBlock(hwnd),
1679 hwndMain,
1680 UM_UPDATERECORDLIST, MPFROMP(li->list), MPVOID);
1681 }
1682 break;
1683
1684 case IDM_REFRESH:
1685 case IDM_DELETE:
1686 {
1687 CHAR *endofit;
1688 PSZ pszCmdLine;
1689 INT z;
1690 CHECKLIST ck;
1691 CHAR prompt[CCHMAXPATH + 257];
1692
1693 if (!dcd->info->delete)
1694 break;
1695 memset(&ck, 0, sizeof(ck));
1696 ck.size = sizeof(ck);
1697 ck.list = li->list;
1698 ck.cmd = li->type;
1699 ck.prompt = prompt;
1700 sprintf(prompt, GetPString(IDS_ARCCNRDELREFTEXT),
1701 (li->type == IDM_DELETE) ?
1702 GetPString(IDS_DELETELOWERTEXT) :
1703 GetPString(IDS_REFRESHLOWERTEXT),
1704 &"s"[li->list[1] == NULL],
1705 dcd->arcname,
1706 (li->type == IDM_DELETE) ?
1707 GetPString(IDS_DELETELOWERTEXT) :
1708 GetPString(IDS_REFRESHLOWERTEXT));
1709 if (!WinDlgBox(HWND_DESKTOP, hwnd, CheckListProc,
1710 FM3ModHandle, CHECK_FRAME, MPFROMP(&ck)))
1711 break;
1712 li->list = ck.list;
1713 if (!li->list || !li->list[0])
1714 break;
1715 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1716 if (!pszCmdLine)
1717 break;
1718 strcpy(pszCmdLine, li->type == IDM_DELETE ?
1719 dcd->info->delete :
1720 dcd->info->create);
1721 strcat(pszCmdLine, " ");
1722 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), dcd->arcname);
1723 endofit = &pszCmdLine[strlen(pszCmdLine)];
1724 z = 0;
1725 do {
1726 for (x = z; li->list[x] &&
1727 strlen(pszCmdLine) + strlen(li->list[x]) < 999; x++) {
1728 strcat(pszCmdLine, " ");
1729 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), li->list[x]);
1730 }
1731 z = x;
1732 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS | WAIT |
1733 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1734 hwnd, pszSrcFile, __LINE__, NullStr, NULL, "%s", pszCmdLine);
1735 *endofit = 0;
1736 free(pszCmdLine);
1737 } while (li->list[x]);
1738 PostMsg(dcd->hwndCnr, UM_RESCAN, MPFROMSHORT(1), MPVOID);
1739 Broadcast(WinQueryAnchorBlock(hwnd),
1740 hwndMain,
1741 UM_UPDATERECORD, MPFROMP(dcd->arcname), MPVOID);
1742 }
1743 break;
1744
1745 case IDM_PRINT:
1746 case IDM_VIRUSSCAN:
1747 case IDM_VIEW:
1748 case IDM_MCIPLAY:
1749 case IDM_VIEWARCHIVE:
1750 case IDM_VIEWTEXT:
1751 case IDM_VIEWBINARY:
1752 case IDM_EDIT:
1753 case IDM_EDITTEXT:
1754 case IDM_EDITBINARY:
1755 case IDM_EXEC:
1756 case IDM_EXTRACTWDIRS:
1757 case IDM_EXTRACT:
1758 case IDM_OPENDEFAULT:
1759 case IDM_OPENSETTINGS:
1760 {
1761 CHAR *endofit, *ptr;
1762 PSZ pszCmdLine;
1763 INT z;
1764 if ((li->type == IDM_EXTRACT && !li->info->extract) ||
1765 ((li->type == IDM_VIEW || li->type == IDM_VIEWTEXT ||
1766 li->type == IDM_VIEWBINARY || li->type == IDM_EDIT ||
1767 li->type == IDM_VIEWARCHIVE || li->type == IDM_EDITTEXT ||
1768 li->type == IDM_EDITBINARY || li->type == IDM_MCIPLAY) &&
1769 (!li->info->extract && !li->info->exwdirs)) ||
1770 (li->type != IDM_EXTRACT && li->type != IDM_EDIT &&
1771 li->type != IDM_VIEW && li->type != IDM_VIEWTEXT &&
1772 li->type != IDM_VIEWBINARY &&
1773 li->type != IDM_VIEWARCHIVE &&
1774 li->type != IDM_EDITTEXT &&
1775 li->type != IDM_EDITBINARY &&
1776 li->type != IDM_MCIPLAY && !li->info->exwdirs)) {
1777 Runtime_Error(pszSrcFile, __LINE__, "no cmd for request");
1778 break;
1779 }
1780 if (li->type == IDM_EXTRACT || li->type == IDM_EXTRACTWDIRS) {
1781
1782 CHAR fullname[CCHMAXPATH * 2];
1783 CHAR **exfiles = NULL;
1784 UINT numfiles = 0, numalloc = 0;
1785
1786 for (x = 0; li->list[x]; x++) {
1787 BldFullPathName(fullname, li->targetpath, li->list[x]);
1788 if (IsFile(fullname) != -1) {
1789 AddToList(li->list[x], &exfiles, &numfiles, &numalloc);
1790 li->list = RemoveFromList(li->list, li->list[x]);
1791 if (!li->list)
1792 break;
1793 x--;
1794 }
1795 }
1796 if (exfiles && numfiles) {
1797
1798 CHECKLIST ckl;
1799 CHAR prompt[(CCHMAXPATH * 2) + 256];
1800
1801 memset(&ckl, 0, sizeof(ckl));
1802 ckl.size = sizeof(ckl);
1803 ckl.list = exfiles;
1804 ckl.prompt = prompt;
1805 ckl.cmd = li->type;
1806 sprintf(prompt,
1807 GetPString(IDS_REPLACEWARNTEXT),
1808 &"s"[numfiles == 1],
1809 li->arcname, &"s"[numfiles != 1], li->targetpath);
1810 if (!WinDlgBox(HWND_DESKTOP, hwnd, CheckListProc,
1811 FM3ModHandle, CHECK_FRAME, MPFROMP(&ckl))) {
1812 if (ckl.list)
1813 FreeList(ckl.list);
1814 break;
1815 }
1816 else if (ckl.list)
1817 li->list = CombineLists(li->list, ckl.list);
1818 }
1819 }
1820 if (!li->list || !li->list[0])
1821 break;
1822 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1823 if (!pszCmdLine)
1824 break;
1825 strcpy(pszCmdLine,
1826 (li->type == IDM_EXTRACT ||
1827 ((li->type == IDM_VIEW ||
1828 li->type == IDM_VIEWTEXT ||
1829 li->type == IDM_VIEWBINARY ||
1830 li->type == IDM_VIEWARCHIVE ||
1831 li->type == IDM_PRINT ||
1832 li->type == IDM_EDIT ||
1833 li->type == IDM_EDITTEXT ||
1834 li->type == IDM_OPENDEFAULT ||
1835 li->type == IDM_OPENSETTINGS ||
1836 (li->type == IDM_EDITBINARY && // JBS No way for this () to be true??
1837 li->type == IDM_MCIPLAY)) &&
1838 !li->info->exwdirs)) ?
1839 li->info->extract :
1840 li->info->exwdirs);
1841 strcat(pszCmdLine, " ");
1842 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), li->arcname);
1843 endofit = &pszCmdLine[strlen(pszCmdLine)];
1844 z = 0;
1845 do {
1846 for (x = z; li->list[x] &&
1847 strlen(pszCmdLine) + strlen(li->list[x]) < MaxComLineStrg - 1 ; x++) {
1848 strcat(pszCmdLine, " ");
1849 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), li->list[x]);
1850 ptr = li->list[x];
1851 while (*ptr) {
1852 if (*ptr == '/')
1853 *ptr = '\\';
1854 ptr++;
1855 }
1856 }
1857 z = x;
1858 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
1859 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1860 hwnd, pszSrcFile, __LINE__,
1861 li->targetpath, NULL, "%s", pszCmdLine);
1862 *endofit = 0;
1863 } while (li->list[x]);
1864 if (li->type == IDM_EXTRACT || li->type == IDM_EXTRACTWDIRS) {
1865 /* update windows */
1866 for (x = 0; li->list[x]; x++) {
1867
1868 CHAR *temp, *p;
1869
1870 temp = li->list[x];
1871 p = temp;
1872 while (*p) {
1873 if (*p == '/')
1874 *p = '\\';
1875 p++;
1876 }
1877 p = xmalloc(strlen(temp) + strlen(li->targetpath) + 2,
1878 pszSrcFile, __LINE__);
1879 if (p) {
1880 BldFullPathName(p, li->targetpath, temp);
1881 li->list[x] = p;
1882 free(temp);
1883 }
1884 }
1885 if (fFolderAfterExtract) {
1886
1887 CHAR objectpath[CCHMAXPATH], *p;
1888 APIRET rc;
1889
1890 GetDesktopName(objectpath, sizeof(objectpath));
1891 rc = WinDlgBox(HWND_DESKTOP, dcd->hwndParent, ObjCnrDlgProc,
1892 FM3ModHandle, OBJCNR_FRAME,
1893 MPFROMP(objectpath));
1894 if (rc) {
1895 if (rc > 1)
1896 strcpy(objectpath, "<WP_DESKTOP>");
1897 p = NULL;
1898 if (li->arcname) {
1899 p = strrchr(li->arcname, '\\');
1900 if (p)
1901 p++;
1902 }
1903 MakeShadows(dcd->hwndParent, li->list, 2, objectpath, p);
1904 }
1905 }
1906 Broadcast(WinQueryAnchorBlock(hwnd),
1907 hwndMain,
1908 UM_UPDATERECORDLIST, MPFROMP(li->list), MPVOID);
1909 }
1910 else if (li->type == IDM_EXEC)
1911 ExecOnList(hwnd,
1912 li->runfile,
1913 WINDOWED | SEPARATEKEEP | PROMPT,
1914 li->targetpath,
1915 NULL, GetPString(IDS_EXECARCFILETITLETEXT),
1916 pszSrcFile, __LINE__);
1917 else if (li->type == IDM_VIRUSSCAN)
1918 ExecOnList(hwnd, virus, PROMPT | WINDOWED | SEPARATEKEEP,
1919 li->targetpath, NULL,
1920 GetPString(IDS_VIRUSSCANARCHIVETITLETEXT),
1921 pszSrcFile, __LINE__);
1922 else if (li->type == IDM_VIEW || li->type == IDM_VIEWTEXT ||
1923 li->type == IDM_VIEWBINARY || li->type == IDM_EDIT ||
1924 li->type == IDM_EDITTEXT ||
1925 li->type == IDM_VIEWARCHIVE ||
1926 li->type == IDM_EDITBINARY ||
1927 li->type == IDM_OPENDEFAULT ||
1928 li->type == IDM_OPENSETTINGS ||
1929 li->type == IDM_MCIPLAY || li->type == IDM_PRINT) {
1930
1931 CHAR *temp, *p;
1932 for (x = 0; li->list[x]; x++) {
1933 if (!li->info->exwdirs) {
1934 temp = li->list[x];
1935 p = strrchr(li->list[x], '\\');
1936 if (p) {
1937 p++;
1938 li->list[x] = xstrdup(p, pszSrcFile, __LINE__);
1939 if (!li->list[x])
1940 li->list[x] = temp;
1941 else {
1942 xfree(temp, pszSrcFile, __LINE__);
1943 }
1944 }
1945 }
1946 BldFullPathName(pszCmdLine, li->targetpath, li->list[x]);
1947 temp = li->list[x];
1948 li->list[x] = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
1949 if (!li->list[x])
1950 li->list[x] = temp;
1951 else
1952 xfree(temp, pszSrcFile, __LINE__);
1953 }
1954 free(pszCmdLine);
1955 if (li->type == IDM_VIEW || li->type == IDM_EDIT) {
1956
1957 BOOL isit = TestBinary(li->list[0]);
1958
1959 if (isit) {
1960 if (li->type == IDM_VIEW)
1961 li->type = IDM_VIEWBINARY;
1962 else
1963 li->type = IDM_EDITBINARY;
1964 }
1965 else {
1966 if (li->type == IDM_VIEW)
1967 li->type = IDM_VIEWTEXT;
1968 else
1969 li->type = IDM_EDITTEXT;
1970 }
1971 }
1972 if (li->type == IDM_MCIPLAY) {
1973
1974 FILE *fp;
1975 CHAR szTempFile[CCHMAXPATH];
1976
1977 BldFullPathName(szTempFile, pTmpDir, "$FM2PLAY.$$$");
1978 fp = xfopen(szTempFile, "w", pszSrcFile, __LINE__);
1979 if (fp) {
1980 fprintf(fp, "%s", ";AV/2-built FM2Play listfile\n");
1981 for (x = 0; li->list[x]; x++)
1982 fprintf(fp, "%s\n", li->list[x]);
1983 fprintf(fp, ";end\n");
1984 fclose(fp);
1985 strrev(szTempFile);
1986 strcat(szTempFile, "@/");
1987 strrev(szTempFile);
1988 RunFM2Util("FM2PLAY.EXE", szTempFile);
1989 }
1990 }
1991 else if (li->type == IDM_PRINT) {
1992 strcpy(li->targetpath, printer);
1993 if (_beginthread(PrintListThread, NULL, 65536, (PVOID) li) !=
1994 -1) {
1995 Runtime_Error(pszSrcFile, __LINE__,
1996 GetPString(IDS_COULDNTSTARTTHREADTEXT));
1997 li = NULL;
1998 }
1999 }
2000 else if (li->type == IDM_VIEWARCHIVE) {
2001
2002 ARC_TYPE *info;
2003
2004 for (x = 0; li->list[x]; x++) {
2005 if (IsFile(li->list[x]) == 1) {
2006 info = NULL; // Do not hide dups - fixme to know why?
2007 if (WinDlgBox(HWND_DESKTOP, HWND_DESKTOP,
2008 SBoxDlgProc, FM3ModHandle, ASEL_FRAME,
2009 (PVOID) & info) && info) {
2010 StartArcCnr(HWND_DESKTOP,
2011 HWND_DESKTOP, li->list[x], 4, info);
2012 }
2013 }
2014 }
2015 }
2016 else if ((li->type == IDM_VIEWTEXT && *viewer) ||
2017 (li->type == IDM_VIEWBINARY && *binview) ||
2018 (li->type == IDM_EDITTEXT && *editor) ||
2019 (li->type == IDM_EDITBINARY && *bined)) {
2020 DosSleep(32); //05 Aug 07 GKY 100
2021 ExecOnList(hwnd, ((li->type == IDM_VIEWTEXT) ? viewer :
2022 (li->type == IDM_VIEWBINARY) ? binview :
2023 (li->type == IDM_EDITTEXT) ? editor :
2024 bined),
2025 WINDOWED | SEPARATE, li->targetpath, li->list,
2026 NULL, pszSrcFile, __LINE__);
2027 }
2028 else if (li->type == IDM_OPENDEFAULT ||
2029 li->type == IDM_OPENSETTINGS) {
2030 WORKER *wk;
2031# ifdef FORTIFY
2032 Fortify_EnterScope();
2033# endif
2034 wk = xmallocz(sizeof(WORKER), pszSrcFile, __LINE__);
2035 if (!wk)
2036 FreeListInfo(li);
2037 else {
2038 wk->size = sizeof(WORKER);
2039 wk->hwndCnr = dcd->hwndCnr;
2040 wk->hwndParent = dcd->hwndParent;
2041 wk->hwndFrame = dcd->hwndFrame;
2042 wk->hwndClient = dcd->hwndClient;
2043 wk->li = li;
2044 strcpy(wk->directory, dcd->directory);
2045 if (_beginthread(Action, NULL, 122880, (PVOID) wk) == -1) {
2046 Runtime_Error(pszSrcFile, __LINE__,
2047 GetPString(IDS_COULDNTSTARTTHREADTEXT));
2048 free(wk);
2049 FreeListInfo((LISTINFO *) mp1);
2050 }
2051 }
2052# ifdef FORTIFY
2053 Fortify_LeaveScope();
2054# endif
2055 }
2056 else {
2057 if (li->hwnd) {
2058
2059 ULONG viewtype;
2060
2061 for (x = 0; li->list[x]; x++) {
2062 if (x == 0) {
2063 if (li->type == IDM_VIEWBINARY ||
2064 li->type == IDM_EDITBINARY)
2065 viewtype = 16;
2066 else
2067 viewtype = 8;
2068 }
2069 else
2070 viewtype = 0;
2071# ifdef FORTIFY
2072 Fortify_EnterScope();
2073# endif
2074 temp = xstrdup(li->list[x], pszSrcFile, __LINE__);
2075 if (temp) {
2076 if (!PostMsg(WinQueryWindow(li->hwnd, QW_PARENT),
2077 UM_LOADFILE,
2078 MPFROMLONG(4L +
2079 (li->type == IDM_VIEWTEXT ||
2080 li->type == IDM_VIEWBINARY) +
2081 viewtype), MPFROMP(temp)))
2082 free(temp);
2083 }
2084# ifdef FORTIFY
2085 DosSleep(1); // Allow MassAction to take ownership
2086 Fortify_LeaveScope();
2087# endif
2088 }
2089 }
2090 }
2091 }
2092 }
2093 break;
2094
2095 case IDM_FIND:
2096 {
2097 UINT numfiles = 0, numalloced = 0;
2098 CHAR **list2 = NULL, fullname[CCHMAXPATH * 2], *p;
2099
2100 for (x = 0; li->list[x]; x++) {
2101 p = li->list[x];
2102 while (*p) {
2103 if (*p == '/')
2104 *p = '\\';
2105 p++;
2106 }
2107 BldFullPathName(fullname, dcd->directory, li->list[x]);
2108 if (IsFile(fullname) != -1)
2109 if (AddToList(fullname, &list2, &numfiles, &numalloced))
2110 break;
2111 if (strchr(li->list[x], '\\')) {
2112 p = strrchr(li->list[x], '\\');
2113 if (p) {
2114 p++;
2115 if (*p) {
2116 BldFullPathName(fullname, dcd->directory, p);
2117 if (IsFile(fullname) != -1)
2118 if (AddToList(fullname, &list2, &numfiles, &numalloced))
2119 break;
2120 }
2121 }
2122 }
2123 }
2124 if (!numfiles || !list2)
2125 Runtime_Error(pszSrcFile, __LINE__, "no files or list");
2126 else {
2127 WinSendMsg(dcd->hwndCnr, WM_COMMAND,
2128 MPFROM2SHORT(IDM_COLLECTOR, 0), MPVOID);
2129 DosSleep(10); //05 Aug 07 GKY 128
2130 if (Collector) {
2131 if (!PostMsg(Collector, WM_COMMAND,
2132 MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list2)))
2133 FreeList(list2);
2134 }
2135 else
2136 FreeList(list2);
2137 }
2138 }
2139 break;
2140 }
2141 }
2142 if (li->type != IDM_OPENDEFAULT && li->type != IDM_OPENSETTINGS)
2143 {
2144 FreeListInfo(li);
2145 }
2146 }
2147 return 0;
2148
2149 case WM_CLOSE:
2150 WinDestroyWindow(hwnd);
2151 break;
2152
2153 case WM_DESTROY:
2154 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
2155 if (dcd) {
2156 if (*dcd->workdir) {
2157 DosSleep(16); //05 Aug 07 GKY 33
2158 wipeallf("%s\\*", dcd->workdir);
2159 if (rmdir(dcd->workdir)) {
2160 DosSleep(100); //05 Aug 07 GKY 256
2161 wipeallf("%s\\*", dcd->workdir);
2162 rmdir(dcd->workdir);
2163 }
2164 }
2165 FreeList(dcd->lastselection);
2166 WinSendMsg(dcd->hwndCnr, UM_CLOSE, MPVOID, MPVOID);
2167 free(dcd);
2168# ifdef FORTIFY
2169 Fortify_LeaveScope();
2170# endif
2171 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, NULL);
2172 }
2173 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
2174 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
2175 break;
2176 } // switch
2177 return WinDefWindowProc(hwnd, msg, mp1, mp2);
2178}
2179
2180static MRESULT EXPENTRY ArcCnrWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
2181 MPARAM mp2)
2182{
2183 DIRCNRDATA *dcd = INSTDATA(hwnd);
2184 CHAR szQuotedArcName[CCHMAXPATH];
2185
2186 switch (msg) {
2187 case DM_PRINTOBJECT:
2188 case DM_DISCARDOBJECT:
2189 if (dcd)
2190 return WinSendMsg(dcd->hwndObject, msg, mp1, mp2);
2191 else
2192 return MRFROMLONG(DRR_TARGET);
2193
2194 case WM_CHAR:
2195 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
2196 if (SHORT1FROMMP(mp1) & KC_KEYUP)
2197 return (MRESULT) TRUE;
2198 if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
2199 switch (SHORT2FROMMP(mp2)) {
2200 case VK_DELETE:
2201 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_DELETE, 0), MPVOID);
2202 break;
2203 }
2204 }
2205 if (shiftstate || fNoSearch)
2206 break;
2207 if (SHORT1FROMMP(mp1) & KC_CHAR) {
2208
2209 ULONG thistime, len;
2210 SEARCHSTRING srch;
2211 PCNRITEM pci;
2212
2213 if (!dcd)
2214 break;
2215 switch (SHORT1FROMMP(mp2)) {
2216 case '\x1b':
2217 case '\r':
2218 case '\n':
2219 dcd->lasttime = 0;
2220 *dcd->szCommonName = 0;
2221 break;
2222 default:
2223 thistime = WinQueryMsgTime(WinQueryAnchorBlock(hwnd));
2224 if (thistime > dcd->lasttime + 1250)
2225 *dcd->szCommonName = 0;
2226 dcd->lasttime = thistime;
2227 if (SHORT1FROMMP(mp2) == ' ' && !*dcd->szCommonName)
2228 break;
2229 KbdRetry:
2230 len = strlen(dcd->szCommonName);
2231 if (len >= CCHMAXPATH - 1) {
2232 *dcd->szCommonName = 0;
2233 len = 0;
2234 }
2235 dcd->szCommonName[len] = toupper(SHORT1FROMMP(mp2));
2236 dcd->szCommonName[len + 1] = 0;
2237 memset(&srch, 0, sizeof(SEARCHSTRING));
2238 srch.cb = (ULONG) sizeof(SEARCHSTRING);
2239 srch.pszSearch = dcd->szCommonName;
2240 srch.fsPrefix = TRUE;
2241 srch.fsCaseSensitive = FALSE;
2242 srch.usView = CV_ICON;
2243 pci = WinSendMsg(hwnd,
2244 CM_SEARCHSTRING,
2245 MPFROMP(&srch), MPFROMLONG(CMA_FIRST));
2246 if (pci && (INT) pci != -1) {
2247
2248 USHORT attrib = CRA_CURSORED;
2249
2250
2251 /* make found item current item */
2252 if (!stricmp(pci->pszFileName, dcd->szCommonName))
2253 attrib |= CRA_SELECTED;
2254 WinSendMsg(hwnd,
2255 CM_SETRECORDEMPHASIS,
2256 MPFROMP(pci), MPFROM2SHORT(TRUE, attrib));
2257 /* make sure that record shows in viewport */
2258 ShowCnrRecord(hwnd, (PMINIRECORDCORE) pci);
2259 return (MRESULT) TRUE;
2260 }
2261 else {
2262 if (SHORT1FROMMP(mp2) == ' ') {
2263 dcd->szCommonName[len] = 0;
2264 break;
2265 }
2266 *dcd->szCommonName = 0;
2267 dcd->lasttime = 0;
2268 if (len) // retry as first letter if no match
2269 goto KbdRetry;
2270 }
2271 break;
2272 }
2273 }
2274 break;
2275
2276 case WM_MOUSEMOVE:
2277 case WM_BUTTON1UP:
2278 case WM_BUTTON2UP:
2279 case WM_BUTTON3UP:
2280 case WM_CHORD:
2281 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
2282 break;
2283
2284 case WM_BUTTON1MOTIONEND:
2285 {
2286 CNRINFO cnri;
2287
2288 memset(&cnri, 0, sizeof(CNRINFO));
2289 cnri.cb = sizeof(CNRINFO);
2290 if (WinSendMsg(hwnd,
2291 CM_QUERYCNRINFO,
2292 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)))) {
2293 if (cnri.flWindowAttr & CV_DETAIL)
2294 PrfWriteProfileData(fmprof,
2295 appname,
2296 "ArcCnrSplitBar",
2297 (PVOID) & cnri.xVertSplitbar, sizeof(LONG));
2298 }
2299 }
2300 break;
2301
2302 case WM_PRESPARAMCHANGED:
2303 PresParamChanged(hwnd, "ArcCnr", mp1, mp2);
2304 break;
2305
2306 case UM_UPDATERECORD:
2307 case UM_UPDATERECORDLIST:
2308 if (dcd && !IsArcThere(hwnd, dcd->arcname))
2309 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2310 return 0;
2311
2312 case WM_SETFOCUS:
2313 /*
2314 * put name of our window (archive name) on status line
2315 */
2316 if (dcd && hwndStatus && mp2)
2317 WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2318 break;
2319
2320 case UM_SETUP2:
2321 if (dcd && dcd->info) {
2322 if (dcd->info->fdpos == -1 || !dcd->info->datetype)
2323 dcd->sortFlags &= (~SORT_LWDATE);
2324 if (dcd->info->nsizepos == -1)
2325 dcd->sortFlags &= (~SORT_EASIZE);
2326 if (dcd->info->osizepos == -1)
2327 dcd->sortFlags &= (~SORT_SIZE);
2328 AdjustCnrColVis(hwnd,
2329 GetPString(IDS_OLDSIZECOLTEXT),
2330 dcd->info->osizepos != -1, FALSE);
2331 AdjustCnrColVis(hwnd,
2332 GetPString(IDS_NEWSIZECOLTEXT),
2333 dcd->info->nsizepos != -1, FALSE);
2334 // Display unsullied date/time string if type 0
2335 AdjustCnrColVis(hwnd,
2336 GetPString(IDS_DATETIMECOLTEXT),
2337 dcd->info->fdpos != -1 && !dcd->info->datetype, FALSE);
2338 // Display parsed date/time columns if type specified
2339 AdjustCnrColVis(hwnd,
2340 GetPString(IDS_TIMECOLTEXT),
2341 dcd->info->fdpos != -1 && dcd->info->datetype, FALSE);
2342 AdjustCnrColVis(hwnd,
2343 GetPString(IDS_DATECOLTEXT),
2344 dcd->info->fdpos != -1 && dcd->info->datetype, FALSE);
2345 WinSendMsg(hwnd, CM_INVALIDATEDETAILFIELDINFO, MPVOID, MPVOID);
2346 }
2347 return 0;
2348
2349 case UM_RESCAN:
2350 if (dcd) {
2351 CNRINFO cnri;
2352 CHAR s[CCHMAXPATH * 2], tb[81], tf[81];
2353 PARCITEM pci;
2354
2355 if (mp1) {
2356 PostMsg(dcd->hwndObject, UM_RESCAN, MPVOID, MPVOID);
2357 return 0;
2358 }
2359 memset(&cnri, 0, sizeof(CNRINFO));
2360 cnri.cb = sizeof(CNRINFO);
2361 WinSendMsg(hwnd,
2362 CM_QUERYCNRINFO,
2363 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
2364 dcd->totalfiles = cnri.cRecords;
2365 commafmt(tf, sizeof(tf), dcd->selectedfiles);
2366 if (dcd->ullTotalBytes)
2367 CommaFmtULL(tb, sizeof(tb), dcd->selectedbytes, 'K');
2368 else
2369 *tb = 0;
2370 sprintf(s, "%s%s%s", tf, *tb ? " / " : NullStr, tb);
2371 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, s);
2372 commafmt(tf, sizeof(tf), dcd->totalfiles);
2373 if (dcd->ullTotalBytes)
2374 CommaFmtULL(tb, sizeof(tb), dcd->ullTotalBytes, 'K');
2375 else
2376 *tb = 0;
2377 sprintf(s, "%s%s%s", tf, *tb ? " / " : NullStr, tb);
2378 WinSetDlgItemText(dcd->hwndClient, DIR_TOTALS, s);
2379 if (hwndStatus &&
2380 dcd->hwndFrame == WinQueryActiveWindow(dcd->hwndParent)) {
2381 sprintf(s, " [%s%s%s]%s%s%s %s",
2382 tf,
2383 *tb ? " / " : NullStr,
2384 tb,
2385 *dcd->mask.szMask ? " (" : NullStr,
2386 *dcd->mask.szMask ? dcd->mask.szMask : NullStr,
2387 *dcd->mask.szMask ? ")" : NullStr, dcd->arcname);
2388 WinSetWindowText(hwndStatus, s);
2389 if (!ParentIsDesktop(hwnd, dcd->hwndParent)) {
2390 pci = WinSendMsg(hwnd,
2391 CM_QUERYRECORDEMPHASIS,
2392 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
2393 if (pci && (INT) pci != -1) {
2394 if (fSplitStatus && hwndStatus2) {
2395 if (dcd->ullTotalBytes)
2396 CommaFmtULL(tb, sizeof(tb), pci->cbFile, ' ');
2397 else
2398 *tb = 0;
2399 sprintf(s, "%s%s%s%s",
2400 *tb ? " " : NullStr,
2401 tb, *tb ? " " : NullStr, pci->pszFileName);
2402 WinSetWindowText(hwndStatus2, s);
2403 }
2404 if (fMoreButtons)
2405 WinSetWindowText(hwndName, pci->pszFileName);
2406 }
2407 else {
2408 WinSetWindowText(hwndStatus2, NullStr);
2409 WinSetWindowText(hwndName, NullStr);
2410 }
2411 WinSetWindowText(hwndDate, NullStr);
2412 WinSetWindowText(hwndAttr, NullStr);
2413 }
2414 }
2415 if ((dcd->arcfilled && !dcd->totalfiles) ||
2416 !IsArcThere(hwnd, dcd->arcname))
2417 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2418 }
2419 return 0;
2420
2421 case UM_SETUP:
2422 if (!dcd) {
2423 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2424 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2425 return 0;
2426 }
2427 else {
2428 if (!dcd->hwndObject) {
2429 /*
2430 * first time through -- set things up
2431 */
2432 {
2433 CHAR *p, *pp;
2434 ULONG z, was;
2435 APIRET rc;
2436
2437 rc = DosCreateDir(dcd->workdir, 0);
2438 if (rc) {
2439 if (rc == ERROR_ACCESS_DENIED) {
2440 p = strrchr(dcd->workdir, '.');
2441 if (p) {
2442 p++;
2443 pp = p;
2444 was = strtoul(p, &pp, 16);
2445 for (z = 0; z < 99; z++) {
2446 was++;
2447 sprintf(p, "%03x");
2448 rc = DosCreateDir(dcd->workdir, 0);
2449 if (!rc || rc != ERROR_ACCESS_DENIED)
2450 break;
2451 }
2452 }
2453 }
2454 if (rc)
2455 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2456 return 0;
2457 }
2458 }
2459 RestorePresParams(hwnd, "ArcCnr");
2460 dcd->mask.fNoAttribs = TRUE;
2461 dcd->mask.fNoDirs = TRUE;
2462 *dcd->mask.prompt = 0;
2463 {
2464 PFIELDINFO pfi, pfiLastLeftCol;
2465 ULONG numcols = CON_COLS;
2466 CNRINFO cnri;
2467 ULONG size;
2468
2469 pfi = WinSendMsg(hwnd,
2470 CM_ALLOCDETAILFIELDINFO,
2471 MPFROMLONG(numcols), NULL);
2472 if (pfi) {
2473
2474 PFIELDINFO pfiFirst;
2475 FIELDINFOINSERT fii;
2476
2477 pfiFirst = pfi;
2478 pfi->flData = CFA_STRING | CFA_LEFT | CFA_FIREADONLY;
2479 pfi->flTitle = CFA_CENTER;
2480 pfi->pTitleData = GetPString(IDS_FILENAMECOLTEXT);
2481 pfi->offStruct = FIELDOFFSET(ARCITEM, pszDisplayName);
2482 pfiLastLeftCol = pfi;
2483 pfi = pfi->pNextFieldInfo;
2484 pfi->flData =
2485 CFA_ULONG | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
2486 pfi->flTitle = CFA_CENTER;
2487 pfi->pTitleData = GetPString(IDS_OLDSIZECOLTEXT);
2488 pfi->offStruct = FIELDOFFSET(ARCITEM, cbFile);
2489 pfi = pfi->pNextFieldInfo;
2490 pfi->flData =
2491 CFA_ULONG | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
2492 pfi->flTitle = CFA_CENTER;
2493 pfi->pTitleData = GetPString(IDS_NEWSIZECOLTEXT);
2494 pfi->offStruct = FIELDOFFSET(ARCITEM, cbComp);
2495 pfi = pfi->pNextFieldInfo;
2496 pfi->flData =
2497 CFA_STRING | CFA_CENTER | CFA_SEPARATOR | CFA_FIREADONLY;
2498 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
2499 pfi->pTitleData = GetPString(IDS_DATETIMECOLTEXT);
2500 pfi->offStruct = FIELDOFFSET(ARCITEM, pszDate);
2501 pfi = pfi->pNextFieldInfo;
2502 pfi->flData = CFA_DATE | CFA_RIGHT | CFA_FIREADONLY;
2503 pfi->flTitle = CFA_CENTER;
2504 pfi->pTitleData = GetPString(IDS_DATECOLTEXT);
2505 pfi->offStruct = FIELDOFFSET(ARCITEM, date);
2506 pfi = pfi->pNextFieldInfo;
2507 pfi->flData = CFA_TIME | CFA_RIGHT | CFA_FIREADONLY;
2508 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
2509 pfi->pTitleData = GetPString(IDS_TIMECOLTEXT);
2510 pfi->offStruct = FIELDOFFSET(ARCITEM, time);
2511 memset(&fii, 0, sizeof(FIELDINFOINSERT));
2512 fii.cb = sizeof(FIELDINFOINSERT);
2513 fii.pFieldInfoOrder = (PFIELDINFO) CMA_FIRST;
2514 fii.cFieldInfoInsert = (SHORT) numcols;
2515 fii.fInvalidateFieldInfo = TRUE;
2516 WinSendMsg(hwnd,
2517 CM_INSERTDETAILFIELDINFO,
2518 MPFROMP(pfiFirst), MPFROMP(&fii));
2519 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
2520
2521 memset(&cnri, 0, sizeof(cnri));
2522 cnri.cb = sizeof(CNRINFO);
2523 cnri.pFieldInfoLast = pfiLastLeftCol;
2524 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET + 32;
2525
2526 size = sizeof(LONG);
2527 PrfQueryProfileData(fmprof, appname, "ArcCnrSplitBar",
2528 &cnri.xVertSplitbar, &size);
2529 if (cnri.xVertSplitbar <= 0)
2530 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET + 32;
2531
2532 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT | CV_NAME));
2533 cnri.flWindowAttr |= (CV_DETAIL | CA_DETAILSVIEWTITLES | CV_FLOW);
2534 cnri.flWindowAttr &= (~(CA_ORDEREDTARGETEMPH |
2535 CA_MIXEDTARGETEMPH));
2536 cnri.pSortRecord = (PVOID) ArcSort;
2537 WinSendMsg(hwnd,
2538 CM_SETCNRINFO,
2539 MPFROMP(&cnri),
2540 MPFROMLONG(CMA_PFIELDINFOLAST |
2541 CMA_XVERTSPLITBAR |
2542 CMA_PSORTRECORD | CMA_FLWINDOWATTR));
2543 }
2544 }
2545 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(ArcSort), MPFROMP(dcd));
2546 if (_beginthread(MakeObjWin, NULL, 245760, (PVOID) dcd) == -1) {
2547 Runtime_Error(pszSrcFile, __LINE__,
2548 GetPString(IDS_COULDNTSTARTTHREADTEXT));
2549 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2550 return 0;
2551 }
2552 else
2553 DosSleep(1);
2554 SayFilter(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2555 DIR_FILTER), &dcd->mask, TRUE);
2556 SaySort(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2557 DIR_SORT), dcd->sortFlags, TRUE);
2558 DefArcSortFlags = dcd->sortFlags; // Remember for new windows
2559 }
2560 }
2561 return 0;
2562
2563 case UM_SETDIR:
2564 if (dcd) {
2565
2566 CHAR s[CCHMAXPATH], *p;
2567 ULONG ret = 0;
2568
2569 WinQueryDlgItemText(dcd->hwndClient, ARC_EXTRACTDIR, CCHMAXPATH, s);
2570 bstrip(s);
2571 MakeFullName(s);
2572 if (*s) {
2573 while ((p = strchr(s, '/')) != NULL)
2574 *p = '\\';
2575 while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
2576 s[strlen(s) - 1] = 0;
2577 if (stricmp(s, dcd->directory)) {
2578 if (IsFullName(s)) {
2579 if (driveflags[toupper(*s) - 'A'] &
2580 (DRIVE_NOTWRITEABLE | DRIVE_IGNORE | DRIVE_INVALID)) {
2581 Runtime_Error(pszSrcFile, __LINE__, "drive %s bad", s);
2582 WinSetDlgItemText(dcd->hwndClient,
2583 ARC_EXTRACTDIR, dcd->directory);
2584 return 0;
2585 }
2586 }
2587 if (!SetDir(dcd->hwndParent, hwnd, s, 0)) {
2588 if (stricmp(dcd->directory, s)) {
2589 DosEnterCritSec();
2590 strcpy(lastextractpath, s);
2591 DosExitCritSec();
2592 }
2593 strcpy(dcd->directory, s);
2594 if ((!isalpha(*s) || s[1] != ':') && *s != '.')
2595 saymsg(MB_ENTER | MB_ICONASTERISK,
2596 hwnd,
2597 GetPString(IDS_WARNINGTEXT),
2598 GetPString(IDS_SPECIFYDRIVETEXT));
2599 }
2600 else
2601 ret = 1;
2602 }
2603 }
2604 WinSetDlgItemText(dcd->hwndClient, ARC_EXTRACTDIR, dcd->directory);
2605 return (MRESULT) ret;
2606 }
2607 return 0;
2608
2609 case UM_ENTER:
2610 if (WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID)) {
2611 free(mp1);
2612 return 0;
2613 }
2614 SetShiftState();
2615 if (dcd && (CHAR *) mp1) {
2616
2617 SWP swp;
2618 CHAR *filename = mp1;
2619 printf("%s %d UM_ENTER %s\n",__FILE__, __LINE__, filename); fflush(stdout);
2620 if (IsFile(filename) != 1) {
2621 free(mp1);
2622 return 0;
2623 }
2624 WinQueryWindowPos(dcd->hwndFrame, &swp);
2625 DefaultViewKeys(hwnd, dcd->hwndFrame, dcd->hwndParent, &swp, filename);
2626 if (fUnHilite)
2627 UnHilite(hwnd, FALSE, &dcd->lastselection, 0);
2628 }
2629 free(mp1);
2630 return 0;
2631
2632 case WM_MENUEND:
2633 if (dcd) {
2634
2635 HWND hwndMenu = (HWND) mp2;
2636
2637 if (hwndMenu == ArcCnrMenu || hwndMenu == ArcMenu) {
2638 MarkAll(hwnd, TRUE, FALSE, TRUE);
2639 if (dcd->cnremphasized) {
2640 WinSendMsg(hwnd,
2641 CM_SETRECORDEMPHASIS,
2642 MPVOID, MPFROM2SHORT(FALSE, CRA_SOURCE));
2643 dcd->cnremphasized = FALSE;
2644 }
2645 }
2646 }
2647 break;
2648
2649 case MM_PORTHOLEINIT:
2650 if (dcd) {
2651 switch (SHORT1FROMMP(mp1)) {
2652 case 0:
2653 case 1:
2654 {
2655 ULONG wmsg;
2656
2657 wmsg = SHORT1FROMMP(mp1) == 0 ? UM_FILESMENU : UM_VIEWSMENU;
2658 PortholeInit((HWND) WinSendMsg(dcd->hwndClient,
2659 wmsg, MPVOID, MPVOID), mp1, mp2);
2660 }
2661 break;
2662 }
2663 }
2664 break;
2665
2666 case UM_INITMENU:
2667 case WM_INITMENU:
2668 if (dcd) {
2669 switch (SHORT1FROMMP(mp1)) {
2670 case IDM_FILESMENU:
2671 if (dcd->info) {
2672 WinEnableMenuItem((HWND) mp2,
2673 IDM_DELETE, dcd->info->delete != NULL);
2674 WinEnableMenuItem((HWND) mp2, IDM_TEST, dcd->info->test != NULL);
2675 WinEnableMenuItem((HWND) mp2,
2676 IDM_EXTRACT, dcd->info->extract != NULL);
2677 WinEnableMenuItem((HWND) mp2,
2678 IDM_EXTRACTWDIRS, dcd->info->exwdirs != NULL);
2679 WinEnableMenuItem((HWND) mp2,
2680 IDM_ARCEXTRACTWDIRS, dcd->info->exwdirs != NULL);
2681 WinEnableMenuItem((HWND) mp2,
2682 IDM_ARCEXTRACTWDIRSEXIT,
2683 dcd->info->exwdirs != NULL);
2684 }
2685 break;
2686
2687 case IDM_VIEWSMENU:
2688 WinCheckMenuItem((HWND) mp2,
2689 IDM_MINIICONS, (dcd->flWindowAttr & CV_MINI) != 0);
2690 WinEnableMenuItem((HWND) mp2,
2691 IDM_RESELECT, (dcd->lastselection != NULL));
2692 break;
2693
2694 case IDM_COMMANDSMENU:
2695 SetupCommandMenu((HWND) mp2, hwnd);
2696 break;
2697
2698 case IDM_SORTSUBMENU:
2699 SetSortChecks((HWND) mp2, dcd->sortFlags);
2700 break;
2701
2702 case IDM_WINDOWSMENU:
2703 /*
2704 * add switchlist entries to end of pulldown menu
2705 */
2706 SetupWinList((HWND)mp2,
2707 hwndMain ? hwndMain : (HWND)0, dcd->hwndFrame);
2708 break;
2709 }
2710 dcd->hwndLastMenu = (HWND) mp2;
2711 }
2712 if (msg == WM_INITMENU)
2713 break;
2714 return 0;
2715
2716 case UM_LOADFILE:
2717 if (dcd && mp2) {
2718
2719 HWND hwnd;
2720
2721 if ((INT)mp1 == 5 || (INT)mp1 == 13 || (INT)mp1 == 21)
2722 hwnd = StartViewer(HWND_DESKTOP, (INT)mp1,
2723 (CHAR *)mp2, dcd->hwndFrame);
2724 else
2725 hwnd = StartMLEEditor(dcd->hwndParent,
2726 (INT)mp1, (CHAR *)mp2, dcd->hwndFrame);
2727 free((CHAR *)mp2);
2728 return MRFROMLONG(hwnd);
2729 }
2730 return 0;
2731
2732 case UM_COMMAND:
2733 if (mp1) {
2734 if (dcd) {
2735 if (!PostMsg(dcd->hwndObject, UM_COMMAND, mp1, mp2)) {
2736 Runtime_Error(pszSrcFile, __LINE__, "post");
2737 FreeListInfo((LISTINFO *) mp1);
2738 }
2739 else
2740 return (MRESULT) TRUE;
2741 }
2742 else
2743 FreeListInfo((LISTINFO *) mp1);
2744 }
2745 return 0;
2746
2747 case UM_OPENWINDOWFORME:
2748 if (dcd) {
2749 if (mp1 && !IsFile((CHAR *) mp1)) {
2750 OpenDirCnr((HWND) 0, hwndMain, dcd->hwndFrame, FALSE, (char *)mp1);
2751 }
2752 else if (mp1 && IsFile(mp1) == 1 &&
2753 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
2754 StartArcCnr(HWND_DESKTOP,
2755 dcd->hwndFrame, (CHAR *) mp1, 4, (ARC_TYPE *) mp2);
2756 }
2757 }
2758 return 0;
2759
2760 case WM_COMMAND:
2761 DosError(FERR_DISABLEHARDERR);
2762 if (dcd) {
2763 if (SwitchCommand(dcd->hwndLastMenu, SHORT1FROMMP(mp1)))
2764 return 0;
2765 if (WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID))
2766 return 0;
2767 if (!IsArcThere(hwnd, dcd->arcname)) {
2768 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2769 return 0;
2770 }
2771 switch (SHORT1FROMMP(mp1)) {
2772 case IDM_TREEVIEW:
2773
2774 break;
2775
2776 case IDM_CONTEXTMENU:
2777 {
2778 PCNRITEM pci;
2779
2780 pci = (PCNRITEM) CurrentRecord(hwnd);
2781 PostMsg(hwnd,
2782 WM_CONTROL,
2783 MPFROM2SHORT(ARC_CNR, CN_CONTEXTMENU), MPFROMP(pci));
2784 }
2785 break;
2786
2787 case IDM_NEXTWINDOW:
2788 case IDM_PREVWINDOW:
2789 {
2790 HWND hwndActive;
2791
2792 hwndActive = WinQueryFocus(HWND_DESKTOP);
2793 WinSetFocus(HWND_DESKTOP,
2794 hwndActive == hwnd ?
2795 WinWindowFromID(dcd->hwndClient, ARC_EXTRACTDIR) :
2796 hwnd);
2797 }
2798 break;
2799
2800 case IDM_FOLDERAFTEREXTRACT:
2801 fFolderAfterExtract = fFolderAfterExtract ? FALSE : TRUE;
2802 PrfWriteProfileData(fmprof, appname, "FolderAfterExtract",
2803 &fFolderAfterExtract, sizeof(BOOL));
2804 break;
2805
2806 case IDM_SHOWSELECT:
2807 QuickPopup(hwnd, dcd, CheckMenu(hwnd, &ArcCnrMenu, ARCCNR_POPUP),
2808 IDM_SELECTSUBMENU);
2809 break;
2810
2811 case IDM_SHOWSORT:
2812 QuickPopup(hwnd, dcd, CheckMenu(hwnd, &ArcCnrMenu, ARCCNR_POPUP),
2813 IDM_SORTSUBMENU);
2814 break;
2815
2816 case IDM_ARCHIVERSETTINGS:
2817 if (!ParentIsDesktop(dcd->hwndParent, dcd->hwndParent))
2818 PostMsg(dcd->hwndParent, msg, MPFROMLONG(IDM_ARCHIVERSETTINGS), mp2);
2819 else {
2820 WinDlgBox(HWND_DESKTOP,
2821 hwnd,
2822 CfgDlgProc,
2823 FM3ModHandle,
2824 CFG_FRAME,
2825 MPFROMLONG(IDM_ARCHIVERSETTINGS));
2826 }
2827 break;
2828
2829 case IDM_RESCAN:
2830 dcd->ullTotalBytes = dcd->totalfiles =
2831 dcd->selectedfiles = dcd->selectedbytes = 0;
2832 WinSetDlgItemText(dcd->hwndClient, DIR_TOTALS, "0");
2833 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, "0 / 0k");
2834 dcd->totalfiles = FillArcCnr(dcd->hwndCnr,
2835 dcd->arcname,
2836 &dcd->info,
2837 &dcd->ullTotalBytes, &dcd->stopflag);
2838 PostMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID);
2839 PostMsg(dcd->hwndCnr, UM_SETUP2, MPVOID, MPVOID);
2840 WinSendMsg(dcd->hwndCnr,
2841 CM_INVALIDATERECORD,
2842 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
2843 break;
2844
2845 case IDM_RESELECT:
2846 SelectList(hwnd, TRUE, FALSE, FALSE, NULL, NULL, dcd->lastselection);
2847 break;
2848
2849 case IDM_HELP:
2850 if (hwndHelp)
2851 WinSendMsg(hwndHelp,
2852 HM_DISPLAY_HELP,
2853 MPFROM2SHORT(HELP_ARCLIST, 0),
2854 MPFROMSHORT(HM_RESOURCEID));
2855 break;
2856
2857 case IDM_WINDOWDLG:
2858 if (!ParentIsDesktop(dcd->hwndParent, dcd->hwndFrame))
2859 PostMsg(dcd->hwndParent,
2860 UM_COMMAND, MPFROM2SHORT(IDM_WINDOWDLG, 0), MPVOID);
2861 break;
2862
2863 case IDM_SELECTALL:
2864 case IDM_SELECTALLFILES:
2865 case IDM_DESELECTALL:
2866 case IDM_DESELECTALLFILES:
2867 case IDM_SELECTMASK:
2868 case IDM_DESELECTMASK:
2869 case IDM_INVERT:
2870 {
2871 PARCITEM pci;
2872
2873 pci = (PARCITEM) WinSendMsg(hwnd,
2874 CM_QUERYRECORDEMPHASIS,
2875 MPFROMLONG(CMA_FIRST),
2876 MPFROMSHORT(CRA_CURSORED));
2877 if ((INT) pci == -1)
2878 pci = NULL;
2879 if (SHORT1FROMMP(mp1) == IDM_HIDEALL) {
2880 if (pci) {
2881 if (!(pci->rc.flRecordAttr & CRA_SELECTED))
2882 pci->rc.flRecordAttr |= CRA_FILTERED;
2883 WinSendMsg(hwnd,
2884 CM_INVALIDATERECORD,
2885 MPFROMP(&pci),
2886 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
2887 break;
2888 }
2889 }
2890 PostMsg(dcd->hwndObject, UM_SELECT, mp1, MPFROMP(pci));
2891 }
2892 break;
2893
2894 case IDM_SORTSMARTNAME:
2895 case IDM_SORTNAME:
2896 case IDM_SORTFILENAME:
2897 case IDM_SORTSIZE:
2898 case IDM_SORTEASIZE:
2899 case IDM_SORTFIRST:
2900 case IDM_SORTLAST:
2901 case IDM_SORTLWDATE:
2902 dcd->sortFlags &= SORT_REVERSE;
2903 /* intentional fallthru */
2904 case IDM_SORTREVERSE:
2905 switch (SHORT1FROMMP(mp1)) {
2906 case IDM_SORTSMARTNAME:
2907 case IDM_SORTFILENAME:
2908 dcd->sortFlags |= SORT_FILENAME;
2909 break;
2910 case IDM_SORTSIZE:
2911 dcd->sortFlags |= SORT_SIZE;
2912 break;
2913 case IDM_SORTEASIZE:
2914 dcd->sortFlags |= SORT_EASIZE;
2915 break;
2916 case IDM_SORTFIRST:
2917 dcd->sortFlags |= SORT_FIRSTEXTENSION;
2918 break;
2919 case IDM_SORTLAST:
2920 dcd->sortFlags |= SORT_LASTEXTENSION;
2921 break;
2922 case IDM_SORTLWDATE:
2923 dcd->sortFlags |= SORT_LWDATE;
2924 break;
2925 case IDM_SORTREVERSE:
2926 if (dcd->sortFlags & SORT_REVERSE)
2927 dcd->sortFlags &= (~SORT_REVERSE);
2928 else
2929 dcd->sortFlags |= SORT_REVERSE;
2930 break;
2931 }
2932 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(ArcSort), MPFROMP(dcd));
2933 SaySort(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2934 DIR_SORT), dcd->sortFlags, TRUE);
2935 DefArcSortFlags = dcd->sortFlags; // Remember for new windows
2936 break;
2937
2938 case IDM_COLLECTOR:
2939 if (!Collector) {
2940 HWND hwndC;
2941 SWP swp;
2942
2943 if (ParentIsDesktop(hwnd, dcd->hwndParent) && !fAutoTile &&
2944 (!fExternalCollector && !strcmp(realappname, FM3Str)))
2945 GetNextWindowPos(dcd->hwndParent, &swp, NULL, NULL);
2946 hwndC = StartCollector(fExternalCollector ||
2947 strcmp(realappname, FM3Str) ?
2948 HWND_DESKTOP : dcd->hwndParent, 4);
2949 if (hwndC) {
2950 if (!ParentIsDesktop(hwnd, dcd->hwndParent) && !fAutoTile &&
2951 (!fExternalCollector && !strcmp(realappname, FM3Str)))
2952 WinSetWindowPos(hwndC,
2953 HWND_TOP,
2954 swp.x,
2955 swp.y,
2956 swp.cx,
2957 swp.cy,
2958 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
2959 else if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
2960 fAutoTile && !strcmp(realappname, FM3Str)) {
2961 TileChildren(dcd->hwndParent, TRUE);
2962 }
2963 WinSetWindowPos(hwndC, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE);
2964 DosSleep(100); //05 Aug 07 GKY 128
2965 }
2966 }
2967 else
2968 StartCollector(dcd->hwndParent, 4);
2969 break;
2970
2971 case IDM_ARCEXTRACTEXIT:
2972 case IDM_ARCEXTRACT:
2973 if (dcd->info->extract)
2974 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
2975 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
2976 hwnd, pszSrcFile, __LINE__,
2977 dcd->directory, NULL, "%s %s", dcd->info->extract,
2978 BldQuotedFileName(szQuotedArcName, dcd->arcname));
2979 if (SHORT1FROMMP(mp1) == IDM_ARCEXTRACTEXIT)
2980 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2981 break;
2982
2983 case IDM_ARCEXTRACTWDIRSEXIT:
2984 case IDM_ARCEXTRACTWDIRS:
2985 if (dcd->info->exwdirs)
2986 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
2987 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
2988 hwnd, pszSrcFile, __LINE__,
2989 dcd->directory, NULL, "%s %s",
2990 dcd->info->exwdirs,
2991 BldQuotedFileName(szQuotedArcName, dcd->arcname));
2992 if (SHORT1FROMMP(mp1) == IDM_ARCEXTRACTWDIRSEXIT)
2993 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2994 break;
2995
2996 case IDM_RESORT:
2997 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(ArcSort), MPFROMP(dcd));
2998 break;
2999
3000 case IDM_FILTER:
3001 {
3002 BOOL empty = FALSE;
3003 PARCITEM pci;
3004
3005 if (!*dcd->mask.szMask) {
3006 empty = TRUE;
3007 pci = (PARCITEM) CurrentRecord(hwnd);
3008 if (pci && strchr(pci->pszFileName, '.'))
3009 strcpy(dcd->mask.szMask, pci->pszFileName);
3010 }
3011
3012 if (WinDlgBox(HWND_DESKTOP, hwnd, PickMaskDlgProc,
3013 FM3ModHandle, MSK_FRAME, MPFROMP(&dcd->mask))) {
3014 WinSendMsg(hwnd, CM_FILTER, MPFROMP(ArcFilter), MPFROMP(dcd));
3015 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3016 }
3017 else if (empty)
3018 *dcd->mask.szMask = 0;
3019 SayFilter(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3020 DIR_FILTER), &dcd->mask, TRUE);
3021 }
3022 break;
3023
3024 case IDM_SWITCH:
3025 if (mp2) {
3026 if (stricmp(dcd->directory, (CHAR *) mp2)) {
3027 DosEnterCritSec();
3028 strcpy(lastextractpath, (CHAR *) mp2);
3029 MakeValidDir(lastextractpath);
3030 DosExitCritSec();
3031 }
3032 strcpy(dcd->directory, (CHAR *) mp2);
3033 MakeValidDir(dcd->directory);
3034 WinSetWindowText(dcd->hwndExtract, dcd->directory);
3035 }
3036 break;
3037
3038 case IDM_WALKDIR:
3039 {
3040 CHAR newdir[CCHMAXPATH];
3041
3042 strcpy(newdir, dcd->directory);
3043 if (!WinDlgBox(HWND_DESKTOP, dcd->hwndParent, WalkExtractDlgProc,
3044 FM3ModHandle, WALK_FRAME,
3045 MPFROMP(newdir)) || !*newdir)
3046 break;
3047 if (stricmp(newdir, dcd->directory)) {
3048 strcpy(dcd->directory, newdir);
3049 if (stricmp(lastextractpath, newdir))
3050 strcpy(lastextractpath, newdir);
3051 WinSetWindowText(dcd->hwndExtract, dcd->directory);
3052 }
3053 }
3054 break;
3055
3056 case IDM_TEST:
3057 if (dcd->info->test)
3058 runemf2(SEPARATEKEEP | WINDOWED | MAXIMIZED,
3059 hwnd, pszSrcFile, __LINE__, NULL, NULL,
3060 "%s %s",dcd->info->test,
3061 BldQuotedFileName(szQuotedArcName, dcd->arcname));
3062 break;
3063
3064 case IDM_REFRESH:
3065 case IDM_DELETE:
3066 case IDM_PRINT:
3067 case IDM_VIEW:
3068 case IDM_VIEWTEXT:
3069 case IDM_VIEWBINARY:
3070 case IDM_VIEWARCHIVE:
3071 case IDM_EDIT:
3072 case IDM_EDITTEXT:
3073 case IDM_EDITBINARY:
3074 case IDM_EXTRACT:
3075 case IDM_EXTRACTWDIRS:
3076 case IDM_FIND:
3077 case IDM_EXEC:
3078 case IDM_VIRUSSCAN:
3079 case IDM_OPENDEFAULT:
3080 case IDM_OPENSETTINGS:
3081 case IDM_MCIPLAY:
3082 {
3083 LISTINFO *li;
3084# ifdef FORTIFY
3085 Fortify_EnterScope();
3086# endif
3087 li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__);
3088 if (li) {
3089 li->type = SHORT1FROMMP(mp1);
3090 li->hwnd = hwnd;
3091 li->list = BuildArcList(hwnd);
3092 if (li->type == IDM_REFRESH) {
3093
3094 CHAR s[CCHMAXPATH], *p;
3095 INT x, y;
3096
3097 for (x = 0; li->list && li->list[x]; x++) {
3098 BldFullPathName(s, dcd->workdir, li->list[x]);
3099 if (IsFile(s) != 1) {
3100 free(li->list[x]);
3101 li->list[x] = NULL;
3102 for (y = x; li->list[y]; y++)
3103 li->list[y] = li->list[y + 1];
3104 li->list =
3105 xrealloc(li->list, y * sizeof(CHAR *), pszSrcFile,
3106 __LINE__);
3107 x--;
3108 }
3109 else {
3110 p = xstrdup(s, pszSrcFile, __LINE__);
3111 if (p) {
3112 free(li->list[x]);
3113 li->list[x] = p;
3114 }
3115 }
3116 } // for
3117 }
3118 strcpy(li->arcname, dcd->arcname);
3119 li->info = dcd->info;
3120 {
3121 PARCITEM pai;
3122
3123 if (SHORT1FROMMP(mp1) != IDM_EXEC)
3124 pai = (PARCITEM) CurrentRecord(hwnd);
3125 else
3126 pai = (PARCITEM) WinSendMsg(hwnd, CM_QUERYRECORDEMPHASIS,
3127 MPFROMLONG(CMA_FIRST),
3128 MPFROMSHORT(CRA_CURSORED));
3129 if (pai && (INT) pai != -1)
3130 strcpy(li->runfile, pai->pszFileName);
3131 else
3132 strcpy(li->runfile, li->list[0]);
3133 }
3134 switch (SHORT1FROMMP(mp1)) {
3135 case IDM_VIEW:
3136 case IDM_VIEWTEXT:
3137 case IDM_VIEWBINARY:
3138 case IDM_VIEWARCHIVE:
3139 case IDM_EDIT:
3140 case IDM_EDITTEXT:
3141 case IDM_EDITBINARY:
3142 case IDM_EXEC:
3143 case IDM_PRINT:
3144 case IDM_VIRUSSCAN:
3145 case IDM_OPENDEFAULT:
3146 case IDM_OPENSETTINGS:
3147 case IDM_MCIPLAY:
3148 strcpy(li->targetpath, dcd->workdir);
3149 break;
3150 default:
3151 strcpy(li->targetpath, dcd->directory);
3152 break;
3153 }
3154 if (li->list) {
3155 if (!PostMsg(dcd->hwndObject, UM_ACTION, MPFROMP(li), MPVOID)) {
3156 Runtime_Error(pszSrcFile, __LINE__, "post");
3157 FreeListInfo(li);
3158 }
3159 else if (fUnHilite && SHORT1FROMMP(mp1) != IDM_EDIT)
3160 UnHilite(hwnd, TRUE, &dcd->lastselection, 0);
3161 }
3162 else {
3163 free(li);
3164 }
3165 }
3166# ifdef FORTIFY
3167 Fortify_LeaveScope();
3168# endif
3169 }
3170 break;
3171 }
3172 }
3173 return 0;
3174
3175 case WM_CONTROL:
3176 DosError(FERR_DISABLEHARDERR);
3177 if (dcd) {
3178 switch (SHORT2FROMMP(mp1)) {
3179 case CN_BEGINEDIT:
3180 PostMsg(hwnd, CM_CLOSEEDIT, MPVOID, MPVOID);
3181 break;
3182
3183 case CN_ENDEDIT:
3184 if (!((PCNREDITDATA) mp2)->pRecord) {
3185
3186 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
3187 USHORT cmd = 0;
3188
3189 if (!pfi || pfi->offStruct == FIELDOFFSET(ARCITEM, pszDisplayName))
3190 cmd = IDM_SORTSMARTNAME;
3191 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, cbFile))
3192 cmd = IDM_SORTSIZE;
3193 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, cbComp))
3194 cmd = IDM_SORTEASIZE;
3195 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, date))
3196 cmd = IDM_SORTLWDATE;
3197 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, time))
3198 cmd = IDM_SORTLWDATE;
3199 if (cmd)
3200 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
3201 }
3202 break;
3203
3204 case CN_DROPHELP:
3205 saymsg(MB_ENTER, hwnd,
3206 GetPString(IDS_DROPHELPHDRTEXT),
3207 GetPString(IDS_ARCCNRDROPHELPTEXT), dcd->arcname);
3208 return 0;
3209
3210 case CN_DRAGLEAVE:
3211 if (mp2) {
3212
3213 PDRAGINFO pDInfo;
3214
3215 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
3216 DrgAccessDraginfo(pDInfo); /* Access DRAGINFO */
3217 DrgFreeDraginfo(pDInfo); /* Free DRAGINFO */
3218 }
3219 return 0;
3220
3221 case CN_DRAGAFTER:
3222 case CN_DRAGOVER:
3223 if (mp2) {
3224
3225 PDRAGITEM pDItem; /* Pointer to DRAGITEM */
3226 PDRAGINFO pDInfo; /* Pointer to DRAGINFO */
3227 PARCITEM pci;
3228
3229 pci = (PARCITEM) ((PCNRDRAGINFO) mp2)->pRecord;
3230 if (SHORT1FROMMP(mp1) == CN_DRAGAFTER)
3231 pci = NULL;
3232 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
3233 DrgAccessDraginfo(pDInfo); /* Access DRAGINFO */
3234 if (*dcd->arcname) {
3235 if ((driveflags[toupper(*dcd->arcname) - 'A'] &
3236 DRIVE_NOTWRITEABLE) || !dcd->info || !dcd->info->create) {
3237 DrgFreeDraginfo(pDInfo);
3238 return MRFROM2SHORT(DOR_NEVERDROP, 0);
3239 }
3240 }
3241 if (pci) {
3242 DrgFreeDraginfo(pDInfo);
3243 return MRFROM2SHORT(DOR_NODROP, 0);
3244 }
3245 pDItem = DrgQueryDragitemPtr(pDInfo, /* Access DRAGITEM */
3246 0); /* Index to DRAGITEM */
3247 if (DrgVerifyRMF(pDItem, /* Check valid rendering */
3248 DRM_OS2FILE, /* mechanisms and data */
3249 NULL) && !(pDItem->fsControl & DC_PREPARE)) {
3250 DrgFreeDraginfo(pDInfo); /* Free DRAGINFO */
3251 return MRFROM2SHORT(DOR_DROP, /* Return okay to drop */
3252 fCopyDefault ? DO_COPY : DO_MOVE);
3253 }
3254 DrgFreeDraginfo(pDInfo); /* Free DRAGINFO */
3255 }
3256 return (MRFROM2SHORT(DOR_NEVERDROP, 0)); /* Drop not valid */
3257
3258 case CN_INITDRAG:
3259 if (mp2) {
3260
3261 BOOL wasemphasized = FALSE;
3262 PCNRDRAGINIT pcd = (PCNRDRAGINIT) mp2;
3263 PARCITEM pci;
3264
3265 if (pcd) {
3266 pci = (PARCITEM) pcd->pRecord;
3267 if (pci) {
3268 if (pci->rc.flRecordAttr & CRA_SELECTED)
3269 wasemphasized = TRUE;
3270 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3271 fSplitStatus && hwndStatus2)
3272 WinSetWindowText(hwndStatus2, GetPString(IDS_DRAGARCMEMTEXT));
3273 if (DoFileDrag(hwnd,
3274 dcd->hwndObject,
3275 mp2, dcd->arcname, NULL, TRUE)) {
3276 if ((fUnHilite && wasemphasized) || dcd->ulItemsToUnHilite)
3277 UnHilite(hwnd, TRUE, &dcd->lastselection, dcd->ulItemsToUnHilite);
3278 }
3279 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3280 fSplitStatus && hwndStatus2) {
3281 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3282 }
3283 }
3284 else {
3285 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3286 fSplitStatus && hwndStatus2)
3287 WinSetWindowText(hwndStatus2,
3288 GetPString(IDS_DRAGARCFILETEXT));
3289 DragOne(hwnd, dcd->hwndObject, dcd->arcname, FALSE);
3290 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3291 fSplitStatus && hwndStatus2)
3292 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3293 }
3294 }
3295 }
3296 return 0;
3297
3298 case CN_DROP:
3299 if (mp2) {
3300
3301 LISTINFO *li;
3302
3303 DosBeep(500, 100); // fixme to know why beep?
3304 li = DoFileDrop(hwnd, dcd->arcname, FALSE, mp1, mp2);
3305 DosBeep(50, 100); // fixme to know why beep?
3306 CheckPmDrgLimit(((PCNRDRAGINFO)mp2)->pDragInfo);
3307 if (li) {
3308 li->type = li->type == DO_MOVE ? IDM_ARCHIVEM : IDM_ARCHIVE;
3309 strcpy(li->targetpath, dcd->arcname);
3310 if (!li->list ||
3311 !li->list[0] ||
3312 !PostMsg(dcd->hwndObject, UM_ACTION, MPFROMP(li), MPVOID))
3313 FreeListInfo(li);
3314 }
3315 }
3316 return 0;
3317
3318 case CN_CONTEXTMENU:
3319 {
3320 PARCITEM pci = (PARCITEM) mp2;
3321
3322 if (pci) {
3323 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPFROMP(pci),
3324 MPFROM2SHORT(TRUE, CRA_CURSORED));
3325 MarkAll(hwnd, FALSE, FALSE, TRUE);
3326 dcd->hwndLastMenu = CheckMenu(hwnd, &ArcMenu, ARC_POPUP);
3327 }
3328 else {
3329 dcd->hwndLastMenu = CheckMenu(hwnd, &ArcCnrMenu, ARCCNR_POPUP);
3330 if (dcd->hwndLastMenu && !dcd->cnremphasized) {
3331 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
3332 MPFROM2SHORT(TRUE, CRA_SOURCE));
3333 dcd->cnremphasized = TRUE;
3334 }
3335 }
3336 if (dcd->hwndLastMenu) {
3337 if (dcd->hwndLastMenu == ArcCnrMenu) {
3338 if (dcd->flWindowAttr & CV_MINI)
3339 WinCheckMenuItem(dcd->hwndLastMenu, IDM_MINIICONS, TRUE);
3340 }
3341 WinCheckMenuItem(dcd->hwndLastMenu, IDM_FOLDERAFTEREXTRACT,
3342 fFolderAfterExtract);
3343 if (!PopupMenu(hwnd, hwnd, dcd->hwndLastMenu)) {
3344 if (dcd->cnremphasized) {
3345 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
3346 MPFROM2SHORT(FALSE, CRA_SOURCE));
3347 dcd->cnremphasized = TRUE;
3348 }
3349 MarkAll(hwnd, TRUE, FALSE, TRUE);
3350 }
3351 }
3352 }
3353 break;
3354
3355 case CN_EMPHASIS:
3356 if (mp2) {
3357
3358 PNOTIFYRECORDEMPHASIS pre = mp2;
3359 PARCITEM pci;
3360 CHAR s[CCHMAXPATHCOMP + 91], tf[81], tb[81];
3361
3362 pci = (PARCITEM)(pre ? pre->pRecord : NULL);
3363 if (!pci) {
3364 if (!ParentIsDesktop(hwnd, dcd->hwndParent)) {
3365 if (hwndStatus2)
3366 WinSetWindowText(hwndStatus2, NullStr);
3367 if (fMoreButtons)
3368 WinSetWindowText(hwndName, NullStr);
3369 }
3370 break;
3371 }
3372 if (pre->fEmphasisMask & CRA_SELECTED) {
3373 if (pci->rc.flRecordAttr & CRA_SELECTED) {
3374 dcd->selectedbytes += pci->cbFile;
3375 dcd->selectedfiles++;
3376 }
3377 else if (dcd->selectedfiles) {
3378 dcd->selectedbytes -= pci->cbFile;
3379 dcd->selectedfiles--;
3380 }
3381 commafmt(tf, sizeof(tf), dcd->selectedfiles);
3382 if (dcd->ullTotalBytes)
3383 CommaFmtULL(tb, sizeof(tb), dcd->selectedbytes, ' ');
3384 else
3385 *tb = 0;
3386 sprintf(s, "%s%s%s", tf, *tb ? " / " : NullStr, tb);
3387 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, s);
3388 }
3389 else if (WinQueryActiveWindow(dcd->hwndParent) ==
3390 dcd->hwndFrame &&
3391 !ParentIsDesktop(hwnd, dcd->hwndParent)) {
3392 if (pre->fEmphasisMask & CRA_CURSORED) {
3393 if (pci->rc.flRecordAttr & CRA_CURSORED) {
3394 if (fSplitStatus && hwndStatus2) {
3395 if (dcd->ullTotalBytes)
3396 CommaFmtULL(tb, sizeof(tb), pci->cbFile, ' ');
3397 else
3398 *tb = 0;
3399 sprintf(s, "%s%s%s%s",
3400 *tb ? " " : NullStr,
3401 tb, *tb ? " " : NullStr, pci->pszFileName);
3402 WinSetWindowText(hwndStatus2, s);
3403 }
3404 if (fMoreButtons)
3405 WinSetWindowText(hwndName, pci->pszFileName);
3406 }
3407 }
3408 }
3409 }
3410 break;
3411
3412 case CN_ENTER:
3413 if (mp2) {
3414
3415 PARCITEM pci = (PARCITEM) ((PNOTIFYRECORDENTER) mp2)->pRecord;
3416
3417 if (pci) {
3418
3419 CHAR *s;
3420
3421 if ((pci->rc.flRecordAttr & CRA_INUSE) ||
3422 (pci->flags & (ARCFLAGS_REALDIR | ARCFLAGS_PSEUDODIR)))
3423 break;
3424 s = xstrdup(pci->pszFileName, pszSrcFile, __LINE__);
3425 if (s) {
3426 if (!PostMsg(dcd->hwndObject, UM_ENTER, MPFROMP(s), MPVOID)) {
3427 Runtime_Error(pszSrcFile, __LINE__, "post");
3428 free(s);
3429 }
3430 }
3431 }
3432 }
3433 break;
3434 }
3435 }
3436 return 0;
3437
3438 case UM_FOLDUP:
3439 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
3440 DosExit(EXIT_PROCESS, 1);
3441 return 0;
3442
3443 case UM_CLOSE:
3444 WinDestroyWindow(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
3445 QW_PARENT));
3446 return 0;
3447
3448 case WM_SAVEAPPLICATION:
3449 if (dcd && ParentIsDesktop(hwnd, dcd->hwndParent)) {
3450 SWP swp;
3451
3452 WinQueryWindowPos(dcd->hwndFrame, &swp);
3453 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE | SWP_MAXIMIZE)))
3454 PrfWriteProfileData(fmprof, appname, "AV2SizePos", &swp, sizeof(swp));
3455 }
3456 break;
3457
3458 case WM_CLOSE:
3459 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
3460 if (dcd)
3461 dcd->stopflag++;
3462 if (dcd && dcd->hwndObject) {
3463 if (!PostMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID))
3464 WinSendMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID);
3465 }
3466 // In case object window frees dcd
3467 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
3468 if (!dcd ||
3469 (!dcd->dontclose &&
3470 !dcd->amextracted && ParentIsDesktop(hwnd, dcd->hwndParent))) {
3471 if (!PostMsg(hwnd, UM_FOLDUP, MPVOID, MPVOID))
3472 WinSendMsg(hwnd, UM_FOLDUP, MPVOID, MPVOID);
3473 }
3474 return 0;
3475
3476 case WM_DESTROY:
3477 if (ArcMenu)
3478 WinDestroyWindow(ArcMenu);
3479 if (ArcCnrMenu)
3480 WinDestroyWindow(ArcCnrMenu);
3481 ArcMenu = ArcCnrMenu = (HWND) 0;
3482 EmptyArcCnr(hwnd);
3483# ifdef FORTIFY
3484 Fortify_LeaveScope();
3485# endif
3486 break;
3487 }
3488 if (dcd && dcd->oldproc){
3489 return dcd->oldproc(hwnd, msg, mp1, mp2);
3490 }
3491 else
3492 return PFNWPCnr(hwnd, msg, mp1, mp2);
3493}
3494
3495MRESULT EXPENTRY ArcCnrMenuProc(HWND hwnd, ULONG msg, MPARAM mp1,
3496 MPARAM mp2)
3497{
3498 PFNWP oldMenuProc = WinQueryWindowPtr(hwnd, QWL_USER);
3499 static short sLastMenuitem;
3500
3501 switch (msg) {
3502 case WM_MOUSEMOVE: {
3503 if (fOtherHelp) {
3504 RECTL rectl;
3505 SHORT i, sCurrentMenuitem;
3506 SHORT MenuItems = 10;
3507 SHORT asMenuIDs[10] = {IDM_VIEW,
3508 IDM_DELETE,
3509 IDM_EXEC,
3510 IDM_EXTRACT,
3511 IDM_TEST,
3512 IDM_VIRUSSCAN,
3513 IDM_RESCAN,
3514 IDM_WALKDIR,
3515 IDM_FILTER,
3516 0};
3517 char *szHelpString = NULL;
3518
3519
3520 for (i=0; i<MenuItems; i++) {
3521 sCurrentMenuitem = asMenuIDs[i];
3522 oldMenuProc(hwnd,MM_QUERYITEMRECT,
3523 MPFROM2SHORT(asMenuIDs[i], FALSE),
3524 &rectl);
3525
3526 if (MOUSEMSG(&msg)->x > rectl.xLeft &&
3527 MOUSEMSG(&msg)->x < rectl.xRight &&
3528 MOUSEMSG(&msg)->y > rectl.yBottom &&
3529 MOUSEMSG(&msg)->y < rectl.yTop)
3530 break;
3531 } // for
3532
3533
3534 switch (sCurrentMenuitem) {
3535 case 0:
3536 break;
3537 case IDM_VIEW:
3538 szHelpString = GetPString(IDS_ARCCNRVIEWMENUHELP);
3539 break;
3540 case IDM_DELETE:
3541 szHelpString = GetPString(IDS_ARCCNRDELETEMENUHELP);
3542 break;
3543 case IDM_EXEC:
3544 szHelpString = GetPString(IDS_ARCCNREXECMENUHELP);
3545 break;
3546 case IDM_EXTRACT:
3547 szHelpString = GetPString(IDS_ARCCNREXTRACTMENUHELP);
3548 break;
3549 case IDM_TEST:
3550 szHelpString = GetPString(IDS_ARCCNRTESTMENUHELP);
3551 break;
3552 case IDM_VIRUSSCAN:
3553 szHelpString = GetPString(IDS_ARCCNRVIRUSMENUHELP);
3554 break;
3555 case IDM_RESCAN:
3556 szHelpString = GetPString(IDS_ARCCNRRESCANMENUHELP);
3557 break;
3558 case IDM_WALKDIR:
3559 szHelpString = GetPString(IDS_ARCCNRWALKDIRMENUHELP);
3560 break;
3561 case IDM_FILTER:
3562 szHelpString = GetPString(IDS_ARCCNRFILTERMENUHELP);
3563 break;
3564 default:
3565 break;
3566 }
3567
3568 if (sLastMenuitem != sCurrentMenuitem && szHelpString) {
3569 sLastMenuitem = sCurrentMenuitem;
3570 MakeBubble(hwnd, TRUE, szHelpString);
3571 }
3572 else if (hwndBubble && !sCurrentMenuitem){
3573 sLastMenuitem = sCurrentMenuitem;
3574 WinDestroyWindow(hwndBubble);
3575 }
3576 }
3577 }
3578 }
3579 return oldMenuProc(hwnd, msg, mp1, mp2);
3580}
3581
3582HWND StartArcCnr(HWND hwndParent, HWND hwndCaller, CHAR * arcname, INT flags,
3583 ARC_TYPE * sinfo)
3584{
3585 /*
3586 * bitmapped flags:
3587 * 1 = am extracted from another archive
3588 * 4 = don't kill proc on close
3589 */
3590
3591 HWND hwndFrame = (HWND) 0, hwndClient;
3592 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
3593 FCF_SIZEBORDER | FCF_MINMAX | FCF_ICON | FCF_NOBYTEALIGN | FCF_ACCELTABLE;
3594 USHORT id;
3595 DIRCNRDATA *dcd;
3596 ARC_TYPE *info = sinfo;
3597 CHAR title[MAXNAMEL + 1] = "AV/2 - ";
3598 CHAR fullname[CCHMAXPATH + 8], *p, temp;
3599 static USHORT idinc = 0;
3600
3601 if (!idinc)
3602 idinc = (rand() % 256);
3603 if (ParentIsDesktop(hwndParent, hwndParent))
3604 FrameFlags |= (FCF_TASKLIST | FCF_MENU);
3605 if (arcname) {
3606 DosError(FERR_DISABLEHARDERR);
3607 if (DosQueryPathInfo(arcname,
3608 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
3609 strcpy(fullname, arcname);
3610 p = fullname;
3611 while (*p) {
3612 if (*p == '/')
3613 *p = '\\';
3614 p++;
3615 }
3616 if (!info)
3617 info = find_type(fullname, arcsighead);
3618 if (!info)
3619 return hwndFrame;
3620 if (strlen(title) + strlen(fullname) > MAXNAMEL) {
3621 p = title + strlen(title);
3622 strncpy(p, fullname, MAXNAMEL / 2 - 5);
3623 strcpy(p + MAXNAMEL / 2 - 5, "...");
3624 strcat(title, fullname + strlen(fullname) - (MAXNAMEL / 2 - 5));
3625 }
3626 else {
3627 strcat(title, fullname);
3628 }
3629 hwndFrame = WinCreateStdWindow(hwndParent,
3630 WS_VISIBLE,
3631 &FrameFlags,
3632 WC_ARCCONTAINER,
3633 title,
3634 WS_VISIBLE | fwsAnimate,
3635 FM3ModHandle, ARC_FRAME, &hwndClient);
3636 if (hwndFrame && hwndClient) {
3637 id = ARC_FRAME + idinc++;
3638 if (idinc > 512)
3639 idinc = 0;
3640 WinSetWindowUShort(hwndFrame, QWS_ID, id);
3641# ifdef FORTIFY
3642 Fortify_EnterScope();
3643# endif
3644 dcd = xmallocz(sizeof(DIRCNRDATA), pszSrcFile, __LINE__);
3645 if (!dcd) {
3646 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3647 hwndFrame = (HWND) 0;
3648 }
3649 else {
3650 dcd->size = sizeof(DIRCNRDATA);
3651 dcd->id = id;
3652 dcd->type = ARC_FRAME;
3653 if (!pTmpDir)
3654 strcpy(dcd->workdir, pFM2SaveDirectory);
3655 MakeTempName(dcd->workdir, ArcTempRoot, 2);
3656 /*if (dcd->workdir[strlen(dcd->workdir) - 1] != '\\')
3657 strcat(dcd->workdir, "\\");
3658 sprintf(dcd->workdir + strlen(dcd->workdir), "%s.%03x",
3659 ArcTempRoot, (clock() & 4095));
3660 else
3661 sprintf(dcd->workdir, "%s.%03x",
3662 ArcTempRoot, (clock() & 4095));*/
3663 strcpy(dcd->arcname, fullname);
3664 if (*extractpath) {
3665 if (!strcmp(extractpath, "*")) {
3666 p = strrchr(fullname, '\\');
3667 if (p) {
3668 if (p < fullname + 3)
3669 p++;
3670 temp = *p;
3671 *p = 0;
3672 strcpy(dcd->directory, fullname);
3673 *p = temp;
3674 }
3675 }
3676 else
3677 strcpy(dcd->directory, extractpath);
3678 }
3679 if (!*dcd->directory && *lastextractpath) {
3680 DosEnterCritSec();
3681 strcpy(dcd->directory, lastextractpath);
3682 DosExitCritSec();
3683 }
3684 if (!*dcd->directory) {
3685 if (!ParentIsDesktop(hwndParent, hwndParent))
3686 TopWindowName(hwndParent, hwndCaller, dcd->directory);
3687 if (!*dcd->directory) {
3688 p = strrchr(fullname, '\\');
3689 if (p) {
3690 if (p < fullname + 3)
3691 p++;
3692 *p = 0;
3693 strcpy(dcd->directory, fullname);
3694 }
3695 }
3696 }
3697 if (!*dcd->directory ||
3698 IsFile(dcd->directory) ||
3699 (isalpha(*dcd->directory) &&
3700 (driveflags[toupper(*dcd->directory) - 'A'] &
3701 DRIVE_NOTWRITEABLE)))
3702 strcpy(dcd->directory, pFM2SaveDirectory);
3703 dcd->hwndParent = hwndParent ? hwndParent : HWND_DESKTOP;
3704 dcd->hwndFrame = hwndFrame;
3705 dcd->hwndClient = hwndClient;
3706 dcd->amextracted = (flags & 1) != 0;
3707 dcd->dontclose = (flags & 4) != 0;
3708 dcd->info = info;
3709 dcd->sortFlags = DefArcSortFlags;
3710 {
3711 PFNWP oldproc;
3712
3713 oldproc = WinSubclassWindow(hwndFrame, (PFNWP) ArcFrameWndProc);
3714 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
3715 }
3716 dcd->hwndCnr = WinCreateWindow(hwndClient,
3717 WC_CONTAINER,
3718 NULL,
3719 CCS_AUTOPOSITION | CCS_MINIICONS |
3720 CCS_MINIRECORDCORE | ulCnrType |
3721 WS_VISIBLE,
3722 0,
3723 0,
3724 0,
3725 0,
3726 hwndClient,
3727 HWND_TOP, (ULONG) ARC_CNR, NULL, NULL);
3728 if (!dcd->hwndCnr) {
3729 Win_Error2(hwndClient, hwndClient, pszSrcFile, __LINE__,
3730 IDS_WINCREATEWINDOW);
3731 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3732 free(dcd);
3733 hwndFrame = (HWND) 0;
3734 }
3735 else {
3736 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, (PVOID) dcd);
3737 dcd->oldproc = WinSubclassWindow(dcd->hwndCnr,
3738 (PFNWP) ArcCnrWndProc);
3739 {
3740 USHORT ids[] = { DIR_TOTALS, DIR_SELECTED, DIR_VIEW, DIR_SORT,
3741 DIR_FILTER, DIR_FOLDERICON, 0
3742 };
3743
3744 CommonCreateTextChildren(dcd->hwndClient,
3745 WC_ARCSTATUS, ids);
3746 }
3747 WinEnableWindow(WinWindowFromID(dcd->hwndClient, DIR_VIEW), FALSE);
3748 dcd->hwndExtract = WinCreateWindow(dcd->hwndClient,
3749 WC_ENTRYFIELD,
3750 NULL,
3751 ES_AUTOSCROLL,
3752 0,
3753 0,
3754 0,
3755 0,
3756 dcd->hwndClient,
3757 HWND_TOP,
3758 ARC_EXTRACTDIR, NULL, NULL);
3759 WinSendMsg(dcd->hwndExtract,
3760 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
3761 WinSetWindowText(dcd->hwndExtract, dcd->directory);
3762 if (!PostMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID))
3763 WinSendMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID);
3764 if (FrameFlags & FCF_MENU) {
3765 PFNWP oldmenuproc;
3766 HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
3767
3768 oldmenuproc = WinSubclassWindow(hwndMenu, (PFNWP) ArcCnrMenuProc);
3769 WinSetWindowPtr(hwndMenu, QWL_USER, (PVOID) oldmenuproc);
3770 if (!fToolbar) {
3771
3772 if (hwndMenu) {
3773 WinSendMsg(hwndMenu, MM_DELETEITEM,
3774 MPFROM2SHORT(IDM_VIEW, FALSE), MPVOID);
3775 WinSendMsg(hwndMenu, MM_DELETEITEM,
3776 MPFROM2SHORT(IDM_EXEC, FALSE), MPVOID);
3777 WinSendMsg(hwndMenu, MM_DELETEITEM,
3778 MPFROM2SHORT(IDM_RESCAN, FALSE), MPVOID);
3779 WinSendMsg(hwndMenu, MM_DELETEITEM,
3780 MPFROM2SHORT(IDM_DELETE, FALSE), MPVOID);
3781 WinSendMsg(hwndMenu, MM_DELETEITEM,
3782 MPFROM2SHORT(IDM_EXTRACT, FALSE), MPVOID);
3783 WinSendMsg(hwndMenu, MM_DELETEITEM,
3784 MPFROM2SHORT(IDM_TEST, FALSE), MPVOID);
3785 WinSendMsg(hwndMenu, MM_DELETEITEM,
3786 MPFROM2SHORT(IDM_VIRUSSCAN, FALSE), MPVOID);
3787 WinSendMsg(hwndMenu, MM_DELETEITEM,
3788 MPFROM2SHORT(IDM_WALKDIR, FALSE), MPVOID);
3789 WinSendMsg(hwndMenu, MM_DELETEITEM,
3790 MPFROM2SHORT(IDM_FILTER, FALSE), MPVOID);
3791 }
3792 }
3793 }
3794 if (FrameFlags & FCF_TASKLIST) {
3795
3796 SWP swp, swpD;
3797 ULONG size = sizeof(swp);
3798 LONG cxScreen, cyScreen;
3799
3800 WinQueryTaskSizePos(WinQueryAnchorBlock(hwndFrame), 0, &swp);
3801 if (PrfQueryProfileData(fmprof,
3802 appname, "AV2SizePos", &swpD, &size)) {
3803 cxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
3804 cyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
3805 if (swp.x + swpD.cx > cxScreen)
3806 swp.x = cxScreen - swpD.cx;
3807 if (swp.y + swpD.cy > cyScreen)
3808 swp.y = cyScreen - swpD.cy;
3809 swp.cx = swpD.cx;
3810 swp.cy = swpD.cy;
3811 }
3812 WinSetWindowPos(hwndFrame,
3813 HWND_TOP,
3814 swp.x,
3815 swp.y,
3816 swp.cx,
3817 swp.cy,
3818 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER |
3819 SWP_ACTIVATE);
3820 }
3821 }
3822 }
3823# ifdef FORTIFY
3824 Fortify_LeaveScope();
3825# endif
3826 }
3827 }
3828 return hwndFrame;
3829}
3830
3831#pragma alloc_text(ARCCNRS,ArcCnrWndProc,ArcObjWndProc,ArcClientWndProc,BldQuotedFullPathName)
3832#pragma alloc_text(ARCCNRS,ArcTextProc,FillArcCnr,ArcFilter,BldQuotedFileName)
3833#pragma alloc_text(ARCCNRS,ArcSort,ArcFrameWndProc,IsArcThere,ArcErrProc)
3834#pragma alloc_text(STARTUP,StartArcCnr)
Note: See TracBrowser for help on using the repository browser.