source: trunk/dll/rename.c@ 1212

Last change on this file since 1212 was 1212, checked in by John Small, 17 years ago

Ticket 187: Move data declarations/definitions out of fm3dll.h

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