source: trunk/dll/arccnrs.c@ 1692

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

Fix failure to create directory from archive file name when the name had a space. Strip extra leading " in extract and remove it from the arc container since it wasn't selectable and doesn't really make sense in that context (at least to me) Ticket 495

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 106.5 KB
Line 
1
2/***********************************************************************
3
4 $Id: arccnrs.c 1692 2013-08-11 17:11:59Z 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 //DbgMsg(pszSrcFile, __LINE__, "Extract dir %s", dcd->directory);
2966 SetDir(dcd->hwndParent, hwnd, dcd->directory, 1);
2967 }
2968 if (dcd->info->extract)
2969 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
2970 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
2971 hwnd, pszSrcFile, __LINE__,
2972 dcd->directory, NULL, "%s %s", dcd->info->extract,
2973 BldQuotedFileName(szQuotedArcName, dcd->arcname));
2974 if (SHORT1FROMMP(mp1) == IDM_ARCEXTRACTEXIT)
2975 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2976 break;
2977
2978 case IDM_ARCEXTRACTWDIRSEXIT:
2979 case IDM_ARCEXTRACTWDIRS:
2980 if (dcd->directory && fFileNameCnrPath &&
2981 stricmp(lastextractpath, dcd->directory)) {
2982 strcpy(lastextractpath, dcd->directory);
2983 SetDir(dcd->hwndParent, hwnd, dcd->directory, 1);
2984 }
2985 if (dcd->info->exwdirs)
2986 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
2987 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
2988 hwnd, pszSrcFile, __LINE__,
2989 dcd->directory, NULL, "%s %s",
2990 dcd->info->exwdirs,
2991 BldQuotedFileName(szQuotedArcName, dcd->arcname));
2992 if (SHORT1FROMMP(mp1) == IDM_ARCEXTRACTWDIRSEXIT)
2993 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2994 break;
2995
2996 case IDM_RESORT:
2997 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(ArcSort), MPFROMP(dcd));
2998 break;
2999
3000 case IDM_FILTER:
3001 {
3002 BOOL empty = FALSE;
3003 PARCITEM pci;
3004
3005 if (!*dcd->mask.szMask) {
3006 empty = TRUE;
3007 pci = (PARCITEM) CurrentRecord(hwnd);
3008 if (pci && strchr(pci->pszFileName, '.'))
3009 strcpy(dcd->mask.szMask, pci->pszFileName);
3010 }
3011
3012 if (WinDlgBox(HWND_DESKTOP, hwnd, PickMaskDlgProc,
3013 FM3ModHandle, MSK_FRAME, MPFROMP(&dcd->mask))) {
3014 WinSendMsg(hwnd, CM_FILTER, MPFROMP(ArcFilter), MPFROMP(dcd));
3015 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3016 }
3017 else if (empty)
3018 *dcd->mask.szMask = 0;
3019 SayFilter(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3020 DIR_FILTER), &dcd->mask, TRUE);
3021 }
3022 break;
3023
3024 case IDM_SWITCH:
3025 if (mp2) {
3026 if (stricmp(dcd->directory, (CHAR *) mp2)) {
3027 //DosEnterCritSec(); //GKY 11-29-08
3028 DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
3029 strcpy(lastextractpath, (CHAR *) mp2);
3030 MakeValidDir(lastextractpath);
3031 DosReleaseMutexSem(hmtxFM2Globals);
3032 //DosExitCritSec();
3033 }
3034 strcpy(dcd->directory, (CHAR *) mp2);
3035 MakeValidDir(dcd->directory);
3036 WinSetWindowText(dcd->hwndExtract, dcd->directory);
3037 }
3038 break;
3039
3040 case IDM_WALKDIR:
3041 {
3042 CHAR newdir[CCHMAXPATH];
3043
3044 strcpy(newdir, dcd->directory);
3045 if (!WinDlgBox(HWND_DESKTOP, dcd->hwndParent, WalkExtractDlgProc,
3046 FM3ModHandle, WALK_FRAME,
3047 MPFROMP(newdir)) || !*newdir)
3048 break;
3049 if (stricmp(newdir, dcd->directory)) {
3050 strcpy(dcd->directory, newdir);
3051 if (stricmp(lastextractpath, newdir))
3052 strcpy(lastextractpath, newdir);
3053 WinSetWindowText(dcd->hwndExtract, dcd->directory);
3054 }
3055 }
3056 break;
3057
3058 case IDM_TEST:
3059 if (dcd->info->test)
3060 runemf2(SEPARATEKEEP | WINDOWED | MAXIMIZED,
3061 hwnd, pszSrcFile, __LINE__, NULL, NULL,
3062 "%s %s",dcd->info->test,
3063 BldQuotedFileName(szQuotedArcName, dcd->arcname));
3064 break;
3065
3066 case IDM_REFRESH:
3067 case IDM_DELETE:
3068 case IDM_PRINT:
3069 case IDM_VIEW:
3070 case IDM_VIEWTEXT:
3071 case IDM_VIEWBINARY:
3072 case IDM_VIEWARCHIVE:
3073 case IDM_EDIT:
3074 case IDM_EDITTEXT:
3075 case IDM_EDITBINARY:
3076 case IDM_EXTRACT:
3077 case IDM_EXTRACTWDIRS:
3078 case IDM_FIND:
3079 case IDM_EXEC:
3080 case IDM_VIRUSSCAN:
3081 case IDM_OPENDEFAULT:
3082 case IDM_OPENSETTINGS:
3083 case IDM_MCIPLAY:
3084 {
3085 LISTINFO *li;
3086# ifdef FORTIFY
3087 Fortify_EnterScope();
3088# endif
3089 li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__);
3090 if (li) {
3091 li->type = SHORT1FROMMP(mp1);
3092 li->hwnd = hwnd;
3093 li->list = BuildArcList(hwnd);
3094 if (li->type == IDM_REFRESH) {
3095
3096 CHAR s[CCHMAXPATH], *p;
3097 INT x, y;
3098
3099 for (x = 0; li->list && li->list[x]; x++) {
3100 BldFullPathName(s, dcd->workdir, li->list[x]);
3101 if (IsFile(s) != 1) {
3102 free(li->list[x]);
3103 li->list[x] = NULL;
3104 for (y = x; li->list[y]; y++)
3105 li->list[y] = li->list[y + 1];
3106 li->list =
3107 xrealloc(li->list, y * sizeof(CHAR *), pszSrcFile,
3108 __LINE__);
3109 x--;
3110 }
3111 else {
3112 p = xstrdup(s, pszSrcFile, __LINE__);
3113 if (p) {
3114 free(li->list[x]);
3115 li->list[x] = p;
3116 }
3117 }
3118 } // for
3119 }
3120 strcpy(li->arcname, dcd->arcname);
3121 li->info = dcd->info;
3122 {
3123 PARCITEM pai;
3124
3125 if (SHORT1FROMMP(mp1) != IDM_EXEC)
3126 pai = (PARCITEM) CurrentRecord(hwnd);
3127 else
3128 pai = (PARCITEM) WinSendMsg(hwnd, CM_QUERYRECORDEMPHASIS,
3129 MPFROMLONG(CMA_FIRST),
3130 MPFROMSHORT(CRA_CURSORED));
3131 if (pai && (INT) pai != -1)
3132 strcpy(li->runfile, pai->pszFileName);
3133 else
3134 strcpy(li->runfile, li->list[0]);
3135 }
3136 switch (SHORT1FROMMP(mp1)) {
3137 case IDM_VIEW:
3138 case IDM_VIEWTEXT:
3139 case IDM_VIEWBINARY:
3140 case IDM_VIEWARCHIVE:
3141 case IDM_EDIT:
3142 case IDM_EDITTEXT:
3143 case IDM_EDITBINARY:
3144 case IDM_EXEC:
3145 case IDM_PRINT:
3146 case IDM_VIRUSSCAN:
3147 case IDM_OPENDEFAULT:
3148 case IDM_OPENSETTINGS:
3149 case IDM_MCIPLAY:
3150 strcpy(li->targetpath, dcd->workdir);
3151 break;
3152 default:
3153 strcpy(li->targetpath, dcd->directory);
3154 break;
3155 }
3156 if (li->list) {
3157 if (!PostMsg(dcd->hwndObject, UM_ACTION, MPFROMP(li), MPVOID)) {
3158 Runtime_Error(pszSrcFile, __LINE__, "post");
3159 FreeListInfo(li);
3160 }
3161 else if (fUnHilite && SHORT1FROMMP(mp1) != IDM_EDIT)
3162 UnHilite(hwnd, TRUE, &dcd->lastselection, 0);
3163 }
3164 else {
3165 free(li);
3166 }
3167 }
3168# ifdef FORTIFY
3169 Fortify_LeaveScope();
3170# endif
3171 }
3172 break;
3173 }
3174 }
3175 return 0;
3176
3177 case WM_CONTROL:
3178 DosError(FERR_DISABLEHARDERR);
3179 if (dcd) {
3180 switch (SHORT2FROMMP(mp1)) {
3181 case CN_BEGINEDIT:
3182 PostMsg(hwnd, CM_CLOSEEDIT, MPVOID, MPVOID);
3183 break;
3184
3185 case CN_ENDEDIT:
3186 if (!((PCNREDITDATA) mp2)->pRecord) {
3187
3188 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
3189 USHORT cmd = 0;
3190
3191 if (!pfi || pfi->offStruct == FIELDOFFSET(ARCITEM, pszDisplayName))
3192 cmd = IDM_SORTSMARTNAME;
3193 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, cbFile))
3194 cmd = IDM_SORTSIZE;
3195 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, cbComp))
3196 cmd = IDM_SORTEASIZE;
3197 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, date))
3198 cmd = IDM_SORTLWDATE;
3199 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, time))
3200 cmd = IDM_SORTLWDATE;
3201 if (cmd)
3202 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
3203 }
3204 break;
3205
3206 case CN_DROPHELP:
3207 saymsg(MB_ENTER, hwnd,
3208 GetPString(IDS_DROPHELPHDRTEXT),
3209 GetPString(IDS_ARCCNRDROPHELPTEXT), dcd->arcname);
3210 return 0;
3211
3212 case CN_DRAGLEAVE:
3213 if (mp2) {
3214
3215 PDRAGINFO pDInfo;
3216
3217 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
3218 DrgAccessDraginfo(pDInfo); // Access DRAGINFO
3219 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
3220 }
3221 return 0;
3222
3223 case CN_DRAGAFTER:
3224 case CN_DRAGOVER:
3225 if (mp2) {
3226
3227 PDRAGITEM pDItem; // Pointer to DRAGITEM
3228 PDRAGINFO pDInfo; // Pointer to DRAGINFO
3229 PARCITEM pci;
3230
3231 pci = (PARCITEM) ((PCNRDRAGINFO) mp2)->pRecord;
3232 if (SHORT1FROMMP(mp1) == CN_DRAGAFTER)
3233 pci = NULL;
3234 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
3235 DrgAccessDraginfo(pDInfo); // Access DRAGINFO
3236 if (*dcd->arcname) {
3237 if ((driveflags[toupper(*dcd->arcname) - 'A'] &
3238 DRIVE_NOTWRITEABLE) || !dcd->info || !dcd->info->create) {
3239 DrgFreeDraginfo(pDInfo);
3240 return MRFROM2SHORT(DOR_NEVERDROP, 0);
3241 }
3242 }
3243 if (pci) {
3244 DrgFreeDraginfo(pDInfo);
3245 return MRFROM2SHORT(DOR_NODROP, 0);
3246 }
3247 pDItem = DrgQueryDragitemPtr(pDInfo, // Access DRAGITEM
3248 0); // Index to DRAGITEM
3249 if (DrgVerifyRMF(pDItem, // Check valid rendering
3250 (CHAR *) DRM_OS2FILE, // mechanisms and data
3251 NULL) && !(pDItem->fsControl & DC_PREPARE)) {
3252 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
3253 return MRFROM2SHORT(DOR_DROP, // Return okay to drop
3254 fCopyDefault ? DO_COPY : DO_MOVE);
3255 }
3256 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
3257 }
3258 return (MRFROM2SHORT(DOR_NEVERDROP, 0)); // Drop not valid
3259
3260 case CN_INITDRAG:
3261 if (mp2) {
3262
3263 BOOL wasemphasized = FALSE;
3264 PCNRDRAGINIT pcd = (PCNRDRAGINIT) mp2;
3265 PARCITEM pci;
3266
3267 if (pcd) {
3268 pci = (PARCITEM) pcd->pRecord;
3269 if (pci) {
3270 if (pci->rc.flRecordAttr & CRA_SELECTED)
3271 wasemphasized = TRUE;
3272 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3273 fSplitStatus && hwndStatus2)
3274 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_DRAGARCMEMTEXT));
3275 if (DoFileDrag(hwnd,
3276 dcd->hwndObject,
3277 mp2, dcd->arcname, NULL, TRUE)) {
3278 if ((fUnHilite && wasemphasized) || dcd->ulItemsToUnHilite)
3279 UnHilite(hwnd, TRUE, &dcd->lastselection, dcd->ulItemsToUnHilite);
3280 }
3281 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3282 fSplitStatus && hwndStatus2) {
3283 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3284 }
3285 }
3286 else {
3287 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3288 fSplitStatus && hwndStatus2)
3289 WinSetWindowText(hwndStatus2,
3290 (CHAR *) GetPString(IDS_DRAGARCFILETEXT));
3291 DragOne(hwnd, dcd->hwndObject, dcd->arcname, FALSE);
3292 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3293 fSplitStatus && hwndStatus2)
3294 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3295 }
3296 }
3297 }
3298 return 0;
3299
3300 case CN_DROP:
3301 if (mp2) {
3302
3303 LISTINFO *li;
3304
3305 //DosBeep(500, 100); // fixme to know why beep?
3306 li = DoFileDrop(hwnd, dcd->arcname, FALSE, mp1, mp2);
3307 //DosBeep(50, 100); // fixme to know why beep?
3308 CheckPmDrgLimit(((PCNRDRAGINFO)mp2)->pDragInfo);
3309 if (li) {
3310 li->type = li->type == DO_MOVE ? IDM_ARCHIVEM : IDM_ARCHIVE;
3311 strcpy(li->targetpath, dcd->arcname);
3312 if (!li->list ||
3313 !li->list[0] ||
3314 !PostMsg(dcd->hwndObject, UM_ACTION, MPFROMP(li), MPVOID))
3315 FreeListInfo(li);
3316 }
3317 }
3318 return 0;
3319
3320 case CN_CONTEXTMENU:
3321 {
3322 PARCITEM pci = (PARCITEM) mp2;
3323
3324 if (pci) {
3325 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPFROMP(pci),
3326 MPFROM2SHORT(TRUE, CRA_CURSORED));
3327 MarkAll(hwnd, FALSE, FALSE, TRUE);
3328 dcd->hwndLastMenu = CheckMenu(hwnd, &ArcMenu, ARC_POPUP);
3329 }
3330 else {
3331 dcd->hwndLastMenu = CheckMenu(hwnd, &ArcCnrMenu, ARCCNR_POPUP);
3332 if (dcd->hwndLastMenu && !dcd->cnremphasized) {
3333 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
3334 MPFROM2SHORT(TRUE, CRA_SOURCE));
3335 dcd->cnremphasized = TRUE;
3336 }
3337 }
3338 if (dcd->hwndLastMenu) {
3339 if (dcd->hwndLastMenu == ArcCnrMenu) {
3340 if (dcd->flWindowAttr & CV_MINI)
3341 WinCheckMenuItem(dcd->hwndLastMenu, IDM_MINIICONS, TRUE);
3342 }
3343 WinCheckMenuItem(dcd->hwndLastMenu, IDM_FOLDERAFTEREXTRACT,
3344 fFolderAfterExtract);
3345 if (!PopupMenu(hwnd, hwnd, dcd->hwndLastMenu)) {
3346 if (dcd->cnremphasized) {
3347 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
3348 MPFROM2SHORT(FALSE, CRA_SOURCE));
3349 dcd->cnremphasized = TRUE;
3350 }
3351 MarkAll(hwnd, TRUE, FALSE, TRUE);
3352 }
3353 }
3354 }
3355 break;
3356
3357 case CN_EMPHASIS:
3358 if (mp2) {
3359
3360 PNOTIFYRECORDEMPHASIS pre = mp2;
3361 PARCITEM pci;
3362 CHAR s[CCHMAXPATHCOMP + 91], tf[81], tb[81];
3363
3364 pci = (PARCITEM)(pre ? pre->pRecord : NULL);
3365 if (!pci) {
3366 if (!ParentIsDesktop(hwnd, dcd->hwndParent)) {
3367 if (hwndStatus2)
3368 WinSetWindowText(hwndStatus2, NullStr);
3369 if (fMoreButtons)
3370 WinSetWindowText(hwndName, NullStr);
3371 }
3372 break;
3373 }
3374 if (pre->fEmphasisMask & CRA_SELECTED) {
3375 if (pci->rc.flRecordAttr & CRA_SELECTED) {
3376 dcd->selectedbytes += pci->cbFile;
3377 dcd->selectedfiles++;
3378 }
3379 else if (dcd->selectedfiles) {
3380 dcd->selectedbytes -= pci->cbFile;
3381 dcd->selectedfiles--;
3382 }
3383 commafmt(tf, sizeof(tf), dcd->selectedfiles);
3384 if (dcd->ullTotalBytes)
3385 CommaFmtULL(tb, sizeof(tb), dcd->selectedbytes, ' ');
3386 else
3387 *tb = 0;
3388 sprintf(s, "%s%s%s", tf, *tb ? " / " : NullStr, tb);
3389 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, s);
3390 }
3391 else if (WinQueryActiveWindow(dcd->hwndParent) ==
3392 dcd->hwndFrame &&
3393 !ParentIsDesktop(hwnd, dcd->hwndParent)) {
3394 if (pre->fEmphasisMask & CRA_CURSORED) {
3395 if (pci->rc.flRecordAttr & CRA_CURSORED) {
3396 if (fSplitStatus && hwndStatus2) {
3397 if (dcd->ullTotalBytes)
3398 CommaFmtULL(tb, sizeof(tb), pci->cbFile, ' ');
3399 else
3400 *tb = 0;
3401 sprintf(s, "%s%s%s%s",
3402 *tb ? " " : NullStr,
3403 tb, *tb ? " " : NullStr, pci->pszFileName);
3404 WinSetWindowText(hwndStatus2, s);
3405 }
3406 if (fMoreButtons)
3407 WinSetWindowText(hwndName, pci->pszFileName);
3408 }
3409 }
3410 }
3411 }
3412 break;
3413
3414 case CN_ENTER:
3415 if (mp2) {
3416
3417 PARCITEM pci = (PARCITEM) ((PNOTIFYRECORDENTER) mp2)->pRecord;
3418
3419 if (pci) {
3420
3421 CHAR *s;
3422
3423 if ((pci->rc.flRecordAttr & CRA_INUSE) ||
3424 (pci->flags & (ARCFLAGS_REALDIR | ARCFLAGS_PSEUDODIR)))
3425 break;
3426 s = xstrdup(pci->pszFileName, pszSrcFile, __LINE__);
3427 if (s) {
3428 if (!PostMsg(dcd->hwndObject, UM_ENTER, MPFROMP(s), MPVOID)) {
3429 Runtime_Error(pszSrcFile, __LINE__, "post");
3430 free(s);
3431 }
3432 }
3433 }
3434 }
3435 break;
3436 }
3437 }
3438 return 0;
3439
3440 case UM_FOLDUP:
3441 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
3442 DosExit(EXIT_PROCESS, 1);
3443 return 0;
3444
3445 case UM_CLOSE:
3446 WinDestroyWindow(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
3447 QW_PARENT));
3448 return 0;
3449
3450 case WM_SAVEAPPLICATION:
3451 if (dcd && ParentIsDesktop(hwnd, dcd->hwndParent)) {
3452 SWP swp;
3453
3454 WinQueryWindowPos(dcd->hwndFrame, &swp);
3455 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE | SWP_MAXIMIZE)))
3456 PrfWriteProfileData(fmprof, appname, "AV2SizePos", &swp, sizeof(swp));
3457 }
3458 break;
3459
3460 case WM_CLOSE:
3461 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
3462 if (dcd)
3463 dcd->stopflag++;
3464 if (dcd && dcd->hwndObject) {
3465 if (!PostMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID))
3466 WinSendMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID);
3467 }
3468 // In case object window frees dcd
3469 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
3470 if (!dcd ||
3471 (!dcd->dontclose &&
3472 !dcd->amextracted && ParentIsDesktop(hwnd, dcd->hwndParent))) {
3473 if (!PostMsg(hwnd, UM_FOLDUP, MPVOID, MPVOID))
3474 WinSendMsg(hwnd, UM_FOLDUP, MPVOID, MPVOID);
3475 }
3476 return 0;
3477
3478 case WM_DESTROY:
3479 if (ArcMenu)
3480 WinDestroyWindow(ArcMenu);
3481 if (ArcCnrMenu)
3482 WinDestroyWindow(ArcCnrMenu);
3483 ArcMenu = ArcCnrMenu = (HWND) 0;
3484 EmptyArcCnr(hwnd);
3485# ifdef FORTIFY
3486 Fortify_LeaveScope();
3487# endif
3488 break;
3489 }
3490 if (dcd && dcd->oldproc){
3491 return dcd->oldproc(hwnd, msg, mp1, mp2);
3492 }
3493 else
3494 return PFNWPCnr(hwnd, msg, mp1, mp2);
3495}
3496
3497MRESULT EXPENTRY ArcCnrMenuProc(HWND hwnd, ULONG msg, MPARAM mp1,
3498 MPARAM mp2)
3499{
3500 PFNWP oldMenuProc = WinQueryWindowPtr(hwnd, QWL_USER);
3501 static short sLastMenuitem;
3502
3503 switch (msg) {
3504 case WM_MOUSEMOVE: {
3505 if (fOtherHelp) {
3506 RECTL rectl;
3507 SHORT i, sCurrentMenuitem;
3508 SHORT MenuItems = 10;
3509 SHORT asMenuIDs[10] = {IDM_VIEW,
3510 IDM_DELETE,
3511 IDM_EXEC,
3512 IDM_EXTRACT,
3513 IDM_TEST,
3514 IDM_VIRUSSCAN,
3515 IDM_RESCAN,
3516 IDM_WALKDIR,
3517 IDM_FILTER,
3518 0};
3519 PCSZ szHelpString = NULL;
3520
3521
3522 for (i=0; i<MenuItems; i++) {
3523 sCurrentMenuitem = asMenuIDs[i];
3524 oldMenuProc(hwnd,MM_QUERYITEMRECT,
3525 MPFROM2SHORT(asMenuIDs[i], FALSE),
3526 &rectl);
3527
3528 if (MOUSEMSG(&msg)->x > rectl.xLeft &&
3529 MOUSEMSG(&msg)->x < rectl.xRight &&
3530 MOUSEMSG(&msg)->y > rectl.yBottom &&
3531 MOUSEMSG(&msg)->y < rectl.yTop)
3532 break;
3533 } // for
3534
3535
3536 switch (sCurrentMenuitem) {
3537 case 0:
3538 break;
3539 case IDM_VIEW:
3540 szHelpString = GetPString(IDS_ARCCNRVIEWMENUHELP);
3541 break;
3542 case IDM_DELETE:
3543 szHelpString = GetPString(IDS_ARCCNRDELETEMENUHELP);
3544 break;
3545 case IDM_EXEC:
3546 szHelpString = GetPString(IDS_ARCCNREXECMENUHELP);
3547 break;
3548 case IDM_EXTRACT:
3549 szHelpString = GetPString(IDS_ARCCNREXTRACTMENUHELP);
3550 break;
3551 case IDM_TEST:
3552 szHelpString = GetPString(IDS_ARCCNRTESTMENUHELP);
3553 break;
3554 case IDM_VIRUSSCAN:
3555 szHelpString = GetPString(IDS_ARCCNRVIRUSMENUHELP);
3556 break;
3557 case IDM_RESCAN:
3558 szHelpString = GetPString(IDS_ARCCNRRESCANMENUHELP);
3559 break;
3560 case IDM_WALKDIR:
3561 szHelpString = GetPString(IDS_ARCCNRWALKDIRMENUHELP);
3562 break;
3563 case IDM_FILTER:
3564 szHelpString = GetPString(IDS_ARCCNRFILTERMENUHELP);
3565 break;
3566 default:
3567 break;
3568 }
3569
3570 if (sLastMenuitem != sCurrentMenuitem && szHelpString) {
3571 sLastMenuitem = sCurrentMenuitem;
3572 MakeBubble(hwnd, TRUE, szHelpString);
3573 }
3574 else if (hwndBubble && !sCurrentMenuitem){
3575 sLastMenuitem = sCurrentMenuitem;
3576 WinDestroyWindow(hwndBubble);
3577 }
3578 }
3579 }
3580 }
3581 return oldMenuProc(hwnd, msg, mp1, mp2);
3582}
3583
3584HWND StartArcCnr(HWND hwndParent, HWND hwndCaller, CHAR * arcname, INT flags,
3585 ARC_TYPE * sinfo)
3586{
3587 /**
3588 * bitmapped flags:
3589 * 1 = am extracted from another archive
3590 * 4 = don't kill proc on close
3591 */
3592
3593 HWND hwndFrame = (HWND) 0, hwndClient;
3594 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
3595 FCF_SIZEBORDER | FCF_MINMAX | FCF_ICON | FCF_NOBYTEALIGN | FCF_ACCELTABLE;
3596 USHORT id;
3597 DIRCNRDATA *dcd;
3598 ARC_TYPE *info = sinfo;
3599 CHAR title[MAXNAMEL + 1] = "AV/2 - ";
3600 CHAR fullname[CCHMAXPATH + 8], *p, temp;
3601 static USHORT idinc = 0;
3602
3603
3604 if (!strcmp(strupr(strrchr(arcname, '.') + 1), "LZ")) {
3605 saymsg(MB_ENTER | MB_ICONASTERISK, HWND_DESKTOP, GetPString(IDS_LZIPLIMITATION),
3606 GetPString(IDS_LZIPNOLIST));
3607 return -1;
3608 }
3609
3610 if (!idinc)
3611 idinc = (rand() % 256);
3612 if (ParentIsDesktop(hwndParent, hwndParent))
3613 FrameFlags |= (FCF_TASKLIST | FCF_MENU);
3614 if (arcname) {
3615 DosError(FERR_DISABLEHARDERR);
3616 if (DosQueryPathInfo(arcname,
3617 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
3618 strcpy(fullname, arcname);
3619 ForwardslashToBackslash(fullname);
3620 if (!info)
3621 info = find_type(fullname, arcsighead);
3622 if (!info)
3623 return hwndFrame;
3624 if (strlen(title) + strlen(fullname) > MAXNAMEL) {
3625 p = title + strlen(title);
3626 strncpy(p, fullname, MAXNAMEL / 2 - 5);
3627 strcpy(p + MAXNAMEL / 2 - 5, "...");
3628 strcat(title, fullname + strlen(fullname) - (MAXNAMEL / 2 - 5));
3629 }
3630 else {
3631 strcat(title, fullname);
3632 }
3633 hwndFrame = WinCreateStdWindow(hwndParent,
3634 WS_VISIBLE,
3635 &FrameFlags,
3636 (CHAR *) WC_ARCCONTAINER,
3637 title,
3638 WS_VISIBLE | fwsAnimate,
3639 FM3ModHandle, ARC_FRAME, &hwndClient);
3640 if (hwndFrame && hwndClient) {
3641 id = ARC_FRAME + idinc++;
3642 if (idinc > 512)
3643 idinc = 0;
3644 WinSetWindowUShort(hwndFrame, QWS_ID, id);
3645# ifdef FORTIFY
3646 Fortify_EnterScope();
3647# endif
3648 dcd = xmallocz(sizeof(DIRCNRDATA), pszSrcFile, __LINE__);
3649 if (!dcd) {
3650 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3651 hwndFrame = (HWND) 0;
3652 }
3653 else {
3654# ifdef FORTIFY
3655 // Will be freed by WM_DESTROY
3656 Fortify_ChangeScope(dcd, -1);
3657# endif
3658 dcd->size = sizeof(DIRCNRDATA);
3659 dcd->id = id;
3660 dcd->type = ARC_FRAME;
3661 if (pTmpDir && !IsValidDir(pTmpDir))
3662 DosCreateDir(pTmpDir, 0);
3663 MakeTempName(dcd->workdir, ArcTempRoot, 2);
3664 strcpy(dcd->arcname, fullname);
3665 if (*extractpath) {
3666 if (!strcmp(extractpath, "*")) {
3667 p = strrchr(fullname, '\\');
3668 if (p) {
3669 if (p < fullname + 3)
3670 p++;
3671 temp = *p;
3672 *p = 0;
3673 strcpy(dcd->directory, fullname);
3674 *p = temp;
3675 }
3676 }
3677 else
3678 strcpy(dcd->directory, extractpath);
3679 }
3680 // Removed because it can't be set from inside the container and names with a space
3681 // break it. I don't think it makes sense from the container any way GKY 8-10-13
3682 /*if (!*dcd->directory && fFileNameCnrPath && dcd->arcname) {
3683 strcpy(fullname, dcd->arcname);
3684 p = strrchr(fullname, '.');
3685 if (p) {
3686 *p = 0;
3687 }
3688 else {
3689 p = fullname + strlen(fullname);
3690 p--;
3691 *p = 0;
3692 }
3693 strcpy(dcd->directory, fullname);
3694 } */
3695 if (!*dcd->directory && *lastextractpath) {
3696 //DosEnterCritSec(); //GKY 11-29-08
3697 DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
3698 strcpy(dcd->directory, lastextractpath);
3699 DosReleaseMutexSem(hmtxFM2Globals);
3700 //DosExitCritSec();
3701 }
3702 if (!*dcd->directory) {
3703 if (!ParentIsDesktop(hwndParent, hwndParent))
3704 TopWindowName(hwndParent, hwndCaller, dcd->directory);
3705 if (!*dcd->directory) {
3706 p = strrchr(fullname, '\\');
3707 if (p) {
3708 if (p < fullname + 3)
3709 p++;
3710 *p = 0;
3711 strcpy(dcd->directory, fullname);
3712 }
3713 }
3714 }
3715 if (!*dcd->directory ||
3716 (IsFile(dcd->directory) == 1) ||
3717 (isalpha(*dcd->directory) &&
3718 (driveflags[toupper(*dcd->directory) - 'A'] &
3719 DRIVE_NOTWRITEABLE)))
3720 strcpy(dcd->directory, pFM2SaveDirectory);
3721 dcd->hwndParent = hwndParent ? hwndParent : HWND_DESKTOP;
3722 dcd->hwndFrame = hwndFrame;
3723 dcd->hwndClient = hwndClient;
3724 dcd->amextracted = (flags & 1) != 0;
3725 dcd->dontclose = (flags & 4) != 0;
3726 dcd->info = info;
3727 dcd->sortFlags = DefArcSortFlags;
3728 {
3729 PFNWP oldproc;
3730
3731 oldproc = WinSubclassWindow(hwndFrame, (PFNWP) ArcFrameWndProc);
3732 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
3733 }
3734 dcd->hwndCnr = WinCreateWindow(hwndClient,
3735 WC_CONTAINER,
3736 NULL,
3737 CCS_AUTOPOSITION | CCS_MINIICONS |
3738 CCS_MINIRECORDCORE | ulCnrType |
3739 WS_VISIBLE,
3740 0,
3741 0,
3742 0,
3743 0,
3744 hwndClient,
3745 HWND_TOP, (ULONG) ARC_CNR, NULL, NULL);
3746 if (!dcd->hwndCnr) {
3747 Win_Error(hwndClient, hwndClient, pszSrcFile, __LINE__,
3748 PCSZ_WINCREATEWINDOW);
3749 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3750 free(dcd);
3751 hwndFrame = (HWND) 0;
3752 }
3753 else {
3754 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, (PVOID) dcd);
3755 dcd->oldproc = WinSubclassWindow(dcd->hwndCnr,
3756 (PFNWP) ArcCnrWndProc);
3757 {
3758 USHORT ids[] = { DIR_TOTALS, DIR_SELECTED, DIR_VIEW, DIR_SORT,
3759 DIR_FILTER, DIR_FOLDERICON, 0
3760 };
3761
3762 CommonCreateTextChildren(dcd->hwndClient,
3763 WC_ARCSTATUS, ids);
3764 }
3765 WinEnableWindow(WinWindowFromID(dcd->hwndClient, DIR_VIEW), FALSE);
3766 dcd->hwndExtract = WinCreateWindow(dcd->hwndClient,
3767 WC_ENTRYFIELD,
3768 NULL,
3769 ES_AUTOSCROLL,
3770 0,
3771 0,
3772 0,
3773 0,
3774 dcd->hwndClient,
3775 HWND_TOP,
3776 ARC_EXTRACTDIR, NULL, NULL);
3777 WinSendMsg(dcd->hwndExtract,
3778 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
3779 WinSetWindowText(dcd->hwndExtract, dcd->directory);
3780 if (!PostMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID))
3781 WinSendMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID);
3782 if (FrameFlags & FCF_MENU) {
3783 PFNWP oldmenuproc;
3784 HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
3785
3786 oldmenuproc = WinSubclassWindow(hwndMenu, (PFNWP) ArcCnrMenuProc);
3787 WinSetWindowPtr(hwndMenu, QWL_USER, (PVOID) oldmenuproc);
3788 if (!fToolbar) {
3789
3790 if (hwndMenu) {
3791 WinSendMsg(hwndMenu, MM_DELETEITEM,
3792 MPFROM2SHORT(IDM_VIEW, FALSE), MPVOID);
3793 WinSendMsg(hwndMenu, MM_DELETEITEM,
3794 MPFROM2SHORT(IDM_EXEC, FALSE), MPVOID);
3795 WinSendMsg(hwndMenu, MM_DELETEITEM,
3796 MPFROM2SHORT(IDM_RESCAN, FALSE), MPVOID);
3797 WinSendMsg(hwndMenu, MM_DELETEITEM,
3798 MPFROM2SHORT(IDM_DELETE, FALSE), MPVOID);
3799 WinSendMsg(hwndMenu, MM_DELETEITEM,
3800 MPFROM2SHORT(IDM_EXTRACT, FALSE), MPVOID);
3801 WinSendMsg(hwndMenu, MM_DELETEITEM,
3802 MPFROM2SHORT(IDM_TEST, FALSE), MPVOID);
3803 WinSendMsg(hwndMenu, MM_DELETEITEM,
3804 MPFROM2SHORT(IDM_VIRUSSCAN, FALSE), MPVOID);
3805 WinSendMsg(hwndMenu, MM_DELETEITEM,
3806 MPFROM2SHORT(IDM_WALKDIR, FALSE), MPVOID);
3807 WinSendMsg(hwndMenu, MM_DELETEITEM,
3808 MPFROM2SHORT(IDM_FILTER, FALSE), MPVOID);
3809 }
3810 }
3811 }
3812 if (FrameFlags & FCF_TASKLIST) {
3813
3814 SWP swp, swpD;
3815 ULONG size = sizeof(swp);
3816 LONG cxScreen, cyScreen;
3817
3818 WinQueryTaskSizePos(WinQueryAnchorBlock(hwndFrame), 0, &swp);
3819 if (PrfQueryProfileData(fmprof, appname, "AV2SizePos", &swpD, &size)) {
3820 cxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
3821 cyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
3822 if (swp.x + swpD.cx > cxScreen)
3823 swp.x = cxScreen - swpD.cx;
3824 if (swp.y + swpD.cy > cyScreen)
3825 swp.y = cyScreen - swpD.cy;
3826 swp.cx = swpD.cx;
3827 swp.cy = swpD.cy;
3828 }
3829 WinSetWindowPos(hwndFrame,
3830 HWND_TOP,
3831 swp.x,
3832 swp.y,
3833 swp.cx,
3834 swp.cy,
3835 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER |
3836 SWP_ACTIVATE);
3837 }
3838 }
3839 }
3840# ifdef FORTIFY
3841 Fortify_LeaveScope();
3842# endif
3843 }
3844 }
3845 return hwndFrame;
3846}
3847
3848#pragma alloc_text(ARCCNRS,ArcCnrWndProc,ArcObjWndProc,ArcClientWndProc,BldQuotedFullPathName)
3849#pragma alloc_text(ARCCNRS,ArcTextProc,FillArcCnr,ArcFilter,BldQuotedFileName)
3850#pragma alloc_text(ARCCNRS,ArcSort,ArcFrameWndProc,IsArcThere,ArcErrProc)
3851#pragma alloc_text(STARTUP,StartArcCnr)
Note: See TracBrowser for help on using the repository browser.