source: trunk/dll/extract.c@ 1207

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

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