source: trunk/dll/rename.c@ 897

Last change on this file since 897 was 897, checked in by Gregg Young, 18 years ago

Use CommaFmtULL for additional file, EA etc sizes display; Modify/Create TestFDates & TestCDates for comparing/sorting files or CNRITEMS by date/time.

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