source: trunk/dll/arccnrs.c@ 1694

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

Added comments for CS 1690 & 1692

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