source: trunk/dll/extract.c@ 1157

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

Ticket 187: Draft 1: Functions only

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