source: trunk/dll/rename.c@ 574

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

Use QWL_USER; Replace doesn't move the command and Okay on cmd dialog removed error on unchanged command

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