123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- #include <Types.h>
- #include <Errors.h>
- #include <Files.h>
- #include <stdio.h>
- #include <string.h>
- #include "zip.h"
- #include "macstuff.h"
- #include "helpers.h"
- #include "recurse.h"
- #include "macglob.h"
- #include "pathname.h"
- struct RecurseGlobals
- {
- short vRefNum;
- CInfoPBRec cPB;
- unsigned char *itemName;
- char *FullPath;
- short FullPathLen;
- OSErr result;
- Boolean quitFlag;
- unsigned short maxLevels;
- unsigned short currentLevel;
- };
- typedef struct RecurseGlobals RecurseGlobals;
- typedef RecurseGlobals *RecurseGlobalsPtr;
- extern MacZipGlobals MacZip;
- extern const char ResourceMark[13];
- extern int extra_fields;
- static RecurseGlobals theGlobals;
- static unsigned long DirLevels = 0;
- static char *buffer;
- extern int verbose;
- int procname(char *filename, int caseflag);
- int MatchWild( char *pPat, char *pStr, int case_sens);
- Boolean IsZipFile(char *name);
- static void RecurseDirectoryLevel(long DirID, RecurseGlobals *Globals);
- static Boolean isRegularItem( RecurseGlobals *Globals);
- static void ProcessFiles(RecurseGlobals *Globals,
- Boolean hasDataFork, Boolean hasResourceFork);
- static void ProcessDirectory(RecurseGlobals *Globals,
- Boolean IncludeItem, long DirID);
- static void ProcessItem(RecurseGlobals *Globals, long DirID);
- static void RecurseDirectoryLevel(long DirID, RecurseGlobals *Globals)
- {
- char buffer2[23];
-
- if ( (Globals->maxLevels == 0) ||
-
- (Globals->currentLevel < Globals->maxLevels) )
- {
- short index = 1;
- ++Globals->currentLevel;
- if (DirLevels < Globals->currentLevel) DirLevels = Globals->currentLevel;
- sprintf(buffer2,"Globals->currentLevel: %d",Globals->currentLevel);
- do
- {
-
- Globals->cPB.dirInfo.ioFDirIndex = index;
- Globals->cPB.dirInfo.ioDrDirID = DirID;
- Globals->result = PBGetCatInfoSync((CInfoPBPtr)&Globals->cPB);
- ShowCounter(false);
- if ( Globals->result == noErr )
- {
- ProcessItem(Globals, DirID);
- }
- ++index;
-
- } while ( (Globals->result == noErr) && (!Globals->quitFlag) );
- if ( (Globals->result == fnfErr) ||
- (Globals->result == afpAccessDenied) )
- {
- Globals->result = noErr;
- }
- --Globals->currentLevel;
- }
- }
- pascal OSErr RecurseDirectory(short vRefNum,
- long thedirID,
- ConstStr255Param name,
- unsigned short maxLevels)
- {
- OSErr result;
- short theVRefNum;
- Boolean isDirectory;
- long DirID;
-
- result = GetDirectoryID(vRefNum, thedirID, name, &DirID, &isDirectory);
- if ( result == noErr )
- {
- if ( isDirectory == true )
- {
-
- result = DetermineVRefNum(name, vRefNum, &theVRefNum);
- if ( result == noErr )
- {
-
- theGlobals.cPB.hFileInfo.ioNamePtr = theGlobals.itemName;
- theGlobals.cPB.hFileInfo.ioVRefNum = theVRefNum;
- theGlobals.itemName[0] = 0;
- theGlobals.result = noErr;
- theGlobals.quitFlag = false;
- theGlobals.maxLevels = maxLevels;
- theGlobals.currentLevel = 0;
-
- RecurseDirectoryLevel(DirID, &theGlobals);
- result = theGlobals.result;
- }
- }
- else
- {
- result = dirNFErr;
- }
- }
- return ( result );
- }
- pascal OSErr FSpRecurseDirectory(const FSSpec *spec,
- unsigned short maxLevels)
- {
- OSErr rc;
- theGlobals.vRefNum = spec->vRefNum;
-
- theGlobals.itemName = (unsigned char *) StrCalloc(NAME_MAX);
- theGlobals.FullPath = StrCalloc(NAME_MAX);
- buffer = StrCalloc(NAME_MAX);
- if ((noisy) && (MacZip.DataForkOnly))
- printf("\n Warning: Datafork only \n");
-
- ShowCounter(true);
- if (noisy) leftStatusString("Build File List; Items done:");
- if (noisy) printf("\n Collecting Filenames ...");
- rc = RecurseDirectory(spec->vRefNum, spec->parID, spec->name,maxLevels);
- printerr("RecurseDirectory:",rc,rc,__LINE__,__FILE__,"");
- if (noisy) printf("\n... done \n\n %6d matched files found \n",
- MacZip.FoundFiles);
- if (noisy) printf(" %6d folders found in %d Levels \n",
- MacZip.FoundDirectories,DirLevels);
- if (MacZip.BytesOfData > (1024*1024))
- if (noisy) printf(" %4.3f MBytes unzipped size\n\n",
- (float) MacZip.BytesOfData/(1024*1024));
- else
- if (noisy) printf(" %4.3f KBytes unzipped size\n\n",
- (float) MacZip.BytesOfData/1024);
-
- theGlobals.itemName = (unsigned char *) StrFree((char *)theGlobals.itemName);
- theGlobals.FullPath = StrFree(theGlobals.FullPath);
- buffer = StrFree(buffer);
- return rc;
- }
- Boolean IsZipFile(char *filen)
- {
- static firstMatch = false;
- if (filen == NULL)
- firstMatch = false;
- if (!firstMatch)
- {
- if (stricmp(filen, MacZip.ZipFullPath) == 0)
- {
- firstMatch = true;
- return true;
- }
- }
- return false;
- }
- static Boolean isRegularItem( RecurseGlobals *Globals)
- {
- Boolean isInvisible = false,
- isAlias = false,
- isSystem = false;
- isSystem = !((Globals->cPB.hFileInfo.ioFlFndrInfo.fdFlags &
- (1 << 12)) == 0 );
- isInvisible = !((Globals->cPB.hFileInfo.ioFlFndrInfo.fdFlags &
- (1 << 14)) == 0 );
- isAlias = !((Globals->cPB.hFileInfo.ioFlFndrInfo.fdFlags &
- (1 << 15)) == 0);
- if (isAlias == true)
- {
- return false;
- }
- if (MacZip.IncludeInvisible == true)
- {
- return true;
- }
- if ((isSystem == true) ||
- (isInvisible == true))
- {
- return false;
- }
- return true;
- }
- static void ProcessFiles(RecurseGlobals *Globals,
- Boolean hasDataFork, Boolean hasResourceFork)
- {
-
- MacZip.FoundFiles++;
- if (hasDataFork == true)
- {
- MacZip.BytesOfData =
- Globals->cPB.hFileInfo.ioFlLgLen +
- MacZip.BytesOfData;
- MacZip.CurrentFork = DataFork;
- MacZip.RawCountOfItems++;
- if (MacZip.DataForkOnly == true)
- {
- procname(Globals->FullPath, false);
- hasResourceFork = false;
- }
- else
- {
- procname(Real2RfDfFilen(buffer,Globals->FullPath,
- DataFork, MacZip.MacZipMode,
- MacZip.DataForkOnly), false);
- }
- }
- if (hasResourceFork == true)
- {
- MacZip.BytesOfData =
- Globals->cPB.hFileInfo.ioFlRLgLen +
- MacZip.BytesOfData;
- MacZip.CurrentFork = ResourceFork;
- MacZip.RawCountOfItems++;
- procname(Real2RfDfFilen(buffer, Globals->FullPath,
- ResourceFork, MacZip.MacZipMode,
- MacZip.DataForkOnly), false);
- }
- }
- static void ProcessDirectory(RecurseGlobals *Globals,
- Boolean IncludeItem, long DirID)
- {
- OSErr rc;
- MacZip.isDirectory = true;
- GetFullPathFromID(Globals->FullPath,Globals->vRefNum, DirID,
- Globals->itemName, &rc);
- MacZip.RawCountOfItems++;
- MacZip.FoundDirectories++;
- if (MacZip.StoreFoldersAlso)
- {
- procname(Globals->FullPath, false);
- }
-
- if ( !Globals->quitFlag && IncludeItem)
- {
-
- RecurseDirectoryLevel(Globals->cPB.dirInfo.ioDrDirID,
- Globals);
- }
- }
- static void ProcessItem(RecurseGlobals *Globals, long DirID)
- {
- OSErr rc;
- Boolean IncludeItem = false, hasDataFork = false;
- Boolean hasResourceFork = false;
- IncludeItem = isRegularItem(Globals);
- if ( (Globals->cPB.hFileInfo.ioFlAttrib & ioDirMask) == 0 )
- {
- PToCCpy(Globals->itemName,MacZip.FileName);
- MacZip.isDirectory = false;
- hasDataFork = (Globals->cPB.hFileInfo.ioFlLgLen != 0);
- hasResourceFork = (Globals->cPB.hFileInfo.ioFlRLgLen != 0);
-
- if ((hasDataFork == 0) && (hasResourceFork == 0))
- hasDataFork = true;
- if ((hasDataFork == 0) &&
- (hasResourceFork != 0) &&
- (extra_fields == false))
- {
- IncludeItem = false;
- }
- GetFullPathFromID(Globals->FullPath,Globals->vRefNum,
- DirID, Globals->itemName, &rc);
- printerr("GetFullPathFromID:",rc,rc,__LINE__,
- __FILE__,MacZip.FileName);
- if (IncludeItem &&
- (!IsZipFile(Globals->FullPath)) )
- {
- if (MATCH(MacZip.Pattern, MacZip.FileName, false) == true)
- {
- ProcessFiles(Globals, hasDataFork, hasResourceFork);
- }
- }
- }
- if ( (Globals->cPB.hFileInfo.ioFlAttrib & ioDirMask) != 0 )
- {
- ProcessDirectory(Globals,IncludeItem, DirID);
- }
- }
|