source: trunk/dll/rename.c@ 1844

Last change on this file since 1844 was 1682, checked in by Gregg Young, 13 years ago

Added optional confirmation dialogs for delete move and copy to compare dir Ticket 277; Added EA compare option to compare dir Ticket 80; Minor code cleanup.

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