source: trunk/dll/rename.c@ 1880

Last change on this file since 1880 was 1880, checked in by Gregg Young, 10 years ago

Remove dead code and comments from remaining c files. #if 0 and #if NEVER were not addressed

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1
2/***********************************************************************
3
4 $Id: rename.c 1880 2015-10-12 18:26:16Z 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_OVEROLD), FALSE);
96 WinShowWindow(WinWindowFromID(hwnd, REN_OVERNEW), FALSE);
97 WinShowWindow(WinWindowFromID(hwnd, REN_NOROWARN), FALSE);
98 }
99 break;
100
101 case UM_RESCAN:
102 {
103 mv = WinQueryWindowPtr(hwnd, QWL_USER);
104 if (mv) {
105
106 FILESTATUS3L fs1, fs2;
107 CHAR s[CCHMAXPATH * 2], *p, chkname[CCHMAXPATH], szCmmaFmtFileSize[81], szDate[DATE_BUF_BYTES];
108 INT sourceexists = 0, targetexists = 0,
109 sourcenewer = 0, sourcesmaller = 0;
110 ForwardslashToBackslash(mv->target);
111 if (!MakeFullName(mv->target))
112 WinSetDlgItemText(hwnd, REN_TARGET, mv->target);
113 if (!MakeFullName(mv->source))
114 WinSetDlgItemText(hwnd, REN_SOURCE, mv->source);
115 if (!DosQueryPathInfo(mv->source, FIL_STANDARDL, &fs1, sizeof(fs1))) {
116 CommaFmtULL(szCmmaFmtFileSize,
117 sizeof(szCmmaFmtFileSize), fs1.cbFile, ' ');
118 FDateFormat(szDate, fs1.fdateLastWrite);
119 sprintf(s, " %s%s %ss %s %02u%s%02u%s%02u",
120 fs1.attrFile & FILE_DIRECTORY ?
121 GetPString(IDS_DIRBRKTTEXT) : NullStr,
122 szCmmaFmtFileSize,
123 GetPString(IDS_BYTETEXT),
124 szDate,
125 fs1.ftimeLastWrite.hours, TimeSeparator,
126 fs1.ftimeLastWrite.minutes, TimeSeparator, fs1.ftimeLastWrite.twosecs * 2);
127 WinSetDlgItemText(hwnd, REN_SOURCEINFO, s);
128 sourceexists = 1;
129 if (fs1.attrFile & FILE_DIRECTORY)
130 sourceexists = 3;
131 }
132 else
133 WinSetDlgItemText(hwnd,
134 REN_SOURCEINFO, (CHAR *) GetPString(IDS_DOESNTEXIST2TEXT));
135 strcpy(chkname, mv->target);
136 p = strrchr(s, '\\');
137 if (p && (strchr(p, '*') || strchr(p, '?'))) {
138 if (!AdjustWildcardName(mv->target, chkname))
139 strcpy(chkname, mv->target);
140 }
141 if (!DosQueryPathInfo(chkname, FIL_STANDARDL, &fs2, sizeof(fs2))) {
142 CommaFmtULL(szCmmaFmtFileSize,
143 sizeof(szCmmaFmtFileSize), fs2.cbFile, ' ');
144 FDateFormat(szDate, fs2.fdateLastWrite);
145 sprintf(s, " %s%s %ss %s %02u%s%02u%s%02u",
146 fs2.attrFile & FILE_DIRECTORY ?
147 GetPString(IDS_DIRBRKTTEXT) : NullStr,
148 szCmmaFmtFileSize,
149 GetPString(IDS_BYTETEXT),
150 szDate,
151 fs2.ftimeLastWrite.hours, TimeSeparator,
152 fs2.ftimeLastWrite.minutes, TimeSeparator, fs2.ftimeLastWrite.twosecs * 2);
153 WinSetDlgItemText(hwnd, REN_TARGETINFO, s);
154 targetexists = 1;
155 if (fs2.attrFile & (FILE_DIRECTORY))
156 targetexists = 3;
157 WinEnableWindow(WinWindowFromID(hwnd, REN_RENEXIST), TRUE);
158 }
159 else {
160 WinSetDlgItemText(hwnd,
161 REN_TARGETINFO, (CHAR *) GetPString(IDS_DOESNTEXIST2TEXT));
162 WinEnableWindow(WinWindowFromID(hwnd, REN_RENEXIST), FALSE);
163 }
164 *s = 0;
165 if (sourceexists)
166 sprintf(s,
167 GetPString(IDS_SOURCEISATEXT),
168 sourceexists & 2 ? GetPString(IDS_DIRECTORYTEXT) :
169 GetPString(IDS_FILETEXT));
170 {
171 FILE *fp = NULL;
172 CHAR *modeab = "ab";
173 if (~sourceexists & 2)
174 fp = xfopen(mv->source, modeab, pszSrcFile, __LINE__, TRUE);
175 if ((!fp && ~sourceexists & 2) || !sourceexists)
176 strcpy(s, GetPString(IDS_CANTACCESSSOURCETEXT));
177 if (fp)
178 fclose(fp);
179 }
180 if (targetexists && stricmp(mv->source, mv->target))
181 sprintf(&s[strlen(s)],
182 GetPString(IDS_TARGETEXISTSISATEXT),
183 targetexists & 2 ? GetPString(IDS_DIRECTORYTEXT) :
184 GetPString(IDS_FILETEXT));
185 if (targetexists && stricmp(mv->source, mv->target))
186 strcpy(&s[strlen(s)], GetPString(IDS_CLICKOVERWRITETEXT));
187 else if (targetexists && !stricmp(mv->source, mv->target))
188 strcpy(&s[strlen(s)], GetPString(IDS_ENTERNEWTARGETTEXT));
189 WinEnableWindow(WinWindowFromID(hwnd, REN_OVERWRITE),
190 stricmp(mv->target, mv->source) &&
191 (!mv->rename || strcmp(mv->target, mv->source)));
192
193 if (targetexists == 1 && sourceexists == 1) {
194 sourcenewer = TestFDates(NULL, NULL,
195 &fs1.fdateLastWrite, &fs1.ftimeLastWrite,
196 &fs2.fdateLastWrite, &fs2.ftimeLastWrite);
197 sourcesmaller = (fs1.cbFile < fs2.cbFile) ? -1 :
198 (fs1.cbFile > fs2.cbFile) ? 1 : 0;
199 sprintf(&s[strlen(s)], GetPString(IDS_SOURCEISTEXT),
200 (sourcenewer == -1) ? GetPString(IDS_NEWERTEXT) :
201 (sourcenewer == 1) ? GetPString(IDS_OLDERTEXT) :
202 GetPString(IDS_SAMEDATETEXT),
203 (sourcesmaller == -1) ? GetPString(IDS_SMALLERTEXT) :
204 (sourcesmaller == 1) ? GetPString(IDS_LARGERTEXT) :
205 GetPString(IDS_SAMESIZETEXT));
206 }
207 WinSetDlgItemText(hwnd, REN_INFORMATION, s);
208 if (targetexists && stricmp(mv->source, mv->target)) {
209 if (WinQueryButtonCheckstate(hwnd, REN_DONTASK))
210 return 0;
211 return MRFROM2SHORT(1, 0);
212 }
213 else if (targetexists && !stricmp(mv->source, mv->target)) {
214 if (mv->rename && strcmp(mv->source, mv->target))
215 return 0;
216 WinEnableWindow(WinWindowFromID(hwnd, REN_RENEXIST), FALSE);
217 return MRFROM2SHORT(2, 0);
218 }
219 }
220 }
221 return 0;
222
223 case WM_COMMAND:
224 switch (SHORT1FROMMP(mp1)) {
225 case DID_CANCEL:
226 WinDismissDlg(hwnd, 0);
227 break;
228
229 case IDM_HELP:
230 if (hwndHelp)
231 WinSendMsg(hwndHelp,
232 HM_DISPLAY_HELP,
233 MPFROM2SHORT(HELP_RENAME, 0), MPFROMSHORT(HM_RESOURCEID));
234 break;
235
236 case REN_SKIP:
237 mv = WinQueryWindowPtr(hwnd, QWL_USER);
238 if (mv) {
239 mv->skip = TRUE;
240 *mv->target = 0;
241 WinDismissDlg(hwnd, 2);
242 }
243 else
244 WinDismissDlg(hwnd, 0);
245 break;
246
247 case REN_RENEXIST:
248 mv = WinQueryWindowPtr(hwnd, QWL_USER);
249 if (mv) {
250
251 CHAR newexist[CCHMAXPATH], fullname[CCHMAXPATH];
252 INT was;
253 APIRET rc;
254 BOOL fResetVerify = FALSE;
255
256 *newexist = 0;
257 WinQueryDlgItemText(hwnd, REN_TARGET, CCHMAXPATH, newexist);
258 if (*newexist) {
259 if (DosQueryPathInfo(newexist,
260 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
261 strcpy(fullname, newexist);
262 was = IsFile(fullname);
263 if (was == -1) {
264 if (fVerify && (driveflags[toupper(*mv->target) - 'A'] & DRIVE_WRITEVERIFYOFF ||
265 driveflags[toupper(*fullname) - 'A'] & DRIVE_WRITEVERIFYOFF)) {
266 DosSetVerify(FALSE);
267 fResetVerify = TRUE;
268 }
269 rc = docopyf(MOVE, mv->target, fullname);
270 if (fResetVerify) {
271 DosSetVerify(fVerify);
272 fResetVerify = FALSE;
273 }
274 if (rc) {
275 if ((LONG) rc > 0)
276 Dos_Error(MB_CANCEL,
277 rc,
278 hwnd,
279 __FILE__,
280 __LINE__,
281 GetPString(IDS_COMPMOVEFAILEDTEXT),
282 mv->target, fullname);
283 else
284 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
285 hwnd,
286 GetPString(IDS_SORRYTEXT),
287 GetPString(IDS_COMPMOVEFAILEDTEXT),
288 mv->target, fullname);
289 }
290 else
291 saymsg(MB_ENTER,
292 hwnd,
293 GetPString(IDS_SUCCESSTEXT),
294 GetPString(IDS_WASMOVEDTOTEXT), mv->target, fullname);
295 }
296 else
297 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
298 hwnd,
299 GetPString(IDS_SORRYTEXT),
300 GetPString(IDS_EXISTSASATEXT),
301 fullname,
302 (was) ?
303 GetPString(IDS_FILETEXT) : GetPString(IDS_DIRECTORYTEXT));
304 }
305 WinSetDlgItemText(hwnd, REN_TARGET, mv->target);
306 }
307 break;
308
309 case REN_OVERWRITE:
310 case DID_OK:
311 mv = WinQueryWindowPtr(hwnd, QWL_USER);
312 if (mv) {
313
314 MRESULT mr;
315
316 if (WinQueryButtonCheckstate(hwnd, REN_DONTASK))
317 mv->dontask = TRUE;
318 if (WinQueryButtonCheckstate(hwnd, REN_OVEROLD))
319 mv->overold = TRUE;
320 if (WinQueryButtonCheckstate(hwnd, REN_OVERNEW))
321 mv->overnew = TRUE;
322 if (WinQueryButtonCheckstate(hwnd,REN_NOROWARN))
323 mv->noreadonlywarn = TRUE;
324 *mv->target = 0;
325 WinQueryDlgItemText(hwnd, REN_TARGET, CCHMAXPATH, mv->target);
326 bstrip(mv->target);
327 mr = WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
328 if (!mr ||
329 (SHORT1FROMMR(mr) != 2 && SHORT1FROMMP(mp1) == REN_OVERWRITE)) {
330
331 CHAR path[CCHMAXPATH], *p;
332
333 mv->overwrite = (SHORT1FROMMP(mp1) == REN_OVERWRITE);
334 strcpy(path, mv->target);
335 p = strrchr(path, '\\');
336 if (p) {
337 p++;
338 *p = 0;
339 if (SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
340 QW_OWNER), hwnd, path, 0)) {
341 if (!fAlertBeepOff)
342 DosBeep(250, 100);
343 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, REN_TARGET));
344 break;
345 }
346 }
347 WinDismissDlg(hwnd, 1);
348 }
349 else {
350 if (!fAlertBeepOff)
351 DosBeep(250, 100);
352 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, REN_TARGET));
353 }
354 }
355 break;
356 }
357 return 0;
358 }
359 return WinDefDlgProc(hwnd, msg, mp1, mp2);
360}
361
362#pragma alloc_text(FMRENAME,RenameProc)
Note: See TracBrowser for help on using the repository browser.