int __PHYSFS_platformClose(void *opaque) { SInt16 ref = *((SInt16 *) opaque); SInt16 vRefNum; Str63 volName; int flushVol = 0; if (GetVRefNum(ref, &vRefNum) == noErr) { HParamBlockRec hpbr; memset(&hpbr, '\0', sizeof (HParamBlockRec)); hpbr.volumeParam.ioNamePtr = volName; hpbr.volumeParam.ioVRefNum = vRefNum; hpbr.volumeParam.ioVolIndex = 0; if (PBHGetVInfoSync(&hpbr) == noErr) flushVol = 1; } /* if */ BAIL_IF_MACRO(oserr(FSClose(ref)) != noErr, NULL, 0); free(opaque); if (flushVol) FlushVol(volName, vRefNum); /* update catalog info, etc. */ return(1); } /* __PHYSFS_platformClose */
int asyncFileClose(AsyncFile *f) { /* Close the given asynchronous file. */ AsyncFileState *state; short int volRefNum; OSErr err; if (!asyncFileValid(f)) return 0; /* already closed */ state = f->state; err = GetVRefNum(state->refNum, &volRefNum); success(err == noErr); err = FSClose(state->refNum); success(err == noErr); if (!interpreterProxy->failed()) err = FlushVol(NULL, volRefNum); success(err == noErr); if (asyncFileCompletionProc != nil) DisposeIOCompletionUPP(asyncFileCompletionProc); asyncFileCompletionProc = nil; if (state->bufferPtr != nil) DisposePtr(state->bufferPtr); DisposePtr((void *) f->state); f->state = nil; f->sessionID = 0; return 0; }
int fflush(FILE * file) { fpos_t position; /* mm 970708 */ ParamBlockRec pb; OSErr error; if (!file) return(__flush_all()); if (file->state.error || file->mode.file_kind == __closed_file) return(EOF); if (file->mode.io_mode == __read) /* mm 980430 */ return 0; /* mm 980430 */ if (file->state.io_state >= __rereading) file->state.io_state = __reading; if (file->state.io_state == __reading) file->buffer_len = 0; if (file->state.io_state != __writing) { file->state.io_state = __neutral; /* mm 970905 */ return(0); } #ifndef _No_Disk_File_OS_Support if (file->mode.file_kind != __disk_file || (position = ftello(file)) < 0) position = 0; #else position = 0; #endif if (__flush_buffer(file, NULL)) { set_error(file); return(EOF); } file->state.io_state = __neutral; file->position = position; file->buffer_len = 0; pb.ioParam.ioRefNum = file->handle; error = PBFlushFileSync(&pb); error = GetVRefNum(pb.ioParam.ioRefNum,&pb.volumeParam.ioVRefNum); pb.volumeParam.ioNamePtr = nil; error = PBFlushVolSync(&pb); return(0); }
// ------------------------------------------------------------------------- // // * ToFrame( void ) // ------------------------------------------------------------------------- // TDCLNSRef TDCLMacFile::ToFrame( void ) { TDCLNSRef theSegment = TDCLFile::ToFrame(); if (IsOnDesktop()) { // Nous sommes sur le bureau. TDCLNSFrame& theSegmentAsFrame = theSegment.ToFrame(); // Ajout du volume. theSegmentAsFrame.Set( "whichVol", TDCLNSRef::MakeInt( GetVRefNum() ) ); } return theSegment; }
OSErr QTInfo_MakeFilePreview (Movie theMovie, short theRefNum, ICMProgressProcRecordPtr theProgressProc) { unsigned long myModDate; PreviewResourceRecord myPNOTRecord; long myEOF; long mySize; unsigned long myAtomHeader[2]; // an atom header: size and type OSType myPreviewType; OSErr myErr = noErr; ////////// // // determine whether theRefNum is a file reference number of a data fork or a resource fork; // if it's a resource fork, then we'll just call the existing ICM function MakeFilePreview // ////////// if (QTInfo_IsRefNumOfResourceFork(theRefNum)) { myErr = MakeFilePreview(theRefNum, theProgressProc); goto bail; } ////////// // // determine the preview type // ////////// // if the movie has a movie preview, use that as the file preview; otherwise use a thumbnail // of the movie poster frame as the file preview if (QTInfo_MovieHasPreview(theMovie)) myPreviewType = MovieAID; else myPreviewType = kQTFileTypePicture; ////////// // // construct the 'pnot' atom // ////////// // fill in the 'pnot' atom header myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + sizeof(myPNOTRecord)); myAtomHeader[1] = EndianU32_NtoB(ShowFilePreviewComponentType); // fill in the 'pnot' atom data GetDateTime(&myModDate); myPNOTRecord.modDate = EndianU32_NtoB(myModDate); // the modification time of the preview myPNOTRecord.version = EndianS16_NtoB(0); // version number; must be 0 myPNOTRecord.resType = EndianU32_NtoB(myPreviewType); // atom type containing preview myPNOTRecord.resID = EndianS16_NtoB(1); // the 1-based index of the atom of the specified type to use ////////// // // write the 'pnot' atom at the end of the data fork // ////////// // get the current logical end-of-file and extend it by the desired amount myErr = GetEOF(theRefNum, &myEOF); if (myErr != noErr) goto bail; myErr = SetEOF(theRefNum, myEOF + sizeof(myAtomHeader) + sizeof(myPNOTRecord)); if (myErr != noErr) goto bail; // set the file mark myErr = SetFPos(theRefNum, fsFromStart, myEOF); if (myErr != noErr) goto bail; // write the atom header into the file mySize = sizeof(myAtomHeader); myErr = FSWrite(theRefNum, &mySize, myAtomHeader); if (myErr != noErr) goto bail; // write the atom data into the file mySize = sizeof(myPNOTRecord); myErr = FSWrite(theRefNum, &mySize, &myPNOTRecord); if (myErr != noErr) goto bail; ////////// // // write the preview data atom at the end of the data fork // ////////// if (myPreviewType == MovieAID) { // in theory, we don't need to do anything here, since our 'pnot' atom points // to the 'moov' atom; in practice, this doesn't work correctly (it seems like // a bug in StandardGetFilePreview) } if (myPreviewType == kQTFileTypePicture) { PicHandle myPicture = NULL; PicHandle myThumbnail = NULL; // get the poster frame picture myPicture = GetMoviePosterPict(theMovie); if (myPicture != NULL) { // create a thumbnail myThumbnail = (PicHandle)NewHandleClear(4); if (myThumbnail != NULL) { myErr = MakeThumbnailFromPicture(myPicture, 0, myThumbnail, theProgressProc); if (myErr == noErr) { myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + GetHandleSize((Handle)myThumbnail)); myAtomHeader[1] = EndianU32_NtoB(myPreviewType); // write the atom header into the file mySize = sizeof(myAtomHeader); myErr = FSWrite(theRefNum, &mySize, myAtomHeader); if (myErr == noErr) { // write the atom data into the file mySize = GetHandleSize((Handle)myThumbnail); myErr = FSWrite(theRefNum, &mySize, *myThumbnail); } } KillPicture(myThumbnail); } KillPicture(myPicture); } } #if 0 // here's how you'd add a text preview; note that the text is hard-coded here.... if (myPreviewType == kQTFileTypeText) { char myText[] = "The penguin gradually appears from the mist of the ice floe."; myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + strlen(myText)); myAtomHeader[1] = EndianU32_NtoB(myPreviewType); // write the atom header into the file mySize = sizeof(myAtomHeader); myErr = FSWrite(theRefNum, &mySize, myAtomHeader); if (myErr != noErr) goto bail; // write the atom data into the file mySize = strlen(myText); myErr = FSWrite(theRefNum, &mySize, myText); if (myErr != noErr) goto bail; } #endif #if TARGET_OS_MAC if (myErr == noErr) { short myVolNum; // flush the volume myErr = GetVRefNum(theRefNum, &myVolNum); if (myErr != noErr) goto bail; myErr = FlushVol(NULL, myVolNum); } #endif bail: return(myErr); }