source: trunk/dll/rename.c@ 1395

Last change on this file since 1395 was 1395, checked in by Gregg Young, 17 years ago

Allow user to turn off alert and/or error beeps in settings notebook. Ticket 341 Move repeated strings to PCSZs. Ticket 6 Add *DateFormat functions to format dates based on locale Ticket 28 Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error Ticket 6

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