source: trunk/dll/rename.c@ 1570

Last change on this file since 1570 was 1545, checked in by Gregg Young, 15 years ago

Added ForwardslashToBackslash function to streamline code.

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