From: Derrick Brashear Date: Tue, 17 Jul 2012 02:32:55 +0000 (-0400) Subject: macos: fix growlagent icon handling X-Git-Tag: upstream/1.6.2_pre2^2~17 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=cddc0c46696e25c590d85afcc71c7c018d42f6a3;p=packages%2Fo%2Fopenafs.git macos: fix growlagent icon handling the whole of the api used for icon handling when you steal it from a resource fork is deprecated in new macos. fine. we'll just make an app bundle by cheating, move andy into a standalone icns file, install him into the "bundle" and open it the macos way. Reviewed-on: http://gerrit.openafs.org/7786 Tested-by: BuildBot Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear (cherry picked from commit 3dd230e8595e2b9635d6ec412a145ae3be229b7a) Change-Id: I9a439601058a4c2f32cbe687865a9143d56b92bf Reviewed-on: http://gerrit.openafs.org/8781 Tested-by: BuildBot Reviewed-by: Paul Smeddle Reviewed-by: Stephan Wiesand --- diff --git a/src/platform/DARWIN/growlagent/Andy.icns b/src/platform/DARWIN/growlagent/Andy.icns new file mode 100644 index 000000000..7c62a76f9 Binary files /dev/null and b/src/platform/DARWIN/growlagent/Andy.icns differ diff --git a/src/platform/DARWIN/growlagent/CFGrowlAdditions.c b/src/platform/DARWIN/growlagent/CFGrowlAdditions.c deleted file mode 100644 index f8592eafb..000000000 --- a/src/platform/DARWIN/growlagent/CFGrowlAdditions.c +++ /dev/null @@ -1,629 +0,0 @@ -// -// CFGrowlAdditions.c -// Growl -// -// Created by Mac-arena the Bored Zo on Wed Jun 18 2004. -// Copyright 2005-2006 The Growl Project. -// -// This file is under the BSD License, refer to License.txt for details - -#include -#include -#include -#include -#include -#include "CFGrowlAdditions.h" - -#ifndef MIN -# define MIN(a,b) ((a) < (b) ? (a) : (b)) -#endif - -//extern Boolean CFStringGetFileSystemRepresentation(CFStringRef str) __attribute__((weak_import)); -extern CFIndex CFStringGetMaximumSizeOfFileSystemRepresentation(CFStringRef string) __attribute__((weak_import)); - -char *createFileSystemRepresentationOfString(CFStringRef str) { - char *buffer; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4 - /* CFStringGetFileSystemRepresentation will cause a link error despite the weak_import attribute above on 10.5 when compiling with 10.2 compatibility using gcc 3.3. - * PPC will therefore always use the 10.3 and below method of creating a file system representation. - */ - if (1/*CFStringGetFileSystemRepresentation*/) { - CFIndex size = CFStringGetMaximumSizeOfFileSystemRepresentation(str); - buffer = malloc(size); - CFStringGetFileSystemRepresentation(str, buffer, size); - } else -#endif - { - buffer = malloc(512); - CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, str, kCFURLPOSIXPathStyle, false); - if (!CFURLGetFileSystemRepresentation(url, false, (UInt8 *)buffer, 512)) { - free(buffer); - buffer = NULL; - } - CFRelease(url); - } - return buffer; -} - -STRING_TYPE createStringWithDate(CFDateRef date) { - CFLocaleRef locale = CFLocaleCopyCurrent(); - CFDateFormatterRef dateFormatter = CFDateFormatterCreate(kCFAllocatorDefault, - locale, - kCFDateFormatterMediumStyle, - kCFDateFormatterMediumStyle); - CFRelease(locale); - CFStringRef dateString = CFDateFormatterCreateStringWithDate(kCFAllocatorDefault, - dateFormatter, - date); - CFRelease(dateFormatter); - return dateString; -} - -STRING_TYPE createStringWithContentsOfFile(CFStringRef filename, CFStringEncoding encoding) { - CFStringRef str = NULL; - - char *path = createFileSystemRepresentationOfString(filename); - if (path) { - FILE *fp = fopen(path, "rb"); - if (fp) { - fseek(fp, 0, SEEK_END); - unsigned long size = ftell(fp); - fseek(fp, 0, SEEK_SET); - unsigned char *buffer = malloc(size); - if (buffer && fread(buffer, 1, size, fp) == size) - str = CFStringCreateWithBytes(kCFAllocatorDefault, buffer, size, encoding, true); - fclose(fp); - } - free(path); - } - - return str; -} - -STRING_TYPE createStringWithStringAndCharacterAndString(STRING_TYPE str0, UniChar ch, STRING_TYPE str1) { - CFStringRef cfstr0 = (CFStringRef)str0; - CFStringRef cfstr1 = (CFStringRef)str1; - CFIndex len0 = (cfstr0 ? CFStringGetLength(cfstr0) : 0); - CFIndex len1 = (cfstr1 ? CFStringGetLength(cfstr1) : 0); - size_t length = (len0 + (ch != 0xffff) + len1); - - UniChar *buf = malloc(sizeof(UniChar) * length); - size_t i = 0U; - - if (cfstr0) { - CFStringGetCharacters(cfstr0, CFRangeMake(0, len0), buf); - i += len0; - } - if (ch != 0xffff) - buf[i++] = ch; - if (cfstr1) - CFStringGetCharacters(cfstr1, CFRangeMake(0, len1), &buf[i]); - - return CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, buf, length, /*contentsDeallocator*/ kCFAllocatorMalloc); -} - -char *copyCString(STRING_TYPE str, CFStringEncoding encoding) { - CFIndex size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), encoding) + 1; - char *buffer = calloc(size, 1); - CFStringGetCString(str, buffer, size, encoding); - return buffer; -} - -STRING_TYPE copyCurrentProcessName(void) { - ProcessSerialNumber PSN = { 0, kCurrentProcess }; - CFStringRef name = NULL; - OSStatus err = CopyProcessName(&PSN, &name); - if (err != noErr) { - NSLog(CFSTR("in copyCurrentProcessName in CFGrowlAdditions: Could not get process name because CopyProcessName returned %li"), (long)err); - name = NULL; - } - return name; -} - -URL_TYPE copyCurrentProcessURL(void) { - ProcessSerialNumber psn = { 0, kCurrentProcess }; - FSRef fsref; - CFURLRef URL = NULL; - OSStatus err = GetProcessBundleLocation(&psn, &fsref); - if (err != noErr) { - NSLog(CFSTR("in copyCurrentProcessURL in CFGrowlAdditions: Could not get application location, because GetProcessBundleLocation returned %li\n"), (long)err); - } else { - URL = CFURLCreateFromFSRef(kCFAllocatorDefault, &fsref); - } - return URL; -} -STRING_TYPE copyCurrentProcessPath(void) { - CFURLRef URL = copyCurrentProcessURL(); - CFStringRef path = CFURLCopyFileSystemPath(URL, kCFURLPOSIXPathStyle); - CFRelease(URL); - return path; -} - -URL_TYPE copyTemporaryFolderURL(void) { - FSRef ref; - CFURLRef url = NULL; - - OSStatus err = FSFindFolder(kOnAppropriateDisk, kTemporaryFolderType, kCreateFolder, &ref); - if (err != noErr) - NSLog(CFSTR("in copyTemporaryFolderPath in CFGrowlAdditions: Could not locate temporary folder because FSFindFolder returned %li"), (long)err); - else - url = CFURLCreateFromFSRef(kCFAllocatorDefault, &ref); - - return url; -} -STRING_TYPE copyTemporaryFolderPath(void) { - CFStringRef path = NULL; - - CFURLRef url = copyTemporaryFolderURL(); - if (url) { - path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); - CFRelease(url); - } - - return path; -} - -DATA_TYPE readFile(const char *filename) -{ - CFDataRef data; - // read the file into a CFDataRef - FILE *fp = fopen(filename, "r"); - if (fp) { - fseek(fp, 0, SEEK_END); - long dataLength = ftell(fp); - fseek(fp, 0, SEEK_SET); - unsigned char *fileData = malloc(dataLength); - fread(fileData, 1, dataLength, fp); - fclose(fp); - data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, fileData, dataLength, kCFAllocatorMalloc); - } else - data = NULL; - - return data; -} - -URL_TYPE copyURLForApplication(STRING_TYPE appName) -{ - CFURLRef appURL = NULL; - OSStatus err = LSFindApplicationForInfo(/*inCreator*/ kLSUnknownCreator, - /*inBundleID*/ NULL, - /*inName*/ appName, - /*outAppRef*/ NULL, - /*outAppURL*/ &appURL); - return (err == noErr) ? appURL : NULL; -} - -STRING_TYPE createStringWithAddressData(DATA_TYPE aAddressData) { - struct sockaddr *socketAddress = (struct sockaddr *)CFDataGetBytePtr(aAddressData); - // IPv6 Addresses are "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF" - // at max, which is 40 bytes (0-terminated) - // IPv4 Addresses are "255.255.255.255" at max which is smaller - char stringBuffer[40]; - CFStringRef addressAsString = NULL; - if (socketAddress->sa_family == AF_INET) { - struct sockaddr_in *ipv4 = (struct sockaddr_in *)socketAddress; - if (inet_ntop(AF_INET, &(ipv4->sin_addr), stringBuffer, 40)) - addressAsString = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%s:%d"), stringBuffer, ipv4->sin_port); - else - addressAsString = CFSTR("IPv4 un-ntopable"); - } else if (socketAddress->sa_family == AF_INET6) { - struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)socketAddress; - if (inet_ntop(AF_INET6, &(ipv6->sin6_addr), stringBuffer, 40)) - // Suggested IPv6 format (see http://www.faqs.org/rfcs/rfc2732.html) - addressAsString = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("[%s]:%d"), stringBuffer, ipv6->sin6_port); - else - addressAsString = CFSTR("IPv6 un-ntopable"); - } else - addressAsString = CFSTR("neither IPv6 nor IPv4"); - - return addressAsString; -} - -STRING_TYPE createHostNameForAddressData(DATA_TYPE aAddressData) { - char hostname[NI_MAXHOST]; - struct sockaddr *socketAddress = (struct sockaddr *)CFDataGetBytePtr(aAddressData); - if (getnameinfo(socketAddress, (socklen_t)CFDataGetLength(aAddressData), - hostname, (socklen_t)sizeof(hostname), - /*serv*/ NULL, /*servlen*/ 0, - NI_NAMEREQD)) - return NULL; - else - return CFStringCreateWithCString(kCFAllocatorDefault, hostname, kCFStringEncodingASCII); -} - -DATA_TYPE copyIconDataForPath(STRING_TYPE path) { - CFDataRef data = NULL; - - //false is probably safest, and is harmless when the object really is a directory. - CFURLRef URL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path, kCFURLPOSIXPathStyle, /*isDirectory*/ false); - if (URL) { - data = copyIconDataForURL(URL); - CFRelease(URL); - } - - return data; -} - -DATA_TYPE copyIconDataForURL(URL_TYPE URL) -{ - CFDataRef data = NULL; - - if (URL) { - FSRef ref; - if (CFURLGetFSRef(URL, &ref)) { - IconRef icon = NULL; - SInt16 label_noOneCares; - OSStatus err = GetIconRefFromFileInfo(&ref, - /*inFileNameLength*/ 0U, /*inFileName*/ NULL, - kFSCatInfoNone, /*inCatalogInfo*/ NULL, - kIconServicesNoBadgeFlag | kIconServicesUpdateIfNeededFlag, - &icon, - &label_noOneCares); - if (err != noErr) { - NSLog(CFSTR("in copyIconDataForURL in CFGrowlAdditions: could not get icon for %@: GetIconRefFromFileInfo returned %li\n"), URL, (long)err); - } else { - IconFamilyHandle fam = NULL; - err = IconRefToIconFamily(icon, kSelectorAllAvailableData, &fam); - if (err != noErr) { - NSLog(CFSTR("in copyIconDataForURL in CFGrowlAdditions: could not get icon for %@: IconRefToIconFamily returned %li\n"), URL, (long)err); - } else { - HLock((Handle)fam); - data = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)*(Handle)fam, GetHandleSize((Handle)fam)); - HUnlock((Handle)fam); - DisposeHandle((Handle)fam); - } - ReleaseIconRef(icon); - } - } - } - - return data; -} - -URL_TYPE createURLByMakingDirectoryAtURLWithName(URL_TYPE parent, STRING_TYPE name) -{ - CFURLRef newDirectory = NULL; - - CFAllocatorRef allocator = parent ? CFGetAllocator(parent) : name ? CFGetAllocator(name) : kCFAllocatorDefault; - - if (parent) parent = CFRetain(parent); - else { - char *cwdBytes = alloca(PATH_MAX); - getcwd(cwdBytes, PATH_MAX); - parent = CFURLCreateFromFileSystemRepresentation(allocator, (const unsigned char *)cwdBytes, strlen(cwdBytes), /*isDirectory*/ true); - if (!name) { - newDirectory = parent; - goto end; - } - } - if (!parent) - NSLog(CFSTR("in createURLByMakingDirectoryAtURLWithName in CFGrowlAdditions: parent directory URL is NULL (please tell the Growl developers)\n"), parent); - else { - if (name) - name = CFRetain(name); - else { - name = CFURLCopyLastPathComponent(parent); - CFURLRef newParent = CFURLCreateCopyDeletingLastPathComponent(allocator, parent); - CFRelease(parent); - parent = newParent; - } - - if (!name) - NSLog(CFSTR("in createURLByMakingDirectoryAtURLWithName in CFGrowlAdditions: name of directory to create is NULL (please tell the Growl developers)\n"), parent); - else { - FSRef parentRef; - if (!CFURLGetFSRef(parent, &parentRef)) - NSLog(CFSTR("in createURLByMakingDirectoryAtURLWithName in CFGrowlAdditions: could not create FSRef for parent directory at %@ (please tell the Growl developers)\n"), parent); - else { - FSRef newDirectoryRef; - - struct HFSUniStr255 nameUnicode; - CFRange range = { 0, MIN(CFStringGetLength(name), USHRT_MAX) }; - CFStringGetCharacters(name, range, nameUnicode.unicode); - nameUnicode.length = range.length; - - struct FSRefParam refPB = { - .ref = &parentRef, - .nameLength = nameUnicode.length, - .name = nameUnicode.unicode, - .whichInfo = kFSCatInfoNone, - .catInfo = NULL, - .textEncodingHint = kTextEncodingUnknown, - .newRef = &newDirectoryRef, - }; - - OSStatus err = PBCreateDirectoryUnicodeSync(&refPB); - if (err == dupFNErr) { - //dupFNErr == file (or folder) exists already. this is fine. - err = PBMakeFSRefUnicodeSync(&refPB); - } - if (err == noErr) { - NSLog(CFSTR("PBCreateDirectoryUnicodeSync or PBMakeFSRefUnicodeSync returned %li; calling CFURLCreateFromFSRef"), (long)err); //XXX - newDirectory = CFURLCreateFromFSRef(allocator, &newDirectoryRef); - NSLog(CFSTR("CFURLCreateFromFSRef returned %@"), newDirectory); //XXX - } else - NSLog(CFSTR("in createURLByMakingDirectoryAtURLWithName in CFGrowlAdditions: could not create directory '%@' in parent directory at %@: FSCreateDirectoryUnicode returned %li (please tell the Growl developers)"), name, parent, (long)err); - } - - } //if (name) - if(parent) - CFRelease(parent); - if(name) - CFRelease(name); - } //if (parent) - -end: - return newDirectory; -} - -#ifndef COPYFORK_BUFSIZE -# define COPYFORK_BUFSIZE 5242880U /*5 MiB*/ -#endif - -static OSStatus copyFork(const struct HFSUniStr255 *forkName, const FSRef *srcFile, const FSRef *destDir, const struct HFSUniStr255 *destName, FSRef *outDestFile) { - OSStatus err, closeErr; - struct FSForkIOParam srcPB = { - .ref = srcFile, - .forkNameLength = forkName->length, - .forkName = forkName->unicode, - .permissions = fsRdPerm, - }; - unsigned char debuggingPathBuf[PATH_MAX] = ""; - OSStatus debuggingPathErr; - - err = PBOpenForkSync(&srcPB); - if (err != noErr) { - debuggingPathErr = FSRefMakePath(srcFile, debuggingPathBuf, PATH_MAX); - if (debuggingPathErr != noErr) - snprintf((char *)debuggingPathBuf, PATH_MAX, "(could not get path for source file: FSRefMakePath returned %li)", (long)debuggingPathErr); - NSLog(CFSTR("in copyFork in CFGrowlAdditions: PBOpenForkSync (source: %s) returned %li"), debuggingPathBuf, (long)err); - } else { - FSRef destFile; - - /*the first thing to do is get the name of the destination file, if one - * wasn't provided. - *and while we're at it, we get the catalogue info as well. - */ - struct FSCatalogInfo catInfo; - struct FSRefParam refPB = { - .ref = srcFile, - .whichInfo = kFSCatInfoGettableInfo & kFSCatInfoSettableInfo, - .catInfo = &catInfo, - .spec = NULL, - .parentRef = NULL, - .outName = destName ? NULL : (struct HFSUniStr255 *)(destName = alloca(sizeof(struct HFSUniStr255))), - }; - - err = PBGetCatalogInfoSync(&refPB); - if (err != noErr) { - debuggingPathErr = FSRefMakePath(srcFile, debuggingPathBuf, PATH_MAX); - if (debuggingPathErr != noErr) - snprintf((char *)debuggingPathBuf, PATH_MAX, "(could not get path for source file: FSRefMakePath returned %li)", (long)debuggingPathErr); - NSLog(CFSTR("in copyFork in CFGrowlAdditions: PBGetCatalogInfoSync (source: %s) returned %li"), debuggingPathBuf, (long)err); - } else { - refPB.ref = destDir; - refPB.nameLength = destName->length; - refPB.name = destName->unicode; - refPB.textEncodingHint = kTextEncodingUnknown; - refPB.newRef = &destFile; - - const char *functionName = "PBMakeFSRefUnicodeSync"; //for error-reporting message - - err = PBMakeFSRefUnicodeSync(&refPB); - if ((err != noErr) && (err != fnfErr)) { - handleMakeFSRefError: - debuggingPathErr = FSRefMakePath(destDir, debuggingPathBuf, PATH_MAX); - if (debuggingPathErr != noErr) - snprintf((char *)debuggingPathBuf, PATH_MAX, "(could not get path for destination directory: FSRefMakePath returned %li)", (long)debuggingPathErr); - - //get filename too - CFStringRef debuggingFilename = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, - destName->unicode, - destName->length, - /*contentsDeallocator*/ kCFAllocatorNull); - if (!debuggingFilename) - debuggingFilename = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, "(could not get filename for destination file: CFStringCreateWithCharactersNoCopy returned NULL)", kCFStringEncodingASCII, /*contentsDeallocator*/ kCFAllocatorNull); - - NSLog(CFSTR("in copyFork in CFGrowlAdditions: %s (destination: %s/%@) returned %li"), functionName, debuggingPathBuf, debuggingFilename, (long)err); - - if (debuggingFilename) CFRelease(debuggingFilename); - } else { - //that file doesn't exist in that folder; create it. - err = PBCreateFileUnicodeSync(&refPB); - if (err == noErr) { - /*make sure the Finder knows about the new file. - *FNNotify returns a status code too, but this isn't an - * essential step, so we just ignore it. - */ - FNNotify(destDir, kFNDirectoryModifiedMessage, kNilOptions); - } else if (err == dupFNErr) { - /*dupFNErr: the file already exists. - *we can safely ignore this error. - */ - err = noErr; - } else { - functionName = "PBCreateFileUnicodeSync"; - goto handleMakeFSRefError; - } - } - } - if (err == noErr) { - if (outDestFile) - memcpy(outDestFile, &destFile, sizeof(destFile)); - - struct FSForkIOParam destPB = { - .ref = &destFile, - .forkNameLength = forkName->length, - .forkName = forkName->unicode, - .permissions = fsWrPerm, - }; - err = PBOpenForkSync(&destPB); - NSLog(CFSTR("in copyFork in CFGrowlAdditions: PBOpenForkSync (dest) returned %li"), (long)err); - if (err != noErr) { - debuggingPathErr = FSRefMakePath(&destFile, debuggingPathBuf, PATH_MAX); - if (debuggingPathErr != noErr) - snprintf((char *)debuggingPathBuf, PATH_MAX, "(could not get path for dest file: FSRefMakePath returned %li)", (long)debuggingPathErr); - NSLog(CFSTR("in copyFork in CFGrowlAdditions: PBOpenForkSync (destination: %s) returned %li"), debuggingPathBuf, (long)err); - } else { - void *buf = malloc(COPYFORK_BUFSIZE); - if (buf) { - srcPB.buffer = destPB.buffer = buf; - srcPB.requestCount = COPYFORK_BUFSIZE; - while (err == noErr) { - err = PBReadForkSync(&srcPB); - if (err == eofErr) { - err = noErr; - if (srcPB.actualCount == 0) - break; - } - if (err != noErr) { - debuggingPathErr = FSRefMakePath(&destFile, debuggingPathBuf, PATH_MAX); - if (debuggingPathErr != noErr) - snprintf((char *)debuggingPathBuf, PATH_MAX, "(could not get path for source file: FSRefMakePath returned %li)", (long)debuggingPathErr); - NSLog(CFSTR("in copyFork in CFGrowlAdditions: PBReadForkSync (source: %s) returned %li"), debuggingPathBuf, (long)err); - } else { - destPB.requestCount = srcPB.actualCount; - err = PBWriteForkSync(&destPB); - if (err != noErr) { - debuggingPathErr = FSRefMakePath(&destFile, debuggingPathBuf, PATH_MAX); - if (debuggingPathErr != noErr) - snprintf((char *)debuggingPathBuf, PATH_MAX, "(could not get path for dest file: FSRefMakePath returned %li)", (long)debuggingPathErr); - NSLog(CFSTR("in copyFork in CFGrowlAdditions: PBWriteForkSync (destination: %s) returned %li"), debuggingPathBuf, (long)err); - } - } - } - - free(buf); - } - - closeErr = PBCloseForkSync(&destPB); - if (closeErr != noErr) { - debuggingPathErr = FSRefMakePath(&destFile, debuggingPathBuf, PATH_MAX); - if (debuggingPathErr != noErr) - snprintf((char *)debuggingPathBuf, PATH_MAX, "(could not get path for dest file: FSRefMakePath returned %li)", (long)debuggingPathErr); - NSLog(CFSTR("in copyFork in CFGrowlAdditions: PBCloseForkSync (destination: %s) returned %li"), debuggingPathBuf, (long)err); - } - if (err == noErr) err = closeErr; - } - } - - closeErr = PBCloseForkSync(&srcPB); - if (closeErr != noErr) { - debuggingPathErr = FSRefMakePath(&destFile, debuggingPathBuf, PATH_MAX); - if (debuggingPathErr != noErr) - snprintf((char *)debuggingPathBuf, PATH_MAX, "(could not get path for source file: FSRefMakePath returned %li)", (long)debuggingPathErr); - NSLog(CFSTR("in copyFork in CFGrowlAdditions: PBCloseForkSync (source: %s) returned %li"), debuggingPathBuf, (long)err); - } - if (err == noErr) err = closeErr; - } - - return err; -} - -static OSStatus GrowlCopyObjectSync(const FSRef *fileRef, const FSRef *destRef, FSRef *destFileRef) { - OSStatus err; - struct HFSUniStr255 forkName; - struct FSForkIOParam forkPB = { - .ref = fileRef, - .forkIterator = { - .initialize = 0 - }, - .outForkName = &forkName, - }; - - do { - err = PBIterateForksSync(&forkPB); - NSLog(CFSTR("PBIterateForksSync returned %li"), (long)err); - if (err != noErr) { - if (err != errFSNoMoreItems) - NSLog(CFSTR("in GrowlCopyObjectSync in CFGrowlAdditions: PBIterateForksSync returned %li"), (long)err); - } else { - err = copyFork(&forkName, fileRef, destRef, /*destName*/ NULL, /*outDestFile*/ destFileRef); - //copyFork prints its own error messages - } - } while (err == noErr); - if (err == errFSNoMoreItems) err = noErr; - - return err; -} - -URL_TYPE createURLByCopyingFileFromURLToDirectoryURL(URL_TYPE file, URL_TYPE dest) -{ - CFURLRef destFileURL = NULL; - - FSRef fileRef, destRef, destFileRef; - Boolean gotFileRef = CFURLGetFSRef(file, &fileRef); - Boolean gotDestRef = CFURLGetFSRef(dest, &destRef); - if (!gotFileRef) - NSLog(CFSTR("in createURLByCopyingFileFromURLToDirectoryURL in CFGrowlAdditions: CFURLGetFSRef failed with source URL %@"), file); - else if (!gotDestRef) - NSLog(CFSTR("in createURLByCopyingFileFromURLToDirectoryURL in CFGrowlAdditions: CFURLGetFSRef failed with destination URL %@"), dest); - else { - OSStatus err; - - /* - * 10.2 has a problem with weak symbols in frameworks so we use - * MAC_OS_X_VERSION_MIN_REQUIRED >= 10.3. - */ -#if defined(NSAppKitVersionNumber10_3) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3 - if (FSCopyObjectSync) { - err = FSCopyObjectSync(&fileRef, &destRef, /*destName*/ NULL, &destFileRef, kFSFileOperationOverwrite); - } else { -#endif - err = GrowlCopyObjectSync(&fileRef, &destRef, &destFileRef); -#if defined(NSAppKitVersionNumber10_3) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3 - } -#endif - - if (err == noErr) - destFileURL = CFURLCreateFromFSRef(kCFAllocatorDefault, &destFileRef); - else - NSLog(CFSTR("in createURLByCopyingFileFromURLToDirectoryURL in CFGrowlAdditions: CopyObjectSync returned %li for source URL %@"), (long)err, file); - } - - return destFileURL; -} - -PLIST_TYPE createPropertyListFromURL(URL_TYPE file, u_int32_t mutability, CFPropertyListFormat *outFormat, STRING_TYPE *outErrorString) -{ - CFPropertyListRef plist = NULL; - - if (!file) - NSLog(CFSTR("in createPropertyListFromURL in CFGrowlAdditions: cannot read from a NULL URL")); - else { - CFReadStreamRef stream = CFReadStreamCreateWithFile(kCFAllocatorDefault, file); - if (!stream) - NSLog(CFSTR("in createPropertyListFromURL in CFGrowlAdditions: could not create stream for reading from URL %@"), file); - else { - if (!CFReadStreamOpen(stream)) - NSLog(CFSTR("in createPropertyListFromURL in CFGrowlAdditions: could not open stream for reading from URL %@"), file); - else { - CFPropertyListFormat format; - CFStringRef errorString = NULL; - - plist = CFPropertyListCreateFromStream(kCFAllocatorDefault, - stream, - /*streamLength*/ 0, - mutability, - &format, - &errorString); - if (!plist) - NSLog(CFSTR("in createPropertyListFromURL in CFGrowlAdditions: could not read property list from URL %@ (error string: %@)"), file, errorString); - - if (outFormat) *outFormat = format; - if (errorString) { - if (outErrorString) - *outErrorString = errorString; - else - CFRelease(errorString); - } - - CFReadStreamClose(stream); - } - - CFRelease(stream); - } - } - - return plist; -} diff --git a/src/platform/DARWIN/growlagent/CFGrowlAdditions.h b/src/platform/DARWIN/growlagent/CFGrowlAdditions.h deleted file mode 100644 index a65d78d06..000000000 --- a/src/platform/DARWIN/growlagent/CFGrowlAdditions.h +++ /dev/null @@ -1,86 +0,0 @@ -// -// CFGrowlAdditions.h -// Growl -// -// Created by Mac-arena the Bored Zo on Wed Jun 18 2004. -// Copyright 2005-2006 The Growl Project. -// -// This file is under the BSD License, refer to License.txt for details - -#ifndef HAVE_CFGROWLADDITIONS_H -#define HAVE_CFGROWLADDITIONS_H - -#include "CFGrowlDefines.h" - -//see GrowlApplicationBridge-Carbon.c for rationale of using NSLog. -extern void NSLog(STRING_TYPE format, ...); - -char *createFileSystemRepresentationOfString(STRING_TYPE str); -STRING_TYPE createStringWithDate(DATE_TYPE date); - -STRING_TYPE createStringWithContentsOfFile(STRING_TYPE filename, CFStringEncoding encoding); - -//you can leave out any of these three components. to leave out the character, pass 0xffff. -STRING_TYPE createStringWithStringAndCharacterAndString(STRING_TYPE str0, UniChar ch, STRING_TYPE str1); - -char *copyCString(STRING_TYPE str, CFStringEncoding encoding); - -STRING_TYPE copyCurrentProcessName(void); -URL_TYPE copyCurrentProcessURL(void); -STRING_TYPE copyCurrentProcessPath(void); - -URL_TYPE copyTemporaryFolderURL(void); -STRING_TYPE copyTemporaryFolderPath(void); - -STRING_TYPE createStringWithAddressData(DATA_TYPE aAddressData); -STRING_TYPE createHostNameForAddressData(DATA_TYPE aAddressData); - -DATA_TYPE readFile(const char *filename); -URL_TYPE copyURLForApplication(STRING_TYPE appName); - -/* @function copyIconDataForPath - * @param path The POSIX path to the file or folder whose icon you want. - * @result The icon data, in IconFamily format (same as used in the 'icns' resource and in .icns files). You are responsible for releasing this object. - */ -DATA_TYPE copyIconDataForPath(STRING_TYPE path); -/* @function copyIconDataForURL - * @param URL The URL to the file or folder whose icon you want. - * @result The icon data, in IconFamily format (same as used in the 'icns' resource and in .icns files). You are responsible for releasing this object. - */ -DATA_TYPE copyIconDataForURL(URL_TYPE URL); - -/* @function createURLByMakingDirectoryAtURLWithName - * @abstract Create a directory. - * @discussion This function has a useful side effect: if you pass - * NULL for both parameters, this function will act basically as - * CFURL version of getcwd(3). - * - * Also, for CF clients: the allocator used to create the returned URL will - * be the allocator for the parent URL, the allocator for the name string, or - * the default allocator, in that order of preference. - * @param parent The directory in which to create the new directory. If this is NULL, the current working directory (as returned by getcwd(3)) will be used. - * @param name The name of the directory you want to create. If this is NULL, the directory specified by the URL will be created. - * @result The URL for the directory if it was successfully created (in which case, you are responsible for releasing this object); else, NULL. - */ -URL_TYPE createURLByMakingDirectoryAtURLWithName(URL_TYPE parent, STRING_TYPE name); - -/* @function createURLByCopyingFileFromURLToDirectoryURL - * @param file The file to copy. - * @param dest The folder to copy it to. - * @result The copy. You are responsible for releasing this object. - */ -URL_TYPE createURLByCopyingFileFromURLToDirectoryURL(URL_TYPE file, URL_TYPE dest); - -/* @function createPropertyListFromURL - * @abstract Reads a property list from the contents of an URL. - * @discussion Creates a property list from the data at an URL (for example, a - * file URL), and returns it. - * @param file The file to read. - * @param mutability A mutability-option constant indicating whether the property list (and possibly its contents) should be mutable. - * @param outFormat If the property list is read successfully, this will point to the format of the property list. You may pass NULL if you are not interested in this information. If the property list is not read successfully, the value at this pointer will be left unchanged. - * @param outErrorString If an error occurs, this will point to a string (which you are responsible for releasing) describing the error. You may pass NULL if you are not interested in this information. If no error occurs, the value at this pointer will be left unchanged. - * @result The property list. You are responsible for releasing this object. - */ -PLIST_TYPE createPropertyListFromURL(URL_TYPE file, u_int32_t mutability, CFPropertyListFormat *outFormat, STRING_TYPE *outErrorString); - -#endif diff --git a/src/platform/DARWIN/growlagent/CFGrowlDefines.h b/src/platform/DARWIN/growlagent/CFGrowlDefines.h deleted file mode 100644 index da7c17c42..000000000 --- a/src/platform/DARWIN/growlagent/CFGrowlDefines.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// CFURLDefines.h -// Growl -// -// Created by Ingmar Stein on Fri Sep 16 2005. -// Copyright 2005-2006 The Growl Project. All rights reserved. -// -// This file is under the BSD License, refer to License.txt for details - -#ifndef HAVE_CFGROWLDEFINES_H -#define HAVE_CFGROWLDEFINES_H - -#ifdef __OBJC__ -# define DATA_TYPE NSData * -# define DATE_TYPE NSDate * -# define DICTIONARY_TYPE NSDictionary * -# define MUTABLE_DICTIONARY_TYPE NSMutableDictionary * -# define STRING_TYPE NSString * -# define ARRAY_TYPE NSArray * -# define URL_TYPE NSURL * -# define PLIST_TYPE NSObject * -# define OBJECT_TYPE id -# define BOOL_TYPE BOOL -#else -# include -# define DATA_TYPE CFDataRef -# define DATE_TYPE CFDateRef -# define DICTIONARY_TYPE CFDictionaryRef -# define MUTABLE_DICTIONARY_TYPE CFMutableDictionaryRef -# define STRING_TYPE CFStringRef -# define ARRAY_TYPE CFArrayRef -# define URL_TYPE CFURLRef -# define PLIST_TYPE CFPropertyListRef -# define OBJECT_TYPE CFTypeRef -# define BOOL_TYPE Boolean -#endif - -#endif diff --git a/src/platform/DARWIN/growlagent/Info.plist b/src/platform/DARWIN/growlagent/Info.plist new file mode 100644 index 000000000..2733788af --- /dev/null +++ b/src/platform/DARWIN/growlagent/Info.plist @@ -0,0 +1,42 @@ + + + + + BuildMachineOSBuild + 11E2620 + CFBundleDevelopmentRegion + English + CFBundleExecutable + growlagent-openafs + CFBundleIdentifier + org.openafs.network.growlagent-openafs + CFBundleIconFile + Andy.icns + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleVersion + 1.0 + DTCompiler + + DTPlatformBuild + 4E3002 + DTPlatformVersion + GM + DTSDKBuild + 11E52 + DTSDKName + macosx10.7 + DTXcode + 0433 + DTXcodeBuild + 4E3002 + LSUIElement + + NSPrincipalClass + NSApplication + + diff --git a/src/platform/DARWIN/growlagent/Makefile.in b/src/platform/DARWIN/growlagent/Makefile.in index 2f80ae9a4..404645449 100644 --- a/src/platform/DARWIN/growlagent/Makefile.in +++ b/src/platform/DARWIN/growlagent/Makefile.in @@ -5,31 +5,31 @@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ -OBJS=main.o CFGrowlAdditions.o +OBJS=main.o all: growlagent-openafs -_growlagent-openafs: ${OBJS} - ${CC} ${CFLAGS} -o $@ ${OBJS} -framework Security -framework AppKit -framework CoreFoundation +growlagent-openafs: ${OBJS} + ${CC} ${CFLAGS} -o $@ ${OBJS} -framework Security \ + -framework AppKit -framework CoreFoundation -growlagent-openafs: _growlagent-openafs - ${CP} $? $@ - Rez -o $@ growlagent.r - SetFile -a "C" $@ - -CFGrowlAdditions.o: CFGrowlAdditions.h -main.o: GrowlDefines.h GrowlPathway.h CFGrowlAdditions.h +main.o: GrowlDefines.h GrowlPathway.h clean: - $(RM) -f *.o growlagent-openafs _growlagent-openafs + $(RM) -f *.o growlagent-openafs install: dest: \ - ${DEST}/tools/growlagent-openafs - -${DEST}/tools/growlagent-openafs: growlagent-openafs - ${INSTALL} $? $@ + ${DEST}/tools/growlagent-openafs.app + +${DEST}/tools/growlagent-openafs.app: growlagent-openafs + -mkdir -p $@ + -mkdir -p $@/Contents/Resources/MacOS + -mkdir -p $@/Contents/MacOS + ${INSTALL} $? $@/Contents/MacOS + ${INSTALL} ${srcdir}/Andy.icns $@/Contents/Resources + ${INSTALL} ${srcdir}/Info.plist $@/Contents include ../../../config/Makefile.version diff --git a/src/platform/DARWIN/growlagent/main.m b/src/platform/DARWIN/growlagent/main.m index c269623fb..a39f77a2b 100644 --- a/src/platform/DARWIN/growlagent/main.m +++ b/src/platform/DARWIN/growlagent/main.m @@ -20,9 +20,9 @@ */ #import +#import #import "GrowlDefines.h" #import "GrowlPathway.h" -#include "CFGrowlAdditions.h" #include #include @@ -168,19 +168,32 @@ static void MySocketReadCallBack(CFSocketRef socket, CFSocketCallBackType callba } } +CFDataRef readFile(const char *filename) +{ + CFDataRef data; + // read the file into a CFDataRef + FILE *fp = fopen(filename, "r"); + if (fp) { + fseek(fp, 0, SEEK_END); + long dataLength = ftell(fp); + fseek(fp, 0, SEEK_SET); + unsigned char *fileData = malloc(dataLength); + fread(fileData, 1, dataLength, fp); + fclose(fp); + data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, fileData, dataLength, kCFAllocatorMalloc); + } else + data = NULL; + + return data; +} + int main(int argc, const char **argv) { BOOL wait = NO; int code = EXIT_SUCCESS; CFDataRef icon = NULL; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - // get icon data for application name - char *selfPath; - getPath(&selfPath); - CFStringRef appPath = CFStringCreateWithCString(kCFAllocatorDefault, selfPath, kCFStringEncodingUTF8); - NSURL *appURL = [NSURL fileURLWithPath:(NSString *)appPath]; - icon = (CFDataRef)copyIconDataForURL(appURL); - free(selfPath); + NSString* myImage = [[NSBundle mainBundle] pathForResource:@"Andy" ofType:@"icns"]; + icon = (CFDataRef) readFile([myImage UTF8String]); // Register with Growl CFStringRef name = NOTIFICATION_NAME;