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
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: rename.c 1358 2008-12-27 00:03:08Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
[574]7 Copyright (c) 2004, 2007 Steven H.Levine
[123]8
[574]9 Revisions
10 01 Aug 04 SHL - Rework lstrip/rstrip usage
11 22 Mar 07 GKY Use QWL_USER
[793]12 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[846]13 27 Sep 07 SHL Correct ULONGLONG size formatting
[897]14 30 Dec 07 GKY Use TestFDates for comparing dates
[1358]15 25 Dec 08 GKY Add code to allow write verify to be turned off on a per drive basis
[123]16
17***********************************************************************/
18
[907]19#include <string.h>
[1354]20#include <ctype.h>
[907]21
[2]22#define INCL_WIN
[841]23#define INCL_LONGLONG
[2]24
[1184]25#include "fm3dll.h"
[1226]26#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
27#include "worker.h" // typedef MOVEIT
28#include "rename.h"
[1212]29#include "notebook.h" // Data declaration(s)
30#include "init.h" // Data declaration(s)
[2]31#include "fm3dlg.h"
32#include "fm3str.h"
[907]33#include "errutil.h" // Dos_Error...
34#include "strutil.h" // GetPString
[1160]35#include "copyf.h" // AdjustWildcardName
36#include "valid.h" // TestFDates
[1184]37#include "mkdir.h" // SetDir
38#include "commafmt.h" // CommaFmtULL
39#include "strips.h" // bstrip
[1354]40#include "info.h" // driveflags
[2]41
[551]42MRESULT EXPENTRY RenameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
43{
[2]44 MOVEIT *mv;
45
[551]46 switch (msg) {
47 case WM_INITDLG:
48 mv = (MOVEIT *) mp2;
[574]49 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) mv);
[551]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)) {
[2]64
[846]65 CHAR *p = strrchr(mv->target, '\\');
[551]66 if (p) {
[2]67
[551]68 USHORT sello, selhi;
[2]69
[846]70 sello = p - mv->target + 1;
[551]71 selhi = strlen(mv->target);
[2]72
[551]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;
[2]81
[551]82 case UM_RESCAN:
83 {
[574]84 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]85 if (mv) {
[2]86
[841]87 FILESTATUS3L fs1, fs2;
[897]88 CHAR s[CCHMAXPATH * 2], *p, chkname[CCHMAXPATH], szCmmaFmtFileSize[81];
[551]89 INT sourceexists = 0, targetexists = 0,
[846]90 sourcenewer = 0, sourcesmaller = 0;
[2]91
[551]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);
[841]102 if (!DosQueryPathInfo(mv->source, FIL_STANDARDL, &fs1, sizeof(fs1))) {
[897]103 CommaFmtULL(szCmmaFmtFileSize,
104 sizeof(szCmmaFmtFileSize), fs1.cbFile, ' ');
[551]105 sprintf(s,
[897]106 " %s%s %ss %04u/%02u/%02u %02u:%02u:%02u",
[846]107 fs1.attrFile & FILE_DIRECTORY ?
108 GetPString(IDS_DIRBRKTTEXT) : NullStr,
[897]109 szCmmaFmtFileSize,
[551]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;
[846]118 if (fs1.attrFile & FILE_DIRECTORY)
[551]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 }
[841]130 if (!DosQueryPathInfo(chkname, FIL_STANDARDL, &fs2, sizeof(fs2))) {
[897]131 CommaFmtULL(szCmmaFmtFileSize,
132 sizeof(szCmmaFmtFileSize), fs2.cbFile, ' ');
[551]133 sprintf(s,
[897]134 " %s%s %ss %04u/%02u/%02u %02u:%02u:%02u",
[846]135 fs2.attrFile & FILE_DIRECTORY ?
136 GetPString(IDS_DIRBRKTTEXT) : NullStr,
[897]137 szCmmaFmtFileSize,
[551]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),
[846]159 sourceexists & 2 ? GetPString(IDS_DIRECTORYTEXT) :
160 GetPString(IDS_FILETEXT));
[551]161 {
162 FILE *fp = NULL;
[846]163 if (~sourceexists & 2)
[551]164 fp = fopen(mv->source, "ab");
[846]165 if ((!fp && ~sourceexists & 2) || !sourceexists)
[551]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),
[846]173 targetexists & 2 ? GetPString(IDS_DIRECTORYTEXT) :
174 GetPString(IDS_FILETEXT));
[551]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),
[846]180 stricmp(mv->target, mv->source) &&
181 (!mv->rename || strcmp(mv->target, mv->source)));
[2]182
[551]183 if (targetexists == 1 && sourceexists == 1) {
[897]184 sourcenewer = TestFDates(NULL, NULL,
185 &fs1.fdateLastWrite, &fs1.ftimeLastWrite,
186 &fs2.fdateLastWrite, &fs2.ftimeLastWrite);
[846]187 sourcesmaller = (fs1.cbFile < fs2.cbFile) ? -1 :
[897]188 (fs1.cbFile > fs2.cbFile) ? 1 : 0;
[551]189 sprintf(&s[strlen(s)], GetPString(IDS_SOURCEISTEXT),
[846]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));
[551]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 }
[2]209 }
[551]210 }
211 return 0;
[2]212
[551]213 case WM_COMMAND:
214 switch (SHORT1FROMMP(mp1)) {
215 case DID_CANCEL:
216 WinDismissDlg(hwnd, 0);
217 break;
[2]218
[551]219 case IDM_HELP:
220 if (hwndHelp)
221 WinSendMsg(hwndHelp,
222 HM_DISPLAY_HELP,
223 MPFROM2SHORT(HELP_RENAME, 0), MPFROMSHORT(HM_RESOURCEID));
224 break;
[2]225
[551]226 case REN_SKIP:
[574]227 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]228 if (mv) {
229 mv->skip = TRUE;
230 *mv->target = 0;
231 WinDismissDlg(hwnd, 2);
232 }
233 else
234 WinDismissDlg(hwnd, 0);
235 break;
[2]236
[551]237 case REN_RENEXIST:
[574]238 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]239 if (mv) {
[2]240
[551]241 CHAR newexist[CCHMAXPATH], fullname[CCHMAXPATH];
242 INT was;
[1354]243 APIRET rc;
244 BOOL fResetVerify = FALSE;
[2]245
[551]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);
[1354]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 }
[551]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;
[2]298
[551]299 case REN_OVERWRITE:
300 case DID_OK:
[574]301 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]302 if (mv) {
[2]303
[551]304 MRESULT mr;
[2]305
[551]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)) {
[2]318
[551]319 CHAR path[CCHMAXPATH], *p;
[2]320
[551]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 }
[2]340 }
[551]341 break;
342 }
343 return 0;
[2]344 }
[551]345 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]346}
[793]347
348#pragma alloc_text(FMRENAME,RenameProc)
Note: See TracBrowser for help on using the repository browser.