source: trunk/dll/arccnrs.c@ 1271

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

A fix for the ticket 58 hang which runs runemf2 with the WAIT flag in a separate thread. This appears to fix Ticket 58 for all cases. Removed semaphore fix and reverted hTermQSem code.

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