source: trunk/dll/arccnrs.c@ 1729

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

Fix toggle to upper case opening a file. Ticket 513

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