source: trunk/dll/extract.c@ 1229

Last change on this file since 1229 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
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: extract.c 1223 2008-09-13 23:11:11Z jbs $
5
6 Copyright (c) 1993-98 M. Kimes
[574]7 Copyright (c) 2004, 2007 Steven H. Levine
[123]8
[186]9 01 Aug 04 SHL Rework lstrip/rstrip usage
10 05 Jun 05 SHL Use QWL_USER
[350]11 17 Jul 06 SHL Use Runtime_Error
[549]12 20 Dec 06 GKY Added checkbox to make default extract with directories
[574]13 22 Mar 07 GKY Use QWL_USER
[618]14 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
[793]15 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[1104]16 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory
[123]17
18***********************************************************************/
19
[907]20#include <string.h>
21#include <ctype.h>
22
[2]23#define INCL_WIN
24#define INCL_DOS
[907]25#define INCL_LONGLONG // dircnrs.h
[2]26
[1179]27#include "fm3dll.h"
[1223]28#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
[1207]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)
[2]33#include "fm3dlg.h"
34#include "fm3str.h"
[907]35#include "errutil.h" // Dos_Error...
36#include "strutil.h" // GetPString
[1157]37#include "cmdline.h" // CmdLineDlgProc
38#include "extract.h"
39#include "walkem.h" // WalkExtractDlgProc
[1179]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
[2]48
49#pragma data_seg(DATA1)
[350]50
51static PSZ pszSrcFile = __FILE__;
[2]52
[551]53MRESULT EXPENTRY ExtractTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[350]54{
[574]55 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
[551]56 static BOOL emphasized = FALSE;
[2]57
[551]58 switch (msg) {
59 case DM_DRAGOVER:
60 if (!emphasized) {
61 emphasized = TRUE;
62 DrawTargetEmphasis(hwnd, emphasized);
63 }
[618]64 if (AcceptOneDrop(hwnd, mp1, mp2))
[551]65 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
66 return MRFROM2SHORT(DOR_NEVERDROP, 0);
[2]67
[551]68 case DM_DRAGLEAVE:
69 if (emphasized) {
70 emphasized = FALSE;
71 DrawTargetEmphasis(hwnd, emphasized);
72 }
73 break;
[2]74
[551]75 case DM_DROPHELP:
76 DropHelp(mp1, mp2, hwnd, GetPString(IDS_EXTDROPHELPTEXT));
77 return 0;
[2]78
[551]79 case DM_DROP:
80 {
81 char szFrom[CCHMAXPATH + 2];
[2]82
[551]83 if (emphasized) {
84 emphasized = FALSE;
85 DrawTargetEmphasis(hwnd, emphasized);
[2]86 }
[618]87 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
[551]88 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
89 MPFROM2SHORT(IDM_SWITCH, 0), MPFROMP(szFrom));
90 }
91 return 0;
[2]92 }
[551]93 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
94 WinDefWindowProc(hwnd, msg, mp1, mp2);
[2]95}
96
[551]97MRESULT EXPENTRY ExtractDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[350]98{
[551]99 EXTRDATA *arcdata = NULL;
[2]100
[551]101 switch (msg) {
102 case WM_INITDLG:
[574]103 WinSetWindowPtr(hwnd, QWL_USER, mp2);
[551]104 arcdata = (EXTRDATA *) mp2;
105 {
106 ULONG size = sizeof(BOOL);
107 BOOL fRemember = FALSE;
108 BOOL fDirectory = FALSE;
109 PFNWP oldproc;
[2]110
[551]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);
[549]143
[551]144 }
145 if (fRemember) {
[2]146
[551]147 CHAR textdir[CCHMAXPATH];
[2]148
[551]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, "*")) {
[2]164
[551]165 CHAR *p;
[2]166
[551]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) {
[2]182
[551]183 CHAR *p;
[2]184
[551]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)
[1104]194 strcpy(arcdata->extractdir, pFM2SaveDirectory);
[2]195 }
[551]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;
[2]211
[551]212 case WM_ADJUSTWINDOWPOS:
213 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
214 break;
[2]215
[551]216 case UM_SETDIR:
217 PaintRecessedWindow(WinWindowFromID(hwnd, EXT_HELP), (HPS) 0, FALSE,
218 TRUE);
219 return 0;
[2]220
[551]221 case WM_CONTROL:
[574]222 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
[551]223 switch (SHORT1FROMMP(mp1)) {
224 case EXT_REMEMBER:
225 {
226 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
[2]227
[551]228 PrfWriteProfileData(fmprof, FM3Str, "RememberExt",
229 (PVOID) & fRemember, sizeof(BOOL));
230 }
231 break;
[2]232
[551]233 case EXT_AWDIRS:
234 {
235 BOOL fDirectory = WinQueryButtonCheckstate(hwnd, EXT_AWDIRS);
[549]236
[551]237 PrfWriteProfileData(fmprof, FM3Str, "DirectoryExt",
238 (PVOID) & fDirectory, sizeof(BOOL));
[549]239
[551]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;
[549]252
[551]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;
[2]259
[551]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;
[2]267
[551]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;
[2]274
[551]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;
[2]281
[551]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;
[2]287
[551]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);
[2]293 }
[551]294 break;
295 }
296 return 0;
[2]297
[551]298 case WM_COMMAND:
[574]299 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
[551]300 switch (SHORT1FROMMP(mp1)) {
301 case IDM_SWITCH:
302 if (mp2) {
[2]303
[551]304 CHAR tdir[CCHMAXPATH];
[2]305
[551]306 strcpy(tdir, (CHAR *) mp2);
307 MakeValidDir(tdir);
308 WinSetDlgItemText(hwnd, EXT_DIRECTORY, tdir);
309 }
310 break;
[2]311
[551]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;
[2]320
[551]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;
[2]363
[551]364 case IDM_HELP:
365 if (hwndHelp)
366 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
367 MPFROM2SHORT(HELP_EXTRACT, 0), MPFROMSHORT(HM_RESOURCEID));
368 break;
[2]369
[551]370 case EXT_WALK:
371 {
372 CHAR temp[CCHMAXPATH + 1];
[2]373
[551]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;
[2]387
[551]388 case EXT_SEE:
389 {
390 CHAR s[1001], *p;
391 EXECARGS ex;
[2]392
[551]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,
[888]411 hwnd, pszSrcFile, __LINE__,
[551]412 NULL, (*ex.environment) ? ex.environment : NULL, "%s", s);
413 }
414 }
[2]415 }
[551]416 break;
417 }
418 return 0;
[2]419
[551]420 case WM_CLOSE:
421 break;
[2]422 }
[551]423 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]424}
[793]425
426#pragma alloc_text(FMEXTRACT,ExtractTextProc,ExtractDlgProc)
Note: See TracBrowser for help on using the repository browser.