source: trunk/dll/arccnrs.c@ 1513

Last change on this file since 1513 was 1513, checked in by Steven Levine, 15 years ago

Avoid referencing buffer after freeing dcd

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