Changeset 1163 for trunk/dll/copyf.c
- Timestamp:
- Sep 5, 2008, 11:43:52 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/copyf.c
r1082 r1163 12 12 14 Oct 02 SHL Drop obsolete debug code 13 13 10 Nov 02 SHL docopyf - don't forget to terminate longname 14 14 optimize longname logic 15 15 01 Aug 04 SHL Rework lstrip/rstrip usage 16 16 28 May 05 SHL Drop debug code … … 34 34 35 35 #include "fm3str.h" 36 #include "errutil.h" // Dos_Error... 37 #include "strutil.h" // GetPString 36 #include "errutil.h" // Dos_Error... 37 #include "strutil.h" // GetPString 38 #include "copyf.h" 39 #include "literal.h" // fixup 38 40 #include "fm3dll.h" 39 41 #include "fortify.h" … … 41 43 static PSZ pszSrcFile = __FILE__; 42 44 45 //static CHAR default_disk(VOID); 46 //static INT unlink_allf(CHAR * string, ...); 47 43 48 #ifndef WinMoveObject 44 49 HOBJECT APIENTRY WinMoveObject(HOBJECT hObjectofObject, 45 50 HOBJECT hObjectofDest, ULONG ulReserved); 46 51 #endif 47 52 #ifndef WinCopyObject 48 53 HOBJECT APIENTRY WinCopyObject(HOBJECT hObjectofObject, 49 54 HOBJECT hObjectofDest, ULONG ulReserved); 50 55 #endif 51 56 … … 90 95 (*p)++; 91 96 while (strchr("*?<>\":/\\|+=;,[]. ", *p)) 92 97 (*p)++; 93 98 *p = toupper(*p); 94 99 } … … 96 101 p--; 97 102 if (p >= o && *p == '.') 98 103 p--; 99 104 goto Loop; 100 105 } … … 126 131 f = oldname + (f - buffer); 127 132 strupr(buffer); 128 while (*f == '.') 133 while (*f == '.') /* skip leading '.'s */ 129 134 f++; 130 135 s = f; 131 while (*f && *f != '.' && f < s + 8) { 136 while (*f && *f != '.' && f < s + 8) { /* skip past rootname */ 132 137 *p = toupper(*f); 133 138 p++; … … 184 189 (*p)++; 185 190 while (strchr("*?<>\":/\\|+=;,[]. ", *p)) 186 191 (*p)++; 187 192 *p = toupper(*p); 188 193 } … … 190 195 p--; 191 196 if (p >= o && *p == '.') 192 197 p--; 193 198 goto Loop; 194 199 } … … 218 223 while (*value) { 219 224 if (*value == '/') 220 225 *value = '\\'; 221 226 value++; 222 227 } … … 235 240 pfealist = xmallocz(1536, pszSrcFile, __LINE__); 236 241 if (pfealist) { 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 242 pfealist->cbList = 1024; 243 eaop.fpGEA2List = pgealist; 244 eaop.fpFEA2List = pfealist; 245 eaop.oError = 0L; 246 DosError(FERR_DISABLEHARDERR); 247 rc = DosQueryPathInfo(oldname, 248 FIL_QUERYEASFROMLIST, 249 (PVOID) & eaop, (ULONG) sizeof(EAOP2)); 250 if (!rc) { 251 pfea = &eaop.fpFEA2List->list[0]; 252 value = pfea->szName + pfea->cbName + 1; 253 value[pfea->cbValue] = 0; 254 if (*(USHORT *) value == EAT_ASCII) 255 strncat(longname, 256 value + (sizeof(USHORT) * 2), 257 CCHMAXPATH - strlen(longname)); 258 longname[CCHMAXPATH - 1] = 0; 259 } 260 free(pfealist); 256 261 } 257 262 free(pgealist); … … 290 295 ealen = sizeof(FEALIST) + 10; 291 296 rc = DosAllocMem((PPVOID) & pfealist, 292 297 ealen + 32L, OBJ_TILE | PAG_COMMIT | PAG_READ | PAG_WRITE); 293 298 if (rc) 294 299 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__, 295 300 GetPString(IDS_OUTOFMEMORY)); 296 301 else { 297 302 memset(pfealist, 0, ealen + 1); … … 317 322 DosError(FERR_DISABLEHARDERR); 318 323 rc = xDosSetPathInfo(filename, FIL_QUERYEASIZE, 319 324 &eaop, sizeof(eaop), DSPI_WRTTHRU); 320 325 DosFreeMem(pfealist); 321 326 if (rc) … … 341 346 p = strrchr(oldname, '\\'); 342 347 if (p && *(p + 1)) { 343 344 345 346 347 348 349 350 348 strcpy(srce, p + 1); 349 DosError(FERR_DISABLEHARDERR); 350 if (!DosEditName(1L, srce, dest, result, (ULONG) sizeof(result))) { 351 p = strrchr(newname, '\\'); 352 p++; 353 strcpy(p, result); 354 ret = TRUE; 355 } 351 356 } 352 357 } … … 355 360 } 356 361 362 #if 0 // JBS 357 363 CHAR default_disk(VOID) 358 364 { … … 363 369 return (CHAR) toupper((INT) ulDriveNum) + '@'; 364 370 } 371 #endif 365 372 366 373 #ifdef NEVER … … 385 392 386 393 if (fb.attrFile & FILE_DIRECTORY) { 387 388 389 390 391 392 393 394 395 396 rc = docopyallf(type,, "%s",);/* recurse */394 DosError(FERR_ENABLEHARDERR); 395 rc = DosCreateDir(); 396 if (rc == ERROR_INVALID_NAME || rc == ERROR_FILENAME_EXCED_RANGE) { 397 398 /* truncate directory name */ 399 /* create that directory */ 400 /* update containers for name used */ 401 402 } 403 rc = docopyallf(type,, "%s",); /* recurse */ 397 404 } 398 405 else 399 rc = docopyf(type,, "%s",);/* copy file */406 rc = docopyf(type,, "%s",); /* copy file */ 400 407 DosError(FERR_DISABLEHARDERR); 401 408 } while (!rc && !DosFindNext()); … … 434 441 va_end(ap); 435 442 436 if (!oldname || !*oldname || !*fullnewname) 443 if (!oldname || !*oldname || !*fullnewname) /* bad string args */ 437 444 return (APIRET) - 1; 438 445 439 446 DosError(FERR_DISABLEHARDERR); 440 447 if (DosQueryPathInfo(oldname, FIL_STANDARDL, &st, sizeof(FILESTATUS3L))) 441 return (APIRET) - 2; 448 return (APIRET) - 2; /* no source */ 442 449 443 450 AdjustWildcardName(oldname, fullnewname); 444 451 MakeFullName(oldname); 445 452 MakeFullName(fullnewname); 446 olddisk = toupper(*oldname); 447 newdisk = toupper(*fullnewname); 453 olddisk = toupper(*oldname); /* source drive */ 454 newdisk = toupper(*fullnewname); /* destination drive */ 448 455 if (!(driveflags[toupper(*oldname) - 'A'] & DRIVE_NOLONGNAMES)) 449 456 *longname = 0; … … 453 460 p = RootName(longname); 454 461 if (p != longname) 455 462 memmove(longname, p, strlen(p) + 1); 456 463 } 457 464 } … … 473 480 hobjsrc = WinQueryObject(oldname); 474 481 if (hobjsrc) { 475 476 477 478 479 480 481 482 483 484 485 486 487 482 strcpy(dir, fullnewname); 483 p = strrchr(dir, '\\'); 484 if (p < dir + 3) 485 p++; 486 *p = 0; 487 ret = ERROR_PATH_NOT_FOUND; 488 hobjdest = WinQueryObject(dir); 489 if (hobjdest) { 490 ret = ERROR_GEN_FAILURE; 491 hobjsrc = WinMoveObject(hobjsrc, hobjdest, 0); 492 if (hobjsrc) 493 ret = 0; 494 } 488 495 } 489 496 } … … 498 505 hobjsrc = WinQueryObject(oldname); 499 506 if (hobjsrc) { 500 501 502 503 504 505 506 507 508 509 510 511 512 507 strcpy(dir, fullnewname); 508 p = strrchr(dir, '\\'); 509 if (p < dir + 3) 510 p++; 511 *p = 0; 512 ret = ERROR_PATH_NOT_FOUND; 513 hobjdest = WinQueryObject(dir); 514 if (hobjdest) { 515 ret = ERROR_GEN_FAILURE; 516 hobjsrc = WinCopyObject(hobjsrc, hobjdest, 0); 517 if (hobjsrc) 518 ret = 0; 519 } 513 520 } 514 521 } … … 517 524 case MOVE: 518 525 *dir = 0; 519 if (olddisk == newdisk) { 526 if (olddisk == newdisk) { /* same drive */ 520 527 /* make temporary copy in case move fails */ 521 528 if (IsFile(fullnewname) != -1 && stricmp(oldname, fullnewname)) { 522 523 524 525 526 527 528 529 529 strcpy(dir, fullnewname); 530 p = strrchr(dir, '\\'); 531 if (p) 532 *p = 0; 533 strcat(dir, "\\"); 534 MakeTempName(dir, NULL, 0); 535 if (DosMove(fullnewname, dir)) 536 *dir = 0; 530 537 } 531 538 DosError(FERR_DISABLEHARDERR); 532 ret = DosMove(oldname, fullnewname); 533 if (ret && *dir) { 534 535 536 539 ret = DosMove(oldname, fullnewname); /* move it */ 540 if (ret && *dir) { /* failed -- clean up */ 541 DosError(FERR_DISABLEHARDERR); 542 if (!DosMove(dir, fullnewname)) 543 Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(dir), MPVOID); 537 544 } 538 545 else if (!ret && *dir) { 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 } 559 } 560 else { 546 if (!IsFile(dir)) { 547 if (!strchr(dir, '?') && !strchr(dir, '*')) 548 wipeallf("%s\\*", dir); 549 DosError(FERR_DISABLEHARDERR); 550 if (DosDeleteDir(dir)) { 551 make_deleteable(dir); 552 DosDeleteDir(dir); 553 } 554 } 555 else if (IsFile(dir) > 0) { 556 DosError(FERR_DISABLEHARDERR); 557 if (DosForceDelete(dir)) { 558 make_deleteable(dir); 559 DosForceDelete(dir); 560 } 561 if (zaplong) 562 ZapLongName(dir); 563 Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(dir), MPVOID); 564 } 565 } 566 } 567 else { /* different drives */ 561 568 DosError(FERR_DISABLEHARDERR); 562 ret = DosCopy(oldname, fullnewname, DCPY_EXISTING); 569 ret = DosCopy(oldname, fullnewname, DCPY_EXISTING); /* <=-NOTE! */ 563 570 if (ret == ERROR_DISK_CHANGE) { 564 565 566 571 DosError(FERR_ENABLEHARDERR); 572 ret = DosCopy(oldname, fullnewname, DCPY_EXISTING); 573 diskchange = TRUE; 567 574 } 568 575 if (ret == ERROR_INVALID_NAME || ret == ERROR_FILENAME_EXCED_RANGE) { 569 if (TruncName(fullnewname, shortname)) {/* make 8.3 filename */570 571 572 if (!ret) {/* success -- write longname ea */573 574 575 576 577 578 579 576 if (TruncName(fullnewname, shortname)) { /* make 8.3 filename */ 577 DosError(FERR_DISABLEHARDERR); 578 ret = DosCopy(oldname, shortname, DCPY_EXISTING); 579 if (!ret) { /* success -- write longname ea */ 580 WriteLongName(shortname, fullnewname); 581 strcpy(fullnewname, shortname); 582 /* broadcast fixup msg to windows */ 583 Broadcast((HAB) 0, 584 hwndMain, UM_UPDATERECORD, MPFROMP(shortname), MPVOID); 585 } 586 } 580 587 } 581 588 else if (!ret && *longname) { 582 589 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 } 600 if (!ret) { 601 602 603 604 605 606 607 608 609 if (!rc && st2.cbFile == st.cbFile) {/* seems to have worked... */610 611 612 613 DosQueryPathInfo(oldname, FIL_STANDARDL, &dummy, sizeof(FILESTATUS3L));/* force disk change */614 615 if (!(st2.attrFile & FILE_DIRECTORY))/* erase file */616 617 else {/* remove directory */618 619 620 621 622 623 624 625 590 CHAR fixname[CCHMAXPATH]; 591 592 strcpy(fixname, fullnewname); 593 p = strrchr(fixname, '\\'); 594 if (p) { 595 p++; 596 *p = 0; 597 } 598 strcat(fixname, longname); 599 DosError(FERR_DISABLEHARDERR); 600 DosMove(fullnewname, fixname); 601 strcpy(fullnewname, fixname); 602 if (zaplong) 603 ZapLongName(fixname); 604 Broadcast((HAB) 0, 605 hwndMain, UM_UPDATERECORD, MPFROMP(fixname), MPVOID); 606 } 607 if (!ret) { /* double-check success */ 608 DosError(FERR_DISABLEHARDERR); 609 rc = DosQueryPathInfo(fullnewname, 610 FIL_STANDARDL, &st2, sizeof(FILESTATUS3L)); 611 if (rc == ERROR_DISK_CHANGE) { 612 DosError(FERR_ENABLEHARDERR); 613 rc = DosQueryPathInfo(fullnewname, 614 FIL_STANDARDL, &st2, sizeof(FILESTATUS3L)); 615 } 616 if (!rc && st2.cbFile == st.cbFile) { /* seems to have worked... */ 617 DosError(FERR_DISABLEHARDERR); 618 if (diskchange) { 619 DosError(FERR_ENABLEHARDERR); 620 DosQueryPathInfo(oldname, FIL_STANDARDL, &dummy, sizeof(FILESTATUS3L)); /* force disk change */ 621 } 622 if (!(st2.attrFile & FILE_DIRECTORY)) /* erase file */ 623 unlinkf("%s", oldname); 624 else { /* remove directory */ 625 wipeallf("%s\\*", oldname); 626 DosError(FERR_DISABLEHARDERR); 627 if (DosDeleteDir(oldname)) { 628 make_deleteable(oldname); 629 DosDeleteDir(oldname); 630 } 631 } 632 } 626 633 } 627 634 } … … 630 637 case COPY: 631 638 DosError(FERR_DISABLEHARDERR); 632 ret = DosCopy(oldname, fullnewname, DCPY_EXISTING); 639 ret = DosCopy(oldname, fullnewname, DCPY_EXISTING); /* <=-NOTE! */ 633 640 if (ret == ERROR_DISK_CHANGE) { 634 641 DosError(FERR_ENABLEHARDERR); … … 638 645 if (ret == ERROR_INVALID_NAME || ret == ERROR_FILENAME_EXCED_RANGE) { 639 646 if (TruncName(fullnewname, shortname)) { 640 641 642 643 644 645 646 647 647 DosError((diskchange) ? FERR_ENABLEHARDERR : FERR_DISABLEHARDERR); 648 ret = DosCopy(oldname, shortname, DCPY_EXISTING); 649 if (!ret) { 650 WriteLongName(shortname, fullnewname); 651 strcpy(fullnewname, shortname); 652 Broadcast((HAB) 0, 653 hwndMain, UM_UPDATERECORD, MPFROMP(shortname), MPVOID); 654 } 648 655 } 649 656 } … … 655 662 p = strrchr(fixname, '\\'); 656 663 if (p) { 657 658 664 p++; 665 *p = 0; 659 666 } 660 667 strcat(fixname, longname); … … 662 669 DosMove(fullnewname, fixname); 663 670 if (zaplong) 664 671 ZapLongName(fixname); 665 672 Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(fixname), MPVOID); 666 673 } 667 674 return ret; 668 675 669 default: 676 default: /* shouldn't happen */ 670 677 Runtime_Error(pszSrcFile, __LINE__, "bad case %u", type); 671 678 break; 672 679 } 673 return (APIRET) - 3; 680 return (APIRET) - 3; /* bad type */ 674 681 } 675 682 … … 717 724 return -1; 718 725 719 { 726 { /* safety net -- disallow deleting a root dir or partial name */ 720 727 CHAR temp; 721 728 … … 726 733 *p = 0; 727 734 if (IsRoot(str) || !IsFullName(str)) { 728 729 730 731 735 /* under no circumstances! */ 736 Runtime_Error(pszSrcFile, __LINE__, "bad name %s", str); 737 free(str); 738 return -1; 732 739 } 733 740 *p = temp; … … 736 743 737 744 p = s; 738 p = strrchr(s, '\\'); 745 p = strrchr(s, '\\'); /* strip s to just path */ 739 746 if (!p) 740 747 p = strrchr(s, ':'); … … 764 771 DosError(FERR_DISABLEHARDERR); 765 772 if (!DosFindFirst(str, &search_handle, FILE_NORMAL | FILE_DIRECTORY | 766 767 773 FILE_SYSTEM | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED, 774 f, sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD)) { 768 775 769 776 strcpy(ss, s); … … 773 780 strcpy(p, f->achName); 774 781 if (f->attrFile & FILE_DIRECTORY) { 775 776 wipeallf("%s/%s", ss, mask);/* recurse to wipe files */777 778 if (DosDeleteDir(ss)) {/* remove directory */779 780 781 782 783 782 if (strcmp(f->achName, ".") && strcmp(f->achName, "..")) { 783 wipeallf("%s/%s", ss, mask); /* recurse to wipe files */ 784 DosError(FERR_DISABLEHARDERR); 785 if (DosDeleteDir(ss)) { /* remove directory */ 786 make_deleteable(ss); 787 DosError(FERR_DISABLEHARDERR); 788 DosDeleteDir(ss); 789 } 790 } 784 791 } 785 792 else { 786 787 788 789 790 791 792 793 793 DosError(FERR_DISABLEHARDERR); 794 if (DosForceDelete(ss)) { 795 make_deleteable(ss); 796 DosError(FERR_DISABLEHARDERR); 797 rc = (INT) DosForceDelete(ss); 798 if (rc) 799 return rc; 800 } 794 801 } 795 802 num_matches = 1; 796 803 DosError(FERR_DISABLEHARDERR); 797 804 } while (!DosFindNext(search_handle, f, sizeof(FILEFINDBUF3), 798 805 &num_matches)); 799 806 DosFindClose(search_handle); 800 807 } … … 806 813 } 807 814 815 #if 0 // JBS 808 816 INT unlink_allf(CHAR * string, ...) 809 817 { … … 834 842 835 843 p = s; 836 p = strrchr(s, '\\'); 844 p = strrchr(s, '\\'); /* strip s to just path */ 837 845 if (!p) 838 846 p = strrchr(s, ':'); … … 858 866 DosError(FERR_DISABLEHARDERR); 859 867 if (!DosFindFirst(str, &search_handle, FILE_NORMAL, f, 860 868 sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD)) { 861 869 862 870 strcpy(ss, s); … … 869 877 DosError(FERR_DISABLEHARDERR); 870 878 } while (!DosFindNext(search_handle, f, sizeof(FILEFINDBUF3), 871 879 &num_matches)); 872 880 DosFindClose(search_handle); 873 881 } … … 878 886 return 0; 879 887 } 888 #endif 880 889 881 890 INT unlinkf(CHAR * string, ...)
Note:
See TracChangeset
for help on using the changeset viewer.