source: trunk/dll/rename.c@ 2

Last change on this file since 2 was 2, checked in by root, 23 years ago

Initial revision

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