source: trunk/dll/rename.c@ 1544

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

Changes to fopen and _fsopen to allow FM2 to be loaded in high memory

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