source: trunk/dll/arccnrs.c@ 1690

Last change on this file since 1690 was 1690, checked in by Gregg Young, 12 years ago

Changes to fix .tar.gz list because of changes in tar 1.20 (maybe earlier). Added lzip support with ungly hack to work around its lack of a list option. Tickets 493, 494

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