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
Line 
1
2/***********************************************************************
3
4 $Id: rename.c 1544 2010-09-30 13:00:59Z 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
22***********************************************************************/
23
24#include <string.h>
25#include <ctype.h>
26
27#define INCL_WIN
28#define INCL_LONGLONG
29
30#include "fm3dll.h"
31#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
32#include "worker.h" // typedef MOVEIT
33#include "rename.h"
34#include "notebook.h" // Data declaration(s)
35#include "init.h" // Data declaration(s)
36#include "fm3dlg.h"
37#include "fm3str.h"
38#include "errutil.h" // Dos_Error...
39#include "strutil.h" // GetPString
40#include "copyf.h" // AdjustWildcardName
41#include "valid.h" // TestFDates
42#include "mkdir.h" // SetDir
43#include "i18nutil.h" // CommaFmtULL
44#include "strips.h" // bstrip
45#include "info.h" // driveflags
46#include "wrappers.h" // xfopen
47
48static PSZ pszSrcFile = __FILE__;
49
50MRESULT EXPENTRY RenameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
51{
52 MOVEIT *mv;
53
54 switch (msg) {
55 case WM_INITDLG:
56 mv = (MOVEIT *) mp2;
57 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) mv);
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)) {
72
73 CHAR *p = strrchr(mv->target, '\\');
74 if (p) {
75
76 USHORT sello, selhi;
77
78 sello = p - mv->target + 1;
79 selhi = strlen(mv->target);
80
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;
89
90 case UM_RESCAN:
91 {
92 mv = WinQueryWindowPtr(hwnd, QWL_USER);
93 if (mv) {
94
95 FILESTATUS3L fs1, fs2;
96 CHAR s[CCHMAXPATH * 2], *p, chkname[CCHMAXPATH], szCmmaFmtFileSize[81], szDate[DATE_BUF_BYTES];
97 INT sourceexists = 0, targetexists = 0,
98 sourcenewer = 0, sourcesmaller = 0;
99
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);
110 if (!DosQueryPathInfo(mv->source, FIL_STANDARDL, &fs1, sizeof(fs1))) {
111 CommaFmtULL(szCmmaFmtFileSize,
112 sizeof(szCmmaFmtFileSize), fs1.cbFile, ' ');
113 FDateFormat(szDate, fs1.fdateLastWrite);
114 sprintf(s, " %s%s %ss %s %02u%s%02u%s%02u",
115 fs1.attrFile & FILE_DIRECTORY ?
116 GetPString(IDS_DIRBRKTTEXT) : NullStr,
117 szCmmaFmtFileSize,
118 GetPString(IDS_BYTETEXT),
119 szDate,
120 fs1.ftimeLastWrite.hours, TimeSeparator,
121 fs1.ftimeLastWrite.minutes, TimeSeparator, fs1.ftimeLastWrite.twosecs * 2);
122 WinSetDlgItemText(hwnd, REN_SOURCEINFO, s);
123 sourceexists = 1;
124 if (fs1.attrFile & FILE_DIRECTORY)
125 sourceexists = 3;
126 }
127 else
128 WinSetDlgItemText(hwnd,
129 REN_SOURCEINFO, (CHAR *) GetPString(IDS_DOESNTEXIST2TEXT));
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 }
136 if (!DosQueryPathInfo(chkname, FIL_STANDARDL, &fs2, sizeof(fs2))) {
137 CommaFmtULL(szCmmaFmtFileSize,
138 sizeof(szCmmaFmtFileSize), fs2.cbFile, ' ');
139 FDateFormat(szDate, fs2.fdateLastWrite);
140 sprintf(s, " %s%s %ss %s %02u%s%02u%s%02u",
141 fs2.attrFile & FILE_DIRECTORY ?
142 GetPString(IDS_DIRBRKTTEXT) : NullStr,
143 szCmmaFmtFileSize,
144 GetPString(IDS_BYTETEXT),
145 szDate,
146 fs2.ftimeLastWrite.hours, TimeSeparator,
147 fs2.ftimeLastWrite.minutes, TimeSeparator, fs2.ftimeLastWrite.twosecs * 2);
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,
156 REN_TARGETINFO, (CHAR *) GetPString(IDS_DOESNTEXIST2TEXT));
157 WinEnableWindow(WinWindowFromID(hwnd, REN_RENEXIST), FALSE);
158 }
159 *s = 0;
160 if (sourceexists)
161 sprintf(s,
162 GetPString(IDS_SOURCEISATEXT),
163 sourceexists & 2 ? GetPString(IDS_DIRECTORYTEXT) :
164 GetPString(IDS_FILETEXT));
165 {
166 FILE *fp = NULL;
167 CHAR *modeab = "ab";
168 if (~sourceexists & 2)
169 fp = xfopen(mv->source, modeab, pszSrcFile, __LINE__, TRUE);
170 if ((!fp && ~sourceexists & 2) || !sourceexists)
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),
178 targetexists & 2 ? GetPString(IDS_DIRECTORYTEXT) :
179 GetPString(IDS_FILETEXT));
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),
185 stricmp(mv->target, mv->source) &&
186 (!mv->rename || strcmp(mv->target, mv->source)));
187
188 if (targetexists == 1 && sourceexists == 1) {
189 sourcenewer = TestFDates(NULL, NULL,
190 &fs1.fdateLastWrite, &fs1.ftimeLastWrite,
191 &fs2.fdateLastWrite, &fs2.ftimeLastWrite);
192 sourcesmaller = (fs1.cbFile < fs2.cbFile) ? -1 :
193 (fs1.cbFile > fs2.cbFile) ? 1 : 0;
194 sprintf(&s[strlen(s)], GetPString(IDS_SOURCEISTEXT),
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));
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 }
214 }
215 }
216 return 0;
217
218 case WM_COMMAND:
219 switch (SHORT1FROMMP(mp1)) {
220 case DID_CANCEL:
221 WinDismissDlg(hwnd, 0);
222 break;
223
224 case IDM_HELP:
225 if (hwndHelp)
226 WinSendMsg(hwndHelp,
227 HM_DISPLAY_HELP,
228 MPFROM2SHORT(HELP_RENAME, 0), MPFROMSHORT(HM_RESOURCEID));
229 break;
230
231 case REN_SKIP:
232 mv = WinQueryWindowPtr(hwnd, QWL_USER);
233 if (mv) {
234 mv->skip = TRUE;
235 *mv->target = 0;
236 WinDismissDlg(hwnd, 2);
237 }
238 else
239 WinDismissDlg(hwnd, 0);
240 break;
241
242 case REN_RENEXIST:
243 mv = WinQueryWindowPtr(hwnd, QWL_USER);
244 if (mv) {
245
246 CHAR newexist[CCHMAXPATH], fullname[CCHMAXPATH];
247 INT was;
248 APIRET rc;
249 BOOL fResetVerify = FALSE;
250
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);
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 }
264 rc = docopyf(MOVE, mv->target, fullname);
265 if (fResetVerify) {
266 DosSetVerify(fVerify);
267 fResetVerify = FALSE;
268 }
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;
303
304 case REN_OVERWRITE:
305 case DID_OK:
306 mv = WinQueryWindowPtr(hwnd, QWL_USER);
307 if (mv) {
308
309 MRESULT mr;
310
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)) {
323
324 CHAR path[CCHMAXPATH], *p;
325
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)) {
334 if (!fAlertBeepOff)
335 DosBeep(250, 100);
336 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, REN_TARGET));
337 break;
338 }
339 }
340 WinDismissDlg(hwnd, 1);
341 }
342 else {
343 if (!fAlertBeepOff)
344 DosBeep(250, 100);
345 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, REN_TARGET));
346 }
347 }
348 break;
349 }
350 return 0;
351 }
352 return WinDefDlgProc(hwnd, msg, mp1, mp2);
353}
354
355#pragma alloc_text(FMRENAME,RenameProc)
Note: See TracBrowser for help on using the repository browser.