source: trunk/dll/extract.c@ 618

Last change on this file since 618 was 618, checked in by Steven Levine, 18 years ago

Add more drag/drop error checking
Use FreeDragInfoData
Sync with NumItemsToUnhilite AcceptOneDrop GetOneDrop mods

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