source: trunk/dll/rename.c@ 123

Last change on this file since 123 was 123, checked in by root, 21 years ago

Rework lstrip/rstrip usage

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