source: trunk/dll/arccnrs.c@ 1314

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

Subdirectory from the arcname for the extract path only created if an extract menu option is selected. (Ticket 22)

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