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
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: rename.c 1880 2015-10-12 18:26:16Z 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
[1664]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
[1682]24 06 Jan 13 GKY Added optional confirmation dialogs for delete move and copy to compare dir Ticket 277
[123]25
26***********************************************************************/
27
[907]28#include <string.h>
[1354]29#include <ctype.h>
[907]30
[2]31#define INCL_WIN
[841]32#define INCL_LONGLONG
[2]33
[1184]34#include "fm3dll.h"
[1226]35#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
36#include "worker.h" // typedef MOVEIT
37#include "rename.h"
[1212]38#include "notebook.h" // Data declaration(s)
39#include "init.h" // Data declaration(s)
[2]40#include "fm3dlg.h"
41#include "fm3str.h"
[907]42#include "errutil.h" // Dos_Error...
43#include "strutil.h" // GetPString
[1160]44#include "copyf.h" // AdjustWildcardName
45#include "valid.h" // TestFDates
[1184]46#include "mkdir.h" // SetDir
[1400]47#include "i18nutil.h" // CommaFmtULL
[1184]48#include "strips.h" // bstrip
[1354]49#include "info.h" // driveflags
[1544]50#include "wrappers.h" // xfopen
[1545]51#include "pathutil.h" // ForwardslashToBackslash
[2]52
[1544]53static PSZ pszSrcFile = __FILE__;
54
[551]55MRESULT EXPENTRY RenameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
56{
[2]57 MOVEIT *mv;
58
[551]59 switch (msg) {
60 case WM_INITDLG:
61 mv = (MOVEIT *) mp2;
[574]62 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) mv);
[551]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)) {
[2]77
[846]78 CHAR *p = strrchr(mv->target, '\\');
[551]79 if (p) {
[2]80
[551]81 USHORT sello, selhi;
[2]82
[846]83 sello = p - mv->target + 1;
[551]84 selhi = strlen(mv->target);
[2]85
[551]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);
[1664]92 WinShowWindow(WinWindowFromID(hwnd, REN_NOROWARN), FALSE);
[551]93 }
[1682]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 }
[551]99 break;
[2]100
[551]101 case UM_RESCAN:
102 {
[574]103 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]104 if (mv) {
[2]105
[841]106 FILESTATUS3L fs1, fs2;
[1397]107 CHAR s[CCHMAXPATH * 2], *p, chkname[CCHMAXPATH], szCmmaFmtFileSize[81], szDate[DATE_BUF_BYTES];
[551]108 INT sourceexists = 0, targetexists = 0,
[846]109 sourcenewer = 0, sourcesmaller = 0;
[1545]110 ForwardslashToBackslash(mv->target);
[551]111 if (!MakeFullName(mv->target))
112 WinSetDlgItemText(hwnd, REN_TARGET, mv->target);
113 if (!MakeFullName(mv->source))
114 WinSetDlgItemText(hwnd, REN_SOURCE, mv->source);
[841]115 if (!DosQueryPathInfo(mv->source, FIL_STANDARDL, &fs1, sizeof(fs1))) {
[897]116 CommaFmtULL(szCmmaFmtFileSize,
117 sizeof(szCmmaFmtFileSize), fs1.cbFile, ' ');
[1395]118 FDateFormat(szDate, fs1.fdateLastWrite);
119 sprintf(s, " %s%s %ss %s %02u%s%02u%s%02u",
[846]120 fs1.attrFile & FILE_DIRECTORY ?
121 GetPString(IDS_DIRBRKTTEXT) : NullStr,
[897]122 szCmmaFmtFileSize,
[551]123 GetPString(IDS_BYTETEXT),
[1395]124 szDate,
125 fs1.ftimeLastWrite.hours, TimeSeparator,
126 fs1.ftimeLastWrite.minutes, TimeSeparator, fs1.ftimeLastWrite.twosecs * 2);
[551]127 WinSetDlgItemText(hwnd, REN_SOURCEINFO, s);
128 sourceexists = 1;
[846]129 if (fs1.attrFile & FILE_DIRECTORY)
[551]130 sourceexists = 3;
131 }
132 else
133 WinSetDlgItemText(hwnd,
[1498]134 REN_SOURCEINFO, (CHAR *) GetPString(IDS_DOESNTEXIST2TEXT));
[551]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 }
[841]141 if (!DosQueryPathInfo(chkname, FIL_STANDARDL, &fs2, sizeof(fs2))) {
[897]142 CommaFmtULL(szCmmaFmtFileSize,
143 sizeof(szCmmaFmtFileSize), fs2.cbFile, ' ');
[1395]144 FDateFormat(szDate, fs2.fdateLastWrite);
145 sprintf(s, " %s%s %ss %s %02u%s%02u%s%02u",
[846]146 fs2.attrFile & FILE_DIRECTORY ?
147 GetPString(IDS_DIRBRKTTEXT) : NullStr,
[897]148 szCmmaFmtFileSize,
[551]149 GetPString(IDS_BYTETEXT),
[1395]150 szDate,
151 fs2.ftimeLastWrite.hours, TimeSeparator,
152 fs2.ftimeLastWrite.minutes, TimeSeparator, fs2.ftimeLastWrite.twosecs * 2);
[551]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,
[1498]161 REN_TARGETINFO, (CHAR *) GetPString(IDS_DOESNTEXIST2TEXT));
[551]162 WinEnableWindow(WinWindowFromID(hwnd, REN_RENEXIST), FALSE);
163 }
164 *s = 0;
165 if (sourceexists)
166 sprintf(s,
167 GetPString(IDS_SOURCEISATEXT),
[846]168 sourceexists & 2 ? GetPString(IDS_DIRECTORYTEXT) :
169 GetPString(IDS_FILETEXT));
[551]170 {
[1544]171 FILE *fp = NULL;
172 CHAR *modeab = "ab";
[846]173 if (~sourceexists & 2)
[1544]174 fp = xfopen(mv->source, modeab, pszSrcFile, __LINE__, TRUE);
[846]175 if ((!fp && ~sourceexists & 2) || !sourceexists)
[551]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),
[846]183 targetexists & 2 ? GetPString(IDS_DIRECTORYTEXT) :
184 GetPString(IDS_FILETEXT));
[551]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),
[846]190 stricmp(mv->target, mv->source) &&
191 (!mv->rename || strcmp(mv->target, mv->source)));
[2]192
[551]193 if (targetexists == 1 && sourceexists == 1) {
[897]194 sourcenewer = TestFDates(NULL, NULL,
195 &fs1.fdateLastWrite, &fs1.ftimeLastWrite,
196 &fs2.fdateLastWrite, &fs2.ftimeLastWrite);
[846]197 sourcesmaller = (fs1.cbFile < fs2.cbFile) ? -1 :
[897]198 (fs1.cbFile > fs2.cbFile) ? 1 : 0;
[551]199 sprintf(&s[strlen(s)], GetPString(IDS_SOURCEISTEXT),
[846]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));
[551]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 }
[2]219 }
[551]220 }
221 return 0;
[2]222
[551]223 case WM_COMMAND:
224 switch (SHORT1FROMMP(mp1)) {
225 case DID_CANCEL:
226 WinDismissDlg(hwnd, 0);
227 break;
[2]228
[551]229 case IDM_HELP:
230 if (hwndHelp)
231 WinSendMsg(hwndHelp,
232 HM_DISPLAY_HELP,
233 MPFROM2SHORT(HELP_RENAME, 0), MPFROMSHORT(HM_RESOURCEID));
234 break;
[2]235
[551]236 case REN_SKIP:
[574]237 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]238 if (mv) {
239 mv->skip = TRUE;
240 *mv->target = 0;
241 WinDismissDlg(hwnd, 2);
242 }
243 else
244 WinDismissDlg(hwnd, 0);
245 break;
[2]246
[551]247 case REN_RENEXIST:
[574]248 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]249 if (mv) {
[2]250
[551]251 CHAR newexist[CCHMAXPATH], fullname[CCHMAXPATH];
252 INT was;
[1354]253 APIRET rc;
254 BOOL fResetVerify = FALSE;
[2]255
[551]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);
[1354]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 }
[1402]269 rc = docopyf(MOVE, mv->target, fullname);
[1354]270 if (fResetVerify) {
271 DosSetVerify(fVerify);
272 fResetVerify = FALSE;
273 }
[551]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;
[2]308
[551]309 case REN_OVERWRITE:
310 case DID_OK:
[574]311 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]312 if (mv) {
[2]313
[551]314 MRESULT mr;
[2]315
[551]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))
[1664]321 mv->overnew = TRUE;
322 if (WinQueryButtonCheckstate(hwnd,REN_NOROWARN))
323 mv->noreadonlywarn = TRUE;
[551]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)) {
[2]330
[551]331 CHAR path[CCHMAXPATH], *p;
[2]332
[551]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)) {
[1395]341 if (!fAlertBeepOff)
342 DosBeep(250, 100);
[551]343 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, REN_TARGET));
344 break;
345 }
346 }
347 WinDismissDlg(hwnd, 1);
348 }
349 else {
[1395]350 if (!fAlertBeepOff)
351 DosBeep(250, 100);
[551]352 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, REN_TARGET));
353 }
[2]354 }
[551]355 break;
356 }
357 return 0;
[2]358 }
[551]359 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]360}
[793]361
362#pragma alloc_text(FMRENAME,RenameProc)
Note: See TracBrowser for help on using the repository browser.