source: trunk/dll/arccnrs.c@ 1554

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

Check that pTmpDir IsValid and recreate if not found; Fixes hangs caused by temp file creation failures. (Ticket 440)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 105.9 KB
Line 
1
2/***********************************************************************
3
4 $Id: arccnrs.c 1554 2010-11-20 23:35:35Z gyoung $
5
6 Archive containers
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001, 2010 Steven H. Levine
10
11 11 Jun 02 SHL Ensure archive name not garbage
12 22 May 03 SHL ArcObjWndProc: fix UM_RESCAN now that we understand it
13 01 Aug 04 SHL Rework lstrip/rstrip usage
14 23 May 05 SHL Use QWL_USER
15 25 May 05 SHL Rename comnam to szCommonName and fix typo
16 25 May 05 SHL Use ULONGLONG and CommaFmtULL
17 05 Jun 05 SHL Drop obsolete, localize
18 05 Jun 05 SHL Correct last sort logic
19 05 Jun 05 SHL Use QWL_USER
20 22 Jun 05 SHL ArcSort: correct typo in last sort fix
21 13 Aug 05 SHL FillArcCnr: optimize
22 08 Dec 05 SHL FillArcCnr: allow list start and end markers to be empty (i.e. tar)
23 08 Dec 05 SHL ArcCnrWndProc: suppress IDM_EXTRACT if no simple extract (i.e. tar)
24 30 Dec 05 SHL ArcCnrWndProc: correct date/time column display setup
25 29 May 06 SHL Comments
26 14 Jul 06 SHL Use Runtime_Error
27 26 Jul 06 SHL Correct SelectAll usage
28 29 Jul 06 SHL Use xfgets_bstripcr
29 31 Jul 06 SHL Lower priority for archives with more than 1000 entries
30 02 Aug 06 SHL Add logic to stop processing large archives
31 23 Aug 06 SHL Integrate John Small's switch list title logic
32 03 Nov 06 SHL Renames
33 14 Mar 07 SHL ArcObjWndProc/UM_ENTER: delay before starting viewer
34 30 Mar 07 GKY Remove GetPString for window class names
35 06 Apr 07 GKY Work around PM DragInfo and DrgFreeISH limit
36 06 Apr 07 GKY Add some error checking in drag/drop
37 20 Apr 07 SHL Sync with NumItemsToUnhilite mods
38 21 Apr 07 GKY Find FM2Utils by path or utils directory
39 12 May 07 SHL Use dcd->ulItemsToUnHilite; sync with UnHilite arg mods
40 10 Jun 07 GKY Add CheckPmDrgLimit including IsFm2Window as part of work around PM drag limit
41 16 Jun 07 SHL Use DosQueryAppType not DosQAppType
42 02 Aug 07 SHL Sync with ARCITEM mods
43 06 Aug 07 SHL Use BldFullPathName and BldQuotedFileName
44 06 Aug 07 SHL Move BldQuotedFileName and BldQuotedFullPathNamehere
45 to be near primary caller
46 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
47 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
48 26 Aug 07 GKY DosSleep(1) in loops changed to (0)
49 22 Nov 07 GKY Use CopyPresParams to fix presparam inconsistencies in menus
50 30 Dec 07 GKY Use TestCDates for sort by date
51 10 Jan 08 SHL Sync with CfgDlgProc mods
52 10 Feb 08 GKY Implement bubble help for bitmap menu items
53 15 Feb 08 SHL Sync with settings menu rework
54 29 Feb 08 GKY Use xfree where appropriate
55 14 Jul 08 JBS Ticket 126: Add support for WPS open default & open settings in arccnrs
56 16 Jul 08 GKY Fix trap on viewing multiple files from an archive (misplaced free)
57 16 Jul 08 GKY Use TMP directory for temp files if present. Use MakeTempName
58 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory
59 25 Aug 08 GKY Check TMP directory space warn if lee than 5 MiB prevent archiver from opening if
60 less than 10 KiB (It hangs and can't be closed)
61 08 Nov 08 GKY Add WaitChildThread to fix hang caused by viewer trying to open a file before
62 the archiver process closes. (Ticket 58)
63 23 Nov 08 JBS Ticket 284: Support archivers with no Start or End of list strings
64 29 Nov 08 GKY Add flag to tell CheckListProc file is in an archive so it won't try to open it.
65 29 Nov 08 GKY Remove or replace with a mutex semaphore DosEnterCriSec where appropriate.
66 30 Nov 08 GKY Add the option of creating a subdirectory from the arcname
67 for the extract path to arc container.
68 02 Dec 08 JBS Ticket 284: Changed string indicating no Start/End of list strings.
69 03 Dec 08 GKY Subdirectory from the arcname for the extract path only created if an "extract"
70 menu option is selected.
71 10 Dec 08 SHL Integrate exception handler support
72 07 Feb 09 GKY Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error
73 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
74 08 Mar 09 GKY Renamed commafmt.h i18nutil.h
75 08 Mar 09 GKY Additional strings move to PCSZs in init.c
76 08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used)
77 12 Mar 09 SHL Use common SearchContainer
78 13 Dec 09 GKY Fixed separate paramenters. Please note that appname should be used in
79 profile calls for user settings that work and are setable in more than one
80 miniapp; FM3Str should be used for setting only relavent to FM/2 or that
81 aren't user settable; realappname should be used for setting applicable to
82 one or more miniapp but not to FM/2
83 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
84 15 Apr 10 JBS Ticket 422: Stop hang when open archive gets deleted or moved
85 23 Oct 10 GKY Add ForwardslashToBackslash function to streamline code
86 20 Nov 10 GKY Check that pTmpDir IsValid and recreate if not found; Fixes hangs caused
87 by temp file creation failures.
88
89***********************************************************************/
90
91#include <stdlib.h> // free..
92#include <string.h>
93#include <ctype.h>
94#include <direct.h> // rmdir
95#include <share.h> // SH_DENYWR
96#include <limits.h> // ULONG_MAX
97
98#if 0
99#include <malloc.h> // _heapchk
100#endif
101
102#define INCL_DOS
103#define INCL_DOSERRORS
104#define INCL_WIN
105#define INCL_LONGLONG
106
107#include "fm3dll.h"
108#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
109#include "arccnrs.h"
110#include "makelist.h" // Typedef
111#include "colors.h" // Typedef
112#include "mainwnd2.h" // Data declaration(s)
113#include "grep.h" // Data declaration(s)
114#include "dircnrs.h" // Data declaration(s)
115#include "info.h" // Data declaration(s)
116#include "init.h" // Data declaration(s)
117#include "fm3dlg.h"
118#include "fm3str.h"
119#include "mle.h"
120#include "pathutil.h" // BldFullPathName
121#include "filldir.h" // EmptyCnr...
122#include "errutil.h" // Dos_Error...
123#include "strutil.h" // GetPString
124#include "notebook.h" // CfgDlgProc
125#include "worker.h" // Action, MassAction
126#include "avv.h" // ArcReviewDlgProc, rewrite_archiverbb2
127#include "chklist.h" // CenterOverWindow, CheckListProc
128#include "common.h" // CommonCreateTextChildren, CommonFrameWndProc, CommonTextPaint
129 // CommonTextButton
130#include "draglist.h" // DoFileDrag, DragOne
131#include "valid.h" // GetDesktopName, TestCDates
132#include "mainwnd.h" // GetNextWindowPos, MakeBubble, TopWindowName
133#include "objwin.h" // MakeObjWin
134#include "shadow.h" // MakeShadows
135#include "objcnr.h" // ObjCnrDlgProc
136#include "printer.h" // PrintListThread
137#include "srchpath.h" // RunFM2Util
138#include "misc.h" // Broadcast, CheckMenu, CurrentRecord, SayFilter, SaySort
139 // DrawTargetEmphasis, IsFm2Window
140#include "select.h" // SelectAll, SelectList
141#include "findrec.h" // ShowCnrRecord
142#include "walkem.h" // WalkExtractDlgProc
143#include "droplist.h" // AcceptOneDrop, CheckPmDrgLimit, DropHelp, GetOneDrop
144#include "archive.h" // ArchiveDlgProc
145#include "common.h" // CommonTextProc
146#include "presparm.h" // CopyPresParams
147#include "defview.h" // DefaultViewKeys
148#include "systemf.h" // ExecOnList
149#include "filter.h" // PickMaskDlgProc
150#include "avl.h" // SBoxDlgProc
151#include "mkdir.h" // SetDir
152#include "collect.h" // StartCollector
153#include "viewer.h" // StartMLEEditor
154#include "newview.h" // StartViewer
155#include "i18nutil.h" // commafmt
156#include "copyf.h" // unlinkf
157#include "literal.h" // wildcard
158#include "wrappers.h" // xrealloc
159#include "misc.h" // AdjustCnrColVis, QuickPopup, SetSortChecks, SwitchCommand
160#include "select.h" // DeselectAll, InvertAll
161#include "strips.h" // bstrip
162#include "dirs.h" // save_dir2
163#include "fortify.h"
164#include "excputil.h" // 06 May 08 SHL added
165
166#define ARCFLAGS_REALDIR 0x00000001
167#define ARCFLAGS_PSEUDODIR 0x00000002
168#define CON_COLS 6
169#define EXTRA_ARCRECORD_BYTES (sizeof(ARCITEM) - sizeof(MINIRECORDCORE))
170#define NO_START_OF_ARCHIVER_LIST_STRING "None"
171#define NO_END_OF_ARCHIVER_LIST_STRING NO_START_OF_ARCHIVER_LIST_STRING
172
173#pragma data_seg(DATA1)
174static INT DefArcSortFlags;
175
176// Data definitions
177static PSZ pszSrcFile = __FILE__;
178#pragma data_seg(GLOBAL1)
179HWND ArcCnrMenu;
180HWND ArcMenu;
181CHAR ArcTempRoot[CCHMAXPATH];
182BOOL fArcStuffVisible;
183BOOL fFileNameCnrPath;
184
185#pragma data_seg(GLOBAL2)
186CHAR lastextractpath[CCHMAXPATH];
187ULONGLONG ullDATFileSpaceNeeded = 10000;
188
189typedef struct {
190
191 HWND hwndCnr; //hwnd you want the message posted to
192 HWND hwndClient; //hwnd calling this thread; NULL will work
193 ULONG RunFlags; //runemf2 flags see systemf.h
194 ULONG msg; //Message to post
195 UINT uiLineNumber;
196 PCSZ pszSrcFile;
197 CHAR filename[CCHMAXPATH]; //file passed as MP1 message parameter (file selected)
198 CHAR *pszDirectory; //Execution directory
199 CHAR *pszEnvironment; //Enviroment -- NULL passes current
200 CHAR *pszCmdLine; //Use sprintf to format multipart command line into single string
201 CHAR formatstring[40]; //Usally "%s"
202}
203WAITCHILD;
204
205/** Creates a thread to wait for a child process to complete then posts a message and closes
206 * This function should only be used for runemf2 calls that include the WAIT flag
207 */
208VOID WaitChildThread(VOID * arg)
209{
210 WAITCHILD *WaitChild;
211 HAB thab;
212 CHAR *filename;
213 INT ret;
214
215 DosError(FERR_DISABLEHARDERR);
216
217# ifdef FORTIFY
218 Fortify_EnterScope();
219# endif
220
221 WaitChild = (WAITCHILD *) arg;
222 if (WaitChild) {
223 filename = xstrdup(WaitChild->filename, pszSrcFile, __LINE__);
224 thab = WinInitialize(0);
225 if (thab) {
226 IncrThreadUsage();
227 priority_normal();
228 ret = runemf2(WaitChild->RunFlags, WaitChild->hwndClient,
229 WaitChild->pszSrcFile, WaitChild->uiLineNumber,
230 WaitChild->pszDirectory, WaitChild->pszEnvironment,
231 WaitChild->formatstring, WaitChild->pszCmdLine);
232 if (ret != -1) {
233 if (IsFile(WaitChild->filename) == 1)
234 PostMsg(WaitChild->hwndCnr, WaitChild->msg, MPFROMP(filename), MPVOID);
235 }
236 DecrThreadUsage();
237 WinTerminate(thab);
238 }
239 xfree(WaitChild->pszDirectory, pszSrcFile, __LINE__);
240 xfree(WaitChild->pszEnvironment, pszSrcFile, __LINE__);
241 xfree(WaitChild->pszCmdLine, pszSrcFile, __LINE__);
242 free(WaitChild);
243 } // if WaitChild
244# ifdef FORTIFY
245 Fortify_LeaveScope();
246# endif
247}
248
249static MRESULT EXPENTRY ArcErrProc(HWND hwnd, ULONG msg, MPARAM mp1,
250 MPARAM mp2)
251{
252 ARCDUMP *ad;
253 CHAR szQuotedArcName[CCHMAXPATH];
254
255 switch (msg) {
256 case WM_INITDLG:
257 if (!mp2)
258 WinDismissDlg(hwnd, 0);
259 else {
260 ad = (ARCDUMP *) mp2;
261 WinSetWindowPtr(hwnd, QWL_USER, ad);
262 if (ad->errmsg)
263 WinSetDlgItemText(hwnd, ARCERR_TEXT, ad->errmsg);
264 if (!ad->info->test)
265 WinEnableWindow(WinWindowFromID(hwnd, ARCERR_TEST), FALSE);
266 if (ad->listname) {
267 MLEsetlimit(WinWindowFromID(hwnd, ARCERR_MLE), -1L);
268 MLEsetformat(WinWindowFromID(hwnd, ARCERR_MLE), MLFIE_NOTRANS);
269 MLEsetcurpos(WinWindowFromID(hwnd, ARCERR_MLE),
270 MLEgetlen(WinWindowFromID(hwnd, ARCERR_MLE)));
271 MLEinsert(WinWindowFromID(hwnd, ARCERR_MLE),
272 GetPString(IDS_ARCHIVERREPORTTEXT));
273 MLEinsertfile(WinWindowFromID(hwnd, ARCERR_MLE), ad->listname);
274 }
275 }
276 break;
277
278 case WM_COMMAND:
279 switch (SHORT1FROMMP(mp1)) {
280 case DID_CANCEL:
281 WinDismissDlg(hwnd, 0);
282 break;
283
284 case IDM_HELP:
285 if (hwndHelp) {
286 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
287 MPFROM2SHORT(HELP_ARCERR, 0), MPFROMSHORT(HM_RESOURCEID));
288 }
289 break;
290
291 case DID_OK:
292 ad = WinQueryWindowPtr(hwnd, QWL_USER);
293 WinDlgBox(HWND_DESKTOP, hwnd, ArcReviewDlgProc, FM3ModHandle,
294 AD_FRAME, MPFROMP(ad));
295 WinDismissDlg(hwnd, 0);
296 break;
297
298 case ARCERR_VIEW:
299 ad = WinQueryWindowPtr(hwnd, QWL_USER);
300 {
301 CHAR *list[2];
302
303 list[0] = ad->arcname;
304 list[1] = NULL;
305 if (TestBinary(ad->arcname)) {
306 if (*binview)
307 ExecOnList((HWND) 0, binview, WINDOWED | SEPARATE, NULL, NULL, list,
308 NULL, pszSrcFile, __LINE__);
309 else
310 StartMLEEditor(HWND_DESKTOP, 16 + 4 + 1, ad->arcname, hwnd);
311 }
312 else {
313 if (*viewer) {
314 ExecOnList((HWND) 0, viewer, WINDOWED | SEPARATE |
315 (fViewChild ? CHILD : 0), NULL,
316 NULL, list, NULL, pszSrcFile, __LINE__);
317 }
318 else
319 StartMLEEditor(HWND_DESKTOP, 8 + 4 + 1, ad->arcname, hwnd);
320 }
321 }
322 break;
323
324 case ARCERR_TEST:
325 ad = WinQueryWindowPtr(hwnd, QWL_USER);
326 runemf2(SEPARATEKEEP | WINDOWED | MAXIMIZED,
327 hwnd, pszSrcFile, __LINE__, NULL, NULL,
328 "%s %s",
329 ad->info->test,
330 BldQuotedFileName(szQuotedArcName, ad->arcname));
331 break;
332 }
333 return 0;
334 }
335 return WinDefDlgProc(hwnd, msg, mp1, mp2);
336}
337
338static SHORT APIENTRY ArcSort(PMINIRECORDCORE pmrc1, PMINIRECORDCORE pmrc2,
339 PVOID pStorage)
340{
341 PARCITEM pai1 = (PARCITEM) pmrc1;
342 PARCITEM pai2 = (PARCITEM) pmrc2;
343 DIRCNRDATA *pdcd = (DIRCNRDATA *) pStorage;
344 SHORT ret = 0;
345 CHAR *pext, *ppext;
346 INT sortFlags;
347
348 if (!pdcd) {
349 HWND hwndCnr = pai1->hwndCnr;
350
351 pdcd = WinQueryWindowPtr(hwndCnr, QWL_USER);
352 if (!pdcd) {
353 Runtime_Error(pszSrcFile, __LINE__, NULL);
354 return ret;
355 }
356 }
357
358 sortFlags = pdcd->sortFlags; // Optimize
359
360 if (sortFlags) {
361 switch (sortFlags & (~SORT_REVERSE)) {
362 case SORT_FIRSTEXTENSION:
363 pext = strchr(pai1->pszFileName, '.');
364 ppext = strchr(pai2->pszFileName, '.');
365 if (!pext)
366 pext = NullStr;
367 if (!ppext)
368 ppext = NullStr;
369 ret = stricmp(pext, ppext);
370 break;
371
372 case SORT_LASTEXTENSION:
373 pext = strrchr(pai1->pszFileName, '.');
374 ppext = strrchr(pai2->pszFileName, '.');
375 if (!pext)
376 pext = NullStr;
377 if (!ppext)
378 ppext = NullStr;
379 ret = stricmp(pext, ppext);
380 break;
381
382 case SORT_LWDATE:
383 ret = TestCDates(&pai1->date, &pai1->time,
384 &pai2->date, &pai2->time);
385 /*(pai1->date.year < pai2->date.year) ? 1 :
386 (pai1->date.year > pai2->date.year) ? -1 :
387 (pai1->date.month < pai2->date.month) ? 1 :
388 (pai1->date.month > pai2->date.month) ? -1 :
389 (pai1->date.day < pai2->date.day) ? 1 :
390 (pai1->date.day > pai2->date.day) ? -1 :
391 (pai1->time.hours < pai2->time.hours) ? 1 :
392 (pai1->time.hours > pai2->time.hours) ? -1 :
393 (pai1->time.minutes < pai2->time.minutes) ? 1 :
394 (pai1->time.minutes > pai2->time.minutes) ? -1 :
395 (pai1->time.seconds < pai2->time.seconds) ? 1 :
396 (pai1->time.seconds > pai2->time.seconds) ? -1 : 0;*/
397 break;
398
399 case SORT_SIZE:
400 ret =
401 (pai1->cbFile < pai2->cbFile) ? 1 : (pai1->cbFile ==
402 pai2->cbFile) ? 0 : -1;
403 if (!ret)
404 ret =
405 (pai1->cbComp < pai2->cbComp) ? 1 : (pai1->cbComp ==
406 pai2->cbComp) ? 0 : -1;
407 break;
408
409 case SORT_EASIZE:
410 ret =
411 (pai1->cbComp < pai2->cbComp) ? 1 : (pai1->cbComp ==
412 pai2->cbComp) ? 0 : -1;
413 if (!ret)
414 ret =
415 (pai1->cbFile < pai2->cbFile) ? 1 : (pai1->cbFile ==
416 pai2->cbFile) ? 0 : -1;
417 break;
418 }
419 if (!ret)
420 ret = (SHORT) stricmp(pai1->pszFileName, pai2->pszFileName);
421 if (ret && (sortFlags & SORT_REVERSE))
422 ret = ret > 0 ? -1 : 1;
423 return ret;
424 }
425 return (SHORT) stricmp(pai1->pszFileName, pai2->pszFileName);
426}
427
428static INT APIENTRY ArcFilter(PMINIRECORDCORE rmini, PVOID arg)
429{
430 DIRCNRDATA *dcd = (DIRCNRDATA *) arg;
431 PARCITEM r;
432 register INT x;
433 INT ret = FALSE;
434
435 if (dcd && *dcd->mask.szMask) {
436 r = (PARCITEM) rmini;
437 if (dcd->mask.pszMasks[1]) {
438 for (x = 0; dcd->mask.pszMasks[x]; x++) {
439 if (*dcd->mask.pszMasks[x]) {
440 if (*dcd->mask.pszMasks[x] != '/') {
441 if (wildcard(r->pszFileName, dcd->mask.pszMasks[x], TRUE))
442 ret = TRUE;
443 }
444 else {
445 if (wildcard(r->pszFileName, dcd->mask.pszMasks[x] + 1, TRUE)) {
446 ret = FALSE;
447 break;
448 }
449 }
450 }
451 }
452 }
453 else {
454 if (wildcard(r->pszFileName, dcd->mask.szMask, TRUE))
455 ret = TRUE;
456 }
457 }
458 else
459 ret = TRUE;
460 return ret;
461}
462
463static MRESULT EXPENTRY ArcFrameWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
464 MPARAM mp2)
465{
466 return CommonFrameWndProc(ARC_CNR, hwnd, msg, mp1, mp2);
467}
468
469static BOOL IsArcThere(HWND hwnd, CHAR * arcname)
470{
471 if (arcname) {
472 if (IsFile(arcname) != 1) {
473 saymsg(MB_CANCEL, hwnd,
474 GetPString(IDS_SAYWHATTEXT),
475 GetPString(IDS_ARCNOTTHERETEXT), arcname);
476 return FALSE;
477 }
478 return TRUE;
479 }
480 return FALSE;
481}
482
483/**
484 * Free storage associated with archive container item
485 * Caller is responsible for correcting pointers
486 */
487
488static VOID FreeArcItemData(PARCITEM pai)
489{
490 // DbgMsg(pszSrcFile, __LINE__, "FreeArcItemData %p", pai);
491 PSZ psz;
492
493 if (pai->pszFileName && pai->pszFileName != NullStr) {
494 psz = pai->pszFileName;
495 pai->pszFileName = NULL; // 08 Jul 08 SHL was NulStr
496 free(psz);
497 }
498}
499
500/**
501 * Remove item(s) from archive container and free associated storage if requested
502 * @param paiFirst points to first item to remove or NULL to remove all
503 * @param usCnt is remove count or 0 to remove all
504 */
505
506static VOID RemoveArcItems(HWND hwnd, PARCITEM paiFirst, USHORT usCnt, USHORT usFlags)
507{
508 INT remaining = usCnt;
509 PARCITEM pai;
510
511 if ((usCnt && !paiFirst) || (!usCnt && paiFirst))
512 Runtime_Error(pszSrcFile, __LINE__, "paiFirst %p usCnt %u mismatch", paiFirst, usCnt);
513 else {
514 // Free our buffers if free requested
515 if (usFlags & CMA_FREE) {
516 if (paiFirst)
517 pai = paiFirst;
518 else {
519 pai = (PARCITEM)WinSendMsg(hwnd, CM_QUERYRECORD, MPVOID,
520 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
521 if ((INT)pai == -1) {
522 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_QUERYRECORD");
523 remaining = -1;
524 pai = NULL;
525 }
526 }
527 while (pai) {
528 FreeArcItemData(pai);
529 pai = (PARCITEM)pai->rc.preccNextRecord;
530 if (remaining && --remaining == 0)
531 break;
532 }
533 }
534 }
535
536 // DbgMsg(pszSrcFile, __LINE__, "RemoveArcItems %p %u %s", pai, usCnt, pai->pszFileName);
537
538 if (remaining != - 1) {
539 remaining = (INT)WinSendMsg(hwnd, CM_REMOVERECORD, MPFROMP(&paiFirst), MPFROM2SHORT(usCnt, usFlags));
540 if (remaining == -1) {
541 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_REMOVERECORD hwnd %x pai %p cnt %u",
542 hwnd, paiFirst, usCnt);
543 }
544 }
545}
546
547/**
548 * Empty all records from an archive container and
549 * free associated storage and free up field infos
550 */
551
552static VOID EmptyArcCnr(HWND hwnd)
553{
554#if 0 // fixme to be gone or to be configurable
555 {
556 int state = _heapchk();
557 if (state != _HEAPOK)
558 Runtime_Error(pszSrcFile, __LINE__, "heap corrupted %d", state);
559 else
560 DbgMsg(pszSrcFile, __LINE__, "_memavl %u", _memavl());
561 }
562#endif
563
564 // Remove all ARCITEM records
565 RemoveArcItems(hwnd, NULL, 0, CMA_FREE);
566
567 // Use common code to remove rest
568 EmptyCnr(hwnd);
569}
570
571//== FillArcCnr() generate archive content list and fill container window ==
572
573static INT FillArcCnr(HWND hwndCnr, CHAR * arcname, ARC_TYPE ** arcinfo,
574 ULONGLONG * pullTotalBytes, volatile PCHAR pStopFlag)
575{
576 FILE *fp;
577 HFILE oldstdout;
578 HFILE newstdout;
579 CHAR s[CCHMAXPATH * 2], lonename[CCHMAXPATH + 2],
580 *nsize, *osize, *fdate, *fname, *p, *pp, *arctemp;
581 BOOL gotstart;
582 BOOL gotend;
583 BOOL wasquote;
584 BOOL nomove = FALSE; // fixme to be gone?
585 INT highest = 0, fieldnum, counter = 0, numarcfiles = 0;
586 PARCITEM lastpai;
587 ARC_TYPE *info;
588 ARC_TYPE *tinfo;
589 ULONG apptype;
590 APIRET rc;
591 CHAR *mode;
592
593 if (!arcname || !arcinfo)
594 return 0;
595
596 info = *arcinfo;
597 if (!info)
598 info = find_type(arcname, NULL);
599 arctemp = xmallocz(CCHMAXPATH, pszSrcFile, __LINE__);
600 if (CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) == 1)
601 saymsg(MB_OK,
602 HWND_DESKTOP,
603 NullStr,
604 GetPString(IDS_ARCTMPDRIVESPACELIMITED),
605 ArcTempRoot);
606 MakeTempName(arctemp, ArcTempRoot, 2);
607
608
609ReTry:
610
611 tinfo = NULL;
612 numarcfiles = counter = highest = 0;
613 gotstart = gotend = FALSE;
614 lastpai = NULL;
615 *pullTotalBytes = 0;
616 if (!info || !info->list)
617 Runtime_Error(pszSrcFile, __LINE__, NULL);
618 else {
619 RemoveArcItems(hwndCnr, NULL, 0, CMA_FREE | CMA_INVALIDATE | CMA_ERASE);
620 *arcinfo = info;
621 highest = info->osizepos;
622 if (info->nsizepos > highest)
623 highest = info->nsizepos;
624 if (info->fdpos > highest)
625 highest = info->fdpos;
626 if (info->fnpos > highest)
627 highest = info->fnpos;
628 if (highest > 50) {
629 saymsg(MB_ENTER | MB_ICONEXCLAMATION, HWND_DESKTOP,
630 GetPString(IDS_SHAMETEXT), GetPString(IDS_BUNGEDUPTEXT));
631 }
632 if (info->fnpos == -1)
633 highest = 32767;
634
635 DosError(FERR_DISABLEHARDERR);
636 DosForceDelete(arctemp);
637 DosError(FERR_DISABLEHARDERR);
638
639 strcpy(s, info->list);
640 p = strchr(s, ' ');
641 if (p)
642 *p = 0;
643 DosError(FERR_DISABLEHARDERR);
644 if (!DosQueryAppType(s, &apptype) &&
645 (apptype & FAPPTYP_DOS ||
646 apptype & FAPPTYP_WINDOWSREAL ||
647 apptype & FAPPTYP_WINDOWSPROT ||
648 apptype & FAPPTYP_WINDOWSPROT31)) {
649 p = GetCmdSpec(TRUE);
650 runemf2(SEPARATE | INVISIBLE | MINIMIZED | BACKGROUND | WAIT,
651 hwndCnr, pszSrcFile, __LINE__, NULL, "DOS_BACKGROUND_EXECUTION=1",
652 "%s /C %s %s >%s",
653 p, // shell
654 info->list, // list command
655 BldQuotedFileName(s, arcname),
656 arctemp);
657 }
658 else {
659 mode = "w";
660 fp = xfopen(arctemp, mode, pszSrcFile, __LINE__, FALSE);
661 if (!fp) {
662 xfree(arctemp, pszSrcFile, __LINE__);
663 return 0;
664 }
665 else {
666 newstdout = -1;
667 DosError(FERR_DISABLEHARDERR);
668 rc = DosDupHandle(fileno(stdout), &newstdout);
669 if (rc) {
670 Dos_Error(MB_CANCEL, rc, hwndCnr, pszSrcFile, __LINE__,
671 PCSZ_DOSDUPHANDLE);
672 xfree(arctemp, pszSrcFile, __LINE__);
673 return 0;
674 }
675 else {
676 oldstdout = fileno(stdout);
677 DosError(FERR_DISABLEHARDERR);
678 rc = DosDupHandle(fileno(fp), &oldstdout);
679 if (rc) {
680 Dos_Error(MB_CANCEL, rc, hwndCnr, pszSrcFile, __LINE__,
681 PCSZ_DOSDUPHANDLE);
682 xfree(arctemp, pszSrcFile, __LINE__);
683 return 0;
684 }
685 else {
686 runemf2(SEPARATE | INVISIBLE | MINIMIZED | BACKGROUND | WAIT,
687 hwndCnr, pszSrcFile, __LINE__, NULL, NULL,
688 "%s %s",
689 info->list,
690 BldQuotedFileName(s, arcname));
691 oldstdout = fileno(stdout);
692 DosError(FERR_DISABLEHARDERR);
693 DosDupHandle(newstdout, &oldstdout);
694 DosClose(newstdout);
695 fclose(fp);
696 }
697 }
698 }
699 }
700
701 DosError(FERR_DISABLEHARDERR);
702 mode = "r";
703 fp = xfsopen(arctemp, mode, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
704
705 if (fp) {
706 gotstart = !info->startlist || // If list has no start marker
707 !*info->startlist ||
708 (stricmp(info->startlist, NO_START_OF_ARCHIVER_LIST_STRING) == 0);
709
710 while (!feof(fp) && !gotend && !*pStopFlag) {
711 if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__))
712 break;
713 if (!gotstart) {
714 if (!strcmp(s, info->startlist))
715 gotstart = TRUE;
716 }
717 else if (info->endlist && !strcmp(s, info->endlist))
718 gotend = TRUE;
719 else {
720 /* add to container */
721 fname = NULL;
722 bstrip(s);
723 if (info->nameisfirst) {
724 strncpy(lonename, s, CCHMAXPATH + 2);
725 lonename[CCHMAXPATH + 1] = 0;
726 fname = lonename;
727 if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__))
728 break;
729 if (*fname == '\"') {
730 memmove(fname, fname + 1, strlen(fname) + 1);
731 p = strchr(fname, '\"');
732 if (p)
733 *p = 0;
734 }
735 }
736 nsize = NULL;
737 osize = fdate = NullStr;
738 p = s;
739 for (fieldnum = 0; fieldnum <= highest; fieldnum++) {
740 pp = p;
741 while (*pp && (*pp == ' ' || *pp == '\t')) /* skip leading */
742 pp++;
743 if (!*pp)
744 break;
745 wasquote = FALSE;
746 p = pp;
747 while (*p && (wasquote ||
748 ((fieldnum != info->fnpos || !info->nameislast) ?
749 (*p != ' ' && *p != '\t') : TRUE))) {
750 if (*p == '\"') {
751 if (!wasquote) {
752 wasquote = TRUE;
753 memmove(p, p + 1, strlen(p));
754 while (*p == ' ' || *p == '\t')
755 p++;
756 }
757 else {
758 memmove(p, p + 1, strlen(p));
759 break;
760 }
761 }
762 else if (*p)
763 p++;
764 }
765 if (*p) {
766 *p = 0;
767 p++;
768 }
769 if (fieldnum == info->nsizepos)
770 nsize = pp;
771 else if (fieldnum == info->osizepos)
772 osize = pp;
773 else if (fieldnum == info->fdpos) {
774 fdate = pp;
775 if (info->fdflds > 1 && info->fdflds < 24) {
776 INT y;
777
778 if (*p) {
779 p--;
780 *p = ' ';
781 for (y = 0; y < info->fdflds - 1; y++) {
782 while (*p && (*p == ' ' || *p == '\t'))
783 p++;
784 while (*p && (*p != ' ' && *p != '\t'))
785 p++;
786 fieldnum++;
787 }
788 if (*p) {
789 *p = 0;
790 p++;
791 }
792 }
793 }
794 }
795 else if (fieldnum == info->fnpos) {
796 fname = pp;
797 if (pp && *pp == '*' && !*(pp + 1)) /* workaround for LH.EXE */
798 fname = NULL;
799 if (info->nameislast)
800 break;
801 }
802 else if ((!p || !*p) && info->fnpos == -1) {
803 fname = pp;
804 break;
805 }
806 }
807 if (info->nameisnext) {
808 if (!xfgets_bstripcr
809 (lonename, sizeof(lonename), fp, pszSrcFile, __LINE__))
810 break;
811 fname = lonename;
812 }
813 // fixme to complain?
814 if (fname && *fname) {
815
816 RECORDINSERT ri;
817 PARCITEM pai;
818
819 pai = WinSendMsg(hwndCnr,
820 CM_ALLOCRECORD,
821 MPFROMLONG(EXTRA_ARCRECORD_BYTES),
822 MPFROMLONG(1L));
823 if (!pai) {
824 Runtime_Error(pszSrcFile, __LINE__, PCSZ_CM_ALLOCRECORD);
825 break;
826 }
827 else {
828 memset(pai, 0, sizeof(ARCITEM));
829 pai->hwndCnr = hwndCnr;
830 if (*fname == '*') {
831 fname++;
832 pai->flags = ARCFLAGS_REALDIR;
833 }
834 if (fname[strlen(fname) - 1] == '\\' ||
835 fname[strlen(fname) - 1] == '/')
836 pai->flags = ARCFLAGS_REALDIR;
837 pai->pszFileName = xstrdup(fname,pszSrcFile, __LINE__);
838# ifdef FORTIFY
839 // Will be freed by WM_DESTROY
840 Fortify_SetOwner(pai->pszFileName, 1);
841 // Fortify_ChangeScope(pai->pszFileName, -1);
842# endif
843
844 pai->pszDisplayName = pai->pszFileName;
845 pai->rc.pszIcon = pai->pszDisplayName;
846 if (fdate)
847 strcpy(pai->szDate, fdate);
848 // pai->pszFileName = pai->pszFileName;
849 pai->rc.pszIcon = pai->pszFileName;
850 pai->rc.hptrIcon = (pai->flags & ARCFLAGS_REALDIR) != 0 ?
851 hptrDir : hptrFile;
852 pai->pszDate = pai->szDate;
853 if (osize)
854 pai->cbFile = atol(osize);
855 if (nsize)
856 pai->cbComp = atol(nsize);
857 if (info->datetype && fdate && *fdate)
858 ArcDateTime(fdate, info->datetype, &pai->date, &pai->time);
859 memset(&ri, 0, sizeof(RECORDINSERT));
860 ri.cb = sizeof(RECORDINSERT);
861 ri.pRecordOrder = (PRECORDCORE) CMA_END;
862 ri.pRecordParent = (PRECORDCORE) NULL;
863 ri.zOrder = (USHORT) CMA_TOP;
864 ri.cRecordsInsert = 1L;
865 ri.fInvalidateRecord = FALSE;
866 if (WinSendMsg(hwndCnr,
867 CM_INSERTRECORD, MPFROMP(pai), MPFROMP(&ri))) {
868 *pullTotalBytes += pai->cbFile;
869 }
870 numarcfiles++;
871 if (!(++counter % 50)) {
872 if (!lastpai)
873 lastpai = pai;
874 WinSendMsg(hwndCnr,
875 CM_INVALIDATERECORD,
876 lastpai,
877 MPFROM2SHORT(10, CMA_ERASE | CMA_REPOSITION));
878 lastpai = pai;
879 }
880 // Avoid hogging system for large archive
881 if (numarcfiles == 100)
882 priority_idle();
883 }
884 }
885 }
886 } // while !eof
887
888 fclose(fp);
889
890 if (*pStopFlag)
891 numarcfiles = 0; // Request close
892 else if (!numarcfiles || !gotstart
893 || (!gotend && info->endlist && *info->endlist && (stricmp(info->endlist, NO_END_OF_ARCHIVER_LIST_STRING)))) {
894 // Oops
895 ARCDUMP ad;
896 CHAR errstr[CCHMAXPATH + 256];
897
898 // Try for alternate archiver
899 tinfo = info;
900 do {
901 tinfo = tinfo->next;
902 if (tinfo)
903 tinfo = find_type(arcname, tinfo);
904 if (tinfo) {
905 DosError(FERR_DISABLEHARDERR);
906 DosForceDelete(arctemp);
907 info = tinfo;
908 goto ReTry;
909 }
910 } while (tinfo);
911 if (!fAlertBeepOff)
912 DosBeep(750, 50); // wake up user
913 sprintf(errstr, GetPString(IDS_ARCERRORINFOTEXT),
914 arcname,
915 !gotstart ? GetPString(IDS_NOGOTSTARTTEXT) : NullStr,
916 !numarcfiles ? GetPString(IDS_NOARCFILESFOUNDTEXT) :
917 NullStr,
918 !gotend ? GetPString(IDS_NOENDOFLISTTEXT) : NullStr);
919 memset(&ad, 0, sizeof(ARCDUMP));
920 ad.info = info;
921 strcpy(ad.listname, arctemp);
922 strcpy(ad.arcname, arcname);
923 ad.errmsg = errstr;
924 WinDlgBox(HWND_DESKTOP,
925 hwndCnr,
926 ArcErrProc, FM3ModHandle, ARCERR_FRAME, MPFROMP(&ad));
927 }
928 else if (!nomove && tinfo) {
929 /* if we got a false hit, move working hit to top */
930 tinfo = info->next;
931 info->next = arcsighead;
932 arcsighead->prev = info;
933 if (tinfo)
934 tinfo->next->prev = info->prev;
935 info->prev->next = tinfo;
936 info->prev = NULL;
937 arcsighead = info;
938 rewrite_archiverbb2(NULL); // Rewrite with warning
939 }
940 } // if opened
941
942 DosError(FERR_DISABLEHARDERR);
943 DosForceDelete(arctemp);
944 xfree(arctemp, pszSrcFile, __LINE__);
945 }
946
947 if (numarcfiles)
948 priority_normal();
949
950 return numarcfiles;
951}
952
953MRESULT EXPENTRY ArcTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
954{
955 static BOOL emphasized = FALSE;
956 static HWND hwndButtonPopup = (HWND) 0;
957 static ULONG timestamp = ULONG_MAX;
958 static USHORT lastid = 0;
959
960 switch (msg) {
961 case WM_CREATE:
962 return CommonTextProc(hwnd, msg, mp1, mp2);
963
964 case WM_COMMAND:
965 return WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
966 ARC_CNR), msg, mp1, mp2);
967
968 case UM_CONTEXTMENU:
969 case WM_CONTEXTMENU:
970 {
971 USHORT id;
972
973 id = WinQueryWindowUShort(hwnd, QWS_ID);
974 switch (id) {
975 case DIR_SELECTED:
976 case DIR_VIEW:
977 case DIR_SORT:
978 {
979 POINTL ptl = { 0, 0 };
980 SWP swp;
981 DIRCNRDATA *dcd;
982
983 if (hwndButtonPopup)
984 WinDestroyWindow(hwndButtonPopup);
985 if (id == DIR_SELECTED)
986 id = DIR_RESTORE;
987 if (id == lastid) {
988
989 ULONG check;
990
991 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &check,
992 sizeof(check));
993 if (check < timestamp + 500) {
994 lastid = 0;
995 goto MenuAbort;
996 }
997 }
998 hwndButtonPopup = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
999 if (hwndButtonPopup) {
1000 WinSetWindowUShort(hwndButtonPopup, QWS_ID, id);
1001 dcd = WinQueryWindowPtr(WinWindowFromID(WinQueryWindow(hwnd,
1002 QW_PARENT),
1003 ARC_CNR), QWL_USER);
1004 if (id == DIR_SORT) {
1005 if (dcd)
1006 SetSortChecks(hwndButtonPopup, dcd->sortFlags);
1007 WinSendMsg(hwndButtonPopup,
1008 MM_DELETEITEM,
1009 MPFROM2SHORT(IDM_SORTNONE, FALSE), MPVOID);
1010 WinSendMsg(hwndButtonPopup,
1011 MM_DELETEITEM,
1012 MPFROM2SHORT(IDM_SORTNAME, FALSE), MPVOID);
1013 WinSendMsg(hwndButtonPopup,
1014 MM_DELETEITEM,
1015 MPFROM2SHORT(IDM_SORTLADATE, FALSE), MPVOID);
1016 WinSendMsg(hwndButtonPopup,
1017 MM_DELETEITEM,
1018 MPFROM2SHORT(IDM_SORTCRDATE, FALSE), MPVOID);
1019 WinSendMsg(hwndButtonPopup,
1020 MM_DELETEITEM,
1021 MPFROM2SHORT(IDM_SORTDIRSFIRST, FALSE), MPVOID);
1022 WinSendMsg(hwndButtonPopup,
1023 MM_DELETEITEM,
1024 MPFROM2SHORT(IDM_SORTDIRSLAST, FALSE), MPVOID);
1025 WinSendMsg(hwndButtonPopup,
1026 MM_DELETEITEM,
1027 MPFROM2SHORT(IDM_SORTSUBJECT, FALSE), MPVOID);
1028 WinSendMsg(hwndButtonPopup,
1029 MM_SETITEMTEXT,
1030 MPFROM2SHORT(IDM_SORTEASIZE, 0),
1031 MPFROMP(GetPString(IDS_COMPRESSEDSIZEMENUTEXT)));
1032 WinSendMsg(hwndButtonPopup,
1033 MM_SETITEMTEXT,
1034 MPFROM2SHORT(IDM_SORTLWDATE, 0),
1035 MPFROMP(GetPString(IDS_DATEMENUTEXT)));
1036 }
1037 ptl.x = 0;
1038 if (WinPopupMenu(HWND_OBJECT,
1039 HWND_OBJECT,
1040 hwndButtonPopup, -32767, -32767, 0, 0)) {
1041 WinQueryWindowPos(hwndButtonPopup, &swp);
1042 ptl.y = -(swp.cy + 2);
1043 }
1044 else {
1045 WinQueryWindowPos(hwnd, &swp);
1046 ptl.y = swp.cy + 2;
1047 }
1048 if (WinPopupMenu(hwnd,
1049 hwnd,
1050 hwndButtonPopup,
1051 ptl.x,
1052 ptl.y,
1053 0,
1054 PU_HCONSTRAIN | PU_VCONSTRAIN |
1055 PU_KEYBOARD | PU_MOUSEBUTTON1)) {
1056 CenterOverWindow(hwndButtonPopup);
1057 PaintRecessedWindow(hwnd, (HPS) 0, FALSE, FALSE);
1058 }
1059 }
1060 }
1061 break;
1062 default:
1063 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1064 ARC_CNR),
1065 WM_CONTROL, MPFROM2SHORT(ARC_CNR, CN_CONTEXTMENU), MPVOID);
1066 break;
1067 }
1068 }
1069 MenuAbort:
1070 if (msg == UM_CONTEXTMENU)
1071 return 0;
1072 break;
1073
1074 case WM_MENUEND:
1075 if (hwndButtonPopup == (HWND) mp2) {
1076 lastid = WinQueryWindowUShort((HWND) mp2, QWS_ID);
1077 WinDestroyWindow(hwndButtonPopup);
1078 hwndButtonPopup = (HWND) 0;
1079 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &timestamp,
1080 sizeof(timestamp));
1081 switch (lastid) {
1082 case DIR_VIEW:
1083 case DIR_SORT:
1084 case DIR_RESTORE:
1085 case DIR_SELECTED:
1086 PaintRecessedWindow(hwnd, (HPS) 0, TRUE, FALSE);
1087 break;
1088 }
1089 }
1090 break;
1091
1092 case WM_MOUSEMOVE:
1093 {
1094 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
1095 PCSZ s = NULL;
1096
1097 if (fOtherHelp) {
1098 if ((!hwndBubble ||
1099 WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd) &&
1100 !WinQueryCapture(HWND_DESKTOP)) {
1101 switch (id) {
1102 case DIR_TOTALS:
1103 s = GetPString(IDS_ARCCNRTOTALSHELPTEXT);
1104 break;
1105 case DIR_SELECTED:
1106 s = GetPString(IDS_ARCCNRSELECTEDHELPTEXT);
1107 break;
1108 case DIR_VIEW:
1109 s = GetPString(IDS_ARCCNRVIEWHELPTEXT);
1110 break;
1111 case DIR_SORT:
1112 s = GetPString(IDS_DIRCNRSORTHELP);
1113 break;
1114 case DIR_FILTER:
1115 s = GetPString(IDS_DIRCNRFILTERHELP);
1116 break;
1117 case DIR_FOLDERICON:
1118 s = GetPString(IDS_ARCCNRFOLDERHELPTEXT);
1119 break;
1120 default:
1121 break;
1122 }
1123 if (s)
1124 MakeBubble(hwnd, TRUE, s);
1125 else if (hwndBubble)
1126 WinDestroyWindow(hwndBubble);
1127 }
1128 }
1129 switch (id) {
1130 case DIR_FILTER:
1131 case DIR_SORT:
1132 case DIR_VIEW:
1133 case DIR_SELECTED:
1134 case DIR_FOLDERICON:
1135 return CommonTextButton(hwnd, msg, mp1, mp2);
1136 }
1137 }
1138 break;
1139
1140 case WM_BUTTON3UP:
1141 case WM_BUTTON1UP:
1142 case WM_BUTTON1DOWN:
1143 case WM_BUTTON3DOWN:
1144 {
1145 USHORT id;
1146
1147 id = WinQueryWindowUShort(hwnd, QWS_ID);
1148 switch (id) {
1149 case DIR_FILTER:
1150 case DIR_SORT:
1151 case DIR_VIEW:
1152 case DIR_SELECTED:
1153 case DIR_FOLDERICON:
1154 return CommonTextButton(hwnd, msg, mp1, mp2);
1155 }
1156 }
1157 break;
1158
1159 case UM_CLICKED:
1160 case UM_CLICKED3:
1161 {
1162 USHORT id, cmd = 0;
1163
1164 id = WinQueryWindowUShort(hwnd, QWS_ID);
1165 switch (id) {
1166 case DIR_FOLDERICON:
1167 switch (msg) {
1168 case WM_BUTTON3CLICK:
1169 case WM_CHORD:
1170 cmd = IDM_RESCAN;
1171 break;
1172 default:
1173 if ((SHORT2FROMMP(mp2) & KC_ALT) != 0)
1174 cmd = IDM_WINDOWDLG;
1175 else
1176 cmd = IDM_WALKDIR;
1177 break;
1178 }
1179 break;
1180 case DIR_VIEW:
1181 case DIR_SORT:
1182 case DIR_SELECTED:
1183 PostMsg(hwnd, UM_CONTEXTMENU, MPVOID, MPVOID);
1184 break;
1185 case DIR_FILTER:
1186 cmd = IDM_FILTER;
1187 break;
1188 default:
1189 break;
1190 }
1191 if (cmd)
1192 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1193 ARC_CNR),
1194 WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
1195 }
1196 return 0;
1197
1198 case WM_BEGINDRAG:
1199 case DM_DROP:
1200 case DM_DRAGOVER:
1201 case DM_DRAGLEAVE:
1202 case DM_DROPHELP:
1203 if (msg == DM_DRAGOVER) {
1204 if (!emphasized) {
1205 emphasized = TRUE;
1206 DrawTargetEmphasis(hwnd, emphasized);
1207 }
1208 }
1209 else if (msg != WM_BEGINDRAG) {
1210 if (emphasized) {
1211 emphasized = FALSE;
1212 DrawTargetEmphasis(hwnd, emphasized);
1213 }
1214 }
1215 switch (WinQueryWindowUShort(hwnd, QWS_ID)) {
1216 case DIR_FOLDERICON:
1217 switch (msg) {
1218 case DM_DRAGOVER:
1219 if (AcceptOneDrop(hwnd, mp1, mp2))
1220 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
1221 return MRFROM2SHORT(DOR_NODROP, 0); /* Drop not valid */
1222 case DM_DROPHELP:
1223 DropHelp(mp1, mp2, hwnd, GetPString(IDS_ARCCNRFOLDERDROPHELPTEXT));
1224 return 0;
1225 case DM_DROP:
1226 {
1227 char szFrom[CCHMAXPATH + 2];
1228
1229 if (emphasized) {
1230 emphasized = FALSE;
1231 DrawTargetEmphasis(hwnd, emphasized);
1232 }
1233 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
1234 WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1235 ARC_CNR),
1236 WM_COMMAND,
1237 MPFROM2SHORT(IDM_SWITCH, 0), MPFROMP(szFrom));
1238 }
1239 return 0;
1240 default:
1241 return PFNWPStatic(hwnd, msg, mp1, mp2);
1242 }
1243 default:
1244 {
1245 CNRDRAGINFO cnd;
1246 USHORT dcmd;
1247
1248 switch (msg) {
1249 case DM_DROP:
1250 dcmd = CN_DROP;
1251 break;
1252 case DM_DRAGOVER:
1253 dcmd = CN_DRAGOVER;
1254 break;
1255 case DM_DRAGLEAVE:
1256 dcmd = CN_DRAGLEAVE;
1257 break;
1258 case DM_DROPHELP:
1259 dcmd = CN_DROPHELP;
1260 break;
1261 case WM_BEGINDRAG:
1262 dcmd = CN_INITDRAG;
1263 break;
1264 }
1265 cnd.pDragInfo = (PDRAGINFO) mp1;
1266 cnd.pRecord = NULL;
1267 return WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
1268 WM_CONTROL,
1269 MPFROM2SHORT(ARC_CNR, dcmd), MPFROMP(&cnd));
1270 }
1271 }
1272 }
1273 return PFNWPStatic(hwnd, msg, mp1, mp2);
1274}
1275
1276MRESULT EXPENTRY ArcClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
1277 MPARAM mp2)
1278{
1279
1280 switch (msg) {
1281 case UM_CONTAINERHWND:
1282 return MRFROMLONG(WinWindowFromID(hwnd, ARC_CNR));
1283
1284 case UM_VIEWSMENU:
1285 // fixme to disble menu items as needed
1286 return MRFROMLONG(CheckMenu(hwnd, &ArcCnrMenu, ARCCNR_POPUP));
1287
1288 case UM_FILESMENU:
1289 // fixme to disble menu items as needed
1290 return MRFROMLONG(CheckMenu(hwnd, &ArcMenu, ARC_POPUP));
1291
1292 case MM_PORTHOLEINIT:
1293 case WM_INITMENU:
1294 case UM_INITMENU:
1295 case UM_COMMAND:
1296 case UM_LOADFILE:
1297 case UM_UPDATERECORD:
1298 case UM_UPDATERECORDLIST:
1299 case WM_COMMAND:
1300 case WM_CONTROL:
1301 case WM_CLOSE:
1302 return WinSendMsg(WinWindowFromID(hwnd, ARC_CNR), msg, mp1, mp2);
1303
1304 case WM_PSETFOCUS:
1305 case WM_SETFOCUS:
1306 if (mp2)
1307 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
1308 break;
1309
1310 case UM_FOCUSME:
1311 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ARC_CNR));
1312 break;
1313
1314 case WM_PAINT:
1315 {
1316 HPS hps;
1317 RECTL rcl;
1318
1319 hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
1320 if (hps) {
1321 WinQueryWindowRect(hwnd, &rcl);
1322 WinFillRect(hps, &rcl, CLR_PALEGRAY);
1323 CommonTextPaint(hwnd, hps);
1324 WinEndPaint(hps);
1325 }
1326 }
1327 break;
1328
1329 case UM_SIZE:
1330 case WM_SIZE:
1331 if (msg == UM_SIZE) {
1332
1333 SWP swp;
1334
1335 WinQueryWindowPos(hwnd, &swp);
1336 mp1 = MPFROM2SHORT(swp.cx, swp.cy);
1337 mp2 = MPFROM2SHORT(swp.cx, swp.cy);
1338 }
1339 {
1340 USHORT cx, cy, bx;
1341
1342 cx = SHORT1FROMMP(mp2);
1343 cy = SHORT2FROMMP(mp2);
1344 WinSetWindowPos(WinWindowFromID(hwnd, ARC_CNR), HWND_TOP,
1345 0,
1346 22, cx, cy - (24 + 22), SWP_SHOW | SWP_MOVE | SWP_SIZE);
1347 WinSetWindowPos(WinWindowFromID(hwnd, ARC_EXTRACTDIR), HWND_TOP,
1348 0, 0, cx, 22, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1349 WinSetWindowPos(WinWindowFromID(hwnd, DIR_FOLDERICON), HWND_TOP,
1350 2, cy - 22, 24, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1351 WinSetWindowPos(WinWindowFromID(hwnd, DIR_TOTALS), HWND_TOP,
1352 29,
1353 cy - 22,
1354 (cx / 3) - 2, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1355 WinSetWindowPos(WinWindowFromID(hwnd, DIR_SELECTED), HWND_TOP,
1356 29 + (cx / 3) + 2,
1357 cy - 22,
1358 (cx / 3) - 2, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1359 bx = (cx - (29 + (((cx / 3) + 2) * 2))) / 3;
1360 WinSetWindowPos(WinWindowFromID(hwnd, DIR_VIEW), HWND_TOP,
1361 29 + (((cx / 3) + 2) * 2),
1362 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1363 WinSetWindowPos(WinWindowFromID(hwnd, DIR_SORT), HWND_TOP,
1364 29 + (((cx / 3) + 2) * 2) + bx,
1365 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1366 WinSetWindowPos(WinWindowFromID(hwnd, DIR_FILTER), HWND_TOP,
1367 29 + (((cx / 3) + 2) * 2) + (bx * 2),
1368 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1369 }
1370 CommonTextPaint(hwnd, (HPS) 0);
1371 if (msg == UM_SIZE) {
1372 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP, 0, 0, 0, 0,
1373 SWP_SHOW | SWP_ZORDER | SWP_ACTIVATE);
1374 return 0;
1375 }
1376 break;
1377 }
1378 return WinDefWindowProc(hwnd, msg, mp1, mp2);
1379}
1380
1381MRESULT EXPENTRY ArcObjWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1382{
1383 DIRCNRDATA *dcd;
1384 PSZ psz;
1385 CHAR szQuotedArcName[CCHMAXPATH];
1386 CHAR szQuotedMemberName[CCHMAXPATH];
1387
1388 switch (msg) {
1389 case WM_CREATE:
1390 DbgMsg(pszSrcFile, __LINE__, "WM_CREATE mp1 %p mp2 %p", mp1, mp2); // 18 Jul 08 SHL fixme
1391 break;
1392
1393 case DM_PRINTOBJECT:
1394 case DM_DISCARDOBJECT:
1395 dcd = INSTDATA(hwnd);
1396 if (dcd) {
1397
1398 LISTINFO *li;
1399 CNRDRAGINFO cni;
1400
1401 cni.pRecord = NULL;
1402 cni.pDragInfo = (PDRAGINFO) mp1;
1403 li = DoFileDrop(dcd->hwndCnr,
1404 dcd->directory, FALSE, MPVOID, MPFROMP(&cni));
1405 CheckPmDrgLimit(cni.pDragInfo);
1406 if (li) {
1407 li->type = (msg == DM_DISCARDOBJECT) ? IDM_DELETE : IDM_PRINT;
1408 if (!li->list ||
1409 !li->list[0] || !PostMsg(hwnd, UM_ACTION, MPFROMP(li), MPVOID))
1410 FreeListInfo(li);
1411 else
1412 return MRFROMLONG(DRR_SOURCE);
1413 }
1414 }
1415 return MRFROMLONG(DRR_TARGET);
1416
1417 case DM_RENDERPREPARE:
1418 return (MRESULT) TRUE;
1419
1420 case DM_RENDER:
1421 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1422 if (dcd && dcd->info && dcd->info->extract && dcd->arcname) {
1423
1424 PDRAGTRANSFER pdt = (PDRAGTRANSFER) mp1;
1425 CHAR filename[CCHMAXPATH];
1426 ULONG len;
1427
1428 if (pdt->hwndClient && pdt->pditem && pdt->hstrSelectedRMF &&
1429 pdt->hstrRenderToName) {
1430 if (pdt->usOperation == DO_COPY || pdt->usOperation == DO_MOVE) {
1431 *filename = 0;
1432 len = DrgQueryStrName(pdt->hstrSelectedRMF, CCHMAXPATH, filename);
1433 filename[len] = 0;
1434 if (strnicmp(filename, "OS2FILE,", 8)) {
1435 *filename = 0;
1436 len = DrgQueryStrName(pdt->hstrRenderToName, CCHMAXPATH, filename);
1437 filename[len] = 0;
1438 if (len && *filename) {
1439 psz = xstrdup(filename, pszSrcFile, __LINE__);
1440 if (psz) {
1441 PostMsg(hwnd, UM_RENDER, MPFROMP(pdt), MPFROMP(psz));
1442 return (MRESULT) TRUE;
1443 }
1444 }
1445 }
1446 }
1447 pdt->fsReply = DMFL_RENDERRETRY;
1448 }
1449 }
1450 return (MRESULT) FALSE;
1451
1452 case UM_RENDER:
1453 {
1454 PDRAGTRANSFER pdt = (PDRAGTRANSFER) mp1;
1455 USHORT usRes = DMFL_RENDERFAIL;
1456
1457 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1458 if (dcd && dcd->info && dcd->info->extract && dcd->arcname) {
1459
1460 CHAR *filename = (CHAR *) mp2, *p;
1461 ULONG len;
1462 CHAR membername[CCHMAXPATH], construct[CCHMAXPATH * 2];
1463
1464 *membername = 0;
1465 len = DrgQueryStrName(pdt->pditem->hstrSourceName,
1466 CCHMAXPATH, membername);
1467 membername[len] = 0;
1468 if (*membername && len && filename) {
1469 unlinkf(filename);
1470 strcpy(construct, filename);
1471 p = strrchr(filename, '\\');
1472 if (!p)
1473 *construct = 0;
1474 else {
1475 if (p == filename || *(p - 1) == ':')
1476 p++;
1477 *p = 0;
1478 }
1479 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS | WAIT |
1480 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1481 dcd->hwndClient, pszSrcFile, __LINE__, construct, NULL,
1482 "%s %s %s",
1483 dcd->info->extract,
1484 BldQuotedFileName(szQuotedArcName, dcd->arcname),
1485 BldQuotedFileName(szQuotedMemberName, membername));
1486 BldFullPathName(construct, construct, membername);
1487 if (IsFile(construct) != -1) {
1488 rename(construct, filename);
1489 unlinkf(construct);
1490 if (IsFile(filename) != -1)
1491 usRes = DMFL_RENDEROK;
1492 }
1493 }
1494 }
1495 xfree((CHAR *)mp2, pszSrcFile, __LINE__);
1496 PostMsg(pdt->hwndClient, DM_RENDERCOMPLETE, MPFROMP(pdt),
1497 MPFROM2SHORT(usRes, 0));
1498 }
1499 return 0;
1500
1501 case UM_SETUP:
1502# ifdef FORTIFY
1503 Fortify_EnterScope();
1504# endif
1505 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1506 if (!dcd) {
1507 Runtime_Error(pszSrcFile, __LINE__, NULL);
1508 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1509 }
1510 else {
1511# ifdef FORTIFY
1512 Fortify_BecomeOwner(dcd);
1513# endif
1514 /* set unique id */
1515 WinSetWindowUShort(hwnd, QWS_ID, ARCOBJ_FRAME + (ARC_FRAME - dcd->id));
1516 dcd->hwndObject = hwnd; // pass back hwnd
1517 if (ParentIsDesktop(hwnd, dcd->hwndParent))
1518 DosSleep(100); //05 Aug 07 GKY 250 // Avoid race?
1519 }
1520 return 0;
1521
1522 case UM_RESCAN:
1523 /*
1524 * populate container
1525 */
1526 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1527 if (dcd) {
1528 if (mp1)
1529 strcpy(dcd->arcname, (CHAR *) mp1); // Update name on request
1530 dcd->ullTotalBytes = dcd->totalfiles =
1531 dcd->selectedfiles = dcd->selectedbytes = 0;
1532 WinSetDlgItemText(dcd->hwndClient, DIR_TOTALS, "0");
1533 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, "0 / 0k");
1534 dcd->totalfiles = FillArcCnr(dcd->hwndCnr,
1535 dcd->arcname,
1536 &dcd->info,
1537 &dcd->ullTotalBytes, &dcd->stopflag);
1538 if (!dcd->totalfiles)
1539 PostMsg(dcd->hwndCnr, WM_CLOSE, MPVOID, MPVOID);
1540 else {
1541 dcd->arcfilled = TRUE;
1542 if (!PostMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID))
1543 WinSendMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID);
1544 PostMsg(dcd->hwndCnr, UM_SETUP2, MPVOID, MPVOID);
1545 WinSendMsg(dcd->hwndCnr,
1546 CM_INVALIDATERECORD,
1547 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
1548 }
1549 }
1550 return 0;
1551
1552 case UM_SELECT:
1553 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1554 if (dcd) {
1555 switch (SHORT1FROMMP(mp1)) {
1556 case IDM_SELECTALL:
1557 case IDM_SELECTALLFILES:
1558 SelectAll(dcd->hwndCnr, TRUE, TRUE, NULL, NULL, TRUE);
1559 break;
1560 case IDM_DESELECTALL:
1561 case IDM_DESELECTALLFILES:
1562 DeselectAll(dcd->hwndCnr, TRUE, TRUE, NULL, NULL, TRUE);
1563 break;
1564 case IDM_DESELECTMASK:
1565 case IDM_SELECTMASK:
1566 {
1567 MASK mask;
1568 PARCITEM pci = (PARCITEM) mp2;
1569
1570 memset(&mask, 0, sizeof(MASK));
1571 mask.fNoAttribs = TRUE;
1572 mask.fNoDirs = TRUE;
1573 mask.fText = TRUE;
1574 strcpy(mask.prompt,
1575 GetPString((SHORT1FROMMP(mp1) == IDM_SELECTMASK) ?
1576 IDS_SELECTFILTERTEXT : IDS_DESELECTFILTERTEXT));
1577 if (pci && (INT) pci != -1)
1578 strcpy(mask.szMask, pci->pszFileName);
1579 if (WinDlgBox(HWND_DESKTOP, dcd->hwndCnr, PickMaskDlgProc,
1580 FM3ModHandle, MSK_FRAME, MPFROMP(&mask))) {
1581 if (SHORT1FROMMP(mp1) == IDM_SELECTMASK)
1582 SelectAll(dcd->hwndCnr, TRUE, TRUE, mask.szMask, NULL, FALSE);
1583 else
1584 DeselectAll(dcd->hwndCnr, TRUE, TRUE, mask.szMask, NULL, FALSE);
1585 }
1586 }
1587 break;
1588
1589 case IDM_INVERT:
1590 InvertAll(dcd->hwndCnr);
1591 break;
1592 }
1593 }
1594 return 0;
1595
1596 case UM_ENTER:
1597 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1598 if (dcd) {
1599
1600 CHAR *s = (CHAR *) mp1, *p, *pp; // filename[CCHMAXPATH];
1601 WAITCHILD *WaitChild;
1602
1603 WaitChild = xmallocz(sizeof(WAITCHILD), pszSrcFile, __LINE__);
1604 WaitChild->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1605 if (!WaitChild)
1606 return 0;
1607 if (s) {
1608 if (!dcd->info->extract) {
1609 Runtime_Error(pszSrcFile, __LINE__, "no extract");
1610 free(s);
1611 return 0;
1612 }
1613 sprintf(WaitChild->pszCmdLine, "%s %s %s",
1614 dcd->info->exwdirs ? dcd->info->exwdirs :
1615 dcd->info->extract,
1616 BldQuotedFileName(szQuotedArcName, dcd->arcname),
1617 BldQuotedFileName(szQuotedMemberName, s));
1618 if (!dcd->info->exwdirs) {
1619 p = s;
1620 p = strrchr(s, '\\');
1621 pp = strrchr(s, '/');
1622 if (p && pp)
1623 p = max(p, pp);
1624 else if (!p)
1625 p = pp;
1626 if (p)
1627 memmove(s, p + 1, strlen(p + 1));
1628 }
1629 sprintf(WaitChild->filename, "%s\\%s", dcd->workdir, s);
1630 ForwardslashToBackslash(WaitChild->filename);
1631 free(s);
1632 WaitChild->RunFlags = SEPARATE | ASYNCHRONOUS | WAIT |
1633 (fArcStuffVisible ? 0 : BACKGROUND);
1634 WaitChild->hwndClient = dcd->hwndClient;
1635 WaitChild->msg = UM_ENTER;
1636 WaitChild->uiLineNumber = __LINE__;
1637 WaitChild->pszSrcFile = pszSrcFile;
1638 WaitChild->pszDirectory = xstrdup(dcd->workdir, pszSrcFile, __LINE__);
1639 WaitChild->pszEnvironment = NULL;
1640 strcpy(WaitChild->formatstring, "%s");
1641 WaitChild->hwndCnr = dcd->hwndCnr;
1642 xbeginthread(WaitChildThread,
1643 65536,
1644 WaitChild,
1645 pszSrcFile,
1646 __LINE__);
1647 }
1648 }
1649 return 0;
1650
1651 case UM_COMMAND:
1652 if (mp1) {
1653 if (PostMsg(hwnd, UM_ACTION, mp1, mp2))
1654 return (MRESULT) TRUE;
1655 }
1656 return 0;
1657
1658 case UM_ACTION:
1659 DosError(FERR_DISABLEHARDERR);
1660 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1661 if (dcd) {
1662
1663 LISTINFO *li = (LISTINFO *) mp1;
1664 register INT x;
1665
1666 if (li && li->list && li->list[0]) {
1667 // printf("%x/r", li->type); fflush(stdout); // 24 Sep 08 SHL
1668 switch (li->type) {
1669 case IDM_ARCHIVE:
1670 case IDM_ARCHIVEM:
1671 {
1672 DIRCNRDATA ad;
1673 CHAR szBuffer[1025], *p;
1674
1675 if (!li->list[1] && !stricmp(li->list[0], dcd->arcname)) {
1676 Runtime_Error(pszSrcFile, __LINE__, "arc to self");
1677 break;
1678 }
1679 ad = *dcd;
1680 ad.namecanchange = 0;
1681 ad.fmoving = (li->type == IDM_ARCHIVEM);
1682 if (!WinDlgBox(HWND_DESKTOP, dcd->hwndClient, ArchiveDlgProc, FM3ModHandle, ARCH_FRAME, (PVOID) & ad) || !*ad.arcname || !*ad.command) /* we blew it */
1683 break;
1684 /* build the sucker */
1685 strcpy(szBuffer, ad.command);
1686 strcat(szBuffer, " ");
1687
1688 BldQuotedFileName(szBuffer + strlen(szBuffer), ad.arcname);
1689
1690 p = &szBuffer[strlen(szBuffer)]; // Remeber where archiver name ends
1691
1692 if (ad.mask.szMask) {
1693 strcat(szBuffer, " ");
1694
1695 BldQuotedFileName(szBuffer + strlen(szBuffer), ad.mask.szMask);
1696 }
1697 strcat(szBuffer, " ");
1698 x = 0;
1699
1700 // Run commands avoiding command line overflow
1701 while (li->list[x]) {
1702
1703 if (IsFile(li->list[x]))
1704 BldQuotedFileName(szBuffer + strlen(szBuffer), li->list[x]);
1705 else
1706 BldQuotedFullPathName(szBuffer + strlen(szBuffer), li->list[x], "*");
1707
1708 x++;
1709 if (!li->list[x] || strlen(szBuffer) +
1710 strlen(li->list[x]) + 5 > MaxComLineStrg) {
1711 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
1712 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1713 hwnd, pszSrcFile, __LINE__,
1714 NULL, NULL, "%s", szBuffer);
1715 *p = 0;
1716 }
1717 strcat(szBuffer, " ");
1718 } // while
1719
1720 PostMsg(dcd->hwndCnr, UM_RESCAN, MPFROMSHORT(1), MPVOID);
1721 Broadcast(WinQueryAnchorBlock(hwnd),
1722 hwndMain, UM_UPDATERECORD, MPFROMP(ad.arcname), MPVOID);
1723 Broadcast(WinQueryAnchorBlock(hwnd),
1724 hwndMain,
1725 UM_UPDATERECORDLIST, MPFROMP(li->list), MPVOID);
1726 }
1727 break;
1728
1729 case IDM_REFRESH:
1730 case IDM_DELETE:
1731 {
1732 CHAR *endofit;
1733 PSZ pszCmdLine;
1734 INT z;
1735 CHECKLIST ck;
1736 CHAR prompt[CCHMAXPATH + 257];
1737
1738 if (!dcd->info->delete)
1739 break;
1740 memset(&ck, 0, sizeof(ck));
1741 ck.size = sizeof(ck);
1742 ck.list = li->list;
1743 ck.cmd = li->type;
1744 ck.prompt = prompt;
1745 ck.flags = CHECK_ARCHIVE;
1746 sprintf(prompt, GetPString(IDS_ARCCNRDELREFTEXT),
1747 (li->type == IDM_DELETE) ?
1748 GetPString(IDS_DELETELOWERTEXT) :
1749 GetPString(IDS_REFRESHLOWERTEXT),
1750 &"s"[li->list[1] == NULL],
1751 dcd->arcname,
1752 (li->type == IDM_DELETE) ?
1753 GetPString(IDS_DELETELOWERTEXT) :
1754 GetPString(IDS_REFRESHLOWERTEXT));
1755 if (!WinDlgBox(HWND_DESKTOP, hwnd, CheckListProc,
1756 FM3ModHandle, CHECK_FRAME, MPFROMP(&ck)))
1757 break;
1758 li->list = ck.list;
1759 if (!li->list || !li->list[0])
1760 break;
1761 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1762 if (!pszCmdLine)
1763 break;
1764 strcpy(pszCmdLine, li->type == IDM_DELETE ?
1765 dcd->info->delete :
1766 dcd->info->create);
1767 strcat(pszCmdLine, " ");
1768 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), dcd->arcname);
1769 endofit = &pszCmdLine[strlen(pszCmdLine)];
1770 z = 0;
1771 do {
1772 for (x = z; li->list[x] &&
1773 strlen(pszCmdLine) + strlen(li->list[x]) < 999; x++) {
1774 strcat(pszCmdLine, " ");
1775 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), li->list[x]);
1776 }
1777 z = x;
1778 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS | WAIT |
1779 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1780 hwnd, pszSrcFile, __LINE__, NullStr, NULL, "%s", pszCmdLine);
1781 *endofit = 0;
1782 free(pszCmdLine);
1783 } while (li->list[x]);
1784 PostMsg(dcd->hwndCnr, UM_RESCAN, MPFROMSHORT(1), MPVOID);
1785 Broadcast(WinQueryAnchorBlock(hwnd),
1786 hwndMain,
1787 UM_UPDATERECORD, MPFROMP(dcd->arcname), MPVOID);
1788 }
1789 break;
1790
1791 case IDM_PRINT:
1792 case IDM_VIRUSSCAN:
1793 case IDM_VIEW:
1794 case IDM_MCIPLAY:
1795 case IDM_VIEWARCHIVE:
1796 case IDM_VIEWTEXT:
1797 case IDM_VIEWBINARY:
1798 case IDM_EDIT:
1799 case IDM_EDITTEXT:
1800 case IDM_EDITBINARY:
1801 case IDM_EXEC:
1802 case IDM_EXTRACTWDIRS:
1803 case IDM_EXTRACT:
1804 case IDM_OPENDEFAULT:
1805 case IDM_OPENSETTINGS:
1806 {
1807 CHAR *endofit, *ptr;
1808 PSZ pszCmdLine;
1809 INT z;
1810 if ((li->type == IDM_EXTRACT && !li->info->extract) ||
1811 ((li->type == IDM_VIEW || li->type == IDM_VIEWTEXT ||
1812 li->type == IDM_VIEWBINARY || li->type == IDM_EDIT ||
1813 li->type == IDM_VIEWARCHIVE || li->type == IDM_EDITTEXT ||
1814 li->type == IDM_EDITBINARY || li->type == IDM_MCIPLAY) &&
1815 (!li->info->extract && !li->info->exwdirs)) ||
1816 (li->type != IDM_EXTRACT && li->type != IDM_EDIT &&
1817 li->type != IDM_VIEW && li->type != IDM_VIEWTEXT &&
1818 li->type != IDM_VIEWBINARY &&
1819 li->type != IDM_VIEWARCHIVE &&
1820 li->type != IDM_EDITTEXT &&
1821 li->type != IDM_EDITBINARY &&
1822 li->type != IDM_MCIPLAY && !li->info->exwdirs)) {
1823 Runtime_Error(pszSrcFile, __LINE__, "no cmd for request");
1824 break;
1825 }
1826 if (li->type == IDM_EXTRACT || li->type == IDM_EXTRACTWDIRS) {
1827
1828 CHAR fullname[CCHMAXPATH * 2];
1829 CHAR **exfiles = NULL;
1830 UINT numfiles = 0, numalloc = 0;
1831
1832 if (li->targetpath && fFileNameCnrPath &&
1833 stricmp(lastextractpath, li->targetpath)) {
1834 strcpy(lastextractpath, li->targetpath);
1835 SetDir(dcd->hwndParent, hwnd, li->targetpath, 1);
1836 }
1837 for (x = 0; li->list[x]; x++) {
1838 BldFullPathName(fullname, li->targetpath, li->list[x]);
1839 //Check if file already exists on disk warn if it does.
1840 if (IsFile(fullname) != -1) {
1841 AddToList(li->list[x], &exfiles, &numfiles, &numalloc);
1842 li->list = RemoveFromList(li->list, li->list[x]);
1843 if (!li->list)
1844 break;
1845 x--;
1846 }
1847 }
1848 if (exfiles && numfiles) {
1849
1850 CHECKLIST ckl;
1851 CHAR prompt[(CCHMAXPATH * 2) + 256];
1852
1853 memset(&ckl, 0, sizeof(ckl));
1854 ckl.size = sizeof(ckl);
1855 ckl.list = exfiles;
1856 ckl.prompt = prompt;
1857 ckl.cmd = li->type;
1858 ckl.flags = CHECK_ARCHIVE;
1859 sprintf(prompt,
1860 GetPString(IDS_REPLACEWARNTEXT),
1861 &"s"[numfiles == 1],
1862 li->arcname, &"s"[numfiles != 1], li->targetpath);
1863 if (!WinDlgBox(HWND_DESKTOP, hwnd, CheckListProc,
1864 FM3ModHandle, CHECK_FRAME, MPFROMP(&ckl))) {
1865 if (ckl.list)
1866 FreeList(ckl.list);
1867 break;
1868 }
1869 else if (ckl.list)
1870 li->list = CombineLists(li->list, ckl.list);
1871 } // end check and warn
1872 }
1873 if (!li->list || !li->list[0])
1874 break;
1875 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1876 if (!pszCmdLine)
1877 break;
1878 strcpy(pszCmdLine,
1879 (li->type == IDM_EXTRACT ||
1880 ((li->type == IDM_VIEW ||
1881 li->type == IDM_VIEWTEXT ||
1882 li->type == IDM_VIEWBINARY ||
1883 li->type == IDM_VIEWARCHIVE ||
1884 li->type == IDM_PRINT ||
1885 li->type == IDM_EDIT ||
1886 li->type == IDM_EDITTEXT ||
1887 li->type == IDM_OPENDEFAULT ||
1888 li->type == IDM_OPENSETTINGS ||
1889 (li->type == IDM_EDITBINARY && // JBS No way for this () to be true??
1890 li->type == IDM_MCIPLAY)) &&
1891 !li->info->exwdirs)) ?
1892 li->info->extract :
1893 li->info->exwdirs);
1894 strcat(pszCmdLine, " ");
1895 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), li->arcname);
1896 endofit = &pszCmdLine[strlen(pszCmdLine)];
1897 z = 0;
1898 do {
1899 for (x = z; li->list[x] &&
1900 strlen(pszCmdLine) + strlen(li->list[x]) < MaxComLineStrg - 1 ; x++) {
1901 strcat(pszCmdLine, " ");
1902 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), li->list[x]);
1903 ptr = li->list[x];
1904 while (*ptr) {
1905 if (*ptr == '/')
1906 *ptr = '\\';
1907 ptr++;
1908 }
1909 }
1910 z = x;
1911 runemf2(SEPARATE | WINDOWED | WAIT |
1912 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1913 hwnd, pszSrcFile, __LINE__,
1914 li->targetpath, NULL, "%s", pszCmdLine);
1915 *endofit = 0;
1916 } while (li->list[x]);
1917 if (li->type == IDM_EXTRACT || li->type == IDM_EXTRACTWDIRS) {
1918 /* update windows */
1919 for (x = 0; li->list[x]; x++) {
1920
1921 CHAR *temp, *p;
1922
1923 temp = li->list[x];
1924 ForwardslashToBackslash(temp);
1925 p = xmalloc(strlen(temp) + strlen(li->targetpath) + 2,
1926 pszSrcFile, __LINE__);
1927 if (p) {
1928 BldFullPathName(p, li->targetpath, temp);
1929 li->list[x] = p;
1930 free(temp);
1931 }
1932 }
1933 if (fFolderAfterExtract) {
1934
1935 CHAR objectpath[CCHMAXPATH], *p;
1936 APIRET rc;
1937
1938 GetDesktopName(objectpath, sizeof(objectpath));
1939 rc = WinDlgBox(HWND_DESKTOP, dcd->hwndParent, ObjCnrDlgProc,
1940 FM3ModHandle, OBJCNR_FRAME,
1941 MPFROMP(objectpath));
1942 if (rc) {
1943 if (rc > 1)
1944 strcpy(objectpath, "<WP_DESKTOP>");
1945 p = NULL;
1946 if (li->arcname) {
1947 p = strrchr(li->arcname, '\\');
1948 if (p)
1949 p++;
1950 }
1951 MakeShadows(dcd->hwndParent, li->list, 2, objectpath, p);
1952 }
1953 }
1954 Broadcast(WinQueryAnchorBlock(hwnd),
1955 hwndMain,
1956 UM_UPDATERECORDLIST, MPFROMP(li->list), MPVOID);
1957 }
1958 else if (li->type == IDM_EXEC)
1959 ExecOnList(hwnd,
1960 li->runfile,
1961 WINDOWED | SEPARATEKEEP | PROMPT,
1962 li->targetpath, NULL, NULL, GetPString(IDS_EXECARCFILETITLETEXT),
1963 pszSrcFile, __LINE__);
1964 else if (li->type == IDM_VIRUSSCAN)
1965 ExecOnList(hwnd, virus, PROMPT | WINDOWED | SEPARATEKEEP,
1966 li->targetpath, NULL, NULL,
1967 GetPString(IDS_VIRUSSCANARCHIVETITLETEXT),
1968 pszSrcFile, __LINE__);
1969 else if (li->type == IDM_VIEW || li->type == IDM_VIEWTEXT ||
1970 li->type == IDM_VIEWBINARY || li->type == IDM_EDIT ||
1971 li->type == IDM_EDITTEXT ||
1972 li->type == IDM_VIEWARCHIVE ||
1973 li->type == IDM_EDITBINARY ||
1974 li->type == IDM_OPENDEFAULT ||
1975 li->type == IDM_OPENSETTINGS ||
1976 li->type == IDM_MCIPLAY || li->type == IDM_PRINT) {
1977
1978 CHAR *temp, *p;
1979 for (x = 0; li->list[x]; x++) {
1980 if (!li->info->exwdirs) {
1981 temp = li->list[x];
1982 p = strrchr(li->list[x], '\\');
1983 if (p) {
1984 p++;
1985 li->list[x] = xstrdup(p, pszSrcFile, __LINE__);
1986 if (!li->list[x])
1987 li->list[x] = temp;
1988 else {
1989 xfree(temp, pszSrcFile, __LINE__);
1990 }
1991 }
1992 }
1993 BldFullPathName(pszCmdLine, li->targetpath, li->list[x]);
1994 temp = li->list[x];
1995 li->list[x] = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
1996 if (!li->list[x])
1997 li->list[x] = temp;
1998 else
1999 xfree(temp, pszSrcFile, __LINE__);
2000 }
2001 free(pszCmdLine);
2002 if (li->type == IDM_VIEW || li->type == IDM_EDIT) {
2003
2004 BOOL isit = TestBinary(li->list[0]);
2005
2006 if (isit) {
2007 if (li->type == IDM_VIEW)
2008 li->type = IDM_VIEWBINARY;
2009 else
2010 li->type = IDM_EDITBINARY;
2011 }
2012 else {
2013 if (li->type == IDM_VIEW)
2014 li->type = IDM_VIEWTEXT;
2015 else
2016 li->type = IDM_EDITTEXT;
2017 }
2018 }
2019 if (li->type == IDM_MCIPLAY) {
2020
2021 FILE *fp;
2022 CHAR szTempFile[CCHMAXPATH];
2023 CHAR *modew = "w";
2024
2025 if (pTmpDir && !IsValidDir(pTmpDir))
2026 DosCreateDir(pTmpDir, 0);
2027 BldFullPathName(szTempFile, pTmpDir, PCSZ_FM2PLAYTEMP);
2028 fp = xfopen(szTempFile, modew, pszSrcFile, __LINE__, FALSE);
2029 if (fp) {
2030 fprintf(fp, "%s", ";AV/2-built FM2Play listfile\n");
2031 for (x = 0; li->list[x]; x++)
2032 fprintf(fp, "%s\n", li->list[x]);
2033 fprintf(fp, ";end\n");
2034 fclose(fp);
2035 strrev(szTempFile);
2036 strcat(szTempFile, "@/");
2037 strrev(szTempFile);
2038 RunFM2Util(PCSZ_FM2PLAYEXE, szTempFile);
2039 }
2040 }
2041 else if (li->type == IDM_PRINT) {
2042 strcpy(li->targetpath, printer);
2043 // 10 Dec 08 SHL correct error handling - looked backward
2044 if (xbeginthread(PrintListThread,
2045 65536,
2046 li,
2047 pszSrcFile,
2048 __LINE__) != -1)
2049 {
2050 li = NULL; // Ensure not freed here
2051 }
2052
2053 }
2054 else if (li->type == IDM_VIEWARCHIVE) {
2055
2056 ARC_TYPE *info;
2057
2058 for (x = 0; li->list[x]; x++) {
2059 if (IsFile(li->list[x]) == 1) {
2060 info = NULL; // Do not hide dups - fixme to know why?
2061 if (WinDlgBox(HWND_DESKTOP, HWND_DESKTOP,
2062 SBoxDlgProc, FM3ModHandle, ASEL_FRAME,
2063 (PVOID) & info) && info) {
2064 StartArcCnr(HWND_DESKTOP,
2065 HWND_DESKTOP, li->list[x], 4, info);
2066 }
2067 }
2068 }
2069 }
2070 else if ((li->type == IDM_VIEWTEXT && *viewer) ||
2071 (li->type == IDM_VIEWBINARY && *binview) ||
2072 (li->type == IDM_EDITTEXT && *editor) ||
2073 (li->type == IDM_EDITBINARY && *bined)) {
2074 //DosSleep(32); // Added WAIT to runemf2 12-12-08 GKY
2075 ExecOnList(hwnd, ((li->type == IDM_VIEWTEXT) ? viewer :
2076 (li->type == IDM_VIEWBINARY) ? binview :
2077 (li->type == IDM_EDITTEXT) ? editor :
2078 bined),
2079 WINDOWED | SEPARATE, NULL, NULL, // li->targetpath,
2080 li->list,
2081 NULL, pszSrcFile, __LINE__);
2082 }
2083 else if (li->type == IDM_OPENDEFAULT ||
2084 li->type == IDM_OPENSETTINGS) {
2085 WORKER *wk;
2086# ifdef FORTIFY
2087 Fortify_EnterScope();
2088# endif
2089 wk = xmallocz(sizeof(WORKER), pszSrcFile, __LINE__);
2090 if (!wk)
2091 FreeListInfo(li);
2092 else {
2093 wk->size = sizeof(WORKER);
2094 wk->hwndCnr = dcd->hwndCnr;
2095 wk->hwndParent = dcd->hwndParent;
2096 wk->hwndFrame = dcd->hwndFrame;
2097 wk->hwndClient = dcd->hwndClient;
2098 wk->li = li;
2099 strcpy(wk->directory, dcd->directory);
2100 if (xbeginthread(Action,
2101 122880,
2102 wk,
2103 pszSrcFile,
2104 __LINE__) == -1)
2105 {
2106 free(wk);
2107 FreeListInfo((LISTINFO *) mp1);
2108 }
2109 }
2110# ifdef FORTIFY
2111 Fortify_LeaveScope();
2112# endif
2113 }
2114 else {
2115 if (li->hwnd) {
2116
2117 ULONG viewtype;
2118
2119 for (x = 0; li->list[x]; x++) {
2120 if (x == 0) {
2121 if (li->type == IDM_VIEWBINARY ||
2122 li->type == IDM_EDITBINARY)
2123 viewtype = 16;
2124 else
2125 viewtype = 8;
2126 }
2127 else
2128 viewtype = 0;
2129# ifdef FORTIFY
2130 Fortify_EnterScope();
2131# endif
2132 temp = xstrdup(li->list[x], pszSrcFile, __LINE__);
2133 if (temp) {
2134 if (!PostMsg(WinQueryWindow(li->hwnd, QW_PARENT),
2135 UM_LOADFILE,
2136 MPFROMLONG(4L +
2137 (li->type == IDM_VIEWTEXT ||
2138 li->type == IDM_VIEWBINARY) +
2139 viewtype), MPFROMP(temp)))
2140 free(temp);
2141 }
2142# ifdef FORTIFY
2143 DosSleep(1); // Allow MassAction to take ownership
2144 Fortify_LeaveScope();
2145# endif
2146 }
2147 }
2148 }
2149 }
2150 }
2151 break;
2152
2153 case IDM_FIND:
2154 {
2155 UINT numfiles = 0, numalloced = 0;
2156 CHAR **list2 = NULL, fullname[CCHMAXPATH * 2], *p;
2157
2158 for (x = 0; li->list[x]; x++) {
2159 ForwardslashToBackslash(li->list[x]);
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 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, NULL); // 13 Apr 10 SHL Set NULL before freeing dcd
2221 free(dcd);
2222# ifdef FORTIFY
2223 Fortify_LeaveScope();
2224# endif
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 PostMsg(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 (CHAR *) 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, (CHAR *) 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 (CHAR *) 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 ForwardslashToBackslash(fullname);
3615 if (!info)
3616 info = find_type(fullname, arcsighead);
3617 if (!info)
3618 return hwndFrame;
3619 if (strlen(title) + strlen(fullname) > MAXNAMEL) {
3620 p = title + strlen(title);
3621 strncpy(p, fullname, MAXNAMEL / 2 - 5);
3622 strcpy(p + MAXNAMEL / 2 - 5, "...");
3623 strcat(title, fullname + strlen(fullname) - (MAXNAMEL / 2 - 5));
3624 }
3625 else {
3626 strcat(title, fullname);
3627 }
3628 hwndFrame = WinCreateStdWindow(hwndParent,
3629 WS_VISIBLE,
3630 &FrameFlags,
3631 (CHAR *) WC_ARCCONTAINER,
3632 title,
3633 WS_VISIBLE | fwsAnimate,
3634 FM3ModHandle, ARC_FRAME, &hwndClient);
3635 if (hwndFrame && hwndClient) {
3636 id = ARC_FRAME + idinc++;
3637 if (idinc > 512)
3638 idinc = 0;
3639 WinSetWindowUShort(hwndFrame, QWS_ID, id);
3640# ifdef FORTIFY
3641 Fortify_EnterScope();
3642# endif
3643 dcd = xmallocz(sizeof(DIRCNRDATA), pszSrcFile, __LINE__);
3644 if (!dcd) {
3645 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3646 hwndFrame = (HWND) 0;
3647 }
3648 else {
3649# ifdef FORTIFY
3650 // Will be freed by WM_DESTROY
3651 Fortify_ChangeScope(dcd, -1);
3652# endif
3653 dcd->size = sizeof(DIRCNRDATA);
3654 dcd->id = id;
3655 dcd->type = ARC_FRAME;
3656 if (pTmpDir && !IsValidDir(pTmpDir))
3657 DosCreateDir(pTmpDir, 0);
3658 MakeTempName(dcd->workdir, ArcTempRoot, 2);
3659 strcpy(dcd->arcname, fullname);
3660 if (*extractpath) {
3661 if (!strcmp(extractpath, "*")) {
3662 p = strrchr(fullname, '\\');
3663 if (p) {
3664 if (p < fullname + 3)
3665 p++;
3666 temp = *p;
3667 *p = 0;
3668 strcpy(dcd->directory, fullname);
3669 *p = temp;
3670 }
3671 }
3672 else
3673 strcpy(dcd->directory, extractpath);
3674 }
3675 if (!*dcd->directory && fFileNameCnrPath && dcd->arcname) {
3676 strcpy(fullname, dcd->arcname);
3677 p = strrchr(fullname, '.');
3678 if (p)
3679 *p = 0;
3680 else {
3681 p = fullname + strlen(fullname);
3682 p--;
3683 *p = 0;
3684 }
3685 strcpy(dcd->directory, fullname);
3686 }
3687 if (!*dcd->directory && *lastextractpath) {
3688 //DosEnterCritSec(); //GKY 11-29-08
3689 DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
3690 strcpy(dcd->directory, lastextractpath);
3691 DosReleaseMutexSem(hmtxFM2Globals);
3692 //DosExitCritSec();
3693 }
3694 if (!*dcd->directory) {
3695 if (!ParentIsDesktop(hwndParent, hwndParent))
3696 TopWindowName(hwndParent, hwndCaller, dcd->directory);
3697 if (!*dcd->directory) {
3698 p = strrchr(fullname, '\\');
3699 if (p) {
3700 if (p < fullname + 3)
3701 p++;
3702 *p = 0;
3703 strcpy(dcd->directory, fullname);
3704 }
3705 }
3706 }
3707 if (!*dcd->directory ||
3708 (IsFile(dcd->directory) == 1) ||
3709 (isalpha(*dcd->directory) &&
3710 (driveflags[toupper(*dcd->directory) - 'A'] &
3711 DRIVE_NOTWRITEABLE)))
3712 strcpy(dcd->directory, pFM2SaveDirectory);
3713 dcd->hwndParent = hwndParent ? hwndParent : HWND_DESKTOP;
3714 dcd->hwndFrame = hwndFrame;
3715 dcd->hwndClient = hwndClient;
3716 dcd->amextracted = (flags & 1) != 0;
3717 dcd->dontclose = (flags & 4) != 0;
3718 dcd->info = info;
3719 dcd->sortFlags = DefArcSortFlags;
3720 {
3721 PFNWP oldproc;
3722
3723 oldproc = WinSubclassWindow(hwndFrame, (PFNWP) ArcFrameWndProc);
3724 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
3725 }
3726 dcd->hwndCnr = WinCreateWindow(hwndClient,
3727 WC_CONTAINER,
3728 NULL,
3729 CCS_AUTOPOSITION | CCS_MINIICONS |
3730 CCS_MINIRECORDCORE | ulCnrType |
3731 WS_VISIBLE,
3732 0,
3733 0,
3734 0,
3735 0,
3736 hwndClient,
3737 HWND_TOP, (ULONG) ARC_CNR, NULL, NULL);
3738 if (!dcd->hwndCnr) {
3739 Win_Error(hwndClient, hwndClient, pszSrcFile, __LINE__,
3740 PCSZ_WINCREATEWINDOW);
3741 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3742 free(dcd);
3743 hwndFrame = (HWND) 0;
3744 }
3745 else {
3746 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, (PVOID) dcd);
3747 dcd->oldproc = WinSubclassWindow(dcd->hwndCnr,
3748 (PFNWP) ArcCnrWndProc);
3749 {
3750 USHORT ids[] = { DIR_TOTALS, DIR_SELECTED, DIR_VIEW, DIR_SORT,
3751 DIR_FILTER, DIR_FOLDERICON, 0
3752 };
3753
3754 CommonCreateTextChildren(dcd->hwndClient,
3755 WC_ARCSTATUS, ids);
3756 }
3757 WinEnableWindow(WinWindowFromID(dcd->hwndClient, DIR_VIEW), FALSE);
3758 dcd->hwndExtract = WinCreateWindow(dcd->hwndClient,
3759 WC_ENTRYFIELD,
3760 NULL,
3761 ES_AUTOSCROLL,
3762 0,
3763 0,
3764 0,
3765 0,
3766 dcd->hwndClient,
3767 HWND_TOP,
3768 ARC_EXTRACTDIR, NULL, NULL);
3769 WinSendMsg(dcd->hwndExtract,
3770 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
3771 WinSetWindowText(dcd->hwndExtract, dcd->directory);
3772 if (!PostMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID))
3773 WinSendMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID);
3774 if (FrameFlags & FCF_MENU) {
3775 PFNWP oldmenuproc;
3776 HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
3777
3778 oldmenuproc = WinSubclassWindow(hwndMenu, (PFNWP) ArcCnrMenuProc);
3779 WinSetWindowPtr(hwndMenu, QWL_USER, (PVOID) oldmenuproc);
3780 if (!fToolbar) {
3781
3782 if (hwndMenu) {
3783 WinSendMsg(hwndMenu, MM_DELETEITEM,
3784 MPFROM2SHORT(IDM_VIEW, FALSE), MPVOID);
3785 WinSendMsg(hwndMenu, MM_DELETEITEM,
3786 MPFROM2SHORT(IDM_EXEC, FALSE), MPVOID);
3787 WinSendMsg(hwndMenu, MM_DELETEITEM,
3788 MPFROM2SHORT(IDM_RESCAN, FALSE), MPVOID);
3789 WinSendMsg(hwndMenu, MM_DELETEITEM,
3790 MPFROM2SHORT(IDM_DELETE, FALSE), MPVOID);
3791 WinSendMsg(hwndMenu, MM_DELETEITEM,
3792 MPFROM2SHORT(IDM_EXTRACT, FALSE), MPVOID);
3793 WinSendMsg(hwndMenu, MM_DELETEITEM,
3794 MPFROM2SHORT(IDM_TEST, FALSE), MPVOID);
3795 WinSendMsg(hwndMenu, MM_DELETEITEM,
3796 MPFROM2SHORT(IDM_VIRUSSCAN, FALSE), MPVOID);
3797 WinSendMsg(hwndMenu, MM_DELETEITEM,
3798 MPFROM2SHORT(IDM_WALKDIR, FALSE), MPVOID);
3799 WinSendMsg(hwndMenu, MM_DELETEITEM,
3800 MPFROM2SHORT(IDM_FILTER, FALSE), MPVOID);
3801 }
3802 }
3803 }
3804 if (FrameFlags & FCF_TASKLIST) {
3805
3806 SWP swp, swpD;
3807 ULONG size = sizeof(swp);
3808 LONG cxScreen, cyScreen;
3809
3810 WinQueryTaskSizePos(WinQueryAnchorBlock(hwndFrame), 0, &swp);
3811 if (PrfQueryProfileData(fmprof, appname, "AV2SizePos", &swpD, &size)) {
3812 cxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
3813 cyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
3814 if (swp.x + swpD.cx > cxScreen)
3815 swp.x = cxScreen - swpD.cx;
3816 if (swp.y + swpD.cy > cyScreen)
3817 swp.y = cyScreen - swpD.cy;
3818 swp.cx = swpD.cx;
3819 swp.cy = swpD.cy;
3820 }
3821 WinSetWindowPos(hwndFrame,
3822 HWND_TOP,
3823 swp.x,
3824 swp.y,
3825 swp.cx,
3826 swp.cy,
3827 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER |
3828 SWP_ACTIVATE);
3829 }
3830 }
3831 }
3832# ifdef FORTIFY
3833 Fortify_LeaveScope();
3834# endif
3835 }
3836 }
3837 return hwndFrame;
3838}
3839
3840#pragma alloc_text(ARCCNRS,ArcCnrWndProc,ArcObjWndProc,ArcClientWndProc,BldQuotedFullPathName)
3841#pragma alloc_text(ARCCNRS,ArcTextProc,FillArcCnr,ArcFilter,BldQuotedFileName)
3842#pragma alloc_text(ARCCNRS,ArcSort,ArcFrameWndProc,IsArcThere,ArcErrProc)
3843#pragma alloc_text(STARTUP,StartArcCnr)
Note: See TracBrowser for help on using the repository browser.