source: trunk/dll/extract.c@ 1179

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

Ticket 187: Draft 2: Move remaining function declarations

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