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