Пример #1
0
static pascal ComponentResult myDataHGetFileName ( DataHandler dh, Str255 str)
{
    Handle storage = GetComponentInstanceStorage(dh);
    DHData *data = (DHData*)*storage;
    TRACE("%p %s\n",str,debugstr_guid(&data->dataRef.streamSubtype));

    /* Todo Expand this list */
    if (IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_MPEG1Video) ||
        IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_MPEG1System))
        CFStringGetPascalString(CFSTR("video.mpg"),str,256,kCFStringEncodingMacRoman);
    else if(IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_Asf))
        CFStringGetPascalString(CFSTR("video.asf"),str,256,kCFStringEncodingMacRoman);
    else if(IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_Avi))
        CFStringGetPascalString(CFSTR("video.avi"),str,256,kCFStringEncodingMacRoman);
    else if(IsEqualIID(&data->dataRef.streamSubtype, &MEDIASUBTYPE_QTMovie))
        CFStringGetPascalString(CFSTR("video.mov"),str,256,kCFStringEncodingMacRoman);
    else
    {
        BYTE header[10] = {0,0,0,0,0,0,0,0,0,0};
        int i;
        IAsyncReader_SyncRead(data->dataRef.pReader, 0, 8, header);

        for (i=0; i < sizeof(stream_sigs)/sizeof(signature); i++)
            if (memcmp(header, stream_sigs[i].sig, stream_sigs[i].sig_length)==0)
            {
                str[0] = strlen(stream_sigs[i].fname);
                memcpy(str + 1, stream_sigs[i].fname, str[0]);
                return noErr;
            }

        return badComponentSelector;
    }

    return noErr;
}
Пример #2
0
void qt_mac_to_pascal_string(const QString &s, Str255 str, TextEncoding encoding, int len)
{
    if(len == -1)
        len = s.length();
#if 0
    UnicodeMapping mapping;
    mapping.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault,
                                                 kTextEncodingDefaultVariant,
                                                 kUnicode16BitFormat);
    mapping.otherEncoding = (encoding ? encoding : );
    mapping.mappingVersion = kUnicodeUseLatestMapping;

    UnicodeToTextInfo info;
    OSStatus err = CreateUnicodeToTextInfo(&mapping, &info);
    if(err != noErr) {
        qDebug("Qt: internal: Unable to create pascal string '%s'::%d [%ld]",
               s.left(len).latin1(), (int)encoding, err);
        return;
    }
    const int unilen = len * 2;
    const UniChar *unibuf = (UniChar *)s.unicode();
    ConvertFromUnicodeToPString(info, unilen, unibuf, str);
    DisposeUnicodeToTextInfo(&info);
#else
    Q_UNUSED(encoding);
    CFStringGetPascalString(QCFString(s), str, 256, CFStringGetSystemEncoding());
#endif
}
Пример #3
0
void DoErrorAlert(OSStatus status, CFStringRef errorFormatString)
{	
    CFStringRef formatStr = NULL, printErrorMsg = NULL;
    SInt16      alertItemHit = 0;
    Str255      stringBuf;

    if ((status != noErr) && (status != 2))           
    {
		formatStr =  CFCopyLocalizedString (errorFormatString, NULL);	
		if (formatStr != NULL)
		{
			printErrorMsg = CFStringCreateWithFormat(
													 NULL,
													 NULL,
													 formatStr,
													 status);
			if (printErrorMsg != NULL)
			{
				if (CFStringGetPascalString (
											 printErrorMsg,
											 stringBuf,
											 sizeof(stringBuf),
											 GetApplicationTextEncoding()))
				{
					StandardAlert(kAlertStopAlert, stringBuf, NULL, NULL, &alertItemHit);
				}
				CFRelease (printErrorMsg);                     
			}
			CFRelease (formatStr);                             
		}
	}
}
Пример #4
0
/* Some classcical Mac APIs use the encoding based on WorldScript. for example, Japanese language envrironment use
ShiftJIS encoding. So, unicode2NativePascalString, this function converts unicode encoded pascal string to suitable
encoding (came from CFStringGetSystemEncoding()).
*/
void unicode2NativePascalString(ConstStr255Param fromString, StringPtr toString) {
	if (fromString != NULL) {
		CFStringRef strRef = CFStringCreateWithPascalString(kCFAllocatorDefault, fromString, gCurrentVMEncoding);
		if (strRef != NULL) {
			CFMutableStringRef mStrRef = CFStringCreateMutableCopy(NULL, 0, strRef);
			if (gCurrentVMEncoding == kCFStringEncodingUTF8) 
				CFStringNormalize(mStrRef, kCFStringNormalizationFormKD);
			CFStringGetPascalString (mStrRef, toString, 256, CFStringGetSystemEncoding());
			CFRelease(mStrRef);
			CFRelease(strRef);
		}
	}
}
Пример #5
0
	boolean directorytopath ( const ptrfilespec fs, bigstring path ) {

		//
		// 2006-09-09 creedon: FSRef-ized
		//			       another way might be to use FSRefMakePath and then push insert the volume name on it
		//

		OSErr err;
		OSStatus status;
		FSRef volumesfsref;
		
		status = FSPathMakeRef ((UInt8 *)"/Volumes", &volumesfsref, NULL);
		
		if ((status == noErr) && (FSCompareFSRefs (&fs->ref, &volumesfsref) == noErr)) {	/* bail if fs is Volumes directory */
		
			setemptystring (path);
			
			return (true);
			}

		CFMutableStringRef ioPath = CFStringCreateMutable (NULL, 0);
		FSCatalogInfo catalogInfo;
		FSRef fsrefnomad = fs->ref;
		HFSUniStr255 names[100];
		int i, n;
		UniChar inSepChar = ':';
		
		err = noErr;

		clearbytes (&catalogInfo, longsizeof (catalogInfo));

		for (n = 0; err == noErr && catalogInfo.nodeID != fsRtDirID && n < 100; n++) {

			err = FSGetCatalogInfo (&fsrefnomad, kFSCatInfoNodeID, &catalogInfo, &names[n], NULL, &fsrefnomad);
			}
			
		if (err != noErr)
			return (false);
			
		for (i = n - 1; i >= 0; --i) {

			CFStringAppendCharacters (ioPath, names[i].unicode, names[i].length);
			
			CFStringAppendCharacters (ioPath, &inSepChar, 1);
			}
		
		boolean success = CFStringGetPascalString (ioPath, path, 256, kCFStringEncodingMacRoman);
		CFRelease(ioPath); //PBS 2/28/11: fixed memory leak
		return success;
	} // directorytopath
Пример #6
0
void Logger::error(const std::string &error_text)
{
    log("Error: %s", error_text.c_str());
#ifdef WIN32
    MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK);
#elif defined __APPLE__
    Str255 msg;
    CFStringRef error;
    error = CFStringCreateWithCString(NULL,
                                      error_text.c_str(),
                                      kCFStringEncodingMacRoman);
    CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman);
//	NSRunAlertPanel("Error", (ConstStr255Param) *msg, "OK", NULL,NULL);
//	CreateStandardAlert(kAlertStopAlert, "Error", (ConstStr255Param) msg, NULL, NULL);
#else
    std::cerr << "Error: " << error_text << std::endl;
#endif
    exit(1);
}
Пример #7
0
void Logger::error(const std::string &error_text)
{
    log("Error: %s", error_text.c_str());
#ifdef WIN32
    MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK);
#elif defined __APPLE__
    Str255 msg;
    CFStringRef error;
    error = CFStringCreateWithCString(NULL,
                                      error_text.c_str(),
                                      kCFStringEncodingMacRoman);
    CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman);
    StandardAlert(kAlertStopAlert,
                  "\pError",
                  (ConstStr255Param) msg, NULL, NULL);
#elif defined __linux__ || __linux
    std::cerr << "Error: " << error_text << std::endl;
    std::string msg="xmessage \"" + error_text + "\"";
    system(msg.c_str());
#else
    std::cerr << "Error: " << error_text << std::endl;
#endif
    exit(1);
}
Пример #8
0
static void resolveLongName(short vRefNum, long parID,unsigned char*shortFileName,FSSpec *possibleSpec,Boolean isFolder,Str255 *name,squeakFileOffsetType *sizeOfFile) {
    
#if TARGET_API_MAC_CARBON 
    if ((Ptr) PBGetCatalogInfoSync != (Ptr)kUnresolvedCFragSymbolAddress) {
        FSRefParam FSRefData;
        FSRef      theFSRef;
        FSCatalogInfo theCatalogInfo;
        HFSUniStr255 	unicodeName;
        OSErr     err;

        if (possibleSpec == nil) {
            FSRefParam FSParam;
            
            FSParam.ioNamePtr = shortFileName;
            FSParam.ioVRefNum = vRefNum;
            FSParam.ioDirID = parID;
            FSParam.newRef = &theFSRef;
            FSParam.ioCompletion = null;

            err = PBMakeFSRefSync(&FSParam);

            if (err != noErr)
                goto done1;   
        } else {
            err = FSpMakeFSRef(possibleSpec,&theFSRef);
            if (err != noErr)
             goto done1;   
        }
                
        FSRefData.ref = &theFSRef;
        FSRefData.whichInfo = kFSCatInfoDataSizes;
        FSRefData.catInfo = &theCatalogInfo;
        FSRefData.spec = nil;
        FSRefData.parentRef = nil;
        FSRefData.outName = &unicodeName;
        
        if (PBGetCatalogInfoSync(&FSRefData) == noErr) {
           CFStringRef 	theString;
           
            if (isFolder) 
                *sizeOfFile = 0;
            else
                *sizeOfFile =  theCatalogInfo.dataLogicalSize; 
                
           theString = CFStringCreateWithCharacters (kCFAllocatorDefault, unicodeName.unicode, (CFIndex) unicodeName.length);
			CFMutableStringRef mStr= CFStringCreateMutableCopy(NULL, 0, theString);
           CFRelease(theString);
			// HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements
			if (gCurrentVMEncoding == kCFStringEncodingUTF8) 
				CFStringNormalize(mStr, kCFStringNormalizationFormKC); // canonical decomposition

           CFStringGetPascalString(mStr, (unsigned char *) name,256, gCurrentVMEncoding);
           CFRelease(mStr);
           return;
        }
   }
   done1:
   memcpy(name,shortFileName,sizeof(StrFileName));
#else
   if (shortFileName == nil)
   	  memcpy(name,possibleSpec->name,sizeof(StrFileName));
   else
   	  memcpy(name,shortFileName,sizeof(StrFileName));
#endif
}
Пример #9
0
int doItTheHardWay(unsigned char *pathString,FSSpec *spec,Boolean noDrillDown) {
    char *token;
    Str255 lookup;
    UniChar   buffer[1024];
    Boolean firstTime=true;
    OSErr   err;
    long    parentDirectory,tokenLength;
    FSRef   parentFSRef,childFSRef;
    CFStringRef aLevel;
    FSSpec	fix;
    
    token = strtok((char*) pathString,":");
    if (token == 0) return -1;
    while (token) 
    {
        tokenLength = strlen(token);
        if (firstTime) {// Mmm will crash if volume name is 255 characters, unlikely
            strncpy((char*) lookup+1,(char*) token,tokenLength);
            lookup[0] = tokenLength+1;
            lookup[lookup[0]] = ':';
            firstTime = false;
            err = FSMakeFSSpecCompat(spec->vRefNum,spec->parID, lookup, spec);
            if (err != noErr)
                return err;
            err = FSpMakeFSRef(spec,&parentFSRef);
            if (err != noErr)
                return err;
        } else {
            fix = *spec;
            fix.name[0] = 0;
            err = FSpMakeFSRef(&fix,&parentFSRef);
            if (err != noErr)
                return err;
           aLevel = CFStringCreateWithCString(kCFAllocatorDefault,token,gCurrentVMEncoding);
           if (aLevel == nil) 
                return -1000;
           tokenLength = CFStringGetLength(aLevel);
           CFStringGetCharacters(aLevel,CFRangeMake(0,tokenLength),buffer);
           err = FSMakeFSRefUnicode(&parentFSRef,tokenLength,buffer,gCurrentVMEncoding,&childFSRef);
           if (err != noErr) {
                CFStringGetPascalString(aLevel,spec->name,64,gCurrentVMEncoding);
                CFRelease(aLevel);
				token = strtok(nil,":"); 
				if (token == nil)
					return err;
				else
					return -1001;
            }
           CFRelease(aLevel);
           parentFSRef = childFSRef;
           err = FSGetCatalogInfo (&parentFSRef,kFSCatInfoNone,nil,nil,spec,nil);
            if (err != noErr)
                return err;
        }
        fetchFileSpec(spec,spec->name,&parentDirectory);
        token = strtok(nil,":"); 
    }
   if (noDrillDown) 
       spec->parID = parentDirectory;
     return noErr;
}
Пример #10
0
//Taken from OS X's Kerberos source code file FSpUtils.c, as found ot:
// http://www.opensource.apple.com/source/Kerberos/Kerberos-47/KerberosFramework/Common/Sources/FSpUtils.c
//Note that the URL might change.
static OSStatus CFURLToFSSpec (CFURLRef pathURL, FSSpec *outSpec)
{
	OSStatus err = noErr;
	FSRef ref;
	FSCatalogInfo info;
	CFStringRef pathString = NULL;
	CFURLRef parentURL = NULL;
	CFStringRef nameString = NULL;
	
	// First, try to create an FSRef for the full path
	if (err == noErr) {
		if (CFURLGetFSRef(pathURL, &ref)) {
			err = FSIsFSRefValid(&ref) ? noErr : fnfErr;
		} else {
			err = fnfErr;
		}
	}
	
	if (err == noErr) {
		// It's a directory or a file that exists; convert directly into an FSSpec:
		err = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, outSpec, NULL);
	} else {
		Str255 fileName;
		// The suck case.  The file doesn't exist.
		err = noErr;
		
		// Get a CFString for the path
		if (err == noErr) {
			pathString = CFURLCopyFileSystemPath(pathURL, kCFURLPOSIXPathStyle);
			if (pathString == NULL)
				err = memFullErr;
		}
		
		// Get a CFURL for the parent
		if (err == noErr) {
			parentURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, pathURL);
			if (parentURL == NULL)
				err = memFullErr;
		}
		
		// Build an FSRef for the parent directory, which must be valid to make an FSSpec
		if (err == noErr) {
			Boolean converted = CFURLGetFSRef(parentURL, &ref);
			if (!converted)
				err = fnfErr;
		}
		
		// Get the node ID of the parent directory
		if (err == noErr)
			err = FSGetCatalogInfo(&ref, kFSCatInfoNodeFlags|kFSCatInfoNodeID|kFSCatInfoVolume, &info, NULL, outSpec, NULL);
		
		// Get a CFString for the file name
		if (err == noErr) {
			nameString = CFURLCopyLastPathComponent(pathURL);
			if (nameString == NULL)
				err = memFullErr;
		}
		
		// Copy the string into the FSSpec
		if (err == noErr) {
			Boolean converted = CFStringGetPascalString(pathString, fileName, sizeof(fileName),
														kCFStringEncodingMacRoman);
			if (!converted)
				converted = CFStringGetPascalString(pathString, fileName, sizeof(fileName),
													CFStringGetSystemEncoding());
			
			if (!converted)
				err = fnfErr;
		}
		
		// Set the node ID in the FSSpec
		if (err == noErr)
			err = FSMakeFSSpec(info.volume, info.nodeID, fileName, outSpec);
	}
	
	// Free allocated memory
	if (pathString != NULL)
		CFRelease(pathString);
	if (parentURL != NULL)
		CFRelease(parentURL);
	if (nameString != NULL)
		CFRelease(nameString);
	
	return err;
}
OSStatus BeginSave( NavDialogRef inDialog, NavReplyRecord* outReply, FSRef* outFileRef )
{
    OSStatus status = paramErr;
    AEDesc		dirDesc;
    AEKeyword	keyword;
    CFIndex		len;

    require( outReply, Return );
    require( outFileRef, Return );

    status = NavDialogGetReply( inDialog, outReply );
    nrequire( status, Return );

    status = AEGetNthDesc( &outReply->selection, 1, typeWildCard, &keyword, &dirDesc );
    nrequire( status, DisposeReply );

    len = CFStringGetLength( outReply->saveFileName );

    if ( dirDesc.descriptorType == typeFSRef )
    {
        const UInt32	kMaxNameLen = 255;
        FSRef		dirRef;
        UniChar		name[ kMaxNameLen ];

        if ( len > kMaxNameLen )
        {
            len = kMaxNameLen;
        }

        status = AEGetDescData( &dirDesc, &dirRef, sizeof( dirRef ));
        nrequire( status, DisposeDesc );

        CFStringGetCharacters( outReply->saveFileName, CFRangeMake( 0, len ), &name[0] );

        status = FSMakeFSRefUnicode( &dirRef, len, &name[0], GetApplicationTextEncoding(), outFileRef );
        if (status == fnfErr )
        {
            // file is not there yet - create it and return FSRef
            status = FSCreateFileUnicode( &dirRef, len, &name[0], 0, NULL, outFileRef, NULL );
        }
        else
        {
            // looks like file is there. Just make sure there is no error
            nrequire( status, DisposeDesc );
        }
    }
    else if ( dirDesc.descriptorType == typeFSS )
    {
        FSSpec	theSpec;
        status = AEGetDescData( &dirDesc, &theSpec, sizeof( FSSpec ));
        nrequire( status, DisposeDesc );

        if ( CFStringGetPascalString( outReply->saveFileName, &(theSpec.name[0]),
                                      sizeof( StrFileName ), GetApplicationTextEncoding()))
        {
            status = FSpMakeFSRef(&theSpec, outFileRef);
            nrequire( status, DisposeDesc );
            status = FSpCreate( &theSpec, 0, 0, smSystemScript );
            nrequire( status, DisposeDesc );
        }
        else
        {
            status = bdNamErr;
            nrequire( status, DisposeDesc );
        }
    }

DisposeDesc:
    AEDisposeDesc( &dirDesc );

DisposeReply:
    if ( status != noErr )
    {
        NavDisposeReply( outReply );
    }

Return:
    return status;
}