예제 #1
0
OSErr squeakFindImage(char* pathName)
{
    NavDialogCreationOptions    dialogOptions;
    NavObjectFilterUPP  filterProc =  NewNavObjectFilterUPP(findImageFilterProc);
    OSErr               anErr = noErr;
    NavDialogRef		navDialog;
	FSRef fileAsFSRef;
	
    //  Specify default options for dialog box
    anErr = NavGetDefaultDialogCreationOptions(&dialogOptions);
    if (anErr != noErr)
		return anErr;
		

	//  Adjust the options to fit our needs
	//  Set default location option
	dialogOptions.optionFlags |= kNavSelectDefaultLocation;
	dialogOptions.optionFlags  |= kNavAllFilesInPopup;
	dialogOptions.optionFlags  |= kNavSelectAllReadableItem;
	//  Clear preview option
	dialogOptions.optionFlags  ^= kNavAllowPreviews;
	
				
	// Call NavGetFile() with specified options and
	// declare our app-defined functions and type list
	NavCreateChooseFileDialog (
			&dialogOptions,
			nil,
			nil,
			nil,
			filterProc,
			nil,
			&navDialog);
	anErr = NavDialogRun (navDialog);
	if (anErr != noErr )
		return anErr;
		
	NavReplyRecord outReply;
	anErr = NavDialogGetReply (navDialog,&outReply);
	
    DisposeNavObjectFilterUPP(filterProc);
	NavDialogDispose(navDialog);	
		
	if (anErr != noErr)
		return anErr;
		
	if (!outReply.validRecord) {
		anErr = NavDisposeReply(&outReply);
		return -1;
	}

	// Get the file
	anErr = AEGetNthPtr(&(outReply.selection), 1, typeFSRef, NULL, NULL, &fileAsFSRef, sizeof(FSRef), NULL);
	PathToFileViaFSRef(pathName,DOCUMENT_NAME_SIZE, &fileAsFSRef, gCurrentVMEncoding);

	//  Dispose of NavReplyRecord, resources, descriptors
	anErr = NavDisposeReply(&outReply);

    return 0;
}
예제 #2
0
pascal Boolean findImageFilterProc(AEDesc* theItem, void* info, 
                            NavCallBackUserData callBackUD,
                            NavFilterModes filterMode)
{
#pragma unused(filterMode,callBackUD)
    NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*)info;
    
    if (theItem->descriptorType == typeFSRef) {
        char checkSuffix[256],pathName[1024];
        OSErr 	error;
        Boolean check;
		FSRef theFSRef;
		
        if (theInfo->isFolder)
            return true;
            
        if (theInfo->fileAndFolder.fileInfo.finderInfo.fdType == 'STim')
            return true;
            
        error = AEGetDescData(theItem,&theFSRef,sizeof(FSRef));
		if (error != noErr) 
            return true;
		PathToFileViaFSRef(pathName, 1024, &theFSRef,kCFStringEncodingUTF8);
		getLastPathComponentInCurrentEncoding(pathName,checkSuffix,kCFStringEncodingUTF8);        
        check = IsImageName(checkSuffix);

        if (check) 
            return true;
        else {
           return false;
		}
    }
    return true;
}
void resolveWhatTheImageNameIs(char *guess)  
{
	char possibleImageName[DOCUMENT_NAME_SIZE+1],  fullPath [DOCUMENT_NAME_SIZE+1],  lastPath [SHORTIMAGE_NAME_SIZE+1];
	FSRef		theFSRef;
	OSErr		err;
	
	strncpy(possibleImageName, guess,DOCUMENT_NAME_SIZE);
	err = getFSRef(possibleImageName,&theFSRef,kCFStringEncodingUTF8);
	if (err) {
		SetImageNameViaString("",gCurrentVMEncoding);
		SetShortImageNameViaString("",gCurrentVMEncoding);
		return;
	}
	PathToFileViaFSRef(fullPath,DOCUMENT_NAME_SIZE, &theFSRef,gCurrentVMEncoding);
	getLastPathComponentInCurrentEncoding(fullPath,lastPath,gCurrentVMEncoding);
	SetImageNameViaString(fullPath,gCurrentVMEncoding);
	SetShortImageNameViaString(lastPath,gCurrentVMEncoding);
}
예제 #4
0
sqInt	ioFilenamefromStringofLengthresolveAliasesRetry(char* dst, char* src, sqInt num, sqInt resolveAlias, Boolean retry) {
 int		bytes;
 FSRef targetFSRef;
 OSStatus err; 
 
 if (retry)
	bytes = sq2uxPath(src, num, dst, DOCUMENT_NAME_SIZE, 1);
 else {
	memcpy(dst,src,num);
	dst[num] = 0x00;
	bytes = num;
 }
  		
 err = getFSRef(dst,&targetFSRef,kCFStringEncodingUTF8); 
 if (retry) {
	if (err) {
		char possiblePath[DOCUMENT_NAME_SIZE+1];
		
		bytes = wanderDownPath(dst,bytes,possiblePath,resolveAlias);
		if (bytes) 
			strcpy(dst,possiblePath);
		return bytes;
	}
 }

  if (err == 0 && resolveAlias) {
		Boolean	targetIsFolder,wasAliased;
		err = FSResolveAliasFileWithMountFlags(&targetFSRef,true,&targetIsFolder,&wasAliased,kResolveAliasFileNoUI);
		if (err || wasAliased == false)
			return bytes; 
		PathToFileViaFSRef(dst, DOCUMENT_NAME_SIZE, &targetFSRef,kCFStringEncodingUTF8);
		bytes = strlen(dst);
	 }
  
 return bytes;
}