forked from quicksilver/Plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMUtilsAEFile.cp
executable file
·80 lines (71 loc) · 2 KB
/
CMUtilsAEFile.cp
1
//**************************************************************************************// Filename: CMUtilsAEFile.cp// Part of Contextual Menu Workshop by Abracode Inc.// http://free.abracode.com/cmworkshop///// Copyright © 2002-2003 Abracode, Inc. All rights reserved.//// Description: static utilities for Contextual Menu Plugins//////**************************************************************************************#include "CMUtils.h"#include "DebugSettings.h"#include "StAEDesc.h"OSErrCMUtils::GetFSSpec(const AEDesc &inDesc, FSSpec &outSpec){ OSErr err = fnfErr; if( (inDesc.descriptorType == typeFSS) && (inDesc.dataHandle != NULL) ) {//no need to coerce err = ::AEGetDescData( &inDesc, &outSpec, sizeof(FSSpec) ); } else if( (inDesc.descriptorType != typeNull) && (inDesc.dataHandle != NULL) ) { StAEDesc coercedSpec; err = ::AECoerceDesc( &inDesc, typeFSS, coercedSpec ); if(err == noErr) { err = ::AEGetDescData( coercedSpec, &outSpec, sizeof(FSSpec) ); } else { DEBUG_STR( "\p\tUnable to coerce to FSSpec..." ); } } return err;}OSErrCMUtils::GetFSRef(const AEDesc &inDesc, FSRef &outRef){ OSErr err = fnfErr; if( (inDesc.descriptorType == typeFSRef) && (inDesc.dataHandle != NULL) ) {//no need to coerce TRACE_STR( "\p\tCMUtils::FSRefGetRef without coercing..." ); err = ::AEGetDescData( &inDesc, &outRef, sizeof(FSRef) ); } else if( (inDesc.descriptorType != typeNull) && (inDesc.dataHandle != NULL) ) { StAEDesc coercedRef; err = ::AECoerceDesc( &inDesc, typeFSRef, coercedRef ); if(err == noErr) { TRACE_STR( "\p\tCMUtils::FSRefGetRef with coercing..." ); err = ::AEGetDescData( coercedRef, &outRef, sizeof(FSRef) ); } else {// Cannot get an FSRef. Try getting an FSSpec and make an FSRef out of it. FSSpec theSpec; err = CMUtils::GetFSSpec(inDesc, theSpec); if(err == noErr) { err = ::FSpMakeFSRef( &theSpec, &outRef ); } else { DEBUG_STR( "\p\tUnable to coerce to FSRef..." ); } } } return err;}