source: trunk/dll/rename.c@ 1358

Last change on this file since 1358 was 1358, checked in by Gregg Young, 17 years ago

Comments for CS 1354/55

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