1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2/* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20#include "NSString_OOoAdditions.hxx" 21#include "NSURL_OOoAdditions.hxx" 22#include <sal/log.hxx> 23 24@implementation NSURL (OOoAdditions) 25- (OUString) OUStringForInfo:(InfoType)info 26{ 27 NSAutoreleasePool *pool = [NSAutoreleasePool new]; 28 29 NSString *sURLString = nil; 30 31 switch(info) { 32 case FULLPATH: 33 SAL_INFO("fpicker.aqua","Extracting the full path of an item"); 34 sURLString = [self absoluteString]; 35 [sURLString retain]; 36 break; 37 case FILENAME: 38 { 39 SAL_INFO("fpicker.aqua","Extracting the file name of an item"); 40 NSString *path = [self path]; 41 if (path == nil) { 42 sURLString = @""; 43 } 44 else { 45 sURLString = [path lastPathComponent]; 46 } 47 [sURLString retain]; 48 } 49 break; 50 case PATHWITHOUTLASTCOMPONENT: 51 { 52 SAL_INFO("fpicker.aqua","Extracting the last but one component of an item's path"); 53 NSString *path = [self absoluteString]; 54 if (path == nil) { 55 sURLString = @""; 56 } 57 else { 58 NSString* lastComponent = [path lastPathComponent]; 59 unsigned int lastLength = [lastComponent length]; 60 sURLString = [path substringToIndex:([path length] - lastLength)]; 61 } 62 [sURLString retain]; 63 } 64 break; 65 default: 66 break; 67 } 68 69 OUString sResult = [sURLString OUString]; 70 [sURLString release]; 71 72 [pool release]; 73 74 return sResult; 75} 76@end 77 78NSString* resolveAlias( NSString* i_pSystemPath ) 79{ 80 NSString* pResolvedPath = nil; 81 CFURLRef rUrl = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, 82 reinterpret_cast<CFStringRef>(i_pSystemPath), 83 kCFURLPOSIXPathStyle, false); 84 if( rUrl != nullptr ) 85 { 86 CFErrorRef rError; 87 CFDataRef rBookmark = CFURLCreateBookmarkDataFromFile( nullptr, rUrl, &rError ); 88 CFRelease( rUrl ); 89 if( rBookmark == nullptr ) 90 { 91 CFRelease( rError ); 92 } 93 else 94 { 95 Boolean bIsStale; 96 CFURLRef rResolvedUrl = CFURLCreateByResolvingBookmarkData( kCFAllocatorDefault, rBookmark, kCFBookmarkResolutionWithoutUIMask, 97 nullptr, nullptr, &bIsStale, &rError ); 98 CFRelease( rBookmark ); 99 if( rResolvedUrl == nullptr ) 100 { 101 CFRelease( rError ); 102 } 103 else 104 { 105 pResolvedPath = const_cast<NSString*>(reinterpret_cast<NSString const *>(CFURLCopyFileSystemPath( rResolvedUrl, kCFURLPOSIXPathStyle ))); 106 CFRelease( rResolvedUrl ); 107 } 108 } 109 } 110 111 return pResolvedPath; 112} 113 114/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 115