source: trunk/dll/extract.c@ 574

Last change on this file since 574 was 574, checked in by Gregg Young, 18 years ago

Use QWL_USER; Replace doesn't move the command and Okay on cmd dialog removed error on unchanged command

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