static char * MakeFolderEnvVar( char * prefixTag, /* Prefix added before result. */ long whichFolder) /* Constant for FSpFindFolder. */ { char * thePath = NULL; char * result = NULL; OSErr theErr = noErr; Handle theString = NULL; FSSpec theFolder; int size; Tcl_DString pathStr; Tcl_DString tagPathStr; Tcl_DStringInit(&pathStr); theErr = FSpFindFolder(kOnSystemDisk, whichFolder, kDontCreateFolder, &theFolder); if (theErr == noErr) { theErr = FSpPathFromLocation(&theFolder, &size, &theString); HLock(theString); tclPlatform = TCL_PLATFORM_MAC; Tcl_DStringAppend(&pathStr, *theString, -1); HUnlock(theString); DisposeHandle(theString); Tcl_DStringInit(&tagPathStr); Tcl_DStringAppend(&tagPathStr, prefixTag, strlen(prefixTag)); Tcl_DStringAppend(&tagPathStr, pathStr.string, pathStr.length); Tcl_DStringFree(&pathStr); /* * Make sure the path ends with a ':' */ if (tagPathStr.string[tagPathStr.length - 1] != ':') { Tcl_DStringAppend(&tagPathStr, ":", 1); } /* * Don't free tagPathStr - rather make sure it's allocated * and return it as the result. */ if (tagPathStr.string == tagPathStr.staticSpace) { result = (char *) ckalloc(tagPathStr.length + 1); strcpy(result, tagPathStr.string); } else { result = tagPathStr.string; } } else { result = (char *) ckalloc(strlen(prefixTag) + 1); strcpy(result, prefixTag); } return result; }
int destroy(char *path) { static char lastpath[NAME_MAX]; static FSSpec trashfolder; static Boolean FirstCall = true; static char Num = 0; static Boolean Immediate_File_Deletion = false; char currpath[NAME_MAX], *envptr; FSSpec fileToDelete; OSErr err; /* init this function */ if ((path == NULL) || (strlen(path) == 0)) { FirstCall = true; Num = 0; return -1; } UserStop(); RfDfFilen2Real(currpath, path, MacZip.MacZipMode, MacZip.DataForkOnly, &MacZip.CurrentFork); GetCompletePath(currpath,currpath,&fileToDelete, &err); if (FirstCall == true) { FirstCall = false; sstrcpy(lastpath,currpath); err = FSpFindFolder(fileToDelete.vRefNum, kTrashFolderType, kDontCreateFolder,&trashfolder); printerr("FSpFindFolder:",err,err,__LINE__,__FILE__,path); envptr = getenv("Immediate_File_Deletion"); if (!(envptr == (char *)NULL || *envptr == '\0')) { if (stricmp(envptr,"yes") == 0) Immediate_File_Deletion = true; else Immediate_File_Deletion = false; } if (Immediate_File_Deletion) { err = FSpDelete(&fileToDelete); return err; } err = CatMove (fileToDelete.vRefNum, fileToDelete.parID, fileToDelete.name, trashfolder.parID, trashfolder.name); return err; } if (strcmp(currpath,lastpath) == 0) { return 0; /* ignore, file is already deleted */ } else { if (Immediate_File_Deletion) { err = FSpDelete(&fileToDelete); sstrcpy(lastpath,path); return err; } err = CatMove (fileToDelete.vRefNum, fileToDelete.parID, fileToDelete.name, trashfolder.parID, trashfolder.name); /* -48 = file is already existing so we have to rename it before moving the file */ if (err == -48) { Num++; if (fileToDelete.name[0] >= 28) /* cut filename if to long */ fileToDelete.name[0] = 28; P2CStr(fileToDelete.name); sprintf(currpath,"%s~%d",(char *)fileToDelete.name,Num); C2PStr(currpath); C2PStr((char *)fileToDelete.name); err = HRename (fileToDelete.vRefNum, fileToDelete.parID, fileToDelete.name, (unsigned char *) currpath); err = CatMove (fileToDelete.vRefNum, fileToDelete.parID, (unsigned char *) currpath, trashfolder.parID, trashfolder.name); } } sstrcpy(lastpath,currpath); return err; }