source: trunk/dll/arccnrs.c@ 1545

Last change on this file since 1545 was 1545, checked in by Gregg Young, 15 years ago

Added ForwardslashToBackslash function to streamline code.

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