source: trunk/dll/arccnrs.c@ 1482

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

Fixed separate parameters; added the ability to set it either globally or for just one app; some files only contain white space changes.

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