source: trunk/dll/rename.c@ 1664

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

Changes to use Unlock to unlock files if Unlock.exe is in path both from menu/toolbar and as part of copy, move and delete operations. Changes to allow copy and move over readonly files with a warning dialog; also added a warning dialog for delete of readonly files

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