source: trunk/dll/rename.c@ 1400

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

Remainder of changes to rename commafmt.h/c (Ticket 28, 82); Additional strings moved to PCSZs in init.c (Ticket 6); Added WriteDetailsSwitches used it and LoadDetailsSwitches to consolidate inline code (Ticket 343, 344)

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