vcl112: #i111819# resolve aliases

This commit is contained in:
Philipp Lohmann [pl] 2010-05-26 10:22:48 +02:00
parent 687c340604
commit 16d2852d25
3 changed files with 50 additions and 4 deletions

View file

@ -35,6 +35,7 @@
// #endif
#include "CFStringUtilities.hxx"
#include "NSString_OOoAdditions.hxx"
#include "NSURL_OOoAdditions.hxx"
#include "FilterHelper.hxx"
@ -428,6 +429,16 @@ sal_Bool FilterHelper::filenameMatchesFilter(NSString* sFilename)
}
}
// might be an alias
NSString* pResolved = resolveAlias( sFilename );
if( pResolved )
{
sal_Bool bResult = filenameMatchesFilter( pResolved );
[pResolved autorelease];
if( bResult )
return sal_True;
}
DBG_PRINT_EXIT(CLASS_NAME, __func__);
return sal_False;

View file

@ -29,15 +29,20 @@
#define _NSURL_OOOADDITIONS_HXX_
#include <premac.h>
#include <Foundation/Foundation.h>
#include <CoreFoundation/CoreFoundation.h>
#include <postmac.h>
#include "CFStringUtilities.hxx"
#include <rtl/ustring.hxx>
// #include <sal/types.h>
@interface NSURL (OOoAdditions)
- (rtl::OUString) OUStringForInfo:(InfoType)info;
@end
#endif
/*
returns the resolved string if there was an alias
if there was no alias, nil is returned
*/
NSString* resolveAlias( NSString* i_pSystemPath );
#endif

View file

@ -80,3 +80,33 @@
return sResult;
}
@end
NSString* resolveAlias( NSString* i_pSystemPath )
{
NSString* pResolvedPath = nil;
CFURLRef rUrl = CFURLCreateWithFileSystemPath( kCFAllocatorDefault,
(CFStringRef)i_pSystemPath,
kCFURLPOSIXPathStyle, false);
if( rUrl != NULL )
{
FSRef rFS;
if( CFURLGetFSRef( rUrl, &rFS ) )
{
MacOSBoolean bIsFolder = false;
MacOSBoolean bAlias = false;
OSErr err = FSResolveAliasFile( &rFS, true, &bIsFolder, &bAlias);
if( (err == noErr) && bAlias )
{
CFURLRef rResolvedUrl = CFURLCreateFromFSRef( kCFAllocatorDefault, &rFS );
if( rResolvedUrl != NULL )
{
pResolvedPath = (NSString*)CFURLCopyFileSystemPath( rResolvedUrl, kCFURLPOSIXPathStyle );
CFRelease( rResolvedUrl );
}
}
}
CFRelease( rUrl );
}
return pResolvedPath;
}