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; }
/* * Open a TIFF file for read/writing. */ TIFF* TIFFOpen(const char* name, const char* mode) { static const char module[] = "TIFFOpen"; Str255 pname; FInfo finfo; short fref; OSErr err; FSSpec fSpec; strcpy((char*) pname, name); ourc2pstr((char*) pname); err = FSMakeFSSpec( 0, 0, pname, &fSpec ); switch (_TIFFgetMode(mode, module)) { default: return ((TIFF*) 0); case O_RDWR | O_CREAT | O_TRUNC: if (FSpGetFInfo(&fSpec, &finfo) == noErr) FSpDelete(&fSpec); /* fall through */ case O_RDWR | O_CREAT: if ((err = FSpGetFInfo(&fSpec, &finfo)) == fnfErr) { if (FSpCreate(&fSpec, ' ', 'TIFF', smSystemScript) != noErr) goto badCreate; if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr) goto badOpen; } else if (err == noErr) { if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr) goto badOpen; } else goto badOpen; break; case O_RDONLY: if (FSpOpenDF(&fSpec, fsRdPerm, &fref) != noErr) goto badOpen; break; case O_RDWR: if (FSpOpenDF(&fSpec, fsRdWrPerm, &fref) != noErr) goto badOpen; break; } return (TIFFFdOpen((int) fref, name, mode)); badCreate: TIFFErrorExt(0, module, "%s: Cannot create", name); return ((TIFF*) 0); badOpen: TIFFErrorExt(0, module, "%s: Cannot open", name); return ((TIFF*) 0); }
void fixmacfile(char *filename) { FInfo fndrinfo; #ifdef OSX_CARBON FSSpec fileSpec; FSRef fileRef; FSPathMakeRef((unsigned char *)filename, &fileRef, NULL); FSGetCatalogInfo(&fileRef, kFSCatInfoNone, NULL, NULL, &fileSpec, NULL); FSpGetFInfo(&fileSpec, &fndrinfo); fndrinfo.fdType='TEXT'; fndrinfo.fdCreator='MSWD'; FSpSetFInfo(&fileSpec, &fndrinfo); #else char filename1[FNMLNGTH]; char filename2[FNMLNGTH]; strcpy(filename1,filename); strcpy(filename2,filename); getfinfo(filename1,0,&fndrinfo); fndrinfo.fdType='TEXT'; fndrinfo.fdCreator='MSWD'; setfinfo(filename2,0,&fndrinfo); #endif }
static OSErr mac_opensessionfrom(FSSpec *fss) { FInfo fi; Session *s; void *sesshandle; OSErr err; s = snew(Session); memset(s, 0, sizeof(*s)); err = FSpGetFInfo(fss, &fi); if (err != noErr) return err; if (fi.fdFlags & kIsStationery) s->hasfile = FALSE; else { s->hasfile = TRUE; s->savefile = *fss; } sesshandle = open_settings_r_fsp(fss); if (sesshandle == NULL) { /* XXX need a way to pass up an error number */ err = -9999; goto fail; } load_open_settings(sesshandle, &s->cfg); close_settings_r(sesshandle); mac_startsession(s); return noErr; fail: sfree(s); return err; }
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed) { short tmpRef, vRefNum; long dirID; FInfo finderInfo; FSSpec theSpec; Str255 fName; OSErr osErr; long gestaltResponse = 0; /* Check that FSSpec calls are available. */ osErr = Gestalt( gestaltFSAttr, &gestaltResponse ); if ( ( osErr != noErr ) || !( gestaltResponse & (1<<gestaltHasFSSpecCalls) ) ) ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required"); /* TO DO: add a proper error message to jerror.h. */ /* Check that FindFolder is available. */ osErr = Gestalt( gestaltFindFolderAttr, &gestaltResponse ); if ( ( osErr != noErr ) || !( gestaltResponse & (1<<gestaltFindFolderPresent) ) ) ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required."); /* TO DO: add a proper error message to jerror.h. */ osErr = FindFolder ( kOnSystemDisk, kTemporaryFolderType, kCreateFolder, &vRefNum, &dirID ); if ( osErr != noErr ) ERREXITS(cinfo, JERR_TFILE_CREATE, "- temporary items folder unavailable"); /* TO DO: Try putting the temp files somewhere else. */ /* Keep generating file names till we find one that's not in use */ for (;;) { next_file_num++; /* advance counter */ sprintf(info->temp_name, TEMP_FILE_NAME, next_file_num); strcpy ( (Ptr)fName+1, info->temp_name ); *fName = strlen (info->temp_name); osErr = FSMakeFSSpec ( vRefNum, dirID, fName, &theSpec ); if ( (osErr = FSpGetFInfo ( &theSpec, &finderInfo ) ) != noErr ) break; } osErr = FSpCreate ( &theSpec, '????', '????', smSystemScript ); if ( osErr != noErr ) ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); osErr = FSpOpenDF ( &theSpec, fsRdWrPerm, &(info->temp_file) ); if ( osErr != noErr ) ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); info->tempSpec = theSpec; info->read_backing_store = read_backing_store; info->write_backing_store = write_backing_store; info->close_backing_store = close_backing_store; TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); }
ImportFileHandle *QTImportPlugin::Open(wxString Filename) { FSSpec inFile; FInfo fileInfo; Movie theMovie = 0; Media theMedia; // Make sure QuickTime is initialized //::EnterMovies(); #ifdef WIN32 char* specFilename = strdup(Filename.GetData()); if (FSMakeFSSpec(0,0,c2pstr(specFilename), &inFile) != noErr) { free(specFilename); return false; } free(specFilename); #else wxMacFilename2FSSpec(Filename, &inFile); #endif OSErr err = FSpGetFInfo(&inFile, &fileInfo); if(err != noErr) return NULL; if (kQTFileTypeSystemSevenSound == fileInfo.fdType) { // TODO: handle this case. it is special because system seven sounds cannot // be opened in place } else { short theRefNum; short theResID = 0; // we want the first movie Boolean wasChanged; // open the movie file err = OpenMovieFile(&inFile, &theRefNum, fsRdPerm); if(err != noErr) return NULL; // instantiate the movie err = NewMovieFromFile(&theMovie, theRefNum, &theResID, NULL, newMovieActive, &wasChanged); CloseMovieFile(theRefNum); if(err != noErr) return NULL; } // get and return the sound track media theMedia = GetMediaFromMovie(theMovie); if(theMedia == NULL) return NULL; return new QTImportFileHandle(theMovie, theMedia); }
bool wxFileConfig::Flush(bool /* bCurrentOnly */) { if ( LineListIsEmpty() || !m_pRootGroup->IsDirty() || !m_strLocalFile ) return TRUE; #ifdef __UNIX__ // set the umask if needed mode_t umaskOld = 0; if ( m_umask != -1 ) { umaskOld = umask((mode_t)m_umask); } #endif // __UNIX__ wxTempFile file(m_strLocalFile); if ( !file.IsOpened() ) { wxLogError(_("can't open user configuration file.")); return FALSE; } // write all strings to file for ( LineList *p = m_linesHead; p != NULL; p = p->Next() ) { if ( !file.Write(p->Text() + wxTextFile::GetEOL()) ) { wxLogError(_("can't write user configuration file.")); return FALSE; } } bool ret = file.Commit(); #if defined(__WXMAC__) && !defined(__UNIX__) if ( ret ) { FSSpec spec ; wxMacFilename2FSSpec( m_strLocalFile , &spec ) ; FInfo finfo ; if ( FSpGetFInfo( &spec , &finfo ) == noErr ) { finfo.fdType = 'TEXT' ; finfo.fdCreator = 'ttxt' ; FSpSetFInfo( &spec , &finfo ) ; } } #endif // __WXMAC__ && !__UNIX__ #ifdef __UNIX__ // restore the old umask if we changed it if ( m_umask != -1 ) { (void)umask(umaskOld); } #endif // __UNIX__ return ret; }
char CheckFileType(FSSpec* fss, long type) { FInfo fi; if(FSpGetFInfo(fss,&fi)==0) return ((long)fi.fdType == type); else return false; }
OSErr getSpecAndFInfo(char *filename, int filenameSize,FSSpec *spec,FInfo *finderInfo) { OSErr err; if ((err = makeFSSpec(filename, filenameSize,spec)) != noErr) return err; if ((err= FSpGetFInfo(spec,finderInfo)) != noErr) return err; return noErr; }
/* Return the file type of the file specified by spec. */ static OSType get_file_type( FSSpec* spec ) { FInfo finfo; if ( FSpGetFInfo( spec, &finfo ) != noErr ) return 0; /* file might not exist */ return finfo.fdType; }
static int GetFileFinderAttributes( Tcl_Interp *interp, /* The interp to report errors with. */ int objIndex, /* The index of the attribute option. */ char *fileName, /* The name of the file. */ Tcl_Obj **attributePtrPtr) /* A pointer to return the object with. */ { OSErr err; FSSpec fileSpec; FInfo finfo; err = FSpLocationFromPath(strlen(fileName), fileName, &fileSpec); if (err == noErr) { err = FSpGetFInfo(&fileSpec, &finfo); } if (err == noErr) { switch (objIndex) { case MAC_CREATOR_ATTRIBUTE: *attributePtrPtr = Tcl_NewOSTypeObj(finfo.fdCreator); break; case MAC_HIDDEN_ATTRIBUTE: *attributePtrPtr = Tcl_NewBooleanObj(finfo.fdFlags & kIsInvisible); break; case MAC_TYPE_ATTRIBUTE: *attributePtrPtr = Tcl_NewOSTypeObj(finfo.fdType); break; } } else if (err == fnfErr) { long dirID; Boolean isDirectory = 0; err = FSpGetDirectoryID(&fileSpec, &dirID, &isDirectory); if ((err == noErr) && isDirectory) { if (objIndex == MAC_HIDDEN_ATTRIBUTE) { *attributePtrPtr = Tcl_NewBooleanObj(0); } else { *attributePtrPtr = Tcl_NewOSTypeObj('Fldr'); } } } if (err != noErr) { errno = TclMacOSErrorToPosixError(err); Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "couldn't get attributes for file \"", fileName, "\": ", Tcl_PosixError(interp), (char *) NULL); return TCL_ERROR; } return TCL_OK; }
PASCAL_RTN OSErr QTApp_HandleOpenDocumentAppleEvent (const AppleEvent *theMessage, AppleEvent *theReply, long theRefcon) { #pragma unused(theReply, theRefcon) long myIndex; long myItemsInList; AEKeyword myKeyWd; AEDescList myDocList; long myActualSize; DescType myTypeCode; FSSpec myFSSpec; OSErr myIgnoreErr = noErr; OSErr myErr = noErr; // get the direct parameter and put it into myDocList myDocList.dataHandle = NULL; myErr = AEGetParamDesc(theMessage, keyDirectObject, typeAEList, &myDocList); // count the descriptor records in the list if (myErr == noErr) myErr = AECountItems(&myDocList, &myItemsInList); else myItemsInList = 0; // open each specified file for (myIndex = 1; myIndex <= myItemsInList; myIndex++) if (myErr == noErr) { myErr = AEGetNthPtr(&myDocList, myIndex, typeFSS, &myKeyWd, &myTypeCode, (Ptr)&myFSSpec, sizeof(myFSSpec), &myActualSize); if (myErr == noErr) { FInfo myFinderInfo; // verify that the file type is MovieFileType; to do this, get the Finder information myErr = FSpGetFInfo(&myFSSpec, &myFinderInfo); if (myErr == noErr) { if (myFinderInfo.fdType == MovieFileType) // we've got a movie file; just open it QTFrame_OpenMovieInWindow(NULL, &myFSSpec); } } } if (myDocList.dataHandle) myIgnoreErr = AEDisposeDesc(&myDocList); // make sure we open the document in the foreground gAppInForeground = true; return(myErr); }
/* close the output file, if opened with PDF_open_file(); * close the output stream if opened */ static void pdf_close_file(PDF *p) { #if defined(MAC) && defined(__MWERKS__) FCBPBRec fcbInfo; Str32 name; FInfo fInfo; FSSpec fSpec; #endif if (p->fp == NULL) return; #if defined(MAC) && defined(__MWERKS__) /* Contributed by Leonard Rosenthol: * On the MacOS, files are not associated with applications by extensions. * Instead, it uses a pair of values called the type & creator. * This block of code sets those values for PDF files. */ memset(&fcbInfo, 0, sizeof(FCBPBRec)); fcbInfo.ioRefNum = (short) p->fp->handle; fcbInfo.ioNamePtr = name; if (!PBGetFCBInfoSync(&fcbInfo) && FSMakeFSSpec(fcbInfo.ioFCBVRefNum, fcbInfo.ioFCBParID, name, &fSpec) == noErr) { FSpGetFInfo(&fSpec, &fInfo); fInfo.fdType = 'PDF '; fInfo.fdCreator = 'CARO'; FSpSetFInfo(&fSpec, &fInfo); } #endif /* * If filename is set, we started with PDF_open_file; therefore * we also close the file ourselves. */ if (p->filename && p->writeproc) { if (strcmp(p->filename, "-")) fclose(p->fp); p->free(p, p->filename); } /* mark fp as dead in case the error handler jumps in later */ p->fp = NULL; }
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; }
int file_getftype(char* filename) { FSSpec fss; Str255 fname; FInfo fndrInfo; int ftype; ftype = GetFileExt(filename); if (ftype == FTYPE_NONE) { mkstr255(fname, filename); FSMakeFSSpec(0, 0, fname, &fss); if (FSpGetFInfo(&fss, &fndrInfo) != noErr) { return(FTYPE_NONE); } ftype = Getfiletype(&fndrInfo); } return(ftype); }
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 }
boolean filesetfinderflag (ptrfilespec pfs, short flagnum, boolean flag) { OSErr ec; FInfo info; ec = FSpGetFInfo (pfs, &info); if (fileerror (pfs, ec)) return (false); if (flag) info.fdFlags = setbit (info.fdFlags, flagnum); else info.fdFlags = clearbit (info.fdFlags, flagnum); ec = FSpSetFInfo (pfs, &info); return (!fileerror (pfs, ec)); } /*filesetfinderflag*/
static OSErr PrintLabelName (FSRef *fileRef) { static char labelNames[8][8] = { "None", "Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Gray" }; FSSpec fileSpec; FInfo finderInfo; DInfo dInfo; OSErr err = noErr; int labelNum = 0; /* retrieve filespec from file ref */ err = FSGetCatalogInfo (fileRef, NULL, NULL, NULL, &fileSpec, NULL); if (err != noErr) { fprintf(stderr, "FSGetCatalogInfo(): Error %d getting file spec from file reference\n", err); return err; } if (IsFolder(fileRef)) { err = FSpGetDInfo (&fileSpec, &dInfo); if (err != noErr) { fprintf(stderr, "FSpGetFInfo(): Error %d getting file Finder Directory Info from file spec\n", err); return err; } labelNum = GetLabelNumber(dInfo.frFlags); } else { err = FSpGetFInfo (&fileSpec, &finderInfo); if (err != noErr) { fprintf(stderr, "FSpGetFInfo(): Error %d getting file Finder File Info from file spec\n", err); return err; } labelNum = GetLabelNumber(finderInfo.fdFlags); } printf("%s\n", (char *)&labelNames[labelNum]); return noErr; }
PGPError PFLNewFileSpecFromFSSpec( PGPMemoryMgrRef memoryMgr, FSSpec const * spec, PFLFileSpecRef * outRef ) { PFLFileSpecRef newFileRef = NULL; PGPError err = kPGPError_NoErr; PGPValidatePtr( outRef ); *outRef = NULL; PGPValidateMemoryMgr( memoryMgr ); PGPValidatePtr( spec ); PGPValidateParam( spec->vRefNum < 0 && spec->parID != 0 && spec->name[ 0 ] != 0 && spec->name[ 0 ] <= 31 ); err = pgpNewFileSpec( memoryMgr, kPFLFileSpecMacType, sizeof( MyData ), &newFileRef ); if ( IsntPGPError( err ) ) { MyData * myData = GetMyData( newFileRef ); pgpClearMemory( myData, sizeof( *myData ) ); myData->spec = *spec; /* volume info not used if vRefNumIsValid */ myData->specIsValid = TRUE; if( FSpGetFInfo( spec, (FInfo *) &myData->metaInfo.fInfo ) != noErr ) { myData->metaInfo.fInfo.fileType = 'BINA'; myData->metaInfo.fInfo.fileCreator = '????'; myData->metaInfo.fInfo.finderFlags = 0; myData->metaInfo.fInfo.location.h = -1; myData->metaInfo.fInfo.location.v = -1; myData->metaInfo.fInfo.reserved = 0; } } *outRef = newFileRef; return err; }
static OSErr PrintLabelNumber (FSRef *fileRef) { FSSpec fileSpec; FInfo finderInfo; DInfo dInfo; OSErr err = noErr; int labelNum = 0; /* retrieve filespec from file ref */ err = FSGetCatalogInfo (fileRef, NULL, NULL, NULL, &fileSpec, NULL); if (err != noErr) { fprintf(stderr, "FSGetCatalogInfo(): Error %d getting file spec from file reference\n", err); return err; } if (IsFolder(fileRef)) { err = FSpGetDInfo (&fileSpec, &dInfo); if (err != noErr) { fprintf(stderr, "FSpGetFInfo(): Error %d getting file Finder Directory Info from file spec\n", err); return err; } labelNum = GetLabelNumber(dInfo.frFlags); } else { err = FSpGetFInfo (&fileSpec, &finderInfo); if (err != noErr) { fprintf(stderr, "FSpGetFInfo(): Error %d getting file Finder File Info from file spec\n", err); return err; } labelNum = GetLabelNumber(finderInfo.fdFlags); } printf("%d\n", labelNum); return noErr; }
static PGPError sExistsProc( PFLFileSpecRef ref, PGPBoolean * exists) { PGPError err = kPGPError_NoErr; MyData * myData = GetMyData( ref ); FInfo fInfo; if ( myData->specIsValid ) { err = FSpGetFInfo( &myData->spec, &fInfo ); *exists = ( err == noErr ); } else { *exists = FALSE; } return( kPGPError_NoErr ); }
static OSErr PrintCreatorCode (FSRef *fileRef) { FSSpec fileSpec; FInfo finderInfo; OSErr err = noErr; char creatorType[5] = "\0"; //if it's a folder if (IsFolder(fileRef)) { printf("MACS\n"); return 0; } // retrieve filespec from file ref err = FSGetCatalogInfo (fileRef, NULL, NULL, NULL, &fileSpec, NULL); if (err != noErr) { fprintf(stderr, "FSGetCatalogInfo(): Error %d getting file spec from file reference\n", err); return err; } // get Finder File Info err = FSpGetFInfo (&fileSpec, &finderInfo); if (err != noErr) { fprintf(stderr, "FSpGetFInfo(): Error %d getting file Finder File Info from file spec\n", err); return err; } /* get creator type string */ OSTypeToStr(finderInfo.fdCreator, creatorType); //print it if (strlen(creatorType) != 0) printf("%s\n", creatorType); return 0; }
/* create icns(icon for MacOS X) with IPIcon */ OSErr MakeXIconWithIPIcon(const FSSpec *theFile,const IPIconRec *ipIcon) { OSErr err; FInfo fndrInfo; short refNum; IconFamilyHandle iconFamily; long count; if (!isIconServicesAvailable) return -1; /* convert IPIcon to icns */ err=IPIconToIconFamily(ipIcon,&iconFamily); if (err!=noErr) return err; /* create a file */ err=FSpGetFInfo(theFile,&fndrInfo); if (err==fnfErr) err=FSpCreate(theFile,kIconPartyCreator,kXIconFileType,smSystemScript); if (err!=noErr) return err; /* open the file */ err=FSpOpenDF(theFile,fsWrPerm,&refNum); if (err!=noErr) return err; /* save icns */ HLock((Handle)iconFamily); count=GetHandleSize((Handle)iconFamily); err=FSWrite(refNum,&count,*iconFamily); err=SetEOF(refNum,count); HUnlock((Handle)iconFamily); DisposeHandle((Handle)iconFamily); /* close the file */ err=FSClose(refNum); return noErr; }
pascal OSErr FSpGetFInfoCompat(const FSSpec *spec, FInfo *fndrInfo) { #if !__MACOSSEVENORLATER if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() ) { OSErr result; HParamBlockRec pb; pb.fileParam.ioVRefNum = spec->vRefNum; pb.fileParam.ioDirID = spec->parID; pb.fileParam.ioNamePtr = (StringPtr) &(spec->name); pb.fileParam.ioFVersNum = 0; pb.fileParam.ioFDirIndex = 0; result = PBHGetFInfoSync(&pb); *fndrInfo = pb.fileParam.ioFlFndrInfo; return ( result ); } else #endif /* !__MACOSSEVENORLATER */ { return ( FSpGetFInfo(spec, fndrInfo) ); } }
/* Return the file type for given pathname */ static OSType get_file_type_from_path( const UInt8* pathname ) { #if HAVE_FSREF FSRef ref; FSCatalogInfo info; if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) ) return ( OSType ) 0; if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoFinderInfo, &info, NULL, NULL, NULL ) ) return ( OSType ) 0; return ((FInfo *)(info.finderInfo))->fdType; #else FSSpec spec; FInfo finfo; if ( noErr != FT_FSPathMakeSpec( pathname, &spec, FALSE ) ) return ( OSType ) 0; if ( noErr != FSpGetFInfo( &spec, &finfo ) ) return ( OSType ) 0; return finfo.fdType; #endif /* HAVE_FSREF */ }
static int SetFileFinderAttributes( Tcl_Interp *interp, /* The interp to report errors with. */ int objIndex, /* The index of the attribute. */ char *fileName, /* The name of the file. */ Tcl_Obj *attributePtr) /* The command line object. */ { OSErr err; FSSpec fileSpec; FInfo finfo; err = FSpLocationFromPath(strlen(fileName), fileName, &fileSpec); if (err == noErr) { err = FSpGetFInfo(&fileSpec, &finfo); } if (err == noErr) { switch (objIndex) { case MAC_CREATOR_ATTRIBUTE: if (Tcl_GetOSTypeFromObj(interp, attributePtr, &finfo.fdCreator) != TCL_OK) { return TCL_ERROR; } break; case MAC_HIDDEN_ATTRIBUTE: { int hidden; if (Tcl_GetBooleanFromObj(interp, attributePtr, &hidden) != TCL_OK) { return TCL_ERROR; } if (hidden) { finfo.fdFlags |= kIsInvisible; } else { finfo.fdFlags &= ~kIsInvisible; } break; } case MAC_TYPE_ATTRIBUTE: if (Tcl_GetOSTypeFromObj(interp, attributePtr, &finfo.fdType) != TCL_OK) { return TCL_ERROR; } break; } err = FSpSetFInfo(&fileSpec, &finfo); } else if (err == fnfErr) { long dirID; Boolean isDirectory = 0; err = FSpGetDirectoryID(&fileSpec, &dirID, &isDirectory); if ((err == noErr) && isDirectory) { Tcl_Obj *resultPtr = Tcl_GetObjResult(interp); Tcl_AppendStringsToObj(resultPtr, "cannot set ", tclpFileAttrStrings[objIndex], ": \"", fileName, "\" is a directory", (char *) NULL); return TCL_ERROR; } } if (err != noErr) { errno = TclMacOSErrorToPosixError(err); Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "couldn't set attributes for file \"", fileName, "\": ", Tcl_PosixError(interp), (char *) NULL); return TCL_ERROR; } return TCL_OK; }
/////////////////////////////////////////////////////////////////// // Make sure file exists and we have privileges. Then set the // file Finder comment. /////////////////////////////////////////////////////////////////// static void SetFileLabel (char *path, short labelNum) { OSErr err = noErr; FSRef fileRef; FSSpec fileSpec; short isFldr; short currentLabel; FInfo finderInfo; CInfoPBRec infoRec; //see if the file in question exists and we can write it if (access(path, R_OK|W_OK|F_OK) == -1) { perror(path); return; } //get file reference from path err = FSPathMakeRef((char *)path, &fileRef, NULL); if (err != noErr) { fprintf(stderr, "FSPathMakeRef: Error %d for file %s\n", err, path); return; } //retrieve filespec from file ref err = FSGetCatalogInfo (&fileRef, NULL, NULL, NULL, &fileSpec, NULL); if (err != noErr) { fprintf(stderr, "FSGetCatalogInfo(): Error %d getting file spec for %s\n", err, path); return; } /* Check if we're dealing with a folder */ isFldr = UnixIsFolder(path); if (isFldr == -1)/* an error occurred in stat */ { perror(path); return; } ///////////////////////// IF SPECIFIED FILE IS A FOLDER ///////////////////////// if (isFldr) { //Get HFS record FSpGetPBRec(&fileSpec, &infoRec); //get current label currentLabel = GetLabelNumber(infoRec.dirInfo.ioDrUsrWds.frFlags); //set new label into record SetLabelInFlags(&infoRec.dirInfo.ioDrUsrWds.frFlags, labelNum); //fill in the requisite fields infoRec.hFileInfo.ioNamePtr = (unsigned char *)fileSpec.name; infoRec.hFileInfo.ioVRefNum = fileSpec.vRefNum; infoRec.hFileInfo.ioDirID = fileSpec.parID; //set the record PBSetCatInfoSync(&infoRec); } ///////////////////////// IF SPECIFIED FILE IS A REGULAR FILE ///////////////////////// else { /* get the finder info */ err = FSpGetFInfo (&fileSpec, &finderInfo); if (err != noErr) { if (!silentMode) fprintf(stderr, "FSpGetFInfo(): Error %d getting file Finder info from file spec for file %s", err, path); } //retrieve the label number of the file currentLabel = GetLabelNumber(finderInfo.fdFlags); //if it's already set with the desired label we return if (currentLabel == labelNum) return; //set the appropriate value in the flags field SetLabelInFlags(&finderInfo.fdFlags, labelNum); //apply the settings to the file err = FSpSetFInfo (&fileSpec, &finderInfo); if (err != noErr) { if (!silentMode) fprintf(stderr, "FSpSetFInfo(): Error %d setting Finder info for %s", err, path); return; } } //print output reporting the changes made if (!silentMode) printf("%s:\n\t%s --> %s\n", path, (char *)&labelNames[currentLabel], (char *)&labelNames[labelNum]); return; }
void AudacityProject::Save(bool overwrite /* = true */ , bool fromSaveAs /* = false */ ) { if (!fromSaveAs && mDirManager.GetProjectName() == "") { SaveAs(); return; } // // Always save a backup of the original project file // wxString safetyFileName = ""; if (wxFileExists(mFileName)) { #ifdef __WXGTK__ safetyFileName = mFileName + "~"; #else safetyFileName = mFileName + ".bak"; #endif if (wxFileExists(safetyFileName)) wxRemoveFile(safetyFileName); wxRename(mFileName, safetyFileName); } wxString project = mFileName; if (project.Len() > 4 && project.Mid(project.Len() - 4) == ".aup") project = project.Mid(0, project.Len() - 4); wxString projName = wxFileNameFromPath(project) + "_data"; wxString projPath = wxPathOnly(project); bool success = mDirManager.SetProject(projPath, projName, !overwrite); if (!success) { wxMessageBox(wxString:: Format ("Could not save project because the directory %s could not be created.", (const char *) project)); if (safetyFileName) wxRename(safetyFileName, mFileName); return; } wxTextFile f(mFileName); #ifdef __WXMAC__ wxFile *temp = new wxFile(); temp->Create(mFileName); delete temp; #else f.Create(); #endif f.Open(); if (!f.IsOpened()) { wxMessageBox("Couldn't write to " + mFileName); if (safetyFileName) wxRename(safetyFileName, mFileName); return; } f.AddLine("AudacityProject"); f.AddLine("Version"); f.AddLine(AUDACITY_FILE_FORMAT_VERSION); f.AddLine("projName"); f.AddLine(projName); f.AddLine("sel0"); f.AddLine(wxString::Format("%g", mViewInfo.sel0)); f.AddLine("sel1"); f.AddLine(wxString::Format("%g", mViewInfo.sel1)); f.AddLine("vpos"); f.AddLine(wxString::Format("%d", mViewInfo.vpos)); f.AddLine("h"); f.AddLine(wxString::Format("%g", mViewInfo.h)); f.AddLine("zoom"); f.AddLine(wxString::Format("%g", mViewInfo.zoom)); f.AddLine("rate"); f.AddLine(wxString::Format("%g", mRate)); f.AddLine("BeginTracks"); mTracks->Save(&f, overwrite); #ifdef __WXMAC__ f.Write(wxTextFileType_Mac); #else f.Write(); #endif f.Close(); #ifdef __WXMAC__ FSSpec spec; wxMacFilename2FSSpec(mFileName, &spec); FInfo finfo; if (FSpGetFInfo(&spec, &finfo) == noErr) { finfo.fdType = AUDACITY_PROJECT_TYPE; finfo.fdCreator = AUDACITY_CREATOR; FSpSetFInfo(&spec, &finfo); } #endif if (mLastSavedTracks) { TrackListIterator iter(mLastSavedTracks); VTrack *t = iter.First(); while (t) { if (t->GetKind() == VTrack::Wave && !overwrite) ((WaveTrack *) t)->DeleteButDontDereference(); else delete t; t = iter.Next(); } delete mLastSavedTracks; } mLastSavedTracks = new TrackList(); TrackListIterator iter(mTracks); VTrack *t = iter.First(); while (t) { mLastSavedTracks->Add(t->Duplicate()); t = iter.Next(); } mStatus->SetField(wxString::Format("Saved %s", (const char *) mFileName), 0); }
void AudacityProject::Save(bool overwrite /* = true */ , bool fromSaveAs /* = false */ ) { if (!fromSaveAs && mDirManager.GetProjectName() == "") { SaveAs(); return; } // // Always save a backup of the original project file // wxString safetyFileName = ""; if (wxFileExists(mFileName)) { #ifdef __WXGTK__ safetyFileName = mFileName + "~"; #else safetyFileName = mFileName + ".bak"; #endif if (wxFileExists(safetyFileName)) wxRemoveFile(safetyFileName); wxRename(mFileName, safetyFileName); } wxString project = mFileName; if (project.Len() > 4 && project.Mid(project.Len() - 4) == ".aup") project = project.Mid(0, project.Len() - 4); wxString projName = wxFileNameFromPath(project) + "_data"; wxString projPath = wxPathOnly(project); // We are about to move files from the current directory to // the new directory. We need to make sure files that belonged // to the last saved project don't get erased, so we "lock" them. // (Otherwise the new project would be fine, but the old one would // be empty of all of its files.) // Lock all blocks in all tracks of the last saved version if (mLastSavedTracks && !overwrite) { TrackListIterator iter(mLastSavedTracks); VTrack *t = iter.First(); while (t) { if (t->GetKind() == VTrack::Wave) ((WaveTrack *) t)->Lock(); t = iter.Next(); } } // This renames the project directory, and moves or copies // all of our block files over bool success = mDirManager.SetProject(projPath, projName, !overwrite); // Unlock all blocks in all tracks of the last saved version if (mLastSavedTracks && !overwrite) { TrackListIterator iter(mLastSavedTracks); VTrack *t = iter.First(); while (t) { if (t->GetKind() == VTrack::Wave) ((WaveTrack *) t)->Unlock(); t = iter.Next(); } } if (!success) { wxMessageBox(wxString:: Format (_("Could not save project. " "Perhaps %s is not writeable,\n" "or the disk is full."), (const char *) project)); if (safetyFileName) wxRename(safetyFileName, mFileName); return; } wxTextFile f(mFileName); f.Create(); f.Open(); if (!f.IsOpened()) { wxMessageBox(_("Couldn't write to file: ") + mFileName); if (safetyFileName) wxRename(safetyFileName, mFileName); return; } f.AddLine("AudacityProject"); f.AddLine("Version"); f.AddLine(AUDACITY_FILE_FORMAT_VERSION); f.AddLine("projName"); f.AddLine(projName); f.AddLine("sel0"); f.AddLine(wxString::Format("%g", mViewInfo.sel0)); f.AddLine("sel1"); f.AddLine(wxString::Format("%g", mViewInfo.sel1)); f.AddLine("vpos"); f.AddLine(wxString::Format("%d", mViewInfo.vpos)); f.AddLine("h"); f.AddLine(wxString::Format("%g", mViewInfo.h)); f.AddLine("zoom"); f.AddLine(wxString::Format("%g", mViewInfo.zoom)); f.AddLine("rate"); f.AddLine(wxString::Format("%g", mRate)); f.AddLine("BeginTracks"); mTracks->Save(&f, overwrite); #ifdef __WXMAC__ f.Write(wxTextFileType_Mac); #else f.Write(); #endif f.Close(); #ifdef __WXMAC__ FSSpec spec; wxMacFilename2FSSpec(mFileName, &spec); FInfo finfo; if (FSpGetFInfo(&spec, &finfo) == noErr) { finfo.fdType = AUDACITY_PROJECT_TYPE; finfo.fdCreator = AUDACITY_CREATOR; FSpSetFInfo(&spec, &finfo); } #endif if (mLastSavedTracks) { mLastSavedTracks->Clear(true); delete mLastSavedTracks; } mLastSavedTracks = new TrackList(); TrackListIterator iter(mTracks); VTrack *t = iter.First(); while (t) { mLastSavedTracks->Add(t->Duplicate()); t = iter.Next(); } mStatus->SetField(wxString::Format(_("Saved %s"), (const char *) mFileName), 0); }
// returns number of tracks imported int Import(AudacityProject *project, wxString fName, WaveTrack *** tracks) { bool success; int numTracks = 0; DirManager *dirManager = project->GetDirManager(); wxWindow *parent = project; if (!fName.Right(3).CmpNoCase("aup")) { wxMessageBox("Audacity does not support importing Audacity Projects.\n" "Please use the Open command instead of Import.", "Import audio file", wxOK | wxCENTRE, parent); return 0; } if (!fName.Right(3).CmpNoCase("mid") || !fName.Right(3).CmpNoCase("midi")) { wxMessageBox("Please use the Import MIDI command instead.", "Import audio file", wxOK | wxCENTRE, parent); return 0; } bool isMP3 = false; if (!fName.Right(3).CmpNoCase("mp3") || !fName.Right(3).CmpNoCase("mp2") || !fName.Right(3).CmpNoCase("mpg") || !fName.Right(4).CmpNoCase("mpeg")) isMP3 = true; #ifdef __WXMAC__ FSSpec spec; FInfo finfo; wxMacFilename2FSSpec(fName, &spec); if (FSpGetFInfo(&spec, &finfo) == noErr) { if (finfo.fdType == 'MP3 ' || finfo.fdType == 'mp3 ' || finfo.fdType == 'MPG ' || finfo.fdType == 'MPG3' || finfo.fdType == 'MPEG') isMP3 = true; } #endif if (isMP3) { #ifdef MP3SUPPORT *tracks = new WaveTrack *[2]; success =::ImportMP3(project, fName, &(*tracks)[0], &(*tracks)[1]); if (!success) return 0; numTracks = 1; if ((*tracks)[1] != NULL) numTracks = 2; return numTracks; #else wxMessageBox("This version of Audacity was not compiled " "with MP3 support."); return 0; #endif } if (!fName.Right(3).CmpNoCase("ogg")) { #ifdef USE_LIBVORBIS success =::ImportOGG(parent, fName, tracks, &numTracks, dirManager); if (!success) return 0; return numTracks; #else wxMessageBox("This version of Audacity was not compiled " "with Ogg Vorbis support.", "Import Ogg Vorbis", wxOK | wxCENTRE, parent); return 0; #endif } if (::IsPCM(fName)) { *tracks = new WaveTrack *[2]; success =::ImportPCM(parent, fName, &(*tracks)[0], &(*tracks)[1], dirManager); if (!success) return 0; numTracks = 1; if ((*tracks)[1] != NULL) numTracks = 2; return numTracks; } int action = wxMessageBox("Audacity did not recognize the type " "of this file.\n" "Would you like to try to import it as " "raw PCM audio data?", "Unknown file type", wxYES_NO | wxICON_EXCLAMATION, parent); if (action == wxYES) { *tracks = new WaveTrack *[2]; success =::ImportRaw(parent, fName, &(*tracks)[0], &(*tracks)[1], dirManager); if (!success) return 0; numTracks = 1; if ((*tracks)[1] != NULL) numTracks = 2; return numTracks; } return 0; }