source: trunk/dll/arccnrs.c@ 1334

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

Remove DosSleep that should be redundant with the addition of WAIT to runemf2 flags for view, edit etc from arc container.

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