Ignore:
Timestamp:
02/22/08 21:43:27 (13 years ago)
Author:
Nicholas Riley
Message:

Remove unnecessary CPS usage and CFBundleGetBundleWithIdentifier.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ICeCoffEE/ICeCoffEE/APEMain.m

    r388 r389  
    1717#import <objc/objc-runtime.h>
    1818#import "ICeCoffEE.h"
    19 #import "CPS.h"
    2019
    2120//¥¥¥ Our settings
     
    6665CFBundleRef ICCF_bundle;
    6766
    68 // With APE 1.3, if we're in the exclude list, APEBundleMainEarlyLoad doesn't get invoked; don't need to use APETools.  But we need to do our own management to avoid loading in non-GUI applications.
     67// With APE 1.3, if we're in the exclude list, APEBundleMainEarlyLoad doesn't get invoked; don't need to use APETools.  But we need to do our own management to avoid loading in background-only applications.
    6968Boolean ICCF_shouldLoad;
     69
     70static Boolean ICCF_IsOne(CFTypeRef value) {
     71    if (value == NULL)
     72        return false;
     73    CFTypeID typeID = CFGetTypeID(value);
     74    if (typeID == CFBooleanGetTypeID())
     75        return CFBooleanGetValue((CFBooleanRef)value);
     76    else if (typeID == CFNumberGetTypeID()) {
     77        static const int one = 1;
     78        static CFNumberRef oneRef = NULL;
     79        if (oneRef == NULL) oneRef = CFNumberCreate(NULL, kCFNumberIntType, &one);
     80        return CFNumberCompare((CFNumberRef)value, oneRef, NULL) == kCFCompareEqualTo;
     81    } else if (typeID == CFStringGetTypeID()) {
     82        return CFStringCompare((CFStringRef)value, CFSTR("1"), 0) == kCFCompareEqualTo;
     83    }
     84    return false;
     85}
    7086
    7187void APEBundleMainEarlyLoad(CFBundleRef inBundle, CFStringRef inAPEToolsApplicationID)
     
    8096
    8197    ICCF_shouldLoad = false;
    82 
    83     CPSProcessSerNum psn;
    84     OSStatus err = CPSGetCurrentProcess(&psn);
    85     if (err != noErr) {
    86 #if ICCF_DEBUG
    87         apeprintf("ICeCoffEE APE: Can't get process serial number for current process (error %ld); still loading because of ICCF_DEBUG\n", err);
    88 #else
    89         apeprintf("ICeCoffEE APE: Can't get process serial number for current process (error %ld); not loading in this application\n", err);
    90         return;
    91 #endif
    92     }
    93 
    94     CPSProcessInfoRec info;
    95     err = CPSGetProcessInfo(&psn, &info, NULL, 0, NULL, NULL, 0);
    96     if (err != noErr) {
    97 #if ICCF_DEBUG
    98         apeprintf("ICeCoffEE APE: Can't get process information (error %ld); still loading because of ICCF_DEBUG\n", err);
    99 #else
    100         apeprintf("ICeCoffEE APE: Can't get process information (error %ld); not loading in this application\n", err);
    101         return;
    102 #endif
    103     } else {
    104         ICapeprintf("ICeCoffEE APE: got process attributes = 0x%lx\n", info.Attributes);
    105         if (info.Attributes & (kCPSBGOnlyAttr | kCPSUIElementAttr | kCPSFullScreenAttr)) {
    106             ICapeprintf("ICeCoffEE APE: not loading as this application is background-only\n");
    107             return;
    108         }
     98   
     99    CFBundleRef appBundle = CFBundleGetMainBundle();
     100    if (appBundle == NULL) {
     101        apeprintf("ICeCoffEE APE: Can't get CFBundle for current process; not loading\n");
     102        return;
     103    }
     104   
     105    if (ICCF_IsOne(CFBundleGetValueForInfoDictionaryKey(appBundle, CFSTR("LSUIElement"))) ||
     106        ICCF_IsOne(CFBundleGetValueForInfoDictionaryKey(appBundle, CFSTR("NSUIElement"))) ||
     107        ICCF_IsOne(CFBundleGetValueForInfoDictionaryKey(appBundle, CFSTR("LSBackgroundOnly"))) ||
     108        ICCF_IsOne(CFBundleGetValueForInfoDictionaryKey(appBundle, CFSTR("NSBackgroundOnly")))) {
     109        ICapeprintf("ICeCoffEE APE: not loading as this application is background-only\n");
     110        return;
    109111    }
    110112    ICCF_shouldLoad = true;
    111113}
    112114
    113 Boolean ICCF_CFBundleIDMatches(CFStringRef bundleID, CFStringRef test) {
     115static Boolean ICCF_CFBundleIDMatches(CFStringRef bundleID, CFStringRef test) {
    114116    return CFStringCompare(bundleID, test, kCFCompareCaseInsensitive) == kCFCompareEqualTo;
    115117}
     
    119121    if (!ICCF_shouldLoad) return;
    120122
    121     ICCF_bundle = CFBundleGetBundleWithIdentifier(kICBundleIdentifier);
     123    ICCF_bundle = inBundle;
    122124    CFStringRef bundleID = CFBundleGetIdentifier(CFBundleGetMainBundle());
    123125    BOOL shouldLoadInNSTextView = YES;
Note: See TracChangeset for help on using the changeset viewer.