source: trunk/dll/rename.c@ 551

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

Indentation cleanup

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