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