source: trunk/dll/arccnrs.c@ 1337

Last change on this file since 1337 was 1335, checked in by Steven Levine, 17 years ago

Ticket 26: Add exception handlers to all threads using xbeginthread

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