source: trunk/dll/rename.c@ 1402

Last change on this file since 1402 was 1402, checked in by Gregg Young, 16 years ago

Remove variable aurgs from docopy & unlinkf (not used); Move more strings to PCSZs and string table; Move PCSZs to compile time initialization; Fix hang on startup caused by a drive scan and a dircnr scan trying to update a drive in the tree at the same time (related to the "treeswitch options); Code cleanup mainly removal of old printfs, SayMsgs, DbgMsg and unneeded %s.

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