source: trunk/dll/arccnrs.c@ 1439

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

Changes to allow high mem loading of dll; Refactor .LONGNAME and .SUBJECT EA fetch to FetchCommonEAs. Add szFSType to FillInRecordFromFSA use to bypass EA scan and size formatting for tree container; Fix labels/FS type to work on scan on NOPRESCAN Drives; Fixed dbl directory names on restore of dir cnrs; (Tickets 47, 339, 363, 368, 369, 370)

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