home *** CD-ROM | disk | FTP | other *** search
- #include "headers.h"
- #include "Util.h"
-
- Handle FileURLFromFileSpec (FSSpec* FileSpec)
- {
- CInfoPBRec myPB; // parameter block for PBGetCatInfo
- Str255 dirName; // a directory name
- OSErr myErr;
- Int32 NameLen = 0;
- Int32 PathLen = 256;
- Handle tempPathHdl = NewHandleClear(256);
- char* tempPath;
- char FileURL[16] = "file:///";
- Int16 move;
-
- if(tempPathHdl == NULL)
- return NULL;
-
- HLock(tempPathHdl);
- tempPath = *tempPathHdl;
-
- tempPath[0] = 0; // initialize full pathname}
- myPB.hFileInfo.ioNamePtr = &dirName[0];
- myPB.hFileInfo.ioVRefNum = FileSpec->vRefNum; // indicate target volume
- myPB.dirInfo.ioDrParID = FileSpec->parID; // initialize parent directory ID
- myPB.dirInfo.ioFDirIndex = -1; // get info about a directory
-
- p2cstr(FileSpec->name);
- strcat(tempPath, (char*)FileSpec->name);
- c2pstr((char*)FileSpec->name);
- NameLen = strlen(tempPath);
- // Get name of each parent directory, up to root directory.
- do
- {
- myPB.dirInfo.ioDrDirID = myPB.dirInfo.ioDrParID;
- myErr = PBGetCatInfoSync(&myPB);
- p2cstr(dirName);
-
- // make sur string is long enough
- while((strlen((char*)dirName) + NameLen) > (PathLen + 2)) // room for name, colon and termintating 0
- {
- PathLen += 256;
- HUnlock(tempPathHdl);
- SetHandleSize(tempPathHdl, PathLen);
- if(tempPathHdl == NULL)
- return NULL;
-
- HLock(tempPathHdl);
- tempPath = *tempPathHdl;
-
- }
- move = strlen((char*)dirName) + 1;
-
- // move existing string to make room for new folder name and ":"
- BlockMove(tempPath, (char*)&tempPath[move], NameLen);
- strcat((char*)dirName, "/");
- move = strlen((char*)dirName);
- BlockMove(dirName, tempPath, move);
- NameLen += strlen((char*)dirName);
- }
- while( myPB.dirInfo.ioDrDirID != fsRtDirID);
-
- // add the file URL prefix
- move = strlen((char*) FileURL);
-
- if ( (NameLen + move) > GetHandleSize(tempPathHdl) )
- {
- HUnlock(tempPathHdl);
- SetHandleSize(tempPathHdl, GetHandleSize(tempPathHdl) + 256);
- if(tempPathHdl == NULL)
- return NULL;
- HLock(tempPathHdl);
- tempPath = *tempPathHdl;
- }
-
- // move existing string to make room for new folder name and ":"
- BlockMove(tempPath, (char*)&tempPath[move], NameLen);
- BlockMove(FileURL, tempPath, move);
-
- HUnlock(tempPathHdl);
-
- return tempPathHdl;
- }
-