source: trunk/dll/arccnrs.c@ 1413

Last change on this file since 1413 was 1413, checked in by Gregg Young, 16 years ago

Fixed select/deselect mask and filtering for wildcards without \ or / in them for archives with path names.

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