source: trunk/dll/arccnrs.c@ 1301

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

Add flag to tell CheckListProc file is in an archive so it won't try to open it. (Ticket 283) Part of remove or replace with a mutex semaphore DosEnterCriSec where appropriate. (Ticket 308)

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