123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- #include "zip.h"
- #include <string.h>
- #include <fcntl.h>
- #include <unix.h>
- #include <sound.h>
- #include "helpers.h"
- #include "pathname.h"
- #include "macopen.h"
- #include "macstuff.h"
- #ifdef MACZIP
- #include "macglob.h"
- extern char *zipfile;
- extern char *tempzip;
- extern MacZipGlobals MacZip;
- #undef open
- #undef fopen
- FILE *MacFopen(const char *path, const char *mode)
- {
- static char TruncPath[NAME_MAX];
- OSErr err = 0;
- AssertStr(path,path)
-
- if (strcmp(zipfile,path) == 0)
- {
- GetCompletePath(MacZip.ZipFullPath,path,&MacZip.ZipFileSpec,&err);
- err = PrintUserHFSerr((err != -43) && (err != 0), err, path);
- printerr("GetCompletePath:",err,err,__LINE__,__FILE__,path);
- if (CheckMountedVolumes(MacZip.ZipFullPath) > 1)
- DoWarnUserDupVol(MacZip.ZipFullPath);
-
- TruncFilename(TruncPath, MacZip.ZipFullPath);
- return fopen(MacZip.ZipFullPath, mode);
- }
- if (strcmp(tempzip,path) == 0)
- {
- sstrcat(TruncPath,tempzip);
- GetCompletePath(MacZip.TempZipFullPath,TruncPath,&MacZip.TempZipFileSpec,&err);
- err = PrintUserHFSerr((err != -43) && (err != 0), err, path);
- printerr("GetCompletePath:",err,err,__LINE__,__FILE__,path);
- return fopen(MacZip.TempZipFullPath, mode);
- }
- printerr("MacFopen:",err,err,__LINE__,__FILE__,path);
- return NULL;
- }
- int MacOpen(const char *path,int oflag, ...)
- {
- char RealFname[NAME_MAX];
- AssertStr(path,path)
- RfDfFilen2Real(RealFname,path, MacZip.MacZipMode, MacZip.DataForkOnly, &MacZip.CurrentFork);
- switch (MacZip.CurrentFork)
- {
- case DataFork:
- {
- return my_open(RealFname, oflag);
- break;
- }
- case ResourceFork:
- {
- return my_open( RealFname, oflag | O_RSRC);
- break;
- }
- default:
- {
- printerr("open: no resource / datafork ",-1,-1,__LINE__,__FILE__,path);
- return -1;
- }
- }
- }
- #ifdef muell
-
- int destroy(char *path)
- {
- static char lastpath[NAME_MAX];
- char currpath[NAME_MAX];
- static Boolean FirstCall = true;
- long rc;
- AssertStr(path,path)
- RfDfFilen2Real(currpath, path, MacZip.MacZipMode, MacZip.DataForkOnly, &MacZip.CurrentFork);
- if (FirstCall == true)
- {
- FirstCall = false;
- rc = remove(currpath);
- }
- else if (strcmp(currpath,lastpath) == 0) return 0;
- else rc = remove(currpath);
- strcpy(lastpath,currpath);
- return rc;
- }
- #endif
- int replace(char *new_f, char *temp_f)
- {
- OSErr err = 0;
- char newfname[NAME_MAX];
- AssertStr(new_f,new_f)
- AssertStr(temp_f,temp_f)
- UserStop();
- GetFilename(newfname, new_f);
- if ((strcmp(zipfile,new_f) == 0) || (strcmp(tempzip,temp_f) == 0))
- {
- remove(MacZip.ZipFullPath);
-
- err = rename(MacZip.TempZipFullPath,MacZip.ZipFullPath);
- printerr("rename:",err,err,__LINE__,__FILE__,MacZip.TempZipFullPath);
- if (err != 0) return ZE_CREAT;
- else return ZE_OK;
- }
- else return ZE_CREAT;
- }
-
-
- 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;
- 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;
- }
- 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);
-
- if (err == -48)
- {
- Num++;
- if (fileToDelete.name[0] >= 28)
- 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;
- }
- #endif
- int my_open(char *path, int oflag)
- {
- FSSpec spec;
- char permission;
- HParamBlockRec hpb;
- OSErr err, errno;
- Boolean targetIsFolder, wasAliased;
- AssertStr(path,path)
-
- if ((oflag & 0x03) == O_RDWR)
- permission = fsRdWrPerm;
- else
- permission = (oflag & O_RDONLY) ? fsRdPerm : 0 + (oflag & O_WRONLY) ? fsWrPerm : 0;
- FSpLocationFromFullPath(strlen(path),path, &spec);
- if ((oflag & (O_ALIAS | O_NRESOLVE)) == 0)
- ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
- hpb.fileParam.ioNamePtr = spec.name;
- hpb.fileParam.ioVRefNum = spec.vRefNum;
- hpb.fileParam.ioDirID = spec.parID;
- hpb.ioParam.ioPermssn = permission;
- if (oflag & O_RSRC)
- err = PBHOpenRFSync(&hpb);
- else
- err = PBHOpenDFSync(&hpb);
- if ((err == fnfErr) && (oflag & O_CREAT)) {
- hpb.fileParam.ioFlVersNum = 0;
- err = PBHCreateSync(&hpb);
- if (err == noErr) {
-
- unsigned long secs;
- unsigned long isbinary = oflag & O_BINARY;
- hpb.fileParam.ioFlFndrInfo.fdType = '\?\?\?\?';
- hpb.fileParam.ioFlFndrInfo.fdCreator = '\?\?\?\?';
- hpb.fileParam.ioFlFndrInfo.fdFlags = 0;
- if (oflag & O_ALIAS)
- hpb.fileParam.ioFlFndrInfo.fdFlags = kIsAlias;
- else
- hpb.fileParam.ioFlFndrInfo.fdFlags = 0;
- GetDateTime(&secs);
- hpb.fileParam.ioFlCrDat = hpb.fileParam.ioFlMdDat = secs;
- PBHSetFInfoSync(&hpb);
- }
- if (err && (err != dupFNErr)) {
- errno = err; return -1;
- }
- if (oflag & O_RSRC)
- err = PBHOpenRFSync(&hpb);
- else
- err = PBHOpenDFSync(&hpb);
- }
- if (err && (err != dupFNErr) && (err != opWrErr)) {
- errno = err; return -1;
- }
- if (oflag & O_TRUNC) {
- IOParam pb;
- pb.ioRefNum = hpb.ioParam.ioRefNum;
- pb.ioMisc = 0L;
- err = PBSetEOFSync((ParmBlkPtr)&pb);
- if (err != noErr) {
- errno = err; return -1;
- }
- }
- if (oflag & O_APPEND) lseek(hpb.ioParam.ioRefNum,0,SEEK_END);
- return (hpb.ioParam.ioRefNum);
- }
|