source: trunk/dll/rename.c@ 1354

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

Added driveflags to over ride write verify for USB removable drives that fail when it is on (Ticket 323); A flag to prevent directory name from being broadcast to drives in the tree cnr prior to a recursive scan of the drive (causes dbl directory names Ticket 321) Add option for multithreaded recursive scan of user selected drives at startup (Ticket 322).

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