1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: copyf.c 173 2005-05-28 17:34:46Z root $
|
---|
5 |
|
---|
6 | Copy functions
|
---|
7 |
|
---|
8 | Copyright (c) 1993-98 M. Kimes
|
---|
9 | Copyright (c) 2001, 2005 Steven H.Levine
|
---|
10 |
|
---|
11 | 14 Sep 02 SHL Drop obsolete debug code
|
---|
12 | 14 Oct 02 SHL Drop obsolete debug code
|
---|
13 | 10 Nov 02 SHL docopyf - don't forget to terminate longname
|
---|
14 | optimize longname logic
|
---|
15 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
16 | 28 May 05 SHL Drop debug code
|
---|
17 |
|
---|
18 | ***********************************************************************/
|
---|
19 |
|
---|
20 | #define INCL_DOS
|
---|
21 | #define INCL_DOSERRORS
|
---|
22 | #define INCL_WIN
|
---|
23 |
|
---|
24 | #include <os2.h>
|
---|
25 | #include <io.h>
|
---|
26 | #include <string.h>
|
---|
27 | #include <stdlib.h>
|
---|
28 | #include <stdio.h>
|
---|
29 | #include <stdarg.h>
|
---|
30 | #include <ctype.h>
|
---|
31 | #include <time.h>
|
---|
32 | #include "fm3dll.h"
|
---|
33 |
|
---|
34 | #ifndef WinMoveObject
|
---|
35 | HOBJECT APIENTRY WinMoveObject(HOBJECT hObjectofObject,
|
---|
36 | HOBJECT hObjectofDest,
|
---|
37 | ULONG ulReserved);
|
---|
38 | #endif
|
---|
39 | #ifndef WinCopyObject
|
---|
40 | HOBJECT APIENTRY WinCopyObject(HOBJECT hObjectofObject,
|
---|
41 | HOBJECT hObjectofDest,
|
---|
42 | ULONG ulReserved);
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | #pragma alloc_text(LONGNAMES,TruncName,GetLongName,WriteLongName)
|
---|
46 | #pragma alloc_text(LONGNAMES,ZapLongName,AdjustWildcardName)
|
---|
47 | #pragma alloc_text(COPYF,default_disk,docopyf)
|
---|
48 | #pragma alloc_text(UNLINKF,unlinkf,unlink_allf,make_deleteable,wipeallf)
|
---|
49 |
|
---|
50 |
|
---|
51 | char *MakeTempName (char *buffer) {
|
---|
52 |
|
---|
53 | FILESTATUS3 fs3;
|
---|
54 | APIRET rc;
|
---|
55 | char *p,*o;
|
---|
56 |
|
---|
57 | p = o = buffer + strlen(buffer);
|
---|
58 | sprintf(p,"%08lx.%03lx",clock(),mypid);
|
---|
59 | p = buffer + (strlen(buffer) - 1);
|
---|
60 | for(;;) {
|
---|
61 | DosError(FERR_DISABLEHARDERR);
|
---|
62 | rc = DosQueryPathInfo(buffer,FIL_STANDARD,&fs3,
|
---|
63 | (ULONG)sizeof(fs3));
|
---|
64 | if(rc == ERROR_DISK_CHANGE) {
|
---|
65 | DosError(FERR_ENABLEHARDERR);
|
---|
66 | rc = DosQueryPathInfo(buffer,FIL_STANDARD,&fs3,
|
---|
67 | (ULONG)sizeof(fs3));
|
---|
68 | }
|
---|
69 | if(rc)
|
---|
70 | break;
|
---|
71 | Loop:
|
---|
72 | if(p < o) {
|
---|
73 | *buffer = 0;
|
---|
74 | return NULL;
|
---|
75 | }
|
---|
76 | if((*p) + 1 < 'Z' + 1) {
|
---|
77 | (*p)++;
|
---|
78 | while(strchr("*?<>\":/\\|+=;,[]. ",*p))
|
---|
79 | (*p)++;
|
---|
80 | *p = toupper(*p);
|
---|
81 | }
|
---|
82 | else {
|
---|
83 | p--;
|
---|
84 | if(p >= o && *p == '.')
|
---|
85 | p--;
|
---|
86 | goto Loop;
|
---|
87 | }
|
---|
88 | }
|
---|
89 | return buffer;
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | CHAR *TruncName (CHAR *oldname,CHAR *buffer) {
|
---|
94 |
|
---|
95 | CHAR *p,*f,*s,*o;
|
---|
96 | FILESTATUS3 fs3;
|
---|
97 | APIRET rc;
|
---|
98 |
|
---|
99 | if(!buffer || !oldname || !*oldname) {
|
---|
100 | if(buffer)
|
---|
101 | *buffer = 0;
|
---|
102 | return NULL;
|
---|
103 | }
|
---|
104 | strcpy(buffer,oldname);
|
---|
105 | f = strrchr(buffer,'\\');
|
---|
106 | if(!f)
|
---|
107 | f = strrchr(buffer,'/');
|
---|
108 | if(!f)
|
---|
109 | f = buffer;
|
---|
110 | else
|
---|
111 | f++;
|
---|
112 | p = f;
|
---|
113 | o = p;
|
---|
114 | f = oldname + (f - buffer);
|
---|
115 | strupr(buffer);
|
---|
116 | while(*f == '.') /* skip leading '.'s */
|
---|
117 | f++;
|
---|
118 | s = f;
|
---|
119 | while(*f && *f != '.' && f < s + 8) { /* skip past rootname */
|
---|
120 | *p = toupper(*f);
|
---|
121 | p++;
|
---|
122 | f++;
|
---|
123 | }
|
---|
124 | while(*f == '.')
|
---|
125 | f++;
|
---|
126 | s = f;
|
---|
127 | f = strrchr(f,'.');
|
---|
128 | if(f) {
|
---|
129 | while(*f == '.')
|
---|
130 | f++;
|
---|
131 | }
|
---|
132 | if(f && *(f + 1))
|
---|
133 | s = f;
|
---|
134 | else
|
---|
135 | f = s;
|
---|
136 | if(*f) {
|
---|
137 | *p = '.';
|
---|
138 | p++;
|
---|
139 | while(*f && *f != '.' && f < s + 3) {
|
---|
140 | *p = toupper(*f);
|
---|
141 | p++;
|
---|
142 | f++;
|
---|
143 | }
|
---|
144 | }
|
---|
145 | *p = 0;
|
---|
146 |
|
---|
147 | p = o;
|
---|
148 | while(*p) {
|
---|
149 | if(strchr("*?<>\":/\\|+=;,[] ",*p) || *p < 0x20)
|
---|
150 | *p = '_';
|
---|
151 | if(*p == '.' && *(p + 1) == '.')
|
---|
152 | *(p + 1) = '_';
|
---|
153 | p++;
|
---|
154 | }
|
---|
155 |
|
---|
156 | p = o + (strlen(o) - 1);
|
---|
157 | for(;;) {
|
---|
158 | DosError(FERR_DISABLEHARDERR);
|
---|
159 | rc = DosQueryPathInfo(buffer,FIL_STANDARD,&fs3,
|
---|
160 | (ULONG)sizeof(fs3));
|
---|
161 | if(rc == ERROR_DISK_CHANGE) {
|
---|
162 | DosError(FERR_ENABLEHARDERR);
|
---|
163 | rc = DosQueryPathInfo(buffer,FIL_STANDARD,&fs3,
|
---|
164 | (ULONG)sizeof(fs3));
|
---|
165 | }
|
---|
166 | if(rc)
|
---|
167 | break;
|
---|
168 | Loop:
|
---|
169 | if(p < o) {
|
---|
170 | *buffer = 0;
|
---|
171 | return NULL;
|
---|
172 | }
|
---|
173 | if((*p) + 1 < 'Z' + 1) {
|
---|
174 | (*p)++;
|
---|
175 | while(strchr("*?<>\":/\\|+=;,[]. ",*p))
|
---|
176 | (*p)++;
|
---|
177 | *p = toupper(*p);
|
---|
178 | }
|
---|
179 | else {
|
---|
180 | p--;
|
---|
181 | if(p >= o && *p == '.')
|
---|
182 | p--;
|
---|
183 | goto Loop;
|
---|
184 | }
|
---|
185 | }
|
---|
186 | return buffer;
|
---|
187 | }
|
---|
188 |
|
---|
189 |
|
---|
190 | CHAR *GetLongName (CHAR *oldname,CHAR *longname) {
|
---|
191 |
|
---|
192 | if(!longname)
|
---|
193 | return NULL;
|
---|
194 | *longname = 0;
|
---|
195 | if(!oldname ||
|
---|
196 | !*oldname)
|
---|
197 | return NULL;
|
---|
198 | if(IsFullName(oldname)) {
|
---|
199 |
|
---|
200 | APIRET rc;
|
---|
201 | EAOP2 eaop;
|
---|
202 | PGEA2LIST pgealist;
|
---|
203 | PFEA2LIST pfealist;
|
---|
204 | PGEA2 pgea;
|
---|
205 | PFEA2 pfea;
|
---|
206 | CHAR *value;
|
---|
207 |
|
---|
208 | strcpy(longname,
|
---|
209 | oldname);
|
---|
210 | value = longname;
|
---|
211 | while(*value) {
|
---|
212 | if(*value == '/')
|
---|
213 | *value = '\\';
|
---|
214 | value++;
|
---|
215 | }
|
---|
216 | value = strrchr(longname,'\\');
|
---|
217 | if(value) {
|
---|
218 | value++;
|
---|
219 | *value = 0;
|
---|
220 | }
|
---|
221 | pgealist = malloc(sizeof(GEA2LIST) + 32);
|
---|
222 | if(pgealist) {
|
---|
223 | memset(pgealist,0,sizeof(GEA2LIST) + 32);
|
---|
224 | pgea = &pgealist->list[0];
|
---|
225 | strcpy(pgea->szName,LONGNAME);
|
---|
226 | pgea->cbName = strlen(pgea->szName);
|
---|
227 | pgea->oNextEntryOffset = 0L;
|
---|
228 | pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
|
---|
229 | pfealist = malloc(1536);
|
---|
230 | if(pfealist) {
|
---|
231 | memset(pfealist,0,1024);
|
---|
232 | pfealist->cbList = 1024;
|
---|
233 | eaop.fpGEA2List = pgealist;
|
---|
234 | eaop.fpFEA2List = pfealist;
|
---|
235 | eaop.oError = 0L;
|
---|
236 | DosError(FERR_DISABLEHARDERR);
|
---|
237 | rc = DosQueryPathInfo(oldname,
|
---|
238 | FIL_QUERYEASFROMLIST,
|
---|
239 | (PVOID)&eaop,
|
---|
240 | (ULONG)sizeof(EAOP2));
|
---|
241 | if(!rc) {
|
---|
242 | pfea = &eaop.fpFEA2List->list[0];
|
---|
243 | value = pfea->szName + pfea->cbName + 1;
|
---|
244 | value[pfea->cbValue] = 0;
|
---|
245 | if(*(USHORT *)value == EAT_ASCII)
|
---|
246 | strncat(longname,
|
---|
247 | value + (sizeof(USHORT) * 2),
|
---|
248 | CCHMAXPATH - strlen(longname));
|
---|
249 | longname[CCHMAXPATH - 1] = 0;
|
---|
250 | }
|
---|
251 | free(pfealist);
|
---|
252 | }
|
---|
253 | free(pgealist);
|
---|
254 | }
|
---|
255 | }
|
---|
256 | return longname;
|
---|
257 | }
|
---|
258 |
|
---|
259 |
|
---|
260 | BOOL ZapLongName (char *filename) {
|
---|
261 |
|
---|
262 | return WriteLongName(filename, "");
|
---|
263 | }
|
---|
264 |
|
---|
265 |
|
---|
266 | BOOL WriteLongName (CHAR *filename,CHAR *longname) {
|
---|
267 |
|
---|
268 | APIRET rc;
|
---|
269 | EAOP2 eaop;
|
---|
270 | PFEA2LIST pfealist = NULL;
|
---|
271 | ULONG ealen;
|
---|
272 | USHORT len;
|
---|
273 | CHAR *eaval,*p;
|
---|
274 |
|
---|
275 | if(!filename ||
|
---|
276 | !*filename ||
|
---|
277 | !longname)
|
---|
278 | return FALSE;
|
---|
279 | p = strrchr(longname,'\\');
|
---|
280 | if(p)
|
---|
281 | memmove(longname,
|
---|
282 | p + 1,
|
---|
283 | strlen(p + 1) + 1);
|
---|
284 | p = strrchr(longname,'/');
|
---|
285 | if(p)
|
---|
286 | memmove(longname,
|
---|
287 | p + 1,
|
---|
288 | strlen(p + 1) + 1);
|
---|
289 | bstrip(longname);
|
---|
290 | len = strlen(longname);
|
---|
291 | if(len)
|
---|
292 | ealen = sizeof(FEA2LIST) + 10 + len + 4;
|
---|
293 | else
|
---|
294 | ealen = sizeof(FEALIST) + 10;
|
---|
295 | if(!DosAllocMem((PPVOID)&pfealist,
|
---|
296 | ealen + 32L,
|
---|
297 | OBJ_TILE | PAG_COMMIT | PAG_READ | PAG_WRITE)) {
|
---|
298 | memset(pfealist,
|
---|
299 | 0,
|
---|
300 | ealen + 1);
|
---|
301 | pfealist->cbList = ealen;
|
---|
302 | pfealist->list[0].oNextEntryOffset = 0L;
|
---|
303 | pfealist->list[0].fEA = 0;
|
---|
304 | pfealist->list[0].cbName = 9;
|
---|
305 | strcpy(pfealist->list[0].szName,
|
---|
306 | LONGNAME);
|
---|
307 | if(len) {
|
---|
308 | eaval = pfealist->list[0].szName + 10;
|
---|
309 | *(USHORT *)eaval = (USHORT)EAT_ASCII;
|
---|
310 | eaval += sizeof(USHORT);
|
---|
311 | *(USHORT *)eaval = (USHORT)len;
|
---|
312 | eaval += sizeof(USHORT);
|
---|
313 | memcpy(eaval,
|
---|
314 | longname,
|
---|
315 | len);
|
---|
316 | pfealist->list[0].cbValue = len + (sizeof(USHORT) * 2);
|
---|
317 | }
|
---|
318 | else
|
---|
319 | pfealist->list[0].cbValue = 0;
|
---|
320 | eaop.fpGEA2List = (PGEA2LIST)0;
|
---|
321 | eaop.fpFEA2List = pfealist;
|
---|
322 | eaop.oError = 0L;
|
---|
323 | DosError(FERR_DISABLEHARDERR);
|
---|
324 | rc = DosSetPathInfo(filename,
|
---|
325 | FIL_QUERYEASIZE,
|
---|
326 | (PVOID)&eaop,
|
---|
327 | (ULONG)sizeof(EAOP2),
|
---|
328 | DSPI_WRTTHRU);
|
---|
329 | DosFreeMem(pfealist);
|
---|
330 | if(rc)
|
---|
331 | return FALSE;
|
---|
332 | }
|
---|
333 | return TRUE;
|
---|
334 | }
|
---|
335 |
|
---|
336 |
|
---|
337 | BOOL AdjustWildcardName (CHAR *oldname,CHAR *newname) {
|
---|
338 |
|
---|
339 | BOOL ret = FALSE;
|
---|
340 |
|
---|
341 | /* NOTE: newname should be CCHMAXPATH chars long! */
|
---|
342 |
|
---|
343 | if(strchr(newname,'*') || strchr(newname,'?')) {
|
---|
344 |
|
---|
345 | CHAR srce[CCHMAXPATHCOMP],dest[CCHMAXPATHCOMP],result[CCHMAXPATHCOMP],*p;
|
---|
346 |
|
---|
347 | p = strrchr(newname,'\\');
|
---|
348 | if(p && *(p + 1)) {
|
---|
349 | strcpy(dest,p + 1);
|
---|
350 | p = strrchr(oldname,'\\');
|
---|
351 | if(p && *(p + 1)) {
|
---|
352 | strcpy(srce,p + 1);
|
---|
353 | DosError(FERR_DISABLEHARDERR);
|
---|
354 | if(!DosEditName(1L,srce,dest,result,(ULONG)sizeof(result))) {
|
---|
355 | p = strrchr(newname,'\\');
|
---|
356 | p++;
|
---|
357 | strcpy(p,result);
|
---|
358 | ret = TRUE;
|
---|
359 | }
|
---|
360 | }
|
---|
361 | }
|
---|
362 | }
|
---|
363 | return ret;
|
---|
364 | }
|
---|
365 |
|
---|
366 |
|
---|
367 | CHAR default_disk (VOID) {
|
---|
368 |
|
---|
369 | ULONG ulDriveNum,ulDriveMap;
|
---|
370 |
|
---|
371 | DosError(FERR_DISABLEHARDERR);
|
---|
372 | DosQCurDisk(&ulDriveNum,&ulDriveMap);
|
---|
373 | return (CHAR)toupper((INT)ulDriveNum) + '@';
|
---|
374 | }
|
---|
375 |
|
---|
376 |
|
---|
377 | #ifdef NEVER
|
---|
378 |
|
---|
379 | APIRET docopyallf (INT type,CHAR *oldname,CHAR *newname,...) {
|
---|
380 |
|
---|
381 | FILEFINDBUF3 fb;
|
---|
382 | ULONG nm;
|
---|
383 | HDIR hdir;
|
---|
384 | APIRET rc = 0;
|
---|
385 | CHAR *enddir,fullname[CCHMAXPATH];
|
---|
386 |
|
---|
387 | va_start(ap,newname);
|
---|
388 | vsprintf(fullname,newname,ap);
|
---|
389 | va_end(ap);
|
---|
390 |
|
---|
391 | DosError(FERR_DISABLEHARDERR);
|
---|
392 | if(!DosFindFirst(oldname)) {
|
---|
393 | do {
|
---|
394 |
|
---|
395 | /* build target name */
|
---|
396 |
|
---|
397 | if(fb.attrFile & FILE_DIRECTORY) {
|
---|
398 | DosError(FERR_ENABLEHARDERR);
|
---|
399 | rc = DosCreateDir();
|
---|
400 | if(rc == ERROR_INVALID_NAME || rc == ERROR_FILENAME_EXCED_RANGE) {
|
---|
401 |
|
---|
402 | /* truncate directory name */
|
---|
403 | /* create that directory */
|
---|
404 | /* update containers for name used */
|
---|
405 |
|
---|
406 | }
|
---|
407 | rc = docopyallf(type,,"%s",); /* recurse */
|
---|
408 | }
|
---|
409 | else
|
---|
410 | rc = docopyf(type,,"%s",); /* copy file */
|
---|
411 | DosError(FERR_DISABLEHARDERR);
|
---|
412 | } while(!rc && !DosFindNext());
|
---|
413 | DosFindClose(hdir);
|
---|
414 | }
|
---|
415 | else
|
---|
416 | rc = ERROR_FILE_NOT_FOUND;
|
---|
417 | return rc;
|
---|
418 | }
|
---|
419 |
|
---|
420 | #endif
|
---|
421 |
|
---|
422 |
|
---|
423 | APIRET docopyf (INT type,CHAR *oldname,CHAR *newname,...) {
|
---|
424 |
|
---|
425 | /*
|
---|
426 | * returns:
|
---|
427 | * 0: success
|
---|
428 | * -1: bad string parameter(s)
|
---|
429 | * -2: source didn't exist
|
---|
430 | * -3: bad type
|
---|
431 | * anything else: API return
|
---|
432 | */
|
---|
433 |
|
---|
434 | CHAR fullnewname[CCHMAXPATH + 1],longname[CCHMAXPATH],
|
---|
435 | shortname[CCHMAXPATH];
|
---|
436 | CHAR olddisk,newdisk,dir[CCHMAXPATH],*p,*pp;
|
---|
437 | APIRET ret = -1,rc;
|
---|
438 | FILESTATUS3 st,st2,dummy;
|
---|
439 | BOOL diskchange = FALSE,zaplong = FALSE;
|
---|
440 | va_list ap;
|
---|
441 |
|
---|
442 | *fullnewname = *shortname = *dir = 0;
|
---|
443 |
|
---|
444 | va_start(ap,
|
---|
445 | newname);
|
---|
446 | vsprintf(fullnewname,
|
---|
447 | newname,
|
---|
448 | ap);
|
---|
449 | va_end(ap);
|
---|
450 |
|
---|
451 | if(!oldname ||
|
---|
452 | !*oldname ||
|
---|
453 | !*fullnewname) /* bad string args */
|
---|
454 | return (APIRET)-1;
|
---|
455 |
|
---|
456 | DosError(FERR_DISABLEHARDERR);
|
---|
457 | if(DosQueryPathInfo(oldname,
|
---|
458 | FIL_STANDARD,
|
---|
459 | &st,
|
---|
460 | sizeof(FILESTATUS3)))
|
---|
461 | return (APIRET)-2; /* no source */
|
---|
462 |
|
---|
463 | AdjustWildcardName(oldname,
|
---|
464 | fullnewname);
|
---|
465 | MakeFullName(oldname);
|
---|
466 | MakeFullName(fullnewname);
|
---|
467 | olddisk = toupper(*oldname); /* source drive */
|
---|
468 | newdisk = toupper(*fullnewname); /* destination drive */
|
---|
469 | if(!(driveflags[toupper(*oldname) - 'A'] & DRIVE_NOLONGNAMES))
|
---|
470 | *longname = 0;
|
---|
471 | else
|
---|
472 | {
|
---|
473 | GetLongName(oldname, longname);
|
---|
474 | if(*longname) {
|
---|
475 | p = RootName(longname);
|
---|
476 | if(p != longname)
|
---|
477 | memmove(longname, p, strlen(p) + 1);
|
---|
478 | }
|
---|
479 | }
|
---|
480 | /* If root name changed make sure longname EA goes away */
|
---|
481 | p = RootName(oldname);
|
---|
482 | pp = RootName(fullnewname);
|
---|
483 | if(stricmp(p, pp))
|
---|
484 | {
|
---|
485 | zaplong = TRUE;
|
---|
486 | }
|
---|
487 |
|
---|
488 | DosError(FERR_DISABLEHARDERR);
|
---|
489 | switch(type)
|
---|
490 | {
|
---|
491 | case WPSMOVE:
|
---|
492 | {
|
---|
493 | HOBJECT hobjsrc;
|
---|
494 | HOBJECT hobjdest;
|
---|
495 |
|
---|
496 | ret = ERROR_FILE_NOT_FOUND;
|
---|
497 | hobjsrc = WinQueryObject(oldname);
|
---|
498 | if(hobjsrc) {
|
---|
499 | strcpy(dir,
|
---|
500 | fullnewname);
|
---|
501 | p = strrchr(dir,'\\');
|
---|
502 | if(p < dir + 3)
|
---|
503 | p++;
|
---|
504 | *p = 0;
|
---|
505 | ret = ERROR_PATH_NOT_FOUND;
|
---|
506 | hobjdest = WinQueryObject(dir);
|
---|
507 | if(hobjdest) {
|
---|
508 | ret = ERROR_GEN_FAILURE;
|
---|
509 | hobjsrc = WinMoveObject(hobjsrc,
|
---|
510 | hobjdest,
|
---|
511 | 0);
|
---|
512 | if(hobjsrc)
|
---|
513 | ret = 0;
|
---|
514 | }
|
---|
515 | }
|
---|
516 | }
|
---|
517 | return ret;
|
---|
518 |
|
---|
519 | case WPSCOPY:
|
---|
520 | {
|
---|
521 | HOBJECT hobjsrc;
|
---|
522 | HOBJECT hobjdest;
|
---|
523 |
|
---|
524 | ret = ERROR_FILE_NOT_FOUND;
|
---|
525 | hobjsrc = WinQueryObject(oldname);
|
---|
526 | if(hobjsrc) {
|
---|
527 | strcpy(dir,
|
---|
528 | fullnewname);
|
---|
529 | p = strrchr(dir,'\\');
|
---|
530 | if(p < dir + 3)
|
---|
531 | p++;
|
---|
532 | *p = 0;
|
---|
533 | ret = ERROR_PATH_NOT_FOUND;
|
---|
534 | hobjdest = WinQueryObject(dir);
|
---|
535 | if(hobjdest) {
|
---|
536 | ret = ERROR_GEN_FAILURE;
|
---|
537 | hobjsrc = WinCopyObject(hobjsrc,
|
---|
538 | hobjdest,
|
---|
539 | 0);
|
---|
540 | if(hobjsrc)
|
---|
541 | ret = 0;
|
---|
542 | }
|
---|
543 | }
|
---|
544 | }
|
---|
545 | return ret;
|
---|
546 |
|
---|
547 | case MOVE:
|
---|
548 | *dir = 0;
|
---|
549 | if(olddisk == newdisk) { /* same drive */
|
---|
550 | /* make temporary copy in case move fails */
|
---|
551 | if(IsFile(fullnewname) != -1 &&
|
---|
552 | stricmp(oldname,
|
---|
553 | fullnewname)) {
|
---|
554 | strcpy(dir,
|
---|
555 | fullnewname);
|
---|
556 | p = strrchr(dir,'\\');
|
---|
557 | if(p)
|
---|
558 | *p = 0;
|
---|
559 | strcat(dir,"\\");
|
---|
560 | MakeTempName(dir);
|
---|
561 | if(DosMove(fullnewname,
|
---|
562 | dir))
|
---|
563 | *dir = 0;
|
---|
564 | }
|
---|
565 | DosError(FERR_DISABLEHARDERR);
|
---|
566 | ret = DosMove(oldname,
|
---|
567 | fullnewname); /* move it */
|
---|
568 | if(ret &&
|
---|
569 | *dir) { /* failed -- clean up */
|
---|
570 | DosError(FERR_DISABLEHARDERR);
|
---|
571 | if(!DosMove(dir,
|
---|
572 | fullnewname))
|
---|
573 | Broadcast((HAB)0,
|
---|
574 | hwndMain,
|
---|
575 | UM_UPDATERECORD,
|
---|
576 | MPFROMP(dir),
|
---|
577 | MPVOID);
|
---|
578 | }
|
---|
579 | else if(!ret &&
|
---|
580 | *dir) {
|
---|
581 | if(!IsFile(dir)) {
|
---|
582 | if(!strchr(dir,'?') &&
|
---|
583 | !strchr(dir,'*'))
|
---|
584 | wipeallf("%s\\*",dir);
|
---|
585 | DosError(FERR_DISABLEHARDERR);
|
---|
586 | if(DosDeleteDir(dir)) {
|
---|
587 | make_deleteable(dir);
|
---|
588 | DosDeleteDir(dir);
|
---|
589 | }
|
---|
590 | }
|
---|
591 | else if(IsFile(dir) > 0) {
|
---|
592 | DosError(FERR_DISABLEHARDERR);
|
---|
593 | if(DosForceDelete(dir)) {
|
---|
594 | make_deleteable(dir);
|
---|
595 | DosForceDelete(dir);
|
---|
596 | }
|
---|
597 | if(zaplong)
|
---|
598 | ZapLongName(dir);
|
---|
599 | Broadcast((HAB)0,
|
---|
600 | hwndMain,
|
---|
601 | UM_UPDATERECORD,
|
---|
602 | MPFROMP(dir),
|
---|
603 | MPVOID);
|
---|
604 | }
|
---|
605 | }
|
---|
606 | }
|
---|
607 | else { /* different drives */
|
---|
608 | DosError(FERR_DISABLEHARDERR);
|
---|
609 | ret = DosCopy(oldname,
|
---|
610 | fullnewname,
|
---|
611 | DCPY_EXISTING); /* <=-NOTE! */
|
---|
612 | if(ret == ERROR_DISK_CHANGE) {
|
---|
613 | DosError(FERR_ENABLEHARDERR);
|
---|
614 | ret = DosCopy(oldname,
|
---|
615 | fullnewname,
|
---|
616 | DCPY_EXISTING);
|
---|
617 | diskchange = TRUE;
|
---|
618 | }
|
---|
619 | if(ret == ERROR_INVALID_NAME ||
|
---|
620 | ret == ERROR_FILENAME_EXCED_RANGE) {
|
---|
621 | if(TruncName(fullnewname,
|
---|
622 | shortname)) { /* make 8.3 filename */
|
---|
623 | DosError(FERR_DISABLEHARDERR);
|
---|
624 | ret = DosCopy(oldname,
|
---|
625 | shortname,
|
---|
626 | DCPY_EXISTING);
|
---|
627 | if(!ret) { /* success -- write longname ea */
|
---|
628 | WriteLongName(shortname,
|
---|
629 | fullnewname);
|
---|
630 | strcpy(fullnewname,
|
---|
631 | shortname);
|
---|
632 | /* broadcast fixup msg to windows */
|
---|
633 | Broadcast((HAB)0,
|
---|
634 | hwndMain,
|
---|
635 | UM_UPDATERECORD,
|
---|
636 | MPFROMP(shortname),
|
---|
637 | MPVOID);
|
---|
638 | }
|
---|
639 | }
|
---|
640 | }
|
---|
641 | else if(!ret &&
|
---|
642 | *longname) {
|
---|
643 |
|
---|
644 | CHAR fixname[CCHMAXPATH];
|
---|
645 |
|
---|
646 | strcpy(fixname,
|
---|
647 | fullnewname);
|
---|
648 | p = strrchr(fixname,'\\');
|
---|
649 | if(p) {
|
---|
650 | p++;
|
---|
651 | *p = 0;
|
---|
652 | }
|
---|
653 | strcat(fixname,
|
---|
654 | longname);
|
---|
655 | DosError(FERR_DISABLEHARDERR);
|
---|
656 | DosMove(fullnewname,
|
---|
657 | fixname);
|
---|
658 | strcpy(fullnewname,
|
---|
659 | fixname);
|
---|
660 | if(zaplong)
|
---|
661 | ZapLongName(fixname);
|
---|
662 | Broadcast((HAB)0,
|
---|
663 | hwndMain,
|
---|
664 | UM_UPDATERECORD,
|
---|
665 | MPFROMP(fixname),
|
---|
666 | MPVOID);
|
---|
667 | }
|
---|
668 | if(!ret) { /* double-check success */
|
---|
669 | DosError(FERR_DISABLEHARDERR);
|
---|
670 | rc = DosQueryPathInfo(fullnewname,
|
---|
671 | FIL_STANDARD,
|
---|
672 | &st2,
|
---|
673 | sizeof(FILESTATUS3));
|
---|
674 | if(rc == ERROR_DISK_CHANGE) {
|
---|
675 | DosError(FERR_ENABLEHARDERR);
|
---|
676 | rc = DosQueryPathInfo(fullnewname,
|
---|
677 | FIL_STANDARD,
|
---|
678 | &st2,
|
---|
679 | sizeof(FILESTATUS3));
|
---|
680 | }
|
---|
681 | if(!rc && st2.cbFile == st.cbFile) { /* seems to have worked... */
|
---|
682 | DosError(FERR_DISABLEHARDERR);
|
---|
683 | if(diskchange) {
|
---|
684 | DosError(FERR_ENABLEHARDERR);
|
---|
685 | DosQueryPathInfo(oldname,
|
---|
686 | FIL_STANDARD,
|
---|
687 | &dummy,
|
---|
688 | sizeof(FILESTATUS3)); /* force disk change */
|
---|
689 | }
|
---|
690 | if(!(st2.attrFile & FILE_DIRECTORY)) /* erase file */
|
---|
691 | unlinkf("%s",oldname);
|
---|
692 | else { /* remove directory */
|
---|
693 | wipeallf("%s\\*",oldname);
|
---|
694 | DosError(FERR_DISABLEHARDERR);
|
---|
695 | if(DosDeleteDir(oldname)) {
|
---|
696 | make_deleteable(oldname);
|
---|
697 | DosDeleteDir(oldname);
|
---|
698 | }
|
---|
699 | }
|
---|
700 | }
|
---|
701 | }
|
---|
702 | }
|
---|
703 | return ret;
|
---|
704 |
|
---|
705 | case COPY:
|
---|
706 | DosError(FERR_DISABLEHARDERR);
|
---|
707 | ret = DosCopy(oldname,
|
---|
708 | fullnewname,
|
---|
709 | DCPY_EXISTING); /* <=-NOTE! */
|
---|
710 | if(ret == ERROR_DISK_CHANGE) {
|
---|
711 | DosError(FERR_ENABLEHARDERR);
|
---|
712 | ret = DosCopy(oldname,
|
---|
713 | fullnewname,
|
---|
714 | DCPY_EXISTING);
|
---|
715 | diskchange = TRUE;
|
---|
716 | }
|
---|
717 | if(ret == ERROR_INVALID_NAME ||
|
---|
718 | ret == ERROR_FILENAME_EXCED_RANGE) {
|
---|
719 | if(TruncName(fullnewname,
|
---|
720 | shortname)) {
|
---|
721 | DosError((diskchange) ?
|
---|
722 | FERR_ENABLEHARDERR :
|
---|
723 | FERR_DISABLEHARDERR);
|
---|
724 | ret = DosCopy(oldname,
|
---|
725 | shortname,
|
---|
726 | DCPY_EXISTING);
|
---|
727 | if(!ret) {
|
---|
728 | WriteLongName(shortname,
|
---|
729 | fullnewname);
|
---|
730 | strcpy(fullnewname,
|
---|
731 | shortname);
|
---|
732 | Broadcast((HAB)0,
|
---|
733 | hwndMain,
|
---|
734 | UM_UPDATERECORD,
|
---|
735 | MPFROMP(shortname),
|
---|
736 | MPVOID);
|
---|
737 | }
|
---|
738 | }
|
---|
739 | }
|
---|
740 | else if(!ret &&
|
---|
741 | *longname) {
|
---|
742 |
|
---|
743 | CHAR fixname[CCHMAXPATH];
|
---|
744 |
|
---|
745 | strcpy(fixname,
|
---|
746 | fullnewname);
|
---|
747 | p = strrchr(fixname,'\\');
|
---|
748 | if(p) {
|
---|
749 | p++;
|
---|
750 | *p = 0;
|
---|
751 | }
|
---|
752 | strcat(fixname,
|
---|
753 | longname);
|
---|
754 | DosError(FERR_DISABLEHARDERR);
|
---|
755 | DosMove(fullnewname,
|
---|
756 | fixname);
|
---|
757 | if(zaplong)
|
---|
758 | ZapLongName(fixname);
|
---|
759 | Broadcast((HAB)0,
|
---|
760 | hwndMain,
|
---|
761 | UM_UPDATERECORD,
|
---|
762 | MPFROMP(fixname),
|
---|
763 | MPVOID);
|
---|
764 | }
|
---|
765 | return ret;
|
---|
766 |
|
---|
767 | default: /* shouldn't happen */
|
---|
768 | DosBeep(50,100);
|
---|
769 | break;
|
---|
770 | }
|
---|
771 | return (APIRET)-3; /* bad type */
|
---|
772 | }
|
---|
773 |
|
---|
774 |
|
---|
775 | INT make_deleteable (CHAR *filename) {
|
---|
776 |
|
---|
777 | INT ret = -1;
|
---|
778 | FILESTATUS3 fsi;
|
---|
779 |
|
---|
780 | DosError(FERR_DISABLEHARDERR);
|
---|
781 | if(!DosQueryPathInfo(filename,
|
---|
782 | FIL_STANDARD,
|
---|
783 | &fsi,
|
---|
784 | sizeof(FILESTATUS3))) {
|
---|
785 | fsi.attrFile = 0;
|
---|
786 | DosError(FERR_DISABLEHARDERR);
|
---|
787 | if(!DosSetPathInfo(filename,
|
---|
788 | FIL_STANDARD,
|
---|
789 | &fsi,
|
---|
790 | sizeof(FILESTATUS3),
|
---|
791 | 0L))
|
---|
792 | ret = 0;
|
---|
793 | }
|
---|
794 | return ret;
|
---|
795 | }
|
---|
796 |
|
---|
797 |
|
---|
798 | INT wipeallf (CHAR *string,...) {
|
---|
799 |
|
---|
800 | /* unlink everything from directory on down... */
|
---|
801 |
|
---|
802 | FILEFINDBUF3 *f;
|
---|
803 | HDIR search_handle;
|
---|
804 | ULONG num_matches;
|
---|
805 | CHAR *p,*ss,*str;
|
---|
806 | CHAR s[CCHMAXPATH],mask[257];
|
---|
807 | va_list ap;
|
---|
808 | INT rc;
|
---|
809 |
|
---|
810 | va_start(ap,string);
|
---|
811 | vsprintf(s,string,ap);
|
---|
812 | va_end(ap);
|
---|
813 |
|
---|
814 | if(!*s)
|
---|
815 | return -1;
|
---|
816 | p = s;
|
---|
817 | while((p = strchr(p,'/')) != NULL) {
|
---|
818 | *p = '\\';
|
---|
819 | p++;
|
---|
820 | }
|
---|
821 |
|
---|
822 | str = strdup(s);
|
---|
823 | if(!str)
|
---|
824 | return -1;
|
---|
825 |
|
---|
826 | { /* safety net -- disallow deleting a root dir or partial name */
|
---|
827 | CHAR temp;
|
---|
828 |
|
---|
829 | p = strrchr(str,'\\');
|
---|
830 | if(p) {
|
---|
831 | p++;
|
---|
832 | temp = *p;
|
---|
833 | *p = 0;
|
---|
834 | if(IsRoot(str) || !IsFullName(str)) { /* under no circumstances! */
|
---|
835 | free(str);
|
---|
836 | DosBeep(100,250);
|
---|
837 | return -1;
|
---|
838 | }
|
---|
839 | *p = temp;
|
---|
840 | }
|
---|
841 | }
|
---|
842 |
|
---|
843 | p = s;
|
---|
844 | p = strrchr(s,'\\'); /* strip s to just path */
|
---|
845 | if(!p)
|
---|
846 | p = strrchr(s,':');
|
---|
847 | if(p) {
|
---|
848 | p++;
|
---|
849 | strncpy(mask,p,256);
|
---|
850 | mask[256] = 0;
|
---|
851 | *p = 0;
|
---|
852 | }
|
---|
853 | else {
|
---|
854 | *mask = 0;
|
---|
855 | *s = 0;
|
---|
856 | }
|
---|
857 |
|
---|
858 | ss = (CHAR *)malloc(CCHMAXPATH);
|
---|
859 | f = (FILEFINDBUF3 *)malloc(sizeof(FILEFINDBUF3));
|
---|
860 | if(!ss || !f) {
|
---|
861 | if(ss)
|
---|
862 | free(ss);
|
---|
863 | if(f)
|
---|
864 | free(f);
|
---|
865 | free(str);
|
---|
866 | return -1;
|
---|
867 | }
|
---|
868 |
|
---|
869 | search_handle = HDIR_CREATE;
|
---|
870 | num_matches = 1L;
|
---|
871 |
|
---|
872 | DosError(FERR_DISABLEHARDERR);
|
---|
873 | if(!DosFindFirst(str,&search_handle,FILE_NORMAL | FILE_DIRECTORY |
|
---|
874 | FILE_SYSTEM | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED,f,
|
---|
875 | sizeof(FILEFINDBUF3),&num_matches,FIL_STANDARD)) {
|
---|
876 |
|
---|
877 | strcpy(ss,s);
|
---|
878 | p = &ss[strlen(ss)];
|
---|
879 |
|
---|
880 | do {
|
---|
881 | strcpy(p,f->achName);
|
---|
882 | if(f->attrFile & FILE_DIRECTORY) {
|
---|
883 | if(strcmp(f->achName,".") && strcmp(f->achName,"..")) {
|
---|
884 | wipeallf("%s/%s",ss,mask); /* recurse to wipe files */
|
---|
885 | DosError(FERR_DISABLEHARDERR);
|
---|
886 | if(DosDeleteDir(ss)) { /* remove directory */
|
---|
887 | make_deleteable(ss);
|
---|
888 | DosError(FERR_DISABLEHARDERR);
|
---|
889 | DosDeleteDir(ss);
|
---|
890 | }
|
---|
891 | }
|
---|
892 | }
|
---|
893 | else {
|
---|
894 | DosError(FERR_DISABLEHARDERR);
|
---|
895 | if(DosForceDelete(ss)) {
|
---|
896 | make_deleteable(ss);
|
---|
897 | DosError(FERR_DISABLEHARDERR);
|
---|
898 | rc = (INT)DosForceDelete(ss);
|
---|
899 | if(rc)
|
---|
900 | return rc;
|
---|
901 | }
|
---|
902 | }
|
---|
903 | num_matches = 1L;
|
---|
904 | DosError(FERR_DISABLEHARDERR);
|
---|
905 | } while(!DosFindNext(search_handle,f,sizeof(FILEFINDBUF3),
|
---|
906 | &num_matches));
|
---|
907 | DosFindClose(search_handle);
|
---|
908 | }
|
---|
909 |
|
---|
910 | free(f);
|
---|
911 | free(ss);
|
---|
912 | free(str);
|
---|
913 | return 0;
|
---|
914 | }
|
---|
915 |
|
---|
916 |
|
---|
917 | INT unlink_allf (CHAR *string,...) {
|
---|
918 |
|
---|
919 | /* wildcard delete */
|
---|
920 |
|
---|
921 | FILEFINDBUF3 *f;
|
---|
922 | HDIR search_handle;
|
---|
923 | ULONG num_matches;
|
---|
924 | CHAR *p,*ss,*str;
|
---|
925 | CHAR s[CCHMAXPATH];
|
---|
926 | va_list ap;
|
---|
927 |
|
---|
928 | va_start(ap,string);
|
---|
929 | vsprintf(s,string,ap);
|
---|
930 | va_end(ap);
|
---|
931 |
|
---|
932 | if(!*s)
|
---|
933 | return -1;
|
---|
934 | p = s;
|
---|
935 | while((p = strchr(p,'/')) != NULL) {
|
---|
936 | *p = '\\';
|
---|
937 | p++;
|
---|
938 | }
|
---|
939 |
|
---|
940 | str = strdup(s);
|
---|
941 | if(!str)
|
---|
942 | return -1;
|
---|
943 |
|
---|
944 | p = s;
|
---|
945 | p = strrchr(s,'\\'); /* strip s to just path */
|
---|
946 | if(!p)
|
---|
947 | p = strrchr(s,':');
|
---|
948 | if(p) {
|
---|
949 | p++;
|
---|
950 | *p = 0;
|
---|
951 | }
|
---|
952 | else
|
---|
953 | *s = 0;
|
---|
954 |
|
---|
955 | ss = (CHAR *)malloc(CCHMAXPATH);
|
---|
956 | f = (FILEFINDBUF3 *)malloc(sizeof(FILEFINDBUF3));
|
---|
957 | if(!ss || !f) {
|
---|
958 | if(ss)
|
---|
959 | free(ss);
|
---|
960 | if(f)
|
---|
961 | free(f);
|
---|
962 | free(str);
|
---|
963 | return -1;
|
---|
964 | }
|
---|
965 |
|
---|
966 | search_handle = HDIR_CREATE;
|
---|
967 | num_matches = 1L;
|
---|
968 |
|
---|
969 | DosError(FERR_DISABLEHARDERR);
|
---|
970 | if(!DosFindFirst(str,&search_handle,FILE_NORMAL,f,
|
---|
971 | sizeof(FILEFINDBUF3),&num_matches,FIL_STANDARD)) {
|
---|
972 |
|
---|
973 | strcpy(ss,s);
|
---|
974 | p = &ss[strlen(ss)];
|
---|
975 |
|
---|
976 | do {
|
---|
977 | strcpy(p,f->achName);
|
---|
978 | unlinkf("%s",ss);
|
---|
979 | num_matches = 1L;
|
---|
980 | DosError(FERR_DISABLEHARDERR);
|
---|
981 | } while(!DosFindNext(search_handle,f,sizeof(FILEFINDBUF3),
|
---|
982 | &num_matches));
|
---|
983 | DosFindClose(search_handle);
|
---|
984 | }
|
---|
985 |
|
---|
986 | free(f);
|
---|
987 | free(ss);
|
---|
988 | free(str);
|
---|
989 | return 0;
|
---|
990 | }
|
---|
991 |
|
---|
992 |
|
---|
993 | INT unlinkf (CHAR *string,...) {
|
---|
994 |
|
---|
995 | CHAR buffer[CCHMAXPATH];
|
---|
996 | va_list ap;
|
---|
997 |
|
---|
998 | va_start(ap,string);
|
---|
999 | vsprintf(buffer,string,ap);
|
---|
1000 | va_end(ap);
|
---|
1001 |
|
---|
1002 | if(!strstr(buffer,ArcTempRoot)) {
|
---|
1003 | DosError(FERR_DISABLEHARDERR);
|
---|
1004 | if(DosDelete(buffer)) {
|
---|
1005 | make_deleteable(buffer);
|
---|
1006 | DosError(FERR_DISABLEHARDERR);
|
---|
1007 | return DosDelete(buffer);
|
---|
1008 | }
|
---|
1009 | }
|
---|
1010 | else {
|
---|
1011 | DosError(FERR_DISABLEHARDERR);
|
---|
1012 | if(DosForceDelete(buffer)) {
|
---|
1013 | make_deleteable(buffer);
|
---|
1014 | DosError(FERR_DISABLEHARDERR);
|
---|
1015 | return DosForceDelete(buffer);
|
---|
1016 | }
|
---|
1017 | }
|
---|
1018 | return 0;
|
---|
1019 | }
|
---|
1020 |
|
---|