Changeset 146 for trunk/launch/launch/main.c
- Timestamp:
- 10/23/03 21:06:33 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/launch/launch/main.c
r138 r146 18 18 /* To do/think about: 19 19 20 - Do we need to assume -b if -h? Hiding the foreground app just makes21 it flash (only if Cocoa?)22 23 - Does -X work at all? What does it return if it fails?24 25 20 - Launching as root: use authentication framework - doesn't work. 26 21 … … 37 32 */ 38 33 39 #define DEBUG 1 34 /* #define DEBUG 1 */ 40 35 #define BROKEN_AUTHORIZATION 1 41 #define BROKEN_L AUNCHNEWINSTANCE136 #define BROKEN_LSOPENFROMURLSPEC 1 42 37 #define kComponentSignatureString "launch" 43 38 … … 56 51 const char *APP_NAME; 57 52 58 #define VERSION "1.0 b3"53 #define VERSION "1.0" 59 54 60 55 #define STRBUF_LEN 1024 … … 90 85 { kLSLaunchInProgressErr, "application is being opened; please try again after the application is open" }, 91 86 { kLSNotRegisteredErr, "application not registered in Launch Services database" }, 87 { kLSNoExecutableErr, "application package contains no executable, or an unusable executable" }, 88 { kLSNoClassicEnvironmentErr, "Classic environment required but not available" }, 92 89 #ifndef BROKEN_AUTHORIZATION 93 90 // Security framework errors … … 102 99 { procNotFound, "unable to connect to system service.\nAre you logged in?" }, 103 100 { kCGErrorIllegalArgument, "window server error.\nAre you logged in?" }, 101 { kCGErrorApplicationRequiresNewerSystem, "application requires a newer Mac OS X version" }, 104 102 { fnfErr, "file not found" }, 105 103 { 0, NULL } … … 119 117 " -w wait for application to finish opening before exiting\n" 120 118 " -b launch application in the background\n" 121 #ifndef BROKEN_LAUNCHNEWINSTANCE122 119 " -m launch application again, even if already running\n" 123 #endif124 120 " -h hide application once it's finished opening\n" 125 121 " -C force CFM/PEF Carbon application to launch in Classic\n" … … 254 250 CFRelease(url); 255 251 url = NULL; 256 } 252 } else { 253 CFRelease(scheme); 254 } 257 255 } 258 256 } … … 382 380 case 'w': LSPEC.launchFlags ^= kLSLaunchAsync; break; // synchronous 383 381 case 'b': LSPEC.launchFlags |= kLSLaunchDontSwitch; break; // open in background 384 #ifdef BROKEN_LAUNCHNEWINSTANCE385 case 'm': errexit("-m option not functional (LaunchServices bug?), sorry");386 #else387 382 case 'm': LSPEC.launchFlags |= kLSLaunchNewInstance; break;// open multiple 388 #endif389 383 case 'h': LSPEC.launchFlags |= kLSLaunchAndHide; break; // hide once launched 390 384 case 'C': LSPEC.launchFlags |= kLSLaunchInClassic; break; // force Classic … … 419 413 if (scheme == NULL || !CFEqual(scheme, CFSTR("file"))) 420 414 errexit("invalid file:// URL (argument of -u)"); 415 CFRelease(scheme); 421 416 } 422 417 } … … 501 496 } 502 497 503 // 'context' is to match prototype for CFArrayApplierFunction, it's unused 504 void printPathFromURL(CFURLRef url, void *context) { 498 void printPathFromURL(CFURLRef url, FILE *stream) { 505 499 CFStringRef scheme, pathOrURL; 506 500 static char strBuffer[STRBUF_LEN]; 507 501 508 check(url != NULL && context == NULL);502 check(url != NULL && stream != NULL); 509 503 510 504 scheme = CFURLCopyScheme(url); … … 517 511 strBuffer[0] = '\0'; 518 512 CFStringGetCString(pathOrURL, strBuffer, STRBUF_LEN, CFStringGetSystemEncoding()); // XXX buffer size issues? 519 printf("%s\n", strBuffer);513 fprintf(stream, "%s\n", strBuffer); 520 514 CFRelease(scheme); 521 515 CFRelease(pathOrURL); … … 700 694 bundleID = CFDictionaryGetValue(infoPlist, kCFBundleIdentifierKey); 701 695 if (bundleID != NULL) CFRetain(bundleID); 702 CFStringRefappVersion = CFDictionaryGetValue(infoPlist, CFSTR("CFBundleShortVersionString"));696 appVersion = CFDictionaryGetValue(infoPlist, CFSTR("CFBundleShortVersionString")); 703 697 if (appVersion == NULL) 704 698 appVersion = CFDictionaryGetValue(infoPlist, kCFBundleVersionKey); … … 723 717 if (bundleID != NULL) CFRetain(bundleID); 724 718 // prefer a short version string, e.g. "1.0 Beta" instead of "51" for Safari 725 CFStringRefappVersion = CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("CFBundleShortVersionString"));719 appVersion = CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("CFBundleShortVersionString")); 726 720 if (appVersion == NULL) 727 721 appVersion = CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleVersionKey); 728 if (appVersion != NULL) 722 if (appVersion != NULL) { 723 CFRetain(appVersion); 729 724 intVersion = CFBundleGetVersionNumber(bundle); 725 } 730 726 CFRelease(bundle); 731 727 } … … 749 745 CFStringGetCString(kind, tmpBuffer, STRBUF_LEN, CFStringGetSystemEncoding()); 750 746 printf("\tkind: %s\n", tmpBuffer); 747 CFRelease(kind); 751 748 printMoreInfoFromURL(url); 752 749 } … … 772 769 773 770 CFRelease(urlStr); 771 } 772 773 OSStatus openFromURLSpec() { 774 #ifndef BROKEN_LSOPENFROMURLSPEC 775 return LSOpenFromURLSpec(&LSPEC, NULL); 776 #else 777 LSLaunchFSRefSpec spec = {NULL, 0, NULL, LSPEC.passThruParams, 778 LSPEC.launchFlags, LSPEC.asyncRefCon}; 779 CFIndex urlIndex, urlCount = LSPEC.itemURLs ? CFArrayGetCount(LSPEC.itemURLs) : 0; 780 FSRef *itemRefs = malloc(urlCount * sizeof(FSRef)); 781 CFURLRef url; 782 CFStringRef scheme, fileScheme = CFSTR("file"); 783 int itemIndex = 0; 784 OSStatus err; 785 786 for (urlIndex = 0 ; urlIndex < urlCount ; urlIndex++) { 787 url = CFArrayGetValueAtIndex(LSPEC.itemURLs, urlIndex); 788 scheme = CFURLCopyScheme(url); 789 if (CFEqual(scheme, fileScheme)) { 790 if (CFURLGetFSRef(url, &itemRefs[itemIndex])) { 791 itemIndex++; 792 CFArrayRemoveValueAtIndex((CFMutableArrayRef)LSPEC.itemURLs, urlIndex); 793 urlIndex--; 794 urlCount--; 795 } else { 796 fprintf(stderr, "%s: unable to locate: ", APP_NAME); 797 printPathFromURL(url, stderr); 798 } 799 } 800 CFRelease(scheme); 801 } 802 803 if (urlCount > 0 || itemIndex == 0) { /* URLs, or no items */ 804 err = LSOpenFromURLSpec(&LSPEC, NULL); 805 if (err != noErr) 806 return err; 807 } 808 if (itemIndex > 0) { 809 FSRef appRef; 810 spec.numDocs = itemIndex; 811 spec.itemRefs = itemRefs; 812 if (LSPEC.appURL != NULL) { 813 if (!CFURLGetFSRef(LSPEC.appURL, &appRef)) { 814 errexit("can't find application"); 815 } 816 spec.appRef = &appRef; 817 } 818 return LSOpenFromRefSpec(&spec, NULL); 819 } 820 return noErr; 821 #endif 774 822 } 775 823 … … 798 846 switch (OPTS.action) { 799 847 case ACTION_FIND: 800 printPathFromURL(LSPEC.appURL, NULL);848 printPathFromURL(LSPEC.appURL, stdout); 801 849 break; 802 850 case ACTION_OPEN: 803 err = LSOpenFromURLSpec(&LSPEC, NULL);851 err = openFromURLSpec(); 804 852 if (err != noErr) osstatusexit(err, "can't open application", argv[1]); 805 853 break; 806 854 case ACTION_FIND_ITEMS: 807 855 CFArrayApplyFunction(LSPEC.itemURLs, CFRangeMake(0, CFArrayGetCount(LSPEC.itemURLs)), 808 (CFArrayApplierFunction) printPathFromURL, NULL);856 (CFArrayApplierFunction) printPathFromURL, stdout); 809 857 break; 810 858 case ACTION_OPEN_ITEMS: 811 err = LSOpenFromURLSpec(&LSPEC, NULL);859 err = openFromURLSpec(); 812 860 if (err != noErr) osstatusexit(err, "can't open items", argv[1]); 813 861 break; … … 819 867 { 820 868 ICInstance icInst; 821 err = ICStart(&icInst, ' ????');869 err = ICStart(&icInst, '\?\?\?\?'); // in case GCC trigraph handling is enabled 822 870 if (err != noErr) osstatusexit(err, "can't initialize Internet Config", argv[1]); 823 871 CFArrayApplyFunction(LSPEC.itemURLs, CFRangeMake(0, CFArrayGetCount(LSPEC.itemURLs)),
Note:
See TracChangeset
for help on using the changeset viewer.