source: trunk/dll/arccnrs.c@ 1402

Last change on this file since 1402 was 1402, checked in by Gregg Young, 16 years ago

Remove variable aurgs from docopy & unlinkf (not used); Move more strings to PCSZs and string table; Move PCSZs to compile time initialization; Fix hang on startup caused by a drive scan and a dircnr scan trying to update a drive in the tree at the same time (related to the "treeswitch options); Code cleanup mainly removal of old printfs, SayMsgs, DbgMsg and unneeded %s.

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