void LoadImportPLUG( MADLibrary *inMADDriver, short No, FSSpec *theSpec) { Handle theRes; short fileID; Str255 tStr; inMADDriver->ThePlug[ No].file = *theSpec; { Boolean targetIsFolder, wasAliased; ResolveAliasFile( &inMADDriver->ThePlug[ No].file, true, &targetIsFolder, &wasAliased); } pStrCpy( inMADDriver->ThePlug[ No].filename, inMADDriver->ThePlug[ No].file.name); fileID = FSpOpenResFile( theSpec, fsCurPerm); /** CODE du Plug-in **/ GetIndString( tStr, 1000, 1); BlockMoveData( tStr + 1, &inMADDriver->ThePlug[ No].type, 4); inMADDriver->ThePlug[ No].type[ 4] = 0; GetIndString( tStr, 1000, 2); BlockMoveData( tStr + 1, &inMADDriver->ThePlug[ No].mode, 4); GetIndString( inMADDriver->ThePlug[ No].MenuName, 1000, 3); GetIndString( inMADDriver->ThePlug[ No].AuthorString, 1000, 4); CloseResFile( fileID); }
/* * We don't bother with the usual FSpExchangeFiles dance here because * it doesn't really matter if the old random seed gets lost. */ void write_random_seed(void *data, int len) { short puttyVRefNum; long puttyDirID; OSErr error; FSSpec dstfile; short refnum; long count = len; if (get_putty_dir(kCreateFolder, &puttyVRefNum, &puttyDirID) != noErr) return; error = FSMakeFSSpec(puttyVRefNum, puttyDirID, "\pPuTTY Random Seed", &dstfile); if (error == fnfErr) { /* Set up standard resources */ FSpCreateResFile(&dstfile, INTERNAL_CREATOR, SEED_TYPE, smRoman); refnum = FSpOpenResFile(&dstfile, fsWrPerm); if (ResError() == noErr) { copy_resource('STR ', -16397); CloseResFile(refnum); } } else if (error != noErr) return; if (FSpOpenDF(&dstfile, fsWrPerm, &refnum) != noErr) return; FSWrite(refnum, &count, data); FSClose(refnum); return; }
OSErr GetToolname(char* toolName) { OSErr error = noErr; FSSpec where; short ref; Handle theString; toolName[0] = '\0'; // Start without a name error = FindPrefs(&where); ref = FSpOpenResFile(&where, fsRdWrPerm); if (ref != -1) { theString = Get1Resource('STR ',kToolNameRes); // Should look in most recent file first if (theString != nil) { HLock(theString); memcpy(toolName, *theString, (*theString)[0] + 1); HUnlock(theString); ReleaseResource(theString); } else { error = -5; } CloseResFile(ref); if (error == noErr) { // CTB is touchy; make sure this tool exists error = VerifyToolExists(toolName); } } else { error = ResError(); } return error; }
OSErr GetConfig(Ptr config) { OSErr error = noErr; FSSpec where; short ref; Handle theString; Ptr temp = nil; long len; config[0] = '\0'; // Start without a name error = FindPrefs(&where); ref = FSpOpenResFile(&where, fsRdWrPerm); if (ref != -1) { theString = Get1Resource('STR ',kConfigRes); // Should look in most recent file first if (theString != nil) { len = SizeResource(theString); SetPtrSize(config, len); // Set the size error = MemError(); // And make sure it worked if (error == noErr) { HLock(theString); temp = (Ptr)*theString; memcpy(config, temp, len); HUnlock(theString); ReleaseResource(theString); } } else { error = -4; } CloseResFile(ref); } else { error = ResError(); } return error; }
/*----------------------------------------------------------------- GetNamedFragmentOffsets Get the offsets into the data fork of the named fragment, by reading the 'cfrg' resoruce. -----------------------------------------------------------------*/ OSErr GetNamedFragmentOffsets(const FSSpec *fileSpec, const char* fragmentName, UInt32 *outOffset, UInt32 *outLength) { CFragResourceHandle cFragHandle; short fileRefNum; OSErr err = noErr; fileRefNum = FSpOpenResFile(fileSpec, fsRdPerm); err = ResError(); if (err != noErr) return err; cFragHandle = (CFragResourceHandle)Get1Resource(kCFragResourceType, kCFragResourceID); if (!cFragHandle) { err = resNotFound; goto done; } /* nothing here moves memory, so no need to lock the handle */ err = cfragNoLibraryErr; /* in case of failure */ *outOffset = 0; *outLength = 0; /* Now look for the named fragment */ if ((**cFragHandle).memberCount > 0) { CFragResourceMemberPtr memberPtr; UInt16 i; for ( i = 0, memberPtr = &(**cFragHandle).firstMember; i < (**cFragHandle).memberCount; i ++, memberPtr = (CFragResourceMemberPtr)((char *)memberPtr + memberPtr->memberSize)) { char memberName[256]; UInt16 nameLen = PR_MIN(memberPtr->name[0], 255); // avoid malloc here for speed strncpy(memberName, (char *)&memberPtr->name[1], nameLen); memberName[nameLen] = '\0'; // fragment names are case insensitive, so act like the system if (PL_strcasecmp(memberName, fragmentName) == 0) { *outOffset = memberPtr->offset; *outLength = memberPtr->length; err = noErr; break; } } } /* Resource handle will go away when the res fork is closed */ done: CloseResFile(fileRefNum); return err; }
static CWResult LinkHeaders(CWPluginContext context, XPIDLSettings& settings) { // find out how many files there are to link. long fileCount = 0; CWResult err = CWGetProjectFileCount(context, &fileCount); if (err != cwNoErr || fileCount == 0) return err; // get the output directory. FSSpec outputDir; err = CWGetOutputFileDirectory(context, &outputDir); if (!CWSUCCESS(err)) return err; // enumerate all of the output header files, and make aliases to them in // the output directory. for (long index = 0; (err == cwNoErr) && (index < fileCount); index++) { // get the name of each output file. CWFileSpec outputFile; err = CWGetStoredObjectFileSpec(context, index, &outputFile); if (err == cwNoErr) { FInfo info; err = FSpGetFInfo(&outputFile, &info); FSSpec aliasFile = { outputDir.vRefNum, outputDir.parID }; BlockMoveData(outputFile.name, aliasFile.name, 1 + outputFile.name[0]); AliasHandle alias = NULL; if (NewAliasMinimal(&outputFile, &alias) == noErr) { // recreate the alias file from scratch. FSpDelete(&aliasFile); FSpCreateResFile(&aliasFile, info.fdCreator, info.fdType, smRoman); short refNum = FSpOpenResFile(&aliasFile, fsRdWrPerm); if (refNum != -1) { UseResFile(refNum); AddResource(Handle(alias), rAliasType, 0, aliasFile.name); ReleaseResource(Handle(alias)); UpdateResFile(refNum); CloseResFile(refNum); } // finally, mark the newly created file as an alias file. FSpGetFInfo(&aliasFile, &info); info.fdFlags |= kIsAlias; FSpSetFInfo(&aliasFile, &info); } } } // create the target file in the output directory. BlockMoveData(settings.output, outputDir.name, 1 + settings.output[0]); FILE* outputFile = FSp_fopen(&outputDir, "w"); if (outputFile != NULL) fclose(outputFile); return err; }
SetupLibraryState::SetupLibraryState() { // Open our resurce fork from the shared library if (mLibraryResFile == -1) { bWasOpen = false; mLibraryResFile = FSpOpenResFile(&gFSSpec, fsRdPerm); } else bWasOpen = true; }
static OSErr OpenLibraryResource( struct CFragInitBlock* initBlkPtr) { /* * The 3.0 version of the Universal headers changed CFragInitBlock * to an opaque pointer type. CFragSystem7InitBlock is now the * real pointer. */ #if !defined(UNIVERSAL_INTERFACES_VERSION) || (UNIVERSAL_INTERFACES_VERSION < 0x0300) struct CFragInitBlock *realInitBlkPtr = initBlkPtr; #else CFragSystem7InitBlock *realInitBlkPtr = (CFragSystem7InitBlock *) initBlkPtr; #endif FSSpec* fileSpec = NULL; OSErr err = noErr; if (realInitBlkPtr->fragLocator.where == kDataForkCFragLocator) { fileSpec = realInitBlkPtr->fragLocator.u.onDisk.fileSpec; } else if (realInitBlkPtr->fragLocator.where == kResourceCFragLocator) { fileSpec = realInitBlkPtr->fragLocator.u.inSegs.fileSpec; } else { err = resFNotFound; } /* * Open the resource fork for this library in read-only mode. * This will make it the current res file, ahead of the * application's own resources. */ if (fileSpec != NULL) { ourResFile = FSpOpenResFile(fileSpec, fsRdPerm); if (ourResFile == kResFileNotOpened) { err = ResError(); } else { #ifdef TCL_REGISTER_LIBRARY ourResToken = Tcl_NewObj(); Tcl_IncrRefCount(ourResToken); p2cstr(realInitBlkPtr->libName); Tcl_SetStringObj(ourResToken, (char *) realInitBlkPtr->libName, -1); c2pstr((char *) realInitBlkPtr->libName); TclMacRegisterResourceFork(ourResFile, ourResToken, TCL_RESOURCE_DONT_CLOSE); #endif SetResFileAttrs(ourResFile, mapReadOnly); } } return err; }
void dump_colors( struct rgb_color_value *colors, short color_count) { CTabHandle new_table; Handle old_bad_clut; struct rgb_color_value *color; short loop; FSSpec file; short refnum; file.vRefNum= -1; file.parID= 2; strcpy((char *)file.name, (const char *)"\pMarathon2 Clut\0"); FSpCreateResFile(&file, 'RSED', 'rsrc', smSystemScript); refnum= FSpOpenResFile(&file, fsWrPerm); if(refnum>=0) { new_table= (CTabHandle) NewHandleClear(sizeof(ColorTable)+color_count*sizeof(ColorSpec)); HLock((Handle) new_table); (*new_table)->ctSeed= GetCTSeed(); (*new_table)->ctFlags= 0; (*new_table)->ctSize= color_count-1; /* Slam the colors.. */ color= colors; for(loop=0; loop<=color_count; ++loop) { (*new_table)->ctTable[loop].rgb.red= color->red; (*new_table)->ctTable[loop].rgb.green= color->green; (*new_table)->ctTable[loop].rgb.blue= color->blue; (*new_table)->ctTable[loop].value= loop; color++; } HUnlock((Handle) new_table); old_bad_clut= GetResource('clut', 5454); if (old_bad_clut) { RmveResource((Handle) old_bad_clut); DisposeHandle((Handle) old_bad_clut); UpdateResFile(CurResFile()); } AddResource((Handle) new_table, 'clut', 5454, "\pMarathon2 Color Table"); if(ResError()) dprintf("Err adding it: %d", ResError()); WriteResource((Handle) new_table); ReleaseResource((Handle) new_table); CloseResFile(refnum); }
pascal short FSpOpenResFileCompat(const FSSpec *spec, SignedByte permission) { #if !__MACOSSEVENORLATER if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() ) { return ( HOpenResFile(spec->vRefNum, spec->parID, spec->name, permission) ); } else #endif /* !__MACOSSEVENORLATER */ { return ( FSpOpenResFile(spec, permission) ); } }
void *open_settings_r_fsp(FSSpec *sessfile) { OSErr error; int fd; int *handle; fd = FSpOpenResFile(sessfile, fsRdPerm); if (fd == 0) {error = ResError(); goto out;} handle = snew(int); *handle = fd; return handle; out: return NULL; }
OSErr PAS_encodeResource(FSSpec *inFile, short outRefNum) { OSErr err; short inRefNum; PASResFork resInfo; SInt32 currentWrite; ResType *resTypes; long typeCount; short *ids; long idCount; short oldResFile; oldResFile=CurResFile(); inRefNum = FSpOpenResFile(inFile, fsRdPerm); if (inRefNum < noErr) return inRefNum; UseResFile(inRefNum); memset(&resInfo, 0, sizeof(PASResFork)); PAS_sortTypes(inRefNum, &resTypes, &typeCount); resInfo.NumberOfTypes = typeCount; currentWrite = sizeof(PASResFork); err = FSWrite(outRefNum, ¤tWrite, &resInfo); if (err != noErr) return err; for (typeCount = 0; ((typeCount < resInfo.NumberOfTypes) && (err == noErr)); typeCount++) { PAS_sortIDs(inRefNum, resTypes[typeCount], &ids, &idCount); err = PAS_flattenResource(resTypes[typeCount], ids, idCount, inRefNum, outRefNum); DisposePtr((Ptr)ids); } DisposePtr((Ptr)resTypes); UseResFile(oldResFile); CloseResFile(inRefNum); return err; }
static Boolean LibInPefContainer(const FSSpec* inSpec, StringPtr inName, UInt32* outCodeOffset, UInt32* outCodeLength) { short refNum; CFragResourceHandle hCfrg; CFragResourceMember* pCurItem; UInt32 curLibIndex; Boolean found; // asume we didn't find it found = false; // open the resource fork, if we can't bail refNum = FSpOpenResFile(inSpec, fsRdPerm); require(-1 != refNum, Exit); // grab out the alias record, if it's not there bail hCfrg = (CFragResourceHandle) Get1Resource(kCFragResourceType, kCFragResourceID); require(NULL != hCfrg, CloseResourceAndExit); HLock((Handle)hCfrg); // get ptr to first item pCurItem = &(*hCfrg)->firstMember; for (curLibIndex = 0; curLibIndex < (*hCfrg)->memberCount; curLibIndex++) { // is this our library? if ((pCurItem->name[0] == inName[0]) && (strncmp((char*) inName + 1, (char*) pCurItem->name + 1, PR_MIN(pCurItem->name[0], inName[0])) == 0)) { *outCodeOffset = pCurItem->offset; *outCodeLength = pCurItem->length; found = true; } // skip to next one pCurItem = (CFragResourceMember*) ((char*) pCurItem + pCurItem->memberSize); } HUnlock((Handle)hCfrg); CloseResourceAndExit: CloseResFile(refNum); Exit: return (found); }
OSErr PAS_encodeMisc(FSSpec *inFile, short outRefNum) { OSErr err; short inRefNum; PASMiscInfo infoBlock; FInfo fInfo; SInt32 currentRead; err = FSpOpenDF(inFile, fsRdPerm, &inRefNum); if (err != noErr) return err; memset(&infoBlock, 0, sizeof(PASMiscInfo)); err = FSpGetFInfo(inFile, &fInfo); if (err != noErr) return err; infoBlock.fileType = fInfo.fdType; infoBlock.fileCreator = fInfo.fdCreator; infoBlock.fileFlags = fInfo.fdFlags; FSClose(inRefNum); inRefNum = FSpOpenResFile(inFile, fsRdPerm); if (inRefNum > noErr) { infoBlock.fileHasResFork = 1; infoBlock.fileResAttrs = GetResFileAttrs(inRefNum); FSClose(inRefNum); } else { infoBlock.fileHasResFork = 0; infoBlock.fileResAttrs = 0; } currentRead = sizeof(PASMiscInfo); err = FSWrite(outRefNum, ¤tRead, &infoBlock); if (err != noErr) return err; CloseResFile(inRefNum); return noErr; }
OSErr CallImportPlug( MADLibrary *inMADDriver, short PlugNo, // CODE du plug OSType order, char *AlienFile, MADMusic *theNewMAD, PPInfoRec *info) { OSErr myErr; short fileID = 0; MADDriverSettings driverSettings; CFragConnectionID connID; Ptr mainAddr; Str255 errName; static OSErr (*mainPLUG)( OSType, char*, MADMusic*, PPInfoRec*, MADDriverSettings *); driverSettings.sysMemory = false; if( !EqualString( RSRCNAME, inMADDriver->ThePlug[ PlugNo].file.name, false, false)) { fileID = FSpOpenResFile( &inMADDriver->ThePlug[ PlugNo].file, fsCurPerm); UseResFile( fileID); } myErr = GetDiskFragment( &inMADDriver->ThePlug[ PlugNo].file, 0, kCFragGoesToEOF, inMADDriver->ThePlug[ PlugNo].file.name, kLoadCFrag, &connID, (Ptr *) &mainPLUG, errName); if( myErr == noErr) { myErr = mainPLUG ( order, AlienFile, theNewMAD, info, &driverSettings); // DisposePtr( (Ptr) mainPLUG); CloseConnection( &connID); } // myErr = TESTmain( order, AlienFile, theNewMAD, info, &driverSettings); if( !EqualString( RSRCNAME, inMADDriver->ThePlug[ PlugNo].file.name, false, false)) CloseResFile( fileID); // theNewMAD->currentDriver = NULL; return( myErr); }
/* time to actually transfer the data. */ int gp_read_macresource(byte *buf, const char *fname, const uint type, const ushort id) { Handle resource = NULL; SInt32 size = 0; FSSpec spec; SInt16 fileref; OSErr result; /* open file */ result = convertPathToSpec(fname, strlen(fname), &spec); if (result != noErr) goto fin; fileref = FSpOpenResFile(&spec, fsRdPerm); if (fileref == -1) goto fin; if_debug1('s', "[s] loading resource from fileref %d\n", fileref); /* load resource */ resource = Get1Resource((ResType)type, (SInt16)id); if (resource == NULL) goto fin; /* allocate res */ /* GetResourceSize() is probably good enough */ //size = GetResourceSizeOnDisk(resource); size = GetMaxResourceSize(resource); if_debug1('s', "[s] resource size on disk is %d bytes\n", size); /* if we don't have a buffer to fill, just return */ if (buf == NULL) goto fin; /* otherwise, copy resource into res from handle */ HLock(resource); memcpy(buf, *resource, size); HUnlock(resource); fin: /* free resource, if necessary */ ReleaseResource(resource); CloseResFile(fileref); return (size); }
void add_finishing_touches_to_save_file(FileSpecifier &File) // FileDesc *file) { short refnum; unsigned char name[64+1]; OSErr err; FSSpec *SpecPtr = &File.GetSpec(); FInfo finder_info; err = FSpGetFInfo((FSSpec *)SpecPtr, &finder_info); if (err != noErr) return; FSpCreateResFile(SpecPtr, finder_info.fdCreator, finder_info.fdType, smSystemScript); if (ResError() != noErr) return; /* Save the STR resource that tells us what our application name is. */ refnum= FSpOpenResFile(&File.GetSpec(), fsWrPerm); // resource_file_ref= FSpOpenResFile((FSSpec *) file, fsWrPerm); if (refnum < 0) return; Handle resource; /* Add in the overhead thumbnail. */ add_overhead_thumbnail(File); /* Add the application name resource.. */ getpstr(name, strFILENAMES, filenameMARATHON_NAME); // add_application_name_to_fsspec((FileDesc *) file, name); // LP: copied out of files_macintosh.c -- add_application_name_to_fsspec(); // this is the only place that uses this code /* Add in the application name */ err= PtrToHand(name, &resource, name[0]+1); assert(!err && resource); AddResource(resource, 'STR ', -16396, "\p"); ReleaseResource(resource); CloseResFile(refnum); // End copying }
/* ファイルのアイコンをチェック */ OSErr FileIconCheck(const FSSpec *theIconFile,short *alertMode) { OSErr err; short refNum; IconFamilyHandle iconFamily; refNum=FSpOpenResFile(theIconFile,fsRdWrPerm); if (refNum <=0) /* 開けない場合は追加確認 */ { if ((err=ResError())==eofErr) { *alertMode = kAddResourceForkMode; return noErr; } return err; } /* 'icns'リソースを探す */ UseResFile(refNum); iconFamily=(IconFamilyHandle)Get1Resource(kXIconFileType,kCustomIconResource); if (iconFamily==nil) /* 'icns'リソースがない場合は問題なし */ { CloseResFile(refNum); UseResFile(gApplRefNum); return noErr; } if (!isIconServicesAvailable) { ReleaseResource((Handle)iconFamily); *alertMode = kDeleteIconFamilyMode; } else if (!IsEditableIconFamily(iconFamily)) *alertMode = kDeleteIconMode; CloseResFile(refNum); UseResFile(gApplRefNum); return noErr; }
static OSErr FT_FSPathMakeRes( const UInt8* pathname, ResFileRefNum* res ) { #if HAVE_FSREF OSErr err; FSRef ref; if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) ) return FT_THROW( Cannot_Open_Resource ); /* at present, no support for dfont format */ err = FSOpenResourceFile( &ref, 0, NULL, fsRdPerm, res ); if ( noErr == err ) return err; /* fallback to original resource-fork font */ *res = FSOpenResFile( &ref, fsRdPerm ); err = ResError(); #else OSErr err; FSSpec spec; if ( noErr != FT_FSPathMakeSpec( pathname, &spec, FALSE ) ) return FT_THROW( Cannot_Open_Resource ); /* at present, no support for dfont format without FSRef */ /* (see above), try original resource-fork font */ *res = FSpOpenResFile( &spec, fsRdPerm ); err = ResError(); #endif /* HAVE_FSREF */ return err; }
/****************************************************************************** Given an FSSpec to a file, open it with write permission. Check to make sure that the file reference returned actually has write permission and return an error if it doesn't. pFSSpec input: The file to be opened. pRefNum output: File reference for the newly opened file. RESULT CODES ____________ Same as results for FSpOpenResFile() ____________ */ pascal OSErr MoreResOpenResFileForWrite(const FSSpec *pFSSpec, SInt16 *pRefNum) { OSErr anErr = noErr; *pRefNum = FSpOpenResFile( pFSSpec, fsRdWrPerm ); if ( *pRefNum == -1 ) { anErr = ResError(); } else // Got it open, but can it be written to? { if ( ! MoreResIsResFileRefNumWritable( *pRefNum ) ) { anErr = permErr; CloseResFile( *pRefNum ); *pRefNum = -1; } } return anErr; }//end MoreResOpenResFileForWrite
/* Create a new FT_Face from a file spec to a suitcase file. */ static FT_Error FT_New_Face_From_Suitcase( FT_Library library, FSSpec* spec, FT_Long face_index, FT_Face *aface ) { FT_Error error = FT_Err_Ok; short res_ref, res_index; Handle fond; res_ref = FSpOpenResFile( spec, fsRdPerm ); if ( ResError() ) return FT_Err_Cannot_Open_Resource; UseResFile( res_ref ); /* face_index may be -1, in which case we just need to do a sanity check */ if ( face_index < 0 ) res_index = 1; else { res_index = (short)( face_index + 1 ); face_index = 0; } fond = Get1IndResource( 'FOND', res_index ); if ( ResError() ) { error = FT_Err_Cannot_Open_Resource; goto Error; } error = FT_New_Face_From_FOND( library, fond, face_index, aface ); Error: CloseResFile( res_ref ); return error; }
/* * NB: Destination file must exist. */ void *open_settings_w_fsp(FSSpec *dstfile) { short tmpVRefNum; long tmpDirID; struct write_settings *ws; OSErr error; Str255 tmpname; ws = snew(struct write_settings); ws->dstfile = *dstfile; /* Create a temporary file to save to first. */ error = FindFolder(ws->dstfile.vRefNum, kTemporaryFolderType, kCreateFolder, &tmpVRefNum, &tmpDirID); if (error != noErr) goto out; c2pstrcpy(tmpname, tmpnam(NULL)); error = FSMakeFSSpec(tmpVRefNum, tmpDirID, tmpname, &ws->tmpfile); if (error != noErr && error != fnfErr) goto out; if (error == noErr) { error = FSpDelete(&ws->tmpfile); if (error != noErr) goto out; } FSpCreateResFile(&ws->tmpfile, PUTTY_CREATOR, SESS_TYPE, smSystemScript); if ((error = ResError()) != noErr) goto out; ws->fd = FSpOpenResFile(&ws->tmpfile, fsWrPerm); if (ws->fd == -1) {error = ResError(); goto out;} /* Set up standard resources. Doesn't matter if these fail. */ copy_resource('STR ', -16396); copy_resource('TMPL', TMPL_Int); return ws; out: safefree(ws); fatalbox("Failed to open session for write (%d)", error); }
static PyObject *Res_FSpOpenResFile(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; short _rv; FSSpec spec; SignedByte permission; #ifndef FSpOpenResFile PyMac_PRECHECK(FSpOpenResFile); #endif if (!PyArg_ParseTuple(_args, "O&b", PyMac_GetFSSpec, &spec, &permission)) return NULL; _rv = FSpOpenResFile(&spec, permission); { OSErr _err = ResError(); if (_err != noErr) return PyMac_Error(_err); } _res = Py_BuildValue("h", _rv); return _res; }
OSErr CreateToolNameRes(StringPtr toolName) { short ref; FSSpec prefs; OSErr error; Handle theStrings; // build the 'STR ' resource error = FindPrefs(&prefs); if (error == noErr) { ref = FSpOpenResFile(&prefs, fsRdWrPerm); if (ref != -1) { theStrings = Get1Resource('STR ',kToolNameRes); if (theStrings != nil) { RemoveResource(theStrings); error = ResError(); } error = PtrToHand(toolName, &theStrings, toolName[0] + 1); AddResource(theStrings, 'STR ', kToolNameRes, "\ptoolName"); error = ResError(); ChangedResource(theStrings); error = ResError(); WriteResource(theStrings); error = ResError(); //ReleaseResource(theStrings); // Release the resource from memory. //error = ResError(); UpdateResFile(ref); // No screwing around; write that resource! error = ResError(); FlushVol(nil, prefs.vRefNum); CloseResFile(ref); } else {
OSErr PAS_decodeMisc(PASEntry *entry, FSSpec *outFile, short inRefNum) { OSErr err; short outRefNum; PASMiscInfo info; SInt32 infoSize; FInfo theFInfo; infoSize = sizeof(PASMiscInfo); err = SetFPos(inRefNum, fsFromStart, (*entry).entryOffset ); if (err != noErr) return err; err = FSRead( inRefNum, &infoSize, &info); if (err != noErr) return err; if(infoSize != sizeof(PASMiscInfo)) { return -1; } err = FSpOpenDF(outFile, fsRdWrPerm, &outRefNum); if (err != noErr) return err; memset(&theFInfo, 0, sizeof(FInfo)); theFInfo.fdType = info.fileType; theFInfo.fdCreator = info.fileCreator; theFInfo.fdFlags = info.fileFlags; err = FSpSetFInfo(outFile, &theFInfo); if (err != noErr) return err; FSClose(outRefNum); if (info.fileHasResFork) { outRefNum = FSpOpenResFile(outFile, fsRdWrPerm); if (outRefNum < noErr) { // maybe it does not have one! FSpCreateResFile(outFile, info.fileCreator, info.fileType, smSystemScript); outRefNum = FSpOpenResFile(outFile, fsRdWrPerm); if (outRefNum < noErr) { return err; } } SetResFileAttrs(outRefNum, info.fileResAttrs); CloseResFile(outRefNum); } return noErr; }
OSErr PAS_decodeResource(PASEntry *entry, FSSpec *outFile, short inRefNum) { OSErr err = noErr; short outRefNum; PASResFork info; SInt32 infoSize; short oldResFile; PASResource pasRes; SInt32 pasResSize; long bufSize; Handle buffer; long counter=0; infoSize = sizeof(PASResFork); err = SetFPos(inRefNum, fsFromStart, (*entry).entryOffset ); if (err != noErr) return err; err = FSRead( inRefNum, &infoSize, &info); if (err != noErr) return err; if(infoSize != sizeof(PASResFork)) { err = -1; goto error; } oldResFile=CurResFile(); outRefNum = FSpOpenResFile(outFile, fsRdWrPerm); if (outRefNum < noErr) return outRefNum; UseResFile(outRefNum); while (1) { pasResSize = sizeof(PASResource); err = FSRead( inRefNum, &pasResSize, &pasRes); if (err != noErr) { if(err == eofErr) err = noErr; break; } bufSize = pasRes.length; buffer = NewHandle(bufSize); HLock(buffer); if(buffer == NULL) { /* if we did not get our memory, try updateresfile */ HUnlock(buffer); UpdateResFile(outRefNum); counter=0; buffer = NewHandle(bufSize); HLock(buffer); if(buffer == NULL) { err = memFullErr; break; } } err = FSRead( inRefNum, &bufSize, &(**buffer)); if (err != noErr && err != eofErr) break; AddResource(buffer, pasRes.attrType, pasRes.attrID, pasRes.attrName); WriteResource(buffer); SetResAttrs(buffer, pasRes.attr); ChangedResource(buffer); WriteResource(buffer); ReleaseResource(buffer); if (counter++ > 100) { UpdateResFile(outRefNum); counter=0; } } error: UseResFile(oldResFile); CloseResFile(outRefNum); return err; }
void QTSound_CreateMySoundTrack (Movie theMovie) { Track theTrack; Media theMedia; Handle sndHandle = nil; SoundDescriptionHandle sndDesc = nil; long sndDataOffset; long sndDataSize; long numSamples; OSErr err = noErr; #if TARGET_OS_WIN32 char path[MAX_PATH+1]; short resID; FSSpec fsspec; fsspec.vRefNum = 0; fsspec.parID = 0; GetModuleFileName( NULL, path, MAX_PATH+1); NativePathNameToFSSpec((char *)&path, &fsspec, 0); /* open our application resource file so we can access the Macintosh 'snd ' resource */ resID = FSpOpenResFile(&fsspec, fsRdPerm); CheckError (ResError(), "FSpOpenResFile error" ); #endif sndHandle = GetResource ('snd ', kOurSoundResourceID); CheckError (ResError(), "GetResource error" ); if (sndHandle == nil) { return; } sndDesc = (SoundDescriptionHandle) NewHandle(4); CheckError (MemError(), "NewHandle error" ); QTSound_CreateSoundDescription (sndHandle, sndDesc, &sndDataOffset, &numSamples, &sndDataSize ); theTrack = NewMovieTrack (theMovie, 0, 0, kFullVolume); CheckError (GetMoviesError(), "NewMovieTrack error" ); theMedia = NewTrackMedia (theTrack, SoundMediaType, FixRound ((**sndDesc).sampleRate), nil, 0); CheckError (GetMoviesError(), "NewTrackMedia error" ); err = BeginMediaEdits (theMedia); CheckError( err, "BeginMediaEdits error" ); err = AddMediaSample(theMedia, sndHandle, sndDataOffset,/* offset in data */ sndDataSize, kSoundSampleDuration,/* duration of each sound sample */ (SampleDescriptionHandle) sndDesc, numSamples, kSyncSample,/* self-contained samples */ nil); CheckError( err, "AddMediaSample error" ); err = EndMediaEdits (theMedia); CheckError( err, "EndMediaEdits error" ); err = InsertMediaIntoTrack (theTrack, kTrackStart,/* track start time */ kMediaStart,/* media start time */ GetMediaDuration (theMedia), fixed1); CheckError( err, "InsertMediaIntoTrack error" ); if (sndDesc != nil) { DisposeHandle( (Handle)sndDesc); } }
int TclLoadFile( Tcl_Interp *interp, /* Used for error reporting. */ char *fileName, /* Name of the file containing the desired * code. */ char *sym1, char *sym2, /* Names of two procedures to look up in * the file's symbol table. */ Tcl_PackageInitProc **proc1Ptr, Tcl_PackageInitProc **proc2Ptr) /* Where to return the addresses corresponding * to sym1 and sym2. */ { CFragConnectionID connID; Ptr dummy; OSErr err; CFragSymbolClass symClass; FSSpec fileSpec; short fragFileRef, saveFileRef; Handle fragResource; UInt32 offset = 0; UInt32 length = kCFragGoesToEOF; char packageName[255]; Str255 errName; /* * First thing we must do is infer the package name from the sym1 * variable. This is kind of dumb since the caller actually knows * this value, it just doesn't give it to us. */ strcpy(packageName, sym1); *packageName = (char) tolower(*packageName); packageName[strlen(packageName) - 5] = NULL; err = FSpLocationFromPath(strlen(fileName), fileName, &fileSpec); if (err != noErr) { interp->result = "could not locate shared library"; return TCL_ERROR; } /* * See if this fragment has a 'cfrg' resource. It will tell us were * to look for the fragment in the file. If it doesn't exist we will * assume we have a ppc frag using the whole data fork. If it does * exist we find the frag that matches the one we are looking for and * get the offset and size from the resource. */ saveFileRef = CurResFile(); SetResLoad(false); fragFileRef = FSpOpenResFile(&fileSpec, fsRdPerm); SetResLoad(true); if (fragFileRef != -1) { UseResFile(fragFileRef); fragResource = Get1Resource(kCFragResourceType, kCFragResourceID); HLock(fragResource); if (ResError() == noErr) { CfrgItem* srcItem; long itemCount, index; Ptr itemStart; itemCount = (*(CfrgHeaderPtrHand)fragResource)->itemCount; itemStart = &(*(CfrgHeaderPtrHand)fragResource)->arrayStart; for (index = 0; index < itemCount; index++, itemStart += srcItem->itemSize) { srcItem = (CfrgItem*)itemStart; if (srcItem->archType != OUR_ARCH_TYPE) continue; if (!strncasecmp(packageName, (char *) srcItem->name + 1, srcItem->name[0])) { offset = srcItem->codeOffset; length = srcItem->codeLength; } } } /* * Close the resource file. If the extension wants to reopen the * resource fork it should use the tclMacLibrary.c file during it's * construction. */ HUnlock(fragResource); ReleaseResource(fragResource); CloseResFile(fragFileRef); UseResFile(saveFileRef); } /* * Now we can attempt to load the fragement using the offset & length * obtained from the resource. We don't worry about the main entry point * as we are going to search for specific entry points passed to us. */ c2pstr(packageName); err = GetDiskFragment(&fileSpec, offset, length, (StringPtr) packageName, kLoadCFrag, &connID, &dummy, errName); if (err != fragNoErr) { p2cstr(errName); Tcl_AppendResult(interp, "couldn't load file \"", fileName, "\": ", errName, (char *) NULL); return TCL_ERROR; } c2pstr(sym1); err = FindSymbol(connID, (StringPtr) sym1, (Ptr *) proc1Ptr, &symClass); p2cstr((StringPtr) sym1); if (err != fragNoErr || symClass == kDataCFragSymbol) { interp->result = "could not find Initialization routine in library"; return TCL_ERROR; } c2pstr(sym2); err = FindSymbol(connID, (StringPtr) sym2, (Ptr *) proc2Ptr, &symClass); p2cstr((StringPtr) sym2); if (err != fragNoErr || symClass == kDataCFragSymbol) { *proc2Ptr = NULL; } return TCL_OK; }
// hdll, pluginmain and audiomaster are set here // must be NULL beforehand! bool VSTPlugin::NewPlugin(const char *plugname) { FLEXT_ASSERT(!pluginmain && !audiomaster); dllname = plugname; #if FLEXT_OS == FLEXT_OS_WIN hdll = LoadLibraryEx(dllname.c_str(),NULL,0 /*DONT_RESOLVE_DLL_REFERENCES*/); /* char buf[255],*c; strcpy(buf,dllname.c_str()); for(c = buf; *c; ++c) if(*c == '/') *c = '\\'; char *sl = strrchr(buf,'\\'); if(sl) *sl = 0; SetCurrentDirectory(buf); hdll = LoadLibrary(dllname.c_str()); */ if(hdll) pluginmain = (PVSTMAIN)GetProcAddress(hdll,"main"); audiomaster = Master; #elif FLEXT_OS == FLEXT_OS_MAC #if 1 CFStringRef fileNameString = CFStringCreateWithCString(NULL, fileName, kCFStringEncodingUTF8); if(fileNameString == 0) goto bail; CFURLRef url = CFURLCreateWithFileSystemPath(NULL, fileNameString, kCFURLPOSIXPathStyle, false); CFRelease(fileNameString); if(url == 0) goto bail; hdll = CFBundleCreate(NULL, url); CFRelease (url); if(hdll && !CFBundleLoadExecutable(hdll)) goto bail; PVSTMAIN mainaddr = PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("VSTPluginMain")); if(!mainaddr) mainaddr = (PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("main_macho")); #ifdef __CFM__ pluginmain = (PVSTMAIN)NewMachOFromCFM(mainaddr); audiomaster = NewCFMFromMachO(Master); #else pluginmain = (PVSTMAIN)mainaddr; audiomaster = Master; #endif #else short resFileID; FSSpec spec; OSErr err; err = FSPathMakeFSSpec(dllname.c_str(),&spec,NULL); resFileID = FSpOpenResFile(&spec, fsRdPerm); short cResCB = Count1Resources('aEff'); for(int i = 0; i < cResCB; i++) { Handle codeH; CFragConnectionID connID; Ptr mainAddr; Str255 errName; Str255 fragName; char fragNameCStr[256]; short resID; OSType resType; codeH = Get1IndResource('aEff', short(i+1)); if(!codeH) continue; GetResInfo(codeH, &resID, &resType, fragName); DetachResource(codeH); HLock(codeH); err = GetMemFragment(*codeH, GetHandleSize(codeH), fragName, kPrivateCFragCopy, &connID, (Ptr *) & mainAddr, errName); if(!err) { #ifdef __CFM__ pluginmain = (PVSTMAIN)NewMachOFromCFM(mainAddr); #else pluginmain = (PVSTMAIN)mainAddr; #endif } } CloseResFile(resFileID); audiomaster = #ifdef __CFM__ NewCFMFromMachO(Master); #else Master; #endif #endif #else #error Platform not supported #endif bail: if(pluginmain && audiomaster) return true; else { FreePlugin(); return false; } }
void LoadVSTPlugins() { #ifdef __MACOSX__ audioMasterCallback audioMasterFPtr = (audioMasterCallback)NewCFMFromMachO(audioMaster); #else // What is the corrct way of creating an audioMasterCallback // in OS 9/Carbon??? // audioMasterCallback audioMasterFPtr = NULL; audioMasterCallback audioMasterFPtr = audioMaster; #endif wxArrayString audacityPathList = wxGetApp().audacityPathList; wxArrayString pathList; wxArrayString files; unsigned int i; for(i=0; i<audacityPathList.GetCount(); i++) { wxString prefix = audacityPathList[i] + wxFILE_SEP_PATH; wxGetApp().AddUniquePathToPathList(prefix + "VST", pathList); wxGetApp().AddUniquePathToPathList(prefix + "Plugins", pathList); wxGetApp().AddUniquePathToPathList(prefix + "Plug-Ins", pathList); } #ifdef __MACOSX__ wxGetApp().AddUniquePathToPathList("/Library/Audio/Plug-Ins/VST", pathList); wxString vstPath; vstPath.Printf("/Users/%s/Library/Audio/Plug-Ins/VST", wxGetenv("USER")); wxGetApp().AddUniquePathToPathList(vstPath, pathList); #endif wxGetApp().FindFilesInPathList("*", pathList, wxFILE, files); for(i=0; i<files.GetCount(); i++) { short resFileID; FSSpec spec; wxMacFilename2FSSpec(FILENAME(files[i]), &spec); resFileID = FSpOpenResFile(&spec, fsRdPerm); short cResCB = Count1Resources('aEff'); for (int i = 0; i < cResCB; i++) { Handle codeH; CFragConnectionID connID; Ptr mainAddr; Str255 errName; Str255 fragName; char fragNameCStr[256]; short resID; OSType resType; OSErr err; codeH = Get1IndResource('aEff', short(i+1)); if (!codeH) continue; GetResInfo(codeH, &resID, &resType, fragName); DetachResource(codeH); HLock(codeH); err = GetMemFragment(*codeH, GetHandleSize(codeH), fragName, kPrivateCFragCopy, &connID, (Ptr *) & mainAddr, errName); if (!err) { vstPluginMain pluginMain; AEffect *theEffect; #ifdef __MACOSX__ pluginMain = (vstPluginMain)NewMachOFromCFM(mainAddr); #else pluginMain = (vstPluginMain)mainAddr; #endif theEffect = pluginMain(audioMasterFPtr); if (theEffect->magic == kEffectMagic) { memcpy(fragNameCStr, &fragName[1], fragName[0]); fragNameCStr[fragName[0]] = 0; VSTEffect *vst = new VSTEffect(wxString(fragNameCStr), theEffect); Effect::RegisterEffect(vst); } #ifdef __MACOSX__ DisposeMachOFromCFM(pluginMain); #endif audacityVSTID++; } } CloseResFile(resFileID); } #ifdef __MACOSX__ DisposeCFMFromMachO(audioMasterFPtr); #endif // __MACOSX__ }