source: trunk/dll/rename.c@ 827

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

Move #pragma alloc_text to end for OpenWatcom compat

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1
2/***********************************************************************
3
4 $Id: rename.c 793 2007-08-21 02:53:38Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2004, 2007 Steven H.Levine
8
9 Revisions
10 01 Aug 04 SHL - Rework lstrip/rstrip usage
11 22 Mar 07 GKY Use QWL_USER
12 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
13
14***********************************************************************/
15
16#define INCL_DOS
17#define INCL_WIN
18
19#include <os2.h>
20#include <stdarg.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <ctype.h>
25#include "fm3dll.h"
26#include "fm3dlg.h"
27#include "fm3str.h"
28
29MRESULT EXPENTRY RenameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
30{
31
32 MOVEIT *mv;
33
34 switch (msg) {
35 case WM_INITDLG:
36 mv = (MOVEIT *) mp2;
37 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) mv);
38 if (!mv || !mv->source) {
39 WinDismissDlg(hwnd, 0);
40 break;
41 }
42 WinSendDlgItemMsg(hwnd,
43 REN_SOURCE,
44 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
45 WinSendDlgItemMsg(hwnd,
46 REN_TARGET,
47 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
48 if (!*mv->target)
49 strcpy(mv->target, mv->source);
50 WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
51 if (mv->rename || !stricmp(mv->target, mv->source)) {
52
53 CHAR *p;
54
55 p = strrchr(mv->target, '\\');
56 if (p) {
57
58 USHORT sello, selhi;
59
60 sello = (p - mv->target) + 1;
61 selhi = strlen(mv->target);
62
63 WinSendDlgItemMsg(hwnd,
64 REN_TARGET,
65 EM_SETSEL, MPFROM2SHORT(sello, selhi), MPVOID);
66 }
67// WinShowWindow(WinWindowFromID(hwnd,REN_DONTASK),FALSE);
68 WinShowWindow(WinWindowFromID(hwnd, REN_OVEROLD), FALSE);
69 WinShowWindow(WinWindowFromID(hwnd, REN_OVERNEW), FALSE);
70 }
71 break;
72
73 case UM_RESCAN:
74 {
75 mv = WinQueryWindowPtr(hwnd, QWL_USER);
76 if (mv) {
77
78 FILESTATUS3 fs1, fs2;
79 CHAR s[CCHMAXPATH * 2], *p, chkname[CCHMAXPATH];
80 INT sourceexists = 0, targetexists = 0,
81 sourcenewer = 0, sourcesmaller = 0;
82
83 p = mv->target;
84 while (*p) {
85 if (*p == '/')
86 *p = '\\';
87 p++;
88 }
89 if (!MakeFullName(mv->target))
90 WinSetDlgItemText(hwnd, REN_TARGET, mv->target);
91 if (!MakeFullName(mv->source))
92 WinSetDlgItemText(hwnd, REN_SOURCE, mv->source);
93 if (!DosQueryPathInfo(mv->source, FIL_STANDARD, &fs1, sizeof(fs1))) {
94 sprintf(s,
95 " %s%lu %ss %04u/%02u/%02u %02u:%02u:%02u",
96 (fs1.attrFile & FILE_DIRECTORY) ?
97 GetPString(IDS_DIRBRKTTEXT) :
98 NullStr,
99 fs1.cbFile,
100 GetPString(IDS_BYTETEXT),
101 fs1.fdateLastWrite.year + 1980,
102 fs1.fdateLastWrite.month,
103 fs1.fdateLastWrite.day,
104 fs1.ftimeLastWrite.hours,
105 fs1.ftimeLastWrite.minutes, fs1.ftimeLastWrite.twosecs * 2);
106 WinSetDlgItemText(hwnd, REN_SOURCEINFO, s);
107 sourceexists = 1;
108 if (fs1.attrFile & (FILE_DIRECTORY))
109 sourceexists = 3;
110 }
111 else
112 WinSetDlgItemText(hwnd,
113 REN_SOURCEINFO, GetPString(IDS_DOESNTEXIST2TEXT));
114 strcpy(chkname, mv->target);
115 p = strrchr(s, '\\');
116 if (p && (strchr(p, '*') || strchr(p, '?'))) {
117 if (!AdjustWildcardName(mv->target, chkname))
118 strcpy(chkname, mv->target);
119 }
120 if (!DosQueryPathInfo(chkname, FIL_STANDARD, &fs2, sizeof(fs2))) {
121 sprintf(s,
122 " %s%lu %ss %04u/%02u/%02u %02u:%02u:%02u",
123 (fs2.attrFile & FILE_DIRECTORY) ?
124 GetPString(IDS_DIRBRKTTEXT) :
125 NullStr,
126 fs2.cbFile,
127 GetPString(IDS_BYTETEXT),
128 fs2.fdateLastWrite.year + 1980,
129 fs2.fdateLastWrite.month,
130 fs2.fdateLastWrite.day,
131 fs2.ftimeLastWrite.hours,
132 fs2.ftimeLastWrite.minutes, fs2.ftimeLastWrite.twosecs * 2);
133 WinSetDlgItemText(hwnd, REN_TARGETINFO, s);
134 targetexists = 1;
135 if (fs2.attrFile & (FILE_DIRECTORY))
136 targetexists = 3;
137 WinEnableWindow(WinWindowFromID(hwnd, REN_RENEXIST), TRUE);
138 }
139 else {
140 WinSetDlgItemText(hwnd,
141 REN_TARGETINFO, GetPString(IDS_DOESNTEXIST2TEXT));
142 WinEnableWindow(WinWindowFromID(hwnd, REN_RENEXIST), FALSE);
143 }
144 *s = 0;
145 if (sourceexists)
146 sprintf(s,
147 GetPString(IDS_SOURCEISATEXT),
148 (sourceexists & 2) ?
149 GetPString(IDS_DIRECTORYTEXT) : GetPString(IDS_FILETEXT));
150 {
151 FILE *fp = NULL;
152
153 if (!(sourceexists & 2))
154 fp = fopen(mv->source, "ab");
155 if ((!fp && !(sourceexists & 2)) || !sourceexists)
156 strcpy(s, GetPString(IDS_CANTACCESSSOURCETEXT));
157 if (fp)
158 fclose(fp);
159 }
160 if (targetexists && stricmp(mv->source, mv->target))
161 sprintf(&s[strlen(s)],
162 GetPString(IDS_TARGETEXISTSISATEXT),
163 (targetexists & 2) ?
164 GetPString(IDS_DIRECTORYTEXT) : GetPString(IDS_FILETEXT));
165 if (targetexists && stricmp(mv->source, mv->target))
166 strcpy(&s[strlen(s)], GetPString(IDS_CLICKOVERWRITETEXT));
167 else if (targetexists && !stricmp(mv->source, mv->target))
168 strcpy(&s[strlen(s)], GetPString(IDS_ENTERNEWTARGETTEXT));
169 WinEnableWindow(WinWindowFromID(hwnd, REN_OVERWRITE),
170 (stricmp(mv->target, mv->source) &&
171 (!mv->rename || strcmp(mv->target, mv->source))));
172
173 if (targetexists == 1 && sourceexists == 1) {
174 sourcenewer =
175 (fs1.fdateLastWrite.year <
176 fs2.fdateLastWrite.year) ? 1 : (fs1.fdateLastWrite.year >
177 fs2.fdateLastWrite.
178 year) ? -1 : (fs1.fdateLastWrite.
179 month <
180 fs2.fdateLastWrite.
181 month) ? 1 : (fs1.
182 fdateLastWrite.
183 month
184 >
185 fs2.
186 fdateLastWrite.
187 month)
188 ? -1 : (fs1.fdateLastWrite.day <
189 fs2.fdateLastWrite.day) ? 1 : (fs1.fdateLastWrite.day >
190 fs2.fdateLastWrite.
191 day) ? -1 : (fs1.
192 ftimeLastWrite.
193 hours <
194 fs2.
195 ftimeLastWrite.
196 hours) ? 1
197 : (fs1.ftimeLastWrite.hours >
198 fs2.ftimeLastWrite.hours) ? -1 : (fs1.ftimeLastWrite.minutes <
199 fs2.ftimeLastWrite.
200 minutes) ? 1 : (fs1.
201 ftimeLastWrite.
202 minutes >
203 fs2.
204 ftimeLastWrite.
205 minutes) ? -1
206 : (fs1.ftimeLastWrite.twosecs <
207 fs2.ftimeLastWrite.twosecs) ? 1 : (fs1.ftimeLastWrite.twosecs >
208 fs2.ftimeLastWrite.
209 twosecs) ? -1 : 0;
210 sourcesmaller =
211 (fs1.cbFile < fs2.cbFile) ? -1 : (fs1.cbFile >
212 fs2.cbFile) ? 1 : 0;
213 sprintf(&s[strlen(s)], GetPString(IDS_SOURCEISTEXT),
214 (sourcenewer ==
215 -1) ? GetPString(IDS_NEWERTEXT) : (sourcenewer ==
216 1) ?
217 GetPString(IDS_OLDERTEXT) : GetPString(IDS_SAMEDATETEXT),
218 (sourcesmaller ==
219 -1) ? GetPString(IDS_SMALLERTEXT) : (sourcesmaller ==
220 1) ?
221 GetPString(IDS_LARGERTEXT) : GetPString(IDS_SAMESIZETEXT));
222 }
223 WinSetDlgItemText(hwnd, REN_INFORMATION, s);
224 if (targetexists && stricmp(mv->source, mv->target)) {
225 if (WinQueryButtonCheckstate(hwnd, REN_DONTASK))
226 return 0;
227 return MRFROM2SHORT(1, 0);
228 }
229 else if (targetexists && !stricmp(mv->source, mv->target)) {
230 if (mv->rename && strcmp(mv->source, mv->target))
231 return 0;
232 WinEnableWindow(WinWindowFromID(hwnd, REN_RENEXIST), FALSE);
233 return MRFROM2SHORT(2, 0);
234 }
235 }
236 }
237 return 0;
238
239 case WM_COMMAND:
240 switch (SHORT1FROMMP(mp1)) {
241 case DID_CANCEL:
242 WinDismissDlg(hwnd, 0);
243 break;
244
245 case IDM_HELP:
246 if (hwndHelp)
247 WinSendMsg(hwndHelp,
248 HM_DISPLAY_HELP,
249 MPFROM2SHORT(HELP_RENAME, 0), MPFROMSHORT(HM_RESOURCEID));
250 break;
251
252 case REN_SKIP:
253 mv = WinQueryWindowPtr(hwnd, QWL_USER);
254 if (mv) {
255 mv->skip = TRUE;
256 *mv->target = 0;
257 WinDismissDlg(hwnd, 2);
258 }
259 else
260 WinDismissDlg(hwnd, 0);
261 break;
262
263 case REN_RENEXIST:
264 mv = WinQueryWindowPtr(hwnd, QWL_USER);
265 if (mv) {
266
267 CHAR newexist[CCHMAXPATH], fullname[CCHMAXPATH];
268 INT was;
269 APIRET rc;
270
271 *newexist = 0;
272 WinQueryDlgItemText(hwnd, REN_TARGET, CCHMAXPATH, newexist);
273 if (*newexist) {
274 if (DosQueryPathInfo(newexist,
275 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
276 strcpy(fullname, newexist);
277 was = IsFile(fullname);
278 if (was == -1) {
279 rc = docopyf(MOVE, mv->target, "%s", fullname);
280 if (rc) {
281 if ((LONG) rc > 0)
282 Dos_Error(MB_CANCEL,
283 rc,
284 hwnd,
285 __FILE__,
286 __LINE__,
287 GetPString(IDS_COMPMOVEFAILEDTEXT),
288 mv->target, fullname);
289 else
290 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
291 hwnd,
292 GetPString(IDS_SORRYTEXT),
293 GetPString(IDS_COMPMOVEFAILEDTEXT),
294 mv->target, fullname);
295 }
296 else
297 saymsg(MB_ENTER,
298 hwnd,
299 GetPString(IDS_SUCCESSTEXT),
300 GetPString(IDS_WASMOVEDTOTEXT), mv->target, fullname);
301 }
302 else
303 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
304 hwnd,
305 GetPString(IDS_SORRYTEXT),
306 GetPString(IDS_EXISTSASATEXT),
307 fullname,
308 (was) ?
309 GetPString(IDS_FILETEXT) : GetPString(IDS_DIRECTORYTEXT));
310 }
311 WinSetDlgItemText(hwnd, REN_TARGET, mv->target);
312 }
313 break;
314
315 case REN_OVERWRITE:
316 case DID_OK:
317 mv = WinQueryWindowPtr(hwnd, QWL_USER);
318 if (mv) {
319
320 MRESULT mr;
321
322 if (WinQueryButtonCheckstate(hwnd, REN_DONTASK))
323 mv->dontask = TRUE;
324 if (WinQueryButtonCheckstate(hwnd, REN_OVEROLD))
325 mv->overold = TRUE;
326 if (WinQueryButtonCheckstate(hwnd, REN_OVERNEW))
327 mv->overnew = TRUE;
328 *mv->target = 0;
329 WinQueryDlgItemText(hwnd, REN_TARGET, CCHMAXPATH, mv->target);
330 bstrip(mv->target);
331 mr = WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
332 if (!mr ||
333 (SHORT1FROMMR(mr) != 2 && SHORT1FROMMP(mp1) == REN_OVERWRITE)) {
334
335 CHAR path[CCHMAXPATH], *p;
336
337 mv->overwrite = (SHORT1FROMMP(mp1) == REN_OVERWRITE);
338 strcpy(path, mv->target);
339 p = strrchr(path, '\\');
340 if (p) {
341 p++;
342 *p = 0;
343 if (SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
344 QW_OWNER), hwnd, path, 0)) {
345 DosBeep(250, 100);
346 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, REN_TARGET));
347 break;
348 }
349 }
350 WinDismissDlg(hwnd, 1);
351 }
352 else {
353 DosBeep(250, 100);
354 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, REN_TARGET));
355 }
356 }
357 break;
358 }
359 return 0;
360 }
361 return WinDefDlgProc(hwnd, msg, mp1, mp2);
362}
363
364#pragma alloc_text(FMRENAME,RenameProc)
Note: See TracBrowser for help on using the repository browser.