예제 #1
0
파일: tif_apple.c 프로젝트: BRAT-DEV/main
/*
 * 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);
}
예제 #2
0
파일: dosio.cpp 프로젝트: FREEWING-JP/np2pi
FILEH file_open_rb(const char *path) {

	FILEH	ret;
	FSSpec	fss;
	Str255	fname;

	mkstr255(fname, path);
	FSMakeFSSpec(0, 0, fname, &fss);
	if ((FSpOpenDF(&fss, fsRdWrShPerm, &ret) == noErr) ||
		(FSpOpenDF(&fss, fsRdPerm, &ret) == noErr)) {
		SetFPos(ret, fsFromStart, 0);
		return(ret);
	}
	return(-1);
}
예제 #3
0
/* convert icns(icons for MacOS X) to IPIcon */
OSErr	XIconToIPIcon(const FSSpec *theFile,IPIconRec *ipIcon)
{
	OSErr	err;
	IconFamilyHandle	theIconFamily;
	short		refNum;
	long		count;
	
	if (isIconServicesAvailable)
	{
		/* open icns file */
		err=FSpOpenDF(theFile,fsRdPerm,&refNum);
		if (err!=noErr) return err;
		
		err=GetEOF(refNum,&count);
		if (err!=noErr)
		{
			FSClose(refNum);
			return err;
		}
		theIconFamily=(IconFamilyHandle)NewHandle(count);
		HLock((Handle)theIconFamily);
		err=FSRead(refNum,&count,*theIconFamily);
		HUnlock((Handle)theIconFamily);
		
		err=FSClose(refNum);
		
		/* convert IconFamily to IPIcon */
		err=IconFamilyToIPIcon(theIconFamily,ipIcon);
		
		DisposeHandle((Handle)theIconFamily);
		return err;
	}
	else
		return -1;
}
예제 #4
0
/*
 * 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;
}
예제 #5
0
//***************************************************
//  Functions to navigate the storage medium itself
//  Modes exist for ANSI File I/O and Macintosh File I/O
//  If ANSI File I/O, lPointer is a pointer to a 
//  character string. If Macintosh File I/O, lPointer
//  is a pointer to the File System Specifier (FSSpec)
//  data structure.
//***************************************************
SHORT RIFFClass::RIFFOpen(void* lPointer)
{
  //***************************************************
  // Keep in mind that whenever a system call is made and
  // _no_ error takes place, errno is _not_ set to 0.
  // Obviously, this means that any previous system call
  // will set errno upon an error, one which is innocuous,
  // but will cause fopen to _appear_ as though it failed.
  // For example, open a temporary file which might not
  // exist:
  //
  //   fopen("tempfile", "wb");
  //
  // If it doesn't exist, errno become 2 (in DOS, at
  // least).  Now call the fopen below for a preexisting
  // RIFF file.  Guess what!  If you didn't reset errno
  // to 0, your return value will be 2, an apparent error.
  //***************************************************
  errno = 0;

  switch (byWhereIsRIFFData)
  {
    case RIFF_ONDISK:
      pFile = fopen((CHAR *)lPointer, "rb");
      return (errno);

  #ifdef USE_MACINTOSH
    case RIFF_ONMACDISK:
      return (FSpOpenDF((FSSpec *)lPointer, fsRdPerm, &fRefNum));
  #endif

    default:
      return (1);
  }
}
예제 #6
0
char * ReadDataFile (long * pBufferSize, FSSpec * pfsspecData)
{
	NavReplyRecord replyNav;
	NavTypeListHandle hTypeList = (NavTypeListHandle) NewHandleClear (sizeof (NavTypeList) + sizeof (OSType) * 1);
	AEKeyword theKeyword;
	DescType actualType;
	Size actualSize;
	OSStatus err = noErr;
    short fileRef;
    char * pFileBuffer;

	HLock ((Handle) hTypeList);
	(**hTypeList).osTypeCount = 2;
	(**hTypeList).osType[0] = 'TEXT';
	(**hTypeList).osType[1] = '????';

    // select sprite file
	err = NavChooseFile (NULL, &replyNav, NULL, NULL, NULL, NULL, hTypeList, NULL); 
	if ((err == noErr) && (replyNav.validRecord))
		err = AEGetNthPtr (&(replyNav.selection), 1, typeFSS, &theKeyword, &actualType,
						   pfsspecData, sizeof (FSSpec), &actualSize);
	NavDisposeReply (&replyNav);
	if (err != noErr)
		return false;
    FSpOpenDF(pfsspecData, fsRdPerm, &fileRef);
    GetEOF(fileRef, pBufferSize);
    pFileBuffer = (char *) NewPtrClear (*pBufferSize);
    FSRead (fileRef, pBufferSize, pFileBuffer);
    FSClose (fileRef);
	return pFileBuffer;
}
예제 #7
0
void open_shapes_file(
	FSSpec *spec)
{
	short refNum;
	OSErr error;
	
	error= FSpOpenDF(spec, fsRdPerm, &refNum);
	if (error==noErr)
	{
		long count= MAXIMUM_COLLECTIONS*sizeof(struct collection_header);
		
		FSRead(refNum, &count, (void *) &collection_headers);
		if (error==noErr)
		{
		}
		
		if (error!=noErr)
		{
			FSClose(refNum);
			refNum= -1;
		}

		close_shapes_file();		
		shapes_file_refnum= refNum;
	}
	
	return;
}
예제 #8
0
/*__________________________________________________________________________*/
Boolean SaveDriverState (short refnum, StringPtr file, OSType creator, OSType type)
{
	FSSpec spec; OSErr err; TDriverInfos dInfos;
	long size, dirID; short vrefNum, ref;
	Ptr ptr;
	
	if (FindMidiShareFolder (true, &vrefNum, &dirID) != noErr) return false;
	if (!MidiGetDriverInfos (refnum, &dInfos)) return false;

	size = Get1DriverStateSize (dInfos.slots);
	if (!size) return true;
	
	ptr = NewPtrSys(size);
	if (!ptr) return false;
		
	Get1DriverState (refnum, dInfos.slots, ptr, size);
	err = FSMakeFSSpec(vrefNum, dirID, file, &spec);
	if (err == fnfErr)
		err = FSpCreate (&spec, creator, type, smSystemScript);
	if (err != noErr) goto err;
		err = FSpOpenDF (&spec, fsWrPerm, &ref);
	if (err != noErr) goto err;
		err = FSWrite (ref, &size, ptr);
	FSClose (ref);
	DisposePtr (ptr);
	return err == noErr;

err:
	DisposePtr (ptr);
	return false;
}
예제 #9
0
OSErr PAS_encodeData(FSSpec *inFile, short outRefNum)
{
	OSErr 		err;	
	short		inRefNum;
	Ptr 		buffer;
	SInt32 		currentRead = 	PAS_BUFFER_SIZE;
		
	buffer	=	NewPtr(currentRead);

	err = FSpOpenDF(inFile, fsRdPerm, &inRefNum);
	if (err != noErr)	return err;
	
	while ( currentRead > 0 )
    {
		err	= FSRead( inRefNum, &currentRead, buffer);
		if (err != noErr && err != eofErr)	return err;
		
		err = FSWrite(outRefNum, &currentRead, buffer);
		if (err != noErr)	return err;
	}
	
	FSClose(inRefNum);
	
	DisposePtr(buffer);
	
	return noErr;
}
예제 #10
0
파일: FSpCompat.c 프로젝트: zv/metamage_1
pascal	OSErr	FSpOpenDFCompat(const FSSpec *spec,
                                char permission,
                                short *refNum)
{
#if !__MACOSSEVENORLATER
    if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() )
    {
        OSErr			result;
        HParamBlockRec	pb;

        pb.ioParam.ioVRefNum = spec->vRefNum;
        pb.fileParam.ioDirID = spec->parID;
        pb.ioParam.ioNamePtr = (StringPtr) &(spec->name);
        pb.ioParam.ioVersNum = 0;
        pb.ioParam.ioPermssn = permission;
        pb.ioParam.ioMisc = NULL;
        result = PBHOpenSync(&pb);	/* OpenDF not supported by System 6, so use Open */
        *refNum = pb.ioParam.ioRefNum;
        return ( result );
    }
    else
#endif	/* !__MACOSSEVENORLATER */
    {
        return ( FSpOpenDF(spec, permission, refNum) );
    }
}
예제 #11
0
unsigned long PAS_getDataSize(FSSpec *spec)
{
	short		refNum;
	OSErr		err;
	Str255 		temp;	
	CInfoPBRec 	cbrec;
	err = FSpOpenDF(spec, fsRdPerm, &refNum);

	memcpy( temp, spec->name, spec->name[0] + 1);

	cbrec.hFileInfo.ioNamePtr 		= temp;
	cbrec.hFileInfo.ioDirID 		= spec->parID;
	cbrec.hFileInfo.ioVRefNum 		= spec->vRefNum;
	cbrec.hFileInfo.ioFDirIndex     = 0;

	err = PBGetCatInfoSync(&cbrec);
	FSClose(refNum);
	
	if(err != noErr)
	{
		cbrec.hFileInfo.ioFlLgLen = err;
	}

	return (cbrec.hFileInfo.ioFlLgLen);
}
예제 #12
0
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);
}
예제 #13
0
void QTCmpr_PromptUserForDiskFileAndSaveCompressed (Handle theHandle, ImageDescriptionHandle theDesc)
{
	FSSpec				myFile;
	Boolean				myIsSelected = false;
	Boolean				myIsReplacing = false;	
	short				myRefNum = -1;
	StringPtr 			myImagePrompt = QTUtils_ConvertCToPascalString(kQTCSaveImagePrompt);
	StringPtr 			myImageFileName = QTUtils_ConvertCToPascalString(kQTCSaveImageFileName);
	OSErr				myErr = noErr;

	// do a little parameter checking....
	if ((theHandle == NULL) || (theDesc == NULL))
		goto bail;
		
	if ((**theDesc).dataSize > GetHandleSize(theHandle))
		goto bail;

	// prompt the user for a file to put the compressed image into; in theory, the name
	// should have a file extension appropriate to the type of compressed data selected by the user;
	// this is left as an exercise for the reader
	QTFrame_PutFile(myImagePrompt, myImageFileName, &myFile, &myIsSelected, &myIsReplacing);
	if (!myIsSelected)
		goto bail;

	HLock(theHandle);

	// create and open the file
	myErr = FSpCreate(&myFile, kImageFileCreator, (**theDesc).cType, 0);
	
	if (myErr == noErr)
		myErr = FSpOpenDF(&myFile, fsRdWrPerm, &myRefNum);
		
	if (myErr == noErr)
		myErr = SetFPos(myRefNum, fsFromStart, 0);

	// now write the data in theHandle into the file
	if (myErr == noErr)
		myErr = FSWrite(myRefNum, &(**theDesc).dataSize, *theHandle);
	
	if (myErr == noErr)
		myErr = SetFPos(myRefNum, fsFromStart, (**theDesc).dataSize);

	if (myErr == noErr)
		myErr = SetEOF(myRefNum, (**theDesc).dataSize);
				 
	if (myRefNum != -1)
		myErr = FSClose(myRefNum);
		
bail:
	free(myImagePrompt);
	free(myImageFileName);

	HUnlock(theHandle);
}
예제 #14
0
파일: dosio.cpp 프로젝트: FREEWING-JP/np2pi
FILEH file_create(const char *path) {

	FILEH	ret;
	FSSpec	fss;
	Str255	fname;
	OSType	creator = kUnknownType;
	OSType	fileType = kUnknownType;

	mkstr255(fname, path);
	FSMakeFSSpec(0, 0, fname, &fss);
	FSpDelete(&fss);

	if (FSpCreate(&fss, creator, fileType, smSystemScript) == noErr) {
		if ((FSpOpenDF(&fss, fsRdPerm | fsWrPerm, &ret) == noErr) ||
			(FSpOpenDF(&fss, fsRdPerm, &ret) == noErr)) {
			SetFPos(ret, fsFromStart, 0);
			return(ret);
		}
	}
	return(-1);
}
예제 #15
0
OSErr PAS_decodeData(PASEntry *entry, FSSpec *outFile, short inRefNum)
{
	OSErr 		err;	
	short		outRefNum;
	Ptr 		buffer;
	SInt32 		currentWrite = 	PAS_BUFFER_SIZE;
	SInt32		totalSize;
	
	
	buffer = NewPtr(currentWrite);
	
	
	err = FSpOpenDF(outFile, fsRdWrPerm, &outRefNum);
	if (err != noErr)	return err;
	
	
	err = SetFPos(inRefNum, fsFromStart, (*entry).entryOffset );
	if (err != noErr)	return err;
	
	err = SetFPos(outRefNum, fsFromStart, 0 );
	if (err != noErr)	return err;
	
	totalSize = (*entry).entryLength;
	
	while(totalSize > 0)
	{	
		currentWrite = PAS_BUFFER_SIZE;

		if (totalSize < currentWrite)
		{
			currentWrite = totalSize;
		}

		err	= FSRead( inRefNum, &currentWrite, buffer);
		if (err != noErr && err != eofErr)	return err;
	
		err = FSWrite(outRefNum, &currentWrite, buffer);
		if (err != noErr)	return err;
		
		totalSize = totalSize - currentWrite;

	}
	
	FSClose(outRefNum);
	
	DisposePtr(buffer);
	
	return noErr;

}
예제 #16
0
Boolean PIOpenFile (FSSpec& fsSpec, FileHandle *fRefNum, short *result)
{
	*fRefNum = 0;
	
	if (!TestAndStoreResult (result, FSpOpenDF (&fsSpec, fsCurPerm, fRefNum)))
	{
		FSpDelete (&fsSpec);
		return FALSE;
	}
	else
	{
		return TRUE;
	}	
}
예제 #17
0
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, &currentRead, &infoBlock);
	if (err != noErr)	return err;
		
	CloseResFile(inRefNum);
	
	return noErr;
}
예제 #18
0
파일: music.c 프로젝트: DrItanium/moo
/* If channel is null, we don't initialize */
boolean initialize_music_handler(
	FileDesc *song_file)
{
	short song_file_refnum;
	OSErr error;

	assert(music_state==NULL);
	assert(NUMBER_OF_SONGS==sizeof(songs)/sizeof(struct song_definition));
		
	/* Does the file exist? */
	error= FSpOpenDF((FSSpec *) song_file, fsRdPerm, &song_file_refnum);
	if(!error && song_file_refnum>0)
	{
		music_state= (struct music_data *) NewPtrClear(sizeof(struct music_data));
		if(music_state)
		{
			music_state->initialized= TRUE;
			music_state->flags= 0;
			music_state->state= _no_song_playing;
			music_state->phase= 0;
			music_state->song_index= 0;
			music_state->next_song_index= NONE;
			music_state->song_file_refnum= song_file_refnum;
			music_state->completion_proc= NewFilePlayCompletionProc(file_play_completion_routine);
			music_state->ticks_at_last_update= TickCount();

			/* Allocate our buffer */
			music_state->sound_buffer_size= kDefaultSoundBufferSize;
			music_state->sound_buffer= NULL;
			
//			music_state->sound_buffer= malloc(music_state->sound_buffer_size);
//			assert(music_state->sound_buffer);

			allocate_music_channel();

			assert(music_state->completion_proc);
			atexit(shutdown_music_handler);
		}
	}
	
	return (music_state!=NULL);
}
예제 #19
0
/* デバッグファイルを作成し、開く */
void CreateDebugFile(void)
{
	OSErr	err;
	FSSpec	spec;
	ProcessSerialNumber	psn;
	ProcessInfoRec		processInfo;
	
	/* アプリケーションの位置を記録 */
	err=GetCurrentProcess(&psn);
	processInfo.processInfoLength=sizeof(ProcessInfoRec);
	processInfo.processName=nil;
	processInfo.processAppSpec=&spec;
	err=GetProcessInformation(&psn,&processInfo);
	
	if (err!=noErr) return;
	
	PStrCpy(kDebugFileName,spec.name);
	
	#ifdef BACKUP_LOG
	{
		/* バックアップする */
		FSSpec	bSpec=spec;
		PStrCpy(kBDebugFileName,bSpec.name);
		
		err=FSpCreate(&bSpec,kDebugFileCreator,kDebugFileType,smSystemScript);
		
		err=FSpExchangeFiles(&spec,&bSpec);
	}
	#endif
	
	/* まず消す */
	err=FSpDelete(&spec);
	
	err=FSpCreate(&spec,kDebugFileCreator,kDebugFileType,smSystemScript);
	if (err!=noErr) return;
	
	err=FSpOpenDF(&spec,fsWrPerm,&debugFileRefNum);
	if (err!=noErr) return;
}
예제 #20
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;
}
예제 #21
0
bool
XMLMacCarbonFile::openWithPermission(const XMLCh* const fileName, int macPermission)
{
    OSErr err = noErr;

    if (mFileValid)
        ThrowXML1(XMLPlatformUtilsException, XMLExcepts::File_CouldNotOpenFile, fileName);

    if (gHasHFSPlusAPIs)
    {
        FSRef ref;
        if (!XMLParsePathToFSRef(fileName, ref))
            err = fnfErr;

        HFSUniStr255 forkName;
        if (err == noErr)
            err = FSGetDataForkName(&forkName);

        if (err == noErr)
            err = FSOpenFork(&ref, forkName.length, forkName.unicode, macPermission, &mFileRefNum);
    }
    else
    {
        FSSpec spec;
        if (!XMLParsePathToFSSpec(fileName, spec))
            err = fnfErr;

        if (err == noErr)
            err = FSpOpenDF(&spec, macPermission, &mFileRefNum);
    }

    if (err != noErr)
        ThrowXML1(XMLPlatformUtilsException, XMLExcepts::File_CouldNotOpenFile, fileName);

    mFileValid = true;
	return mFileValid;
}
예제 #22
0
/*__________________________________________________________________________*/
void RestoreDriverState	(short refnum, StringPtr file)
{
	long size, dirID; short vrefNum, ref; Ptr ptr;
	OSErr err; FSSpec spec; TDriverInfos dInfos;

	if (FindMidiShareFolder (false, &vrefNum, &dirID) != noErr) return;
	if (!MidiGetDriverInfos (refnum, &dInfos)) return;

	FSMakeFSSpec(vrefNum, dirID, file, &spec);
	err = FSpOpenDF (&spec, fsRdPerm, &ref);
	if (err != noErr) return;

	size = GetFileSize (&spec);
	if (size) {
		ptr = NewPtrSys (size);
		if (ptr) {
			err = FSRead (ref, &size, ptr);
			if (err == noErr)
				Set1DriverState (refnum, dInfos.slots, ptr, size);
			DisposePtr (ptr);
		}
	}
	FSClose (ref);
}
예제 #23
0
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;
	
	

}
예제 #24
0
OSErr PAS_DecodeFile(FSSpec *inSpec, FSSpec *outSpec)
{
	OSErr		err;
	short		inRefNum;
	
	PASHeader	header;
	
	PASEntry 	dataEntry, miscEntry, resourceEntry;
	long		sizeOfEntry;

	if (inSpec == NULL || outSpec == NULL)
		return paramErr;
		
		
	FSpDelete( outSpec ) ;
	
	err = FSpCreate( outSpec, kCreator, kType ,smSystemScript );
	
	if (err != noErr) 	return err;
	
	
	
	err = FSpOpenDF(inSpec, fsRdPerm, &inRefNum);
	
	if (err != noErr)  goto error;

	
	/* Read Header */
		
	err	= PAS_decodeHeader(inRefNum, &header);
	if (err != noErr)  goto error;
	
	if(	header.magicNum != PAS_MAGIC_NUM ||
		header.versionNum != PAS_VERSION)
	{
		err = -1;
		goto error;
	}
	
	
	
	/* Read Data Entry */
	
	
	err = SetFPos(inRefNum, fsFromStart, sizeof(PASHeader));
	if (err != noErr) 	goto error;
	
	sizeOfEntry			=	sizeof(PASEntry);

	err = FSRead(inRefNum, &sizeOfEntry, &dataEntry);
	if (err != noErr) 	goto error;
	
	
	
	
	/* Read Misc Entry */
	
	
	err = SetFPos(inRefNum, fsFromStart, (sizeof(PASHeader) + sizeof(PASEntry)));
	if (err != noErr) 	goto error;
	
	sizeOfEntry			=	sizeof(PASEntry);

	err = FSRead(inRefNum, &sizeOfEntry, &miscEntry);
	if (err != noErr) 	goto error;
	

	/* Read Resource Entry */
	
	
	err = SetFPos(inRefNum, fsFromStart, (sizeof(PASHeader) + (2 * sizeof(PASEntry)))) ;
	if (err != noErr) 	goto error;
	
	sizeOfEntry			=	sizeof(PASEntry);

	err = FSRead(inRefNum, &sizeOfEntry, &resourceEntry);
	if (err != noErr) 	goto error;





	err =  PAS_decodeData(&dataEntry, outSpec, inRefNum);	
	if (err != noErr) 	goto error;

	err =  PAS_decodeMisc(&miscEntry, outSpec, inRefNum);
	if (err != noErr) 	goto error;

	err =  PAS_decodeResource(&resourceEntry, outSpec, inRefNum);	
	if (err == kResFileNotOpened)
	{
		// there was no resource fork
		err = noErr;
	}
	else if (err != noErr)
	{
		goto error;
	}

	
	FSClose(inRefNum);
	
	return noErr;
	
	
	
error:

	if (inRefNum != kResFileNotOpened)
	{
		FSClose(inRefNum);
	}
		
	FSpDelete( outSpec ) ;
	
	return err;
	
}
예제 #25
0
파일: file.c 프로젝트: forostm/libecw
NCSError NCSFileOpen(const NCSTChar *szFilename, int iFlags, NCS_FILE_HANDLE *phFile)
{
#ifdef WIN32
	DWORD dwMode = GENERIC_READ;
	DWORD dwCreate = OPEN_EXISTING;

	if(iFlags & NCS_FILE_READ) dwMode = GENERIC_READ;
	if(iFlags & NCS_FILE_READ_WRITE) dwMode = GENERIC_READ|GENERIC_WRITE;
	if(iFlags & NCS_FILE_CREATE) dwCreate = CREATE_ALWAYS;
	if(iFlags & NCS_FILE_CREATE_UNIQUE) dwCreate = CREATE_NEW;
	if(iFlags & NCS_FILE_APPEND) dwCreate = OPEN_ALWAYS;

	*phFile = CreateFile(szFilename,			        // file name
						 dwMode,						// Generic read mode 
						 FILE_SHARE_READ,				// Let anyone access and share the file
						 NULL,							// No security info (so can't be inherited by child process)
						 dwCreate,						// File must exist to be opened
						 FILE_FLAG_RANDOM_ACCESS,		// Going to be doing lots of random access
						 NULL);							// And no template file for attributes
	if( *phFile == INVALID_HANDLE_VALUE ) {
		return( NCS_FILE_OPEN_FAILED );
	} else {
		return( NCS_SUCCESS );
	}

#elif defined MACINTOSH
#if __POWERPC__
	
	int i,length, result;
	Str255		pascalString;
	FSSpec		fileSpec;
		//	We have a C string, we need a PASCAL string.
	length = strlen(szFilename) + 1;
	for(i = 1; i < length; ++i)
		pascalString[i] = szFilename[i - 1];
	pascalString[0] = strlen(szFilename);
			
	//	Create a File Specification Record, then create a File
	result = FSMakeFSSpec(0,0,pascalString,&fileSpec);	// return is meaningless, since the only possible error doesn't effect processing in this case
			
	switch(result) {
		case noErr:
				// we could dRes pFile here, but we are the only user
				result =FSpOpenDF(&fileSpec, fsRdPerm, (short *)phFile);
				if(result) return NCS_FILE_OPEN_FAILED;
				else return NCS_SUCCESS;
			break;
		default:
			    return NCS_SUCCESS;
		    break;
	}

#else	/* __POWERPC__ */

	int i,length, result;
	Str255		pascalString;
	//	We have a C string, we need a PASCAL string.
	length = strlen(szFilename) + 1;
	for(i = 1; i < length; ++i)
		pascalString[i] = szFilename[i - 1];
	pascalString[0] = strlen(szFilename);
		
	result =FSOpen(pascalString, 0, (short *)phFile);
	if(result) return TRUE;
	else return FALSE;

#endif	/* __POWERPC__ */
#elif defined PALM

	NCS_FILE_HANDLE hFile;
	Err eErr;
	UInt32 nMode = 0;
	
	if(hFile = (NCS_FILE_HANDLE)NCSMalloc(sizeof(NCS_FILE_HANDLE_STRUCT), TRUE)) {
		hFile->dbID = DmFindDatabase(0, szFilename);
		
		if(hFile->dbID) {
	   		Char nameP[dmDBNameLength];
	   		UInt16 attributes;
	   		UInt16 version;
	   		UInt32 crDate;
	   		UInt32 modDate;
	   		UInt32 bckUpDate;
	   		UInt32 modNum;
	   		LocalID appInfoID;
	   		LocalID sortInfoID;
	   		UInt32 type;
	   		UInt32 creator;
					
	   		DmDatabaseInfo(0, hFile->dbID, nameP,
	   					   &attributes, 
	   					   &version,
	   					   &crDate,
	   					   &modDate,
	   					   &bckUpDate,
	   					   &modNum,
	   					   &appInfoID,
	   					   &sortInfoID,
	   					   &type,
	   					   &creator);
	   					   
	   		if(creator == NCS_PALM_CREATOR_ID) {
	   			if(hFile->dbRef = DmOpenDatabase(0, hFile->dbID, dmModeReadOnly|dmModeShowSecret)) {
	   				UInt32 nRecords;
	   				UInt32 nTotalBytes;
	   				UInt32 nDataBytes;
	   				
	   				eErr = DmDatabaseSize(0, hFile->dbID, &nRecords, &nTotalBytes, &nDataBytes);
	   				
	   				if(eErr == errNone) {
	   					MemHandle hRecord;
	   					
	   					hFile->nRecords = nRecords;
	   					hFile->nDBSize = nDataBytes;
#ifdef NOTDEF	   					
	   					if(hRecord = DmGetRecord(hFile->dbRef, 0)) {
	   						MemPtr pData;
	   						
							if(pData = MemHandleLock(hRecord)) {
								hFile->nRecordSize = ((UINT16*)pData)[0];
							
								MemHandleUnlock(hRecord);
							}
							DmReleaseRecord(hFile->dbRef, 0, false);
						}
#endif
						*phFile = hFile;
						return(NCS_SUCCESS);
	   				}
	   				DmCloseDatabase(hFile->dbRef);
	   				return(NCSPalmGetNCSError(eErr));
	   			}
	   		}
		}
	} else {
		return(NCS_COULDNT_ALLOC_MEMORY);
	}
/*	
	if(iFlags & NCS_FILE_READ) nMode = fileModeReadOnly|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_READ_WRITE) nMode = fileModeUpdate|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_CREATE) nMode = fileModeReadWrite|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_CREATE_UNIQUE) nMode = fileModeReadWrite|fileModeDontOverwrite|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_APPEND) nMode = fileModeAppend|fileModeAnyTypeCreator;
	
	*phFile = FileOpen(0, (char*)szFilename, 0, 0, nMode, &eErr);
	
	return(NCSPalmGetNCSError(eErr));			   
*/					
#elif defined(POSIX)

	int flags = O_RDONLY;

	if(iFlags & NCS_FILE_READ) flags = O_RDONLY;
	if(iFlags & NCS_FILE_READ_WRITE) flags = O_RDWR;
	if(iFlags & NCS_FILE_CREATE) flags |= O_CREAT;
	if(iFlags & NCS_FILE_CREATE_UNIQUE) flags |= O_CREAT|O_EXCL;
	if(iFlags & NCS_FILE_APPEND) flags |= O_APPEND;

#if defined SOLARIS || (defined(HPUX) && !defined(__LP64__))
	// Enable 64bit!
	flags |= O_LARGEFILE;
#endif

#ifdef HPUX
	*phFile = open64((const char*)CHAR_STRING(szFilename), (int)flags);

#ifdef NOTDEF
	if (*phFile < 0) {
		fprintf(stderr, "Error opening file : %ld\n", errno); 
		if (errno == EOVERFLOW) {
			fprintf(stderr, "The named file is a regular file and the size "
                          "of the file cannot be represented correctly in an object of "
                          "size off_t.");
		}
	}
#endif

#else
	*phFile = open((const char*)CHAR_STRING(szFilename), (int)flags, S_IRUSR|S_IWUSR);
#endif
	if(*phFile != -1) {
		return(NCS_SUCCESS);
	} else {
		return(NCS_FILE_OPEN_FAILED);
	}

#else	/* SOLARIS||IRIX */
#error ERROR  EcwFileCreate() routine is not defined for this platform
#endif	/* WIN32 */
}
예제 #26
0
void saveToPICTFile()
{

/*
Saving a PixMap as a PICT file isn't too hard.

1.  Open a Picture with the port set to the destination of #2.
2.  CopyBits the PixMap onto itself or another port.  (Because CopyBits is
recorded in Pictures.
3.  Close the picture.
4.  Open the data fork for the file.
5.  Write out 512 bytes of zeros followed by the contents of the Picture
handle.
6.  Close the file.
*/

	PicHandle			picHandle;
	OSErr				anErr = noErr;
	OSType              fileTypeToSave = 'PICT';
    OSType              creatorType = 'ogle';
    NavReplyRecord      reply;
    NavDialogOptions    dialogOptions;
    FSSpec      		documentFSSpec;
    long				inOutCount;
    short				refNum, count;
    AEKeyword   		theKeyword;
    DescType    		actualType;
	unsigned char 		header[512];
	Size        		actualSize;
	Rect				tempRect1;
	
	CopyBits(GetPortBitMapForCopyBits(GetWindowPort(FrontWindow())), (BitMap*) &gPixMap, 
	 GetPortBounds(GetWindowPort(gWindow), &tempRect1), &gPixMap.bounds, srcCopy, 0L);
	
	SetPortWindowPort(gWindow);
	
	picHandle = OpenPicture(&gPixMap.bounds);
	
	CopyBits((BitMap*) &gPixMap, GetPortBitMapForCopyBits(GetWindowPort(FrontWindow())), &gPixMap.bounds, 
	 GetPortBounds(GetWindowPort(gWindow), &tempRect1), srcCopy, 0L);
	 
	ClosePicture();

    for (count = 0; count < 512; count++)
		header[count] = 0x00;

    anErr = NavGetDefaultDialogOptions(&dialogOptions); 
    dialogOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
    
    anErr = NavPutFile( nil, 
    					&reply, 
    					&dialogOptions, 
    					nil,
                        fileTypeToSave, 
                        creatorType, 
                        nil );

	if (anErr == noErr && reply.validRecord) {
		anErr = AEGetNthPtr(&(reply.selection), 1, typeFSS,
                                &theKeyword, &actualType,
                                &documentFSSpec, sizeof(documentFSSpec),
                                &actualSize );
    if (anErr == noErr) {
  	  
  	  		anErr = FSpCreate(&documentFSSpec, creatorType, fileTypeToSave, smSystemScript);
			if (anErr == dupFNErr) {
				anErr = FSpDelete(&documentFSSpec);
				anErr = FSpCreate(&documentFSSpec, creatorType, fileTypeToSave, smSystemScript);
			}		// this is quick 'n' dirty or there'd be more robust handling here
			
    		// write the file
    		FSpOpenDF(&documentFSSpec, fsRdWrPerm, &refNum );
    		inOutCount = 512;
   			anErr = FSWrite(refNum, &inOutCount, header);		// write the header
    		if (anErr == noErr) {
    			inOutCount = GetHandleSize((Handle)picHandle);
				anErr = FSWrite(refNum,&inOutCount,*picHandle);
    		}
    		FSClose( refNum );
  	  }
  	  reply.translationNeeded = false;
  	  anErr = NavCompleteSave(&reply, kNavTranslateInPlace);
    
 	  NavDisposeReply(&reply);
    }
	
	KillPicture(picHandle);
}
예제 #27
0
OSErr
IsFlattenedResourceFile(
	ConstFSSpecPtr	inFile,
	Boolean*		outIsFlat)
{
	OSErr		err;
	CInfoPBRec	pb;
	
	if (not inFile)
	{
		// This can occur when we create a new project document (Cmd-N)
		*outIsFlat = false;
		return noErr;
	}

	pb.hFileInfo.ioNamePtr = (StringPtr)inFile->name;
	pb.hFileInfo.ioVRefNum = inFile->vRefNum;
	pb.hFileInfo.ioDirID = inFile->parID;
	pb.hFileInfo.ioFDirIndex = 0;

	err = PBGetCatInfoSync(&pb);
	if (err == noErr)
	{
		if (pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask)
		{
			// This is a directory
			*outIsFlat = false;
			return paramErr;
		}
		else
		{
			UInt32	dfSize;
			UInt32	rfSize;
			SInt16	dfRefNum;
			SInt32	filePos;
			
			dfSize = pb.hFileInfo.ioFlLgLen;
			rfSize = pb.hFileInfo.ioFlRLgLen;
			
			if (rfSize > 0)
			{
				*outIsFlat = false;
			}
			else if (dfSize == 0)
			{
				// This file has no data or resource fork.
				*outIsFlat = false;
			}
			else
			{
				// Only the data fork is non-empty.
				// Now we need to determine if it contains resources or not.
				UInt32	firstFourWords[4];
				SInt32	byteCount;
				
				err = FSpOpenDF(inFile, fsRdPerm, &dfRefNum);
				if (err)	return err;
				
				err = GetFPos(dfRefNum, &filePos);
				
				byteCount = sizeof(firstFourWords);

				err = FSRead(dfRefNum, &byteCount, &firstFourWords);
				if (err == noErr)
				{
					// Test is based on resource file format as described in IM: More Mac Toolbox
					// <http://developer.apple.com/techpubs/mac/MoreToolbox/MoreToolbox-99.html#HEADING99-0>
					//
					// First four words of the file represent the resource header
					// Word1:  Offset from beginning of resource fork to resource data
					// Word2:  Offset from beginning of resource fork to resource map
					// Word3:  Length of resource data
					// Word4:  Length of resource map
					//
					// So...
					// (Word1 + Word3 + Word4) == (Word2 + Word4) == size of resource fork

					if ((byteCount == sizeof(firstFourWords)) and
						(EndianU32_BtoN(firstFourWords[0]) + EndianU32_BtoN(firstFourWords[2]) +
						 EndianU32_BtoN(firstFourWords[3]) == dfSize) and
						(EndianU32_BtoN(firstFourWords[1]) + EndianU32_BtoN(firstFourWords[3]) == dfSize))
					{
						*outIsFlat = true;
					}
				}
				
				err = SetFPos(dfRefNum, fsFromStart, filePos);

				err = FSClose(dfRefNum);
			}
		}
	}
	
	return err;
}
예제 #28
0
OSErr PAS_EncodeFile(FSSpec *inSpec, FSSpec *outSpec)
{
	OSErr		err;
	short		outRefNum;
	
	PASEntry 	dataEntry, miscEntry, resourceEntry;
	long		sizeOfEntry;


	if (inSpec == NULL || outSpec == NULL)
		return paramErr;
		

	memset(&dataEntry, 0, sizeof(PASEntry));
	memset(&miscEntry, 0, sizeof(PASEntry));
	memset(&resourceEntry, 0, sizeof(PASEntry));
	
	FSpDelete( outSpec ) ;
	
	err = FSpCreate( outSpec, kCreator, kType ,smSystemScript );
	
	if (err != noErr) 	return err;
	
	
	err = FSpOpenDF(outSpec, fsRdWrPerm, &outRefNum);
	
	if (err != noErr)  goto error;
	

	/* Write Out Header */
		
	err = PAS_encodeHeader(outRefNum);
	if (err != noErr)  goto error;
	
	/* Why am I using three (3)?
		
		E stand for entry.
		
	   The data for the entry is after the THREE headers 
	
		|---------|----|----|----|---------------------->
		   header    E    E    E
	
	*/
	
	
	/* Write Out Data Entry */
	dataEntry.entryID		=	ePas_Data;
	dataEntry.entryLength	=	PAS_getDataSize(inSpec);
	dataEntry.entryOffset	=	sizeof(PASHeader) + (3 * sizeof(PASEntry));
	
	sizeOfEntry			=	sizeof(PASEntry);
	if(dataEntry.entryLength < 0)
	{
		err	= dataEntry.entryLength;
		goto error;
	}
	
	err = FSWrite(outRefNum, &sizeOfEntry, &dataEntry);
	if (err != noErr) 	goto error;
	
	
	
	/* Write Out Misc Entry */
	miscEntry.entryID		=	ePas_Misc;
	miscEntry.entryLength	=	sizeof(PASMiscInfo);
	miscEntry.entryOffset	=	sizeof(PASHeader) + (3 * sizeof(PASEntry)) + dataEntry.entryLength;

	sizeOfEntry			=	sizeof(PASEntry);
	err = FSWrite(outRefNum, &sizeOfEntry, &miscEntry);
	if (err != noErr) 	goto error;
	
	
	/* Write Out Resource Entry */
	resourceEntry.entryID		=	ePas_Resource;
	resourceEntry.entryLength	=	-1;
	resourceEntry.entryOffset	=	sizeof(PASHeader) + (3 * sizeof(PASEntry)) + dataEntry.entryLength + miscEntry.entryLength;


	sizeOfEntry			=	sizeof(PASEntry);
	err = FSWrite(outRefNum, &sizeOfEntry, &resourceEntry);
	if (err != noErr) 	goto error;
	
	err =  PAS_encodeData(inSpec, outRefNum);	
	if (err != noErr) 	goto error;
	
	
	err =  PAS_encodeMisc(inSpec, outRefNum);	
	if (err != noErr) 	goto error;
	
	err =  PAS_encodeResource(inSpec, outRefNum);	
	
	if (err == kResFileNotOpened)
	{
		// there was no resource fork
		err = noErr;
	}
	else if (err != noErr)
	{
		goto error;
	}
		
	FSClose(outRefNum);
	
	return noErr;
	
	
	
error:
		
		
	if (outRefNum != kResFileNotOpened)
	{
		FSClose(outRefNum);
	}
		
	FSpDelete( outSpec ) ;
	 
	return err;

}
예제 #29
0
OSErr PAS_decodeMisc(PASEntry *entry, FSSpec *outFile, short inRefNum)
{
	OSErr 		err = noErr;	
	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 outRefNum;
			}
		}
		
		SetResFileAttrs(outRefNum, info.fileResAttrs);
		
		
		CloseResFile(outRefNum);
	}	
	
	
	if(info.fileType == 'APPL')
	{
		// we need to add applications to the desktop database.
		
/*	FIX :: need to find DTSetAPPL() function	
		err = DTSetAPPL( NULL,
                    	 outFile->vRefNum,
			             info.fileCreator,
			             outFile->parID,
                         outFile->name);
*/	}
	
	
	return err;
	
	

}
예제 #30
0
static OSErr mainQTInst(void					*unused,
						OSType					order,				// Order to execute
						InstrData				*InsHeader,			// Ptr on instrument header
						sData					**sample,			// Ptr on samples data
						short					*sampleID,			// If you need to replace/add only a sample, not replace the entire instrument (by example for 'AIFF' sound)
																	// If sampleID == -1 : add sample else replace selected sample.
						CFURLRef				AlienFileURLRef,	// IN/OUT file
						PPInfoPlug				*thePPInfoPlug)
{
	MADErr		myErr = MADNoErr;
	FSIORefNum	iFileRefI = -1;
	ByteCount	inOutBytes;
	FSSpec		tmpSpec;
	OSErr		QTErr = noErr;
	
	myErr = CFURLToFSSpec(AlienFileURLRef, &tmpSpec);
	switch (myErr) {
		case memFullErr:
			return MADNeedMemory;
			break;
			
		default:
		case fnfErr:
			return order == MADPlugExport ? MADWritingErr : MADReadingErr;
			break;
						
		case noErr:
			break;
	}
	
	switch (order) {
		case MADPlugPlay:
			break;
			
		case MADPlugImport:
		{
			Ptr				theSound;
			int				lS, lE;
			short			sS;
			unsigned long	rate;
			bool			stereo;
			FSSpec			newFile;
			
			myErr = ConvertDataToWAVE(tmpSpec, &newFile, thePPInfoPlug);
			if (myErr == noErr) {
				theSound = ConvertWAV(&newFile, &lS, &lE, &sS, &rate, &stereo);
				
				if (theSound) {
					long sndSize = GetPtrSize(theSound);
					Ptr newSound = malloc(sndSize);
					memcpy(newSound, theSound, sndSize);
					DisposePtr(theSound);
					myErr = inAddSoundToMAD(newSound, sndSize, lS, lE, sS, 60, rate, stereo, newFile.name, InsHeader, sample, sampleID);
				} else {
					myErr = MADNeedMemory;
				}
				
				FSpDelete(&newFile);
			}
		}
			break;
			
		case MADPlugTest:
		{
			Boolean canOpenAsMovie = false;
			FInfo fInfo;
			
			FSpGetFInfo(&tmpSpec, &fInfo);
			QTErr = CanQuickTimeOpenFile(&tmpSpec, fInfo.fdType, 0, NULL, &canOpenAsMovie, NULL, 0);
			if (QTErr == noErr && canOpenAsMovie == true) {
				myErr = MADNoErr;
			} else {
				myErr = MADIncompatibleFile;
			}
		}
			break;
			
		case MADPlugExport:
			if (*sampleID >= 0) {
				OSType			compType = 'NONE';
				unsigned long	rate;
				sData 			*curData = sample[*sampleID];
				short			numChan;
				
				FSpDelete(&tmpSpec);
				myErr = FSpCreate(&tmpSpec, 'TVOD', 'AIFF', smCurrentScript);
				if(myErr == noErr)
					myErr = FSpOpenDF(&tmpSpec, fsCurPerm, &iFileRefI);
				
				if (myErr == noErr) {
					inOutBytes 	= curData->size;
					rate		= curData->c2spd;
					
					if (curData->stereo)
						numChan = 2;
					else
						numChan = 1;
					
					myErr = SetupAIFFHeader(iFileRefI, numChan, rate << 16L, curData->amp, compType, inOutBytes, 0);
					
					if(myErr == noErr)
						myErr = FSWriteFork(iFileRefI, fsAtMark, 0, inOutBytes, curData->data, &inOutBytes);
					FSCloseFork(iFileRefI);
				}
			}
			break;
			
		default:
			myErr = MADOrderNotImplemented;
			break;
	}
	
	return myErr;
}