source: trunk/dll/extract.c@ 1223

Last change on this file since 1223 was 1223, checked in by John Small, 17 years ago

Ticket 187: Moved typedef's and some #define's from fm3dll.h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1
2/***********************************************************************
3
4 $Id: extract.c 1223 2008-09-13 23:11:11Z jbs $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2004, 2007 Steven H. Levine
8
9 01 Aug 04 SHL Rework lstrip/rstrip usage
10 05 Jun 05 SHL Use QWL_USER
11 17 Jul 06 SHL Use Runtime_Error
12 20 Dec 06 GKY Added checkbox to make default extract with directories
13 22 Mar 07 GKY Use QWL_USER
14 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
15 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
16 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory
17
18***********************************************************************/
19
20#include <string.h>
21#include <ctype.h>
22
23#define INCL_WIN
24#define INCL_DOS
25#define INCL_LONGLONG // dircnrs.h
26
27#include "fm3dll.h"
28#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
29#include "init.h" // Data declaration(s)
30#include "arccnrs.h" // Data declaration(s)
31#include "notebook.h" // Data declaration(s)
32#include "mainwnd.h" // Data declaration(s)
33#include "fm3dlg.h"
34#include "fm3str.h"
35#include "errutil.h" // Dos_Error...
36#include "strutil.h" // GetPString
37#include "cmdline.h" // CmdLineDlgProc
38#include "extract.h"
39#include "walkem.h" // WalkExtractDlgProc
40#include "droplist.h" // AcceptOneDrop, DropHelp, GetOneDrop
41#include "misc.h" // DrawTargetEmphasis
42#include "chklist.h" // PosOverOkay
43#include "mkdir.h" // SetDir
44#include "valid.h" // MakeValidDir
45#include "systemf.h" // runemf2
46#include "dirs.h" // save_dir2
47#include "strips.h" // bstrip
48
49#pragma data_seg(DATA1)
50
51static PSZ pszSrcFile = __FILE__;
52
53MRESULT EXPENTRY ExtractTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
54{
55 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
56 static BOOL emphasized = FALSE;
57
58 switch (msg) {
59 case DM_DRAGOVER:
60 if (!emphasized) {
61 emphasized = TRUE;
62 DrawTargetEmphasis(hwnd, emphasized);
63 }
64 if (AcceptOneDrop(hwnd, mp1, mp2))
65 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
66 return MRFROM2SHORT(DOR_NEVERDROP, 0);
67
68 case DM_DRAGLEAVE:
69 if (emphasized) {
70 emphasized = FALSE;
71 DrawTargetEmphasis(hwnd, emphasized);
72 }
73 break;
74
75 case DM_DROPHELP:
76 DropHelp(mp1, mp2, hwnd, GetPString(IDS_EXTDROPHELPTEXT));
77 return 0;
78
79 case DM_DROP:
80 {
81 char szFrom[CCHMAXPATH + 2];
82
83 if (emphasized) {
84 emphasized = FALSE;
85 DrawTargetEmphasis(hwnd, emphasized);
86 }
87 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
88 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
89 MPFROM2SHORT(IDM_SWITCH, 0), MPFROMP(szFrom));
90 }
91 return 0;
92 }
93 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
94 WinDefWindowProc(hwnd, msg, mp1, mp2);
95}
96
97MRESULT EXPENTRY ExtractDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
98{
99 EXTRDATA *arcdata = NULL;
100
101 switch (msg) {
102 case WM_INITDLG:
103 WinSetWindowPtr(hwnd, QWL_USER, mp2);
104 arcdata = (EXTRDATA *) mp2;
105 {
106 ULONG size = sizeof(BOOL);
107 BOOL fRemember = FALSE;
108 BOOL fDirectory = FALSE;
109 PFNWP oldproc;
110
111 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, EXT_DIRECTORY),
112 (PFNWP) ExtractTextProc);
113 if (oldproc)
114 WinSetWindowPtr(WinWindowFromID(hwnd, EXT_DIRECTORY),
115 QWL_USER, (PVOID) oldproc);
116 PrfQueryProfileData(fmprof, FM3Str, "RememberExt",
117 (PVOID) & fRemember, &size);
118 PrfQueryProfileData(fmprof, FM3Str, "DirectoryExt",
119 (PVOID) & fDirectory, &size);
120 WinCheckButton(hwnd, EXT_REMEMBER, fRemember);
121 WinCheckButton(hwnd, EXT_AWDIRS, fDirectory);
122 WinSendDlgItemMsg(hwnd, EXT_DIRECTORY, EM_SETTEXTLIMIT,
123 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
124 WinSendDlgItemMsg(hwnd, EXT_COMMAND, EM_SETTEXTLIMIT,
125 MPFROM2SHORT(256, 0), MPVOID);
126 WinSendDlgItemMsg(hwnd, EXT_MASK, EM_SETTEXTLIMIT,
127 MPFROM2SHORT(256, 0), MPVOID);
128 WinSendDlgItemMsg(hwnd, EXT_FILENAME, EM_SETTEXTLIMIT,
129 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
130 if (arcdata->arcname && *arcdata->arcname)
131 WinSetDlgItemText(hwnd, EXT_FILENAME, arcdata->arcname);
132 else
133 WinSetDlgItemText(hwnd, EXT_FILENAME, GetPString(IDS_EXTVARIOUSTEXT));
134 if (fDirectory) {
135 WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_SETCHECK,
136 MPFROM2SHORT(TRUE, 0), MPVOID);
137 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
138 }
139 else {
140 WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_SETCHECK,
141 MPFROM2SHORT(TRUE, 0), MPVOID);
142 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
143
144 }
145 if (fRemember) {
146
147 CHAR textdir[CCHMAXPATH];
148
149 size = sizeof(textdir);
150 *textdir = 0;
151 PrfQueryProfileData(fmprof, FM3Str, "Ext_ExtractDir",
152 (PVOID) textdir, &size);
153 if (*textdir && !IsFile(textdir))
154 strcpy(arcdata->extractdir, textdir);
155 size = sizeof(textdir);
156 *textdir = 0;
157 PrfQueryProfileData(fmprof, FM3Str, "Ext_Mask", (PVOID) textdir,
158 &size);
159 WinSetDlgItemText(hwnd, EXT_MASK, textdir);
160 }
161 if (*extractpath && (!fRemember || !*arcdata->extractdir)) {
162 if (arcdata->arcname && *arcdata->arcname &&
163 !strcmp(extractpath, "*")) {
164
165 CHAR *p;
166
167 strcpy(arcdata->extractdir, arcdata->arcname);
168 p = strrchr(arcdata->extractdir, '\\');
169 if (p) {
170 if (p < arcdata->extractdir + 3)
171 p++;
172 *p = 0;
173 }
174 }
175 else
176 strcpy(arcdata->extractdir, extractpath);
177 }
178 if (!*arcdata->extractdir) {
179 if (*lastextractpath)
180 strcpy(arcdata->extractdir, lastextractpath);
181 else if (arcdata->arcname && *arcdata->arcname) {
182
183 CHAR *p;
184
185 strcpy(arcdata->extractdir, arcdata->arcname);
186 p = strrchr(arcdata->extractdir, '\\');
187 if (p) {
188 if (p < arcdata->extractdir + 3)
189 p++;
190 *p = 0;
191 }
192 }
193 if (!*arcdata->extractdir)
194 strcpy(arcdata->extractdir, pFM2SaveDirectory);
195 }
196 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
197 if (!arcdata->info->exwdirs)
198 WinEnableWindow(WinWindowFromID(hwnd, EXT_WDIRS), FALSE);
199 else if (fRemember) {
200 size = sizeof(BOOL);
201 fRemember = FALSE;
202 PrfQueryProfileData(fmprof, FM3Str, "Ext_WDirs",
203 (PVOID) & fRemember, &size);
204 if (fRemember)
205 PostMsg(WinWindowFromID(hwnd, EXT_WDIRS), BM_CLICK, MPVOID, MPVOID);
206 }
207 }
208 *arcdata->command = 0;
209 PosOverOkay(hwnd);
210 break;
211
212 case WM_ADJUSTWINDOWPOS:
213 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
214 break;
215
216 case UM_SETDIR:
217 PaintRecessedWindow(WinWindowFromID(hwnd, EXT_HELP), (HPS) 0, FALSE,
218 TRUE);
219 return 0;
220
221 case WM_CONTROL:
222 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
223 switch (SHORT1FROMMP(mp1)) {
224 case EXT_REMEMBER:
225 {
226 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
227
228 PrfWriteProfileData(fmprof, FM3Str, "RememberExt",
229 (PVOID) & fRemember, sizeof(BOOL));
230 }
231 break;
232
233 case EXT_AWDIRS:
234 {
235 BOOL fDirectory = WinQueryButtonCheckstate(hwnd, EXT_AWDIRS);
236
237 PrfWriteProfileData(fmprof, FM3Str, "DirectoryExt",
238 (PVOID) & fDirectory, sizeof(BOOL));
239
240 if (fDirectory) {
241 WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_SETCHECK,
242 MPFROM2SHORT(TRUE, 0), MPVOID);
243 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
244 }
245 else {
246 WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_SETCHECK,
247 MPFROM2SHORT(TRUE, 0), MPVOID);
248 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
249 }
250 }
251 break;
252
253 case EXT_FILENAME:
254 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
255 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
256 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
257 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCARCNAMEHELPTEXT));
258 break;
259
260 case EXT_DIRECTORY:
261 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
262 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
263 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
264 WinSetDlgItemText(hwnd, EXT_HELP,
265 GetPString(IDS_EXTEXTRACTDIRHELPTEXT));
266 break;
267
268 case EXT_COMMAND:
269 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
270 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
271 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
272 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCCMDHELPTEXT));
273 break;
274
275 case EXT_MASK:
276 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
277 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
278 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
279 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCMASKHELPTEXT));
280 break;
281
282 case EXT_NORMAL:
283 if ((BOOL) WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_QUERYCHECK,
284 MPVOID, MPVOID))
285 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
286 break;
287
288 case EXT_WDIRS:
289 if (arcdata->info->exwdirs) {
290 if ((BOOL) WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_QUERYCHECK,
291 MPVOID, MPVOID))
292 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
293 }
294 break;
295 }
296 return 0;
297
298 case WM_COMMAND:
299 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
300 switch (SHORT1FROMMP(mp1)) {
301 case IDM_SWITCH:
302 if (mp2) {
303
304 CHAR tdir[CCHMAXPATH];
305
306 strcpy(tdir, (CHAR *) mp2);
307 MakeValidDir(tdir);
308 WinSetDlgItemText(hwnd, EXT_DIRECTORY, tdir);
309 }
310 break;
311
312 case DID_CANCEL:
313 arcdata->ret = 0;
314 WinDismissDlg(hwnd, 0);
315 break;
316 case DID_OK:
317 {
318 CHAR s[CCHMAXPATH + 1];
319 BOOL fRemember;
320
321 fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
322 *s = 0;
323 WinQueryDlgItemText(hwnd, EXT_DIRECTORY, CCHMAXPATH, s);
324 bstrip(s);
325 if (*s) {
326 if (!SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
327 QW_OWNER), hwnd, s, 0)) {
328 strcpy(arcdata->extractdir, s);
329 WinSetDlgItemText(hwnd, EXT_DIRECTORY, s);
330 if ((!isalpha(*s) || s[1] != ':') && *s != '.')
331 saymsg(MB_ENTER, hwnd,
332 GetPString(IDS_WARNINGTEXT),
333 GetPString(IDS_SPECIFYDRIVETEXT));
334 }
335 else
336 break;
337 strcpy(lastextractpath, s);
338 if (fRemember) {
339 PrfWriteProfileString(fmprof, FM3Str, "Ext_ExtractDir", s);
340 fRemember = WinQueryButtonCheckstate(hwnd, EXT_WDIRS);
341 PrfWriteProfileData(fmprof, FM3Str, "Ext_WDirs",
342 (PVOID) & fRemember, sizeof(BOOL));
343 fRemember = TRUE;
344 }
345 *s = 0;
346 WinQueryDlgItemText(hwnd, EXT_COMMAND, 256, s);
347 if (*s) {
348 strcpy(arcdata->command, s);
349 *s = 0;
350 WinQueryDlgItemText(hwnd, EXT_MASK, 256, s);
351 *arcdata->masks = 0;
352 strcpy(arcdata->masks, s);
353 if (fRemember)
354 PrfWriteProfileString(fmprof, FM3Str, "Ext_Mask", s);
355 arcdata->ret = 1;
356 WinDismissDlg(hwnd, 1);
357 break;
358 }
359 }
360 }
361 DosBeep(50, 100); // Complain a refuse to quit
362 break;
363
364 case IDM_HELP:
365 if (hwndHelp)
366 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
367 MPFROM2SHORT(HELP_EXTRACT, 0), MPFROMSHORT(HM_RESOURCEID));
368 break;
369
370 case EXT_WALK:
371 {
372 CHAR temp[CCHMAXPATH + 1];
373
374 strcpy(temp, arcdata->extractdir);
375 if (WinDlgBox(HWND_DESKTOP, WinQueryWindow(WinQueryWindow(hwnd,
376 QW_PARENT),
377 QW_OWNER),
378 WalkExtractDlgProc, FM3ModHandle, WALK_FRAME,
379 (PVOID) temp)) {
380 if (*temp && stricmp(temp, arcdata->extractdir)) {
381 strcpy(arcdata->extractdir, temp);
382 }
383 }
384 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
385 }
386 break;
387
388 case EXT_SEE:
389 {
390 CHAR s[1001], *p;
391 EXECARGS ex;
392
393 WinQueryDlgItemText(hwnd, EXT_COMMAND, 256, s);
394 lstrip(s);
395 if (!*s)
396 Runtime_Error(pszSrcFile, __LINE__, "no command");
397 else {
398 p = strchr(s, ' ');
399 if (p)
400 *p = 0; // Drop options
401 memset(&ex, 0, sizeof(EXECARGS));
402 ex.commandline = s;
403 ex.flags = WINDOWED | SEPARATEKEEP | MAXIMIZED;
404 *ex.path = 0;
405 *ex.environment = 0;
406 if (WinDlgBox(HWND_DESKTOP,
407 hwnd,
408 CmdLineDlgProc,
409 FM3ModHandle, EXEC_FRAME, MPFROMP(&ex)) && *s) {
410 runemf2(ex.flags,
411 hwnd, pszSrcFile, __LINE__,
412 NULL, (*ex.environment) ? ex.environment : NULL, "%s", s);
413 }
414 }
415 }
416 break;
417 }
418 return 0;
419
420 case WM_CLOSE:
421 break;
422 }
423 return WinDefDlgProc(hwnd, msg, mp1, mp2);
424}
425
426#pragma alloc_text(FMEXTRACT,ExtractTextProc,ExtractDlgProc)
Note: See TracBrowser for help on using the repository browser.