source: trunk/dll/rename.c@ 1505

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

Changes to get FM2 to compile with the latest watcom 1.9 beta (mostly type casts of CHAR CONSTANT * to CHAR *). Changes to get the environment settings working everywhere again (broken by the change that moved commands to the INI); Added an environment size variable (set to 2048 which was the largest I found hard coded). Still need to find everywhere the environment size is set and use this variable.

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