this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

LaunchServices implementation progress

+1859 -283
+1 -8
src/frameworks/CoreServices/include/CoreServices/CoreServicesPriv.h
··· 5 5 #include <CoreFoundation/CFURLPriv.h> 6 6 7 7 #include <CoreServices/CoreServices.h> 8 + #include <LaunchServices/LaunchServicesPriv.h> 8 9 9 10 CF_EXTERN_C_BEGIN 10 11 11 12 Boolean _CSCheckFix(CFStringRef str); 12 - 13 - // Assumed 14 - #define kLSDownloadRiskCategoryKey CFSTR("LSDownloadRiskCategory") 15 - 16 - #define kLSRiskCategorySafe "LSRiskCategorySafe" 17 - #define kLSRiskCategoryNeutral "LSRiskCategoryNeutral" 18 - #define kLSRiskCategoryUnknown "LSRiskCategoryUnknown" 19 - #define kLSRiskCategoryMayContainUnsafeExecutable "LSRiskCategoryMayContainUnsafeExecutable" 20 13 21 14 // Also assumed 22 15 #define QTN_FLAG_ASSESSMENT_OK 1
+138
src/frameworks/CoreServices/include/LaunchServices/LSInfo.h
··· 1 + #ifndef __LSINFO__ 2 + #define __LSINFO__ 3 + 4 + #include <CoreFoundation/CoreFoundation.h> 5 + #include <CoreServices/MacTypes.h> 6 + #include <CoreServices/FileManager.h> 7 + 8 + #ifdef __cplusplus 9 + extern "C" { 10 + #endif 11 + 12 + 13 + #pragma pack(push, 2) 14 + enum { 15 + kLSAppInTrashErr = -10660, 16 + kLSExecutableIncorrectFormat = -10661, 17 + kLSAttributeNotFoundErr = -10662, 18 + kLSAttributeNotSettableErr = -10663, 19 + kLSIncompatibleApplicationVersionErr = -10664, 20 + kLSNoRosettaEnvironmentErr = -10665, 21 + kLSGarbageCollectionUnsupportedErr = -10666, 22 + kLSUnknownErr = -10810, 23 + kLSNotAnApplicationErr = -10811, 24 + kLSNotInitializedErr = -10812, 25 + kLSDataUnavailableErr = -10813, 26 + kLSApplicationNotFoundErr = -10814, 27 + kLSUnknownTypeErr = -10815, 28 + kLSDataTooOldErr = -10816, 29 + kLSDataErr = -10817, 30 + kLSLaunchInProgressErr = -10818, 31 + kLSNotRegisteredErr = -10819, 32 + kLSAppDoesNotClaimTypeErr = -10820, 33 + kLSAppDoesNotSupportSchemeWarning = -10821, 34 + kLSServerCommunicationErr = -10822, 35 + kLSCannotSetInfoErr = -10823, 36 + kLSNoRegistrationInfoErr = -10824, 37 + kLSIncompatibleSystemVersionErr = -10825, 38 + kLSNoLaunchPermissionErr = -10826, 39 + kLSNoExecutableErr = -10827, 40 + kLSNoClassicEnvironmentErr = -10828, 41 + kLSMultipleSessionsNotSupportedErr = -10829, 42 + }; 43 + 44 + typedef OptionBits LSRolesMask; 45 + 46 + enum { 47 + kLSRolesNone = 0x00000001, 48 + kLSRolesViewer = 0x00000002, 49 + kLSRolesEditor = 0x00000004, 50 + kLSRolesShell = 0x00000008, 51 + kLSRolesAll = (UInt32)0xFFFFFFFF 52 + }; 53 + 54 + enum { 55 + kLSUnknownType = 0, 56 + kLSUnknownCreator = 0 57 + }; 58 + 59 + typedef OptionBits LSAcceptanceFlags; 60 + enum { 61 + kLSAcceptDefault = 0x00000001, 62 + kLSAcceptAllowLoginUI = 0x00000002 63 + }; 64 + 65 + extern _Nullable CFURLRef 66 + LSCopyDefaultApplicationURLForURL( 67 + CFURLRef inURL, 68 + LSRolesMask inRoleMask, 69 + _Nullable CFErrorRef *_Nullable outError); 70 + 71 + extern _Nullable CFURLRef 72 + LSCopyDefaultApplicationURLForContentType( 73 + CFStringRef inContentType, 74 + LSRolesMask inRoleMask, 75 + _Nullable CFErrorRef *_Nullable outError); 76 + 77 + extern _Nullable CFArrayRef 78 + LSCopyApplicationURLsForBundleIdentifier( 79 + CFStringRef inBundleIdentifier, 80 + _Nullable CFErrorRef *_Nullable outError); 81 + 82 + extern _Nullable CFArrayRef 83 + LSCopyApplicationURLsForURL( 84 + CFURLRef inURL, 85 + LSRolesMask inRoleMask); 86 + 87 + extern OSStatus 88 + LSCanURLAcceptURL( 89 + CFURLRef inItemURL, 90 + CFURLRef inTargetURL, 91 + LSRolesMask inRoleMask, 92 + LSAcceptanceFlags inFlags, 93 + Boolean * outAcceptsItem); 94 + 95 + extern OSStatus 96 + LSRegisterURL( 97 + CFURLRef inURL, 98 + Boolean inUpdate); 99 + 100 + extern _Nullable CFStringRef 101 + LSCopyDefaultRoleHandlerForContentType( 102 + CFStringRef inContentType, 103 + LSRolesMask inRole); 104 + 105 + extern _Nullable CFArrayRef 106 + LSCopyAllRoleHandlersForContentType( 107 + CFStringRef inContentType, 108 + LSRolesMask inRole); 109 + 110 + extern OSStatus 111 + LSSetDefaultRoleHandlerForContentType( 112 + CFStringRef inContentType, 113 + LSRolesMask inRole, 114 + CFStringRef inHandlerBundleID); 115 + 116 + extern _Nullable CFStringRef 117 + LSCopyDefaultHandlerForURLScheme(CFStringRef inURLScheme); 118 + 119 + extern _Nullable CFArrayRef 120 + LSCopyAllHandlersForURLScheme(CFStringRef inURLScheme); 121 + 122 + extern OSStatus 123 + LSSetDefaultHandlerForURLScheme( 124 + CFStringRef inURLScheme, 125 + CFStringRef inHandlerBundleID); 126 + 127 + 128 + #pragma pack(pop) 129 + 130 + 131 + #ifdef __cplusplus 132 + } 133 + #endif 134 + 135 + #include <LaunchServices/LSInfoDeprecated.h> 136 + 137 + #endif 138 +
+206
src/frameworks/CoreServices/include/LaunchServices/LSInfoDeprecated.h
··· 1 + #ifdef __cplusplus 2 + extern "C" { 3 + #endif 4 + 5 + #pragma pack(push, 2) 6 + 7 + typedef CF_OPTIONS(OptionBits, LSRequestedInfo) { 8 + kLSRequestExtension = 0x00000001, 9 + kLSRequestTypeCreator = 0x00000002, 10 + kLSRequestBasicFlagsOnly = 0x00000004, 11 + kLSRequestAppTypeFlags = 0x00000008, 12 + kLSRequestAllFlags = 0x00000010, 13 + kLSRequestIconAndKind = 0x00000020, 14 + kLSRequestExtensionFlagsOnly = 0x00000040, 15 + kLSRequestAllInfo = (UInt32)0xFFFFFFFF 16 + }; 17 + 18 + 19 + 20 + typedef CF_OPTIONS(OptionBits, LSItemInfoFlags) { 21 + kLSItemInfoIsPlainFile = 0x00000001, 22 + kLSItemInfoIsPackage = 0x00000002, 23 + kLSItemInfoIsApplication = 0x00000004, 24 + kLSItemInfoIsContainer = 0x00000008, 25 + kLSItemInfoIsAliasFile = 0x00000010, 26 + kLSItemInfoIsSymlink = 0x00000020, 27 + kLSItemInfoIsInvisible = 0x00000040, 28 + kLSItemInfoIsNativeApp = 0x00000080, 29 + kLSItemInfoIsClassicApp = 0x00000100, 30 + kLSItemInfoAppPrefersNative = 0x00000200, 31 + kLSItemInfoAppPrefersClassic = 0x00000400, 32 + kLSItemInfoAppIsScriptable = 0x00000800, 33 + kLSItemInfoIsVolume = 0x00001000, 34 + kLSItemInfoExtensionIsHidden = 0x00100000 35 + }; 36 + 37 + typedef struct LSItemInfoRecord { 38 + LSItemInfoFlags flags; 39 + OSType filetype; 40 + OSType creator; 41 + CFStringRef extension; 42 + } LSItemInfoRecord; 43 + 44 + extern OSStatus 45 + LSCopyItemInfoForURL( 46 + CFURLRef inURL, 47 + LSRequestedInfo inWhichInfo, 48 + LSItemInfoRecord * outItemInfo); 49 + 50 + extern OSStatus 51 + LSCopyItemInfoForRef( 52 + const FSRef * inItemRef, 53 + LSRequestedInfo inWhichInfo, 54 + LSItemInfoRecord * outItemInfo); 55 + 56 + extern OSStatus 57 + LSGetExtensionInfo( 58 + UniCharCount inNameLen, 59 + const UniChar inNameBuffer[], 60 + UniCharCount * outExtStartIndex); 61 + 62 + extern OSStatus 63 + LSCopyDisplayNameForRef( 64 + const FSRef * inRef, 65 + CFStringRef * outDisplayName); 66 + 67 + extern OSStatus 68 + LSCopyDisplayNameForURL( 69 + CFURLRef inURL, 70 + CFStringRef * outDisplayName); 71 + 72 + extern OSStatus 73 + LSSetExtensionHiddenForRef( 74 + const FSRef * inRef, 75 + Boolean inHide); 76 + 77 + extern OSStatus 78 + LSSetExtensionHiddenForURL( 79 + CFURLRef inURL, 80 + Boolean inHide); 81 + 82 + extern OSStatus 83 + LSCopyKindStringForRef( 84 + const FSRef * inFSRef, 85 + CFStringRef * outKindString); 86 + 87 + extern OSStatus 88 + LSCopyKindStringForURL( 89 + CFURLRef inURL, 90 + CFStringRef * outKindString); 91 + 92 + extern OSStatus 93 + LSCopyKindStringForTypeInfo( 94 + OSType inType, 95 + OSType inCreator, 96 + CFStringRef inExtension, 97 + CFStringRef * outKindString); 98 + 99 + extern OSStatus 100 + LSCopyKindStringForMIMEType( 101 + CFStringRef inMIMEType, 102 + CFStringRef * outKindString); 103 + 104 + extern OSStatus 105 + LSGetApplicationForItem( 106 + const FSRef * inItemRef, 107 + LSRolesMask inRoleMask, 108 + FSRef * outAppRef, 109 + CFURLRef * outAppURL); 110 + 111 + extern OSStatus 112 + LSGetApplicationForInfo( 113 + OSType inType, 114 + OSType inCreator, 115 + CFStringRef inExtension, 116 + LSRolesMask inRoleMask, 117 + FSRef * outAppRef, 118 + CFURLRef * outAppURL); 119 + 120 + extern OSStatus 121 + LSCopyApplicationForMIMEType( 122 + CFStringRef inMIMEType, 123 + LSRolesMask inRoleMask, 124 + CFURLRef * outAppURL); 125 + 126 + extern OSStatus 127 + LSGetApplicationForURL( 128 + CFURLRef inURL, 129 + LSRolesMask inRoleMask, 130 + FSRef * outAppRef, 131 + CFURLRef * outAppURL); 132 + 133 + extern OSStatus 134 + LSFindApplicationForInfo( 135 + OSType inCreator, 136 + CFStringRef inBundleID, 137 + CFStringRef inName, 138 + FSRef * outAppRef, 139 + CFURLRef * outAppURL); 140 + 141 + extern OSStatus 142 + LSCanRefAcceptItem( 143 + const FSRef * inItemFSRef, 144 + const FSRef * inTargetRef, 145 + LSRolesMask inRoleMask, 146 + LSAcceptanceFlags inFlags, 147 + Boolean * outAcceptsItem); 148 + 149 + extern OSStatus 150 + LSRegisterFSRef( 151 + const FSRef * inRef, 152 + Boolean inUpdate); 153 + 154 + extern const CFStringRef kLSItemContentType; 155 + extern const CFStringRef kLSItemFileType; 156 + extern const CFStringRef kLSItemFileCreator; 157 + extern const CFStringRef kLSItemExtension; 158 + extern const CFStringRef kLSItemDisplayName; 159 + extern const CFStringRef kLSItemDisplayKind; 160 + extern const CFStringRef kLSItemRoleHandlerDisplayName; 161 + extern const CFStringRef kLSItemIsInvisible; 162 + extern const CFStringRef kLSItemExtensionIsHidden; 163 + extern const CFStringRef kLSItemQuarantineProperties; 164 + 165 + extern OSStatus 166 + LSCopyItemAttribute( 167 + const FSRef * inItem, 168 + LSRolesMask inRoles, 169 + CFStringRef inAttributeName, 170 + CFTypeRef * outValue); 171 + 172 + extern OSStatus 173 + LSCopyItemAttributes( 174 + const FSRef * inItem, 175 + LSRolesMask inRoles, 176 + CFArrayRef inAttributeNames, 177 + CFDictionaryRef * outValues); 178 + 179 + extern OSStatus 180 + LSSetItemAttribute( 181 + const FSRef * inItem, 182 + LSRolesMask inRoles, 183 + CFStringRef inAttributeName, 184 + CFTypeRef inValue); 185 + 186 + typedef CF_OPTIONS(OptionBits, LSHandlerOptions) { 187 + kLSHandlerOptionsDefault = 0, 188 + kLSHandlerOptionsIgnoreCreator = 1 189 + }; 190 + 191 + extern LSHandlerOptions 192 + LSGetHandlerOptionsForContentType(CFStringRef inContentType); 193 + 194 + extern OSStatus 195 + LSSetHandlerOptionsForContentType( 196 + CFStringRef inContentType, 197 + LSHandlerOptions inOptions); 198 + 199 + 200 + 201 + #pragma pack(pop) 202 + 203 + #ifdef __cplusplus 204 + } 205 + #endif 206 +
+54
src/frameworks/CoreServices/include/LaunchServices/LSOpen.h
··· 1 + #ifndef __LSOPEN__ 2 + #define __LSOPEN__ 3 + 4 + #include <CoreFoundation/CoreFoundation.h> 5 + #include <LaunchServices/LSInfo.h> 6 + #include <CoreServices/FileManager.h> 7 + #include <AE/AE.h> 8 + 9 + #ifdef __cplusplus 10 + extern "C" { 11 + #endif 12 + 13 + #pragma pack(push, 2) 14 + typedef OptionBits LSLaunchFlags; 15 + 16 + enum { 17 + kLSLaunchDefaults = 0x00000001, 18 + kLSLaunchAndPrint = 0x00000002, 19 + kLSLaunchAndDisplayErrors = 0x00000040, 20 + kLSLaunchDontAddToRecents = 0x00000100, 21 + kLSLaunchDontSwitch = 0x00000200, 22 + kLSLaunchAsync = 0x00010000, 23 + kLSLaunchNewInstance = 0x00080000, 24 + kLSLaunchAndHide = 0x00100000, 25 + kLSLaunchAndHideOthers = 0x00200000, 26 + }; 27 + 28 + typedef struct LSLaunchURLSpec { 29 + _Nullable CFURLRef appURL; 30 + _Nullable CFArrayRef itemURLs; 31 + const AEDesc * _Nullable passThruParams; 32 + LSLaunchFlags launchFlags; 33 + void * _Nullable asyncRefCon; 34 + } LSLaunchURLSpec; 35 + 36 + extern OSStatus 37 + LSOpenCFURLRef( 38 + CFURLRef inURL, 39 + _Nullable CFURLRef *_Nullable outLaunchedURL); 40 + 41 + extern OSStatus 42 + LSOpenFromURLSpec( 43 + const LSLaunchURLSpec * inLaunchSpec, 44 + _Nullable CFURLRef *_Nullable outLaunchedURL); 45 + 46 + #pragma pack(pop) 47 + 48 + #ifdef __cplusplus 49 + } 50 + #endif 51 + 52 + #include <LaunchServices/LSOpenDeprecated.h> 53 + 54 + #endif
+77
src/frameworks/CoreServices/include/LaunchServices/LSOpenDeprecated.h
··· 1 + #ifdef __cplusplus 2 + extern "C" { 3 + #endif 4 + 5 + #pragma pack(push, 2) 6 + 7 + enum { 8 + kLSLaunchInhibitBGOnly= 0x00000080, 9 + kLSLaunchNoParams = 0x00000800, 10 + kLSLaunchStartClassic = 0x00020000, 11 + kLSLaunchInClassic = 0x00040000, 12 + kLSLaunchHasUntrustedContents = 0x00400000, 13 + }; 14 + 15 + 16 + typedef struct LSLaunchFSRefSpec { 17 + const FSRef * appRef; 18 + ItemCount numDocs; 19 + const FSRef * itemRefs; 20 + const AEDesc * passThruParams; 21 + 22 + LSLaunchFlags launchFlags; 23 + void * asyncRefCon; 24 + } LSLaunchFSRefSpec; 25 + 26 + extern OSStatus 27 + LSOpenFSRef( 28 + const FSRef * inRef, 29 + FSRef * outLaunchedRef); 30 + 31 + extern OSStatus 32 + LSOpenFromRefSpec( 33 + const LSLaunchFSRefSpec * inLaunchSpec, 34 + FSRef * outLaunchedRef); 35 + 36 + typedef struct LSApplicationParameters { 37 + CFIndex version; 38 + LSLaunchFlags flags; 39 + const FSRef * application; 40 + void * asyncLaunchRefCon; 41 + CFDictionaryRef environment; 42 + 43 + CFArrayRef argv; 44 + 45 + AppleEvent * initialEvent; 46 + } LSApplicationParameters; 47 + 48 + extern OSStatus 49 + LSOpenApplication( 50 + const LSApplicationParameters * appParams, 51 + ProcessSerialNumber * outPSN); 52 + 53 + extern OSStatus 54 + LSOpenItemsWithRole( 55 + const FSRef * inItems, 56 + CFIndex inItemCount, 57 + LSRolesMask inRole, 58 + const AEKeyDesc * inAEParam, 59 + const LSApplicationParameters * inAppParams, 60 + ProcessSerialNumber * outPSNs, 61 + CFIndex inMaxPSNCount); 62 + 63 + extern OSStatus 64 + LSOpenURLsWithRole( 65 + CFArrayRef inURLs, 66 + LSRolesMask inRole, 67 + const AEKeyDesc * inAEParam, 68 + const LSApplicationParameters * inAppParams, 69 + ProcessSerialNumber * outPSNs, 70 + CFIndex inMaxPSNCount); 71 + 72 + #pragma pack(pop) 73 + 74 + #ifdef __cplusplus 75 + } 76 + #endif 77 +
+4 -102
src/frameworks/CoreServices/include/LaunchServices/LaunchServices.h
··· 1 1 #ifndef LAUNCHSERVICES_H 2 2 #define LAUNCHSERVICES_H 3 3 4 - #include <CoreServices/MacTypes.h> 5 - #include <CoreServices/FileManager.h> 6 - #include <HIServices/Processes.h> 7 - #include <CoreFoundation/CFDictionary.h> 8 - #include <CoreFoundation/CFArray.h> 9 - #include <CoreFoundation/CFURL.h> 10 - 11 - #include <AE/AE.h> 12 - 13 - #ifdef __cplusplus 14 - extern "C" { 15 - #endif 16 - 17 - typedef OptionBits LSInitializeFlags; 18 - typedef OptionBits LSLaunchFlags; 19 - typedef int LSNotificationCode; 20 - typedef int LSNotificationID; 21 - typedef int LSASN; 22 - typedef CFTypeRef LSASNRef; 23 - typedef int LSSessionID; 24 - 25 - #define kLSNotificationInvalidID -1 26 - #define kLSNotifyApplicationDeath 1 27 - #define kLSUnknownErr -1 28 - 29 - #define kLSApplicationNotFoundErr -10814; 30 - 31 - #define kLSDefaultSessionID 1 32 - 33 - enum 34 - { 35 - kLSLaunchDefaults = 0x00000001, 36 - kLSLaunchAndPrint = 0x00000002, 37 - kLSLaunchReserved2 = 0x00000004, 38 - kLSLaunchReserved3 = 0x00000008, 39 - kLSLaunchReserved4 = 0x00000010, 40 - kLSLaunchReserved5 = 0x00000020, 41 - kLSLaunchAndDisplayErrors = 0x00000040, 42 - kLSLaunchInhibitBGOnly = 0x00000080, 43 - kLSLaunchDontAddToRecents = 0x00000100, 44 - kLSLaunchDontSwitch = 0x00000200, 45 - kLSLaunchNoParams = 0x00000800, 46 - kLSLaunchAsync = 0x00010000, 47 - kLSLaunchStartClassic = 0x00020000, 48 - kLSLaunchInClassic = 0x00040000, 49 - kLSLaunchNewInstance = 0x00080000, 50 - kLSLaunchAndHide = 0x00100000, 51 - kLSLaunchAndHideOthers = 0x00200000, 52 - kLSLaunchHasUntrustedContents = 0x00400000 53 - }; 54 - 55 - typedef struct LSApplicationParameters 56 - { 57 - CFIndex version; 58 - LSLaunchFlags flags; 59 - const FSRef * application; 60 - void * asyncLaunchRefCon; 61 - CFDictionaryRef environment; 62 - CFArrayRef argv; 63 - AppleEvent * initialEvent; 64 - } LSApplicationParameters; 65 - 66 - OSStatus LSInit(LSInitializeFlags flags); 67 - OSStatus LSTerm(void); 68 - 69 - typedef struct LSLaunchURLSpec 70 - { 71 - CFURLRef appURL; 72 - CFArrayRef itemURLs; 73 - const AEDesc *passThruParams; 74 - LSLaunchFlags launchFlags; 75 - void *asyncRefCon; 76 - } LSLaunchURLSpec; 77 - 78 - 79 - OSStatus LSOpenApplication(const LSApplicationParameters *appParams, ProcessSerialNumber *outPSN); 80 - OSStatus LSOpenCFURLRef(CFURLRef inURL, CFURLRef *outLaunchedURL); 81 - OSStatus LSOpenFromURLSpec(const LSLaunchURLSpec *inLaunchSpec, CFURLRef *outLaunchedURL); 82 - OSStatus LSOpenFSRef(const FSRef *inRef, FSRef *outLaunchedRef); 83 - 84 - OSStatus LSGetExtensionInfo(UniCharCount inNameLen, const UniChar* inNameBuffer, UniCharCount *outExtStartIndex); 85 - OSStatus LSSetExtensionHiddenForRef(const FSRef *inRef, Boolean hide); 86 - OSStatus LSSetExtensionHiddenForURL(CFURLRef inURL, Boolean hide); 87 - 88 - CFTypeRef _LSCopyApplicationInformationItem(int /* hopefully */, CFTypeRef asn, CFStringRef what); 89 - 90 - CFDictionaryRef _LSCopyApplicationInformation(int, CFTypeRef asn, int); 91 - 92 - LSASNRef _LSASNCreateWithPid(CFAllocatorRef allocator, pid_t pid); 93 - 94 - extern CFStringRef LSUserApplicationType, LSSystemApplicationType, LSInternalApplicationType, LSPlugInKitType, LSVPNPluginType; 95 - 96 - //OSStatus _LSOpenURLsWithRole(CFArrayRef inURLs, LSRolesMask inRole, void *unknown); 97 - 98 - // TODO: many other functions 99 - 100 - // Undocumented, not sure on correct parameters 101 - OSStatus _LSLaunchApplication(CFURLRef appPath); 102 - 103 - #ifdef __cplusplus 104 - } 105 - #endif 4 + #include <LaunchServices/LSInfo.h> 5 + #include <LaunchServices/LSOpen.h> 6 + #include <LaunchServices/UTCoreTypes.h> 7 + #include <LaunchServices/UTType.h> 106 8 107 9 #endif 108 10
+33 -4
src/frameworks/CoreServices/include/LaunchServices/LaunchServicesPriv.h
··· 8 8 extern "C" { 9 9 #endif 10 10 11 + typedef CFTypeRef LSASNRef; 12 + typedef int LSSessionID; 13 + typedef int LSNotificationCode; 14 + typedef int LSNotificationID; 15 + typedef OptionBits LSInitializeFlags; 16 + 11 17 enum 12 18 { 13 - _kLSDefaultSessionID = -2, 19 + kLSDefaultSessionID = -2, 20 + }; 21 + 22 + // Used in Security 23 + enum 24 + { 25 + kLSNotificationInvalidID = -1, 26 + kLSNotifyApplicationDeath = 1, 14 27 }; 15 28 16 29 enum ··· 62 75 extern const CFStringRef _kLSExecutableFormatCFMKey; 63 76 64 77 // Example call: 65 - // _LSApplicationCheckIn(_kLSDefaultSessionID, CFBundleGetInfoDictionary(CFBundleGetMainBundle())) 78 + // _LSApplicationCheckIn(kLSDefaultSessionID, CFBundleGetInfoDictionary(CFBundleGetMainBundle())) 66 79 // Normally to be called from -[NSApplication init] 67 - CFDictionaryRef _LSApplicationCheckIn(int sessionID, CFDictionaryRef applicationInfo); 80 + CFDictionaryRef _LSApplicationCheckIn(LSSessionID sessionID, CFDictionaryRef applicationInfo); 68 81 69 82 CFTypeRef _LSGetCurrentApplicationASN(void); 70 - OSStatus _LSSetApplicationInformationItem(int sessionID, LSASNRef asn, CFStringRef key, CFStringRef value, CFDictionaryRef *info); 83 + OSStatus _LSSetApplicationInformationItem(LSSessionID sessionID, LSASNRef asn, CFStringRef key, CFStringRef value, CFDictionaryRef *info); 71 84 72 85 typedef bool (^LSServerConnectionAllowedBlock) ( CFDictionaryRef optionsRef ); 73 86 void _LSSetApplicationLaunchServicesServerConnectionStatus(uint64_t flags, LSServerConnectionAllowedBlock block); 87 + 88 + CFTypeRef _LSCopyApplicationInformationItem(LSSessionID sessionID, CFTypeRef asn, CFStringRef what); 89 + 90 + CFDictionaryRef _LSCopyApplicationInformation(LSSessionID sessionID, CFTypeRef asn, int); 91 + 92 + LSASNRef _LSASNCreateWithPid(CFAllocatorRef allocator, pid_t pid); 93 + 94 + OSStatus _LSLaunchApplication(CFURLRef appPath); 95 + 96 + // Assumed 97 + #define kLSDownloadRiskCategoryKey CFSTR("LSDownloadRiskCategory") 98 + 99 + #define kLSRiskCategorySafe "LSRiskCategorySafe" 100 + #define kLSRiskCategoryNeutral "LSRiskCategoryNeutral" 101 + #define kLSRiskCategoryUnknown "LSRiskCategoryUnknown" 102 + #define kLSRiskCategoryMayContainUnsafeExecutable "LSRiskCategoryMayContainUnsafeExecutable" 74 103 75 104 #ifdef __cplusplus 76 105 }
+146
src/frameworks/CoreServices/include/LaunchServices/UTCoreTypes.h
··· 1 + #ifndef _UTCORETYPES_H 2 + #define _UTCORETYPES_H 3 + #include <CoreFoundation/CFString.h> 4 + 5 + #ifdef __cplusplus 6 + extern "C" { 7 + #endif 8 + 9 + extern const CFStringRef kUTTypeItem; 10 + extern const CFStringRef kUTTypeContent; 11 + extern const CFStringRef kUTTypeCompositeContent; 12 + extern const CFStringRef kUTTypeMessage; 13 + extern const CFStringRef kUTTypeContact; 14 + extern const CFStringRef kUTTypeArchive; 15 + extern const CFStringRef kUTTypeDiskImage; 16 + extern const CFStringRef kUTTypeData; 17 + extern const CFStringRef kUTTypeDirectory; 18 + extern const CFStringRef kUTTypeResolvable; 19 + extern const CFStringRef kUTTypeSymLink; 20 + extern const CFStringRef kUTTypeExecutable; 21 + extern const CFStringRef kUTTypeMountPoint; 22 + extern const CFStringRef kUTTypeAliasFile; 23 + extern const CFStringRef kUTTypeAliasRecord; 24 + extern const CFStringRef kUTTypeURLBookmarkData; 25 + extern const CFStringRef kUTTypeURL; 26 + extern const CFStringRef kUTTypeFileURL; 27 + extern const CFStringRef kUTTypeText; 28 + extern const CFStringRef kUTTypePlainText; 29 + extern const CFStringRef kUTTypeUTF8PlainText; 30 + extern const CFStringRef kUTTypeUTF16ExternalPlainText; 31 + extern const CFStringRef kUTTypeUTF16PlainText; 32 + extern const CFStringRef kUTTypeDelimitedText; 33 + extern const CFStringRef kUTTypeCommaSeparatedText; 34 + extern const CFStringRef kUTTypeTabSeparatedText; 35 + extern const CFStringRef kUTTypeUTF8TabSeparatedText; 36 + extern const CFStringRef kUTTypeRTF; 37 + extern const CFStringRef kUTTypeHTML; 38 + extern const CFStringRef kUTTypeXML; 39 + extern const CFStringRef kUTTypeSourceCode; 40 + extern const CFStringRef kUTTypeAssemblyLanguageSource; 41 + extern const CFStringRef kUTTypeCSource; 42 + extern const CFStringRef kUTTypeObjectiveCSource; 43 + extern const CFStringRef kUTTypeSwiftSource; 44 + extern const CFStringRef kUTTypeCPlusPlusSource; 45 + extern const CFStringRef kUTTypeObjectiveCPlusPlusSource; 46 + extern const CFStringRef kUTTypeCHeader; 47 + extern const CFStringRef kUTTypeCPlusPlusHeader; 48 + extern const CFStringRef kUTTypeJavaSource; 49 + extern const CFStringRef kUTTypeScript; 50 + extern const CFStringRef kUTTypeAppleScript; 51 + extern const CFStringRef kUTTypeOSAScript; 52 + extern const CFStringRef kUTTypeOSAScriptBundle; 53 + extern const CFStringRef kUTTypeJavaScript; 54 + extern const CFStringRef kUTTypeShellScript; 55 + extern const CFStringRef kUTTypePerlScript; 56 + extern const CFStringRef kUTTypePythonScript; 57 + extern const CFStringRef kUTTypeRubyScript; 58 + extern const CFStringRef kUTTypePHPScript; 59 + extern const CFStringRef kUTTypeJSON; 60 + extern const CFStringRef kUTTypePropertyList; 61 + extern const CFStringRef kUTTypeXMLPropertyList; 62 + extern const CFStringRef kUTTypeBinaryPropertyList; 63 + extern const CFStringRef kUTTypePDF; 64 + extern const CFStringRef kUTTypeRTFD; 65 + extern const CFStringRef kUTTypeFlatRTFD; 66 + extern const CFStringRef kUTTypeTXNTextAndMultimediaData; 67 + extern const CFStringRef kUTTypeWebArchive; 68 + extern const CFStringRef kUTTypeImage; 69 + extern const CFStringRef kUTTypeJPEG; 70 + extern const CFStringRef kUTTypeJPEG2000; 71 + extern const CFStringRef kUTTypeTIFF; 72 + extern const CFStringRef kUTTypePICT; 73 + extern const CFStringRef kUTTypeGIF; 74 + extern const CFStringRef kUTTypePNG; 75 + extern const CFStringRef kUTTypeQuickTimeImage; 76 + extern const CFStringRef kUTTypeAppleICNS; 77 + extern const CFStringRef kUTTypeBMP; 78 + extern const CFStringRef kUTTypeICO; 79 + extern const CFStringRef kUTTypeRawImage; 80 + extern const CFStringRef kUTTypeScalableVectorGraphics; 81 + extern const CFStringRef kUTTypeLivePhoto; 82 + extern const CFStringRef kUTTypeAudiovisualContent; 83 + extern const CFStringRef kUTTypeMovie; 84 + extern const CFStringRef kUTTypeVideo; 85 + extern const CFStringRef kUTTypeAudio; 86 + extern const CFStringRef kUTTypeQuickTimeMovie; 87 + extern const CFStringRef kUTTypeMPEG; 88 + extern const CFStringRef kUTTypeMPEG2Video; 89 + extern const CFStringRef kUTTypeMPEG2TransportStream; 90 + extern const CFStringRef kUTTypeMP3; 91 + extern const CFStringRef kUTTypeMPEG4; 92 + extern const CFStringRef kUTTypeMPEG4Audio; 93 + extern const CFStringRef kUTTypeAppleProtectedMPEG4Audio; 94 + extern const CFStringRef kUTTypeAppleProtectedMPEG4Video; 95 + extern const CFStringRef kUTTypeAVIMovie; 96 + extern const CFStringRef kUTTypeAudioInterchangeFileFormat; 97 + extern const CFStringRef kUTTypeWaveformAudio; 98 + extern const CFStringRef kUTTypeMIDIAudio; 99 + extern const CFStringRef kUTTypePlaylist; 100 + extern const CFStringRef kUTTypeM3UPlaylist; 101 + extern const CFStringRef kUTTypeFolder; 102 + extern const CFStringRef kUTTypeVolume; 103 + extern const CFStringRef kUTTypePackage; 104 + extern const CFStringRef kUTTypeBundle; 105 + extern const CFStringRef kUTTypePluginBundle; 106 + extern const CFStringRef kUTTypeSpotlightImporter; 107 + extern const CFStringRef kUTTypeQuickLookGenerator; 108 + extern const CFStringRef kUTTypeXPCService; 109 + extern const CFStringRef kUTTypeFramework; 110 + extern const CFStringRef kUTTypeApplication; 111 + extern const CFStringRef kUTTypeApplicationBundle; 112 + extern const CFStringRef kUTTypeApplicationFile; 113 + extern const CFStringRef kUTTypeUnixExecutable; 114 + 115 + 116 + extern const CFStringRef kUTTypeWindowsExecutable; 117 + extern const CFStringRef kUTTypeJavaClass; 118 + extern const CFStringRef kUTTypeJavaArchive; 119 + 120 + 121 + extern const CFStringRef kUTTypeSystemPreferencesPane; 122 + extern const CFStringRef kUTTypeGNUZipArchive; 123 + extern const CFStringRef kUTTypeBzip2Archive; 124 + extern const CFStringRef kUTTypeZipArchive; 125 + extern const CFStringRef kUTTypeSpreadsheet; 126 + extern const CFStringRef kUTTypePresentation; 127 + extern const CFStringRef kUTTypeDatabase; 128 + extern const CFStringRef kUTTypeVCard; 129 + extern const CFStringRef kUTTypeToDoItem; 130 + extern const CFStringRef kUTTypeCalendarEvent; 131 + extern const CFStringRef kUTTypeEmailMessage; 132 + extern const CFStringRef kUTTypeInternetLocation; 133 + extern const CFStringRef kUTTypeInkText; 134 + extern const CFStringRef kUTTypeFont; 135 + extern const CFStringRef kUTTypeBookmark; 136 + extern const CFStringRef kUTType3DContent; 137 + extern const CFStringRef kUTTypePKCS12; 138 + extern const CFStringRef kUTTypeX509Certificate; 139 + extern const CFStringRef kUTTypeElectronicPublication; 140 + extern const CFStringRef kUTTypeLog; 141 + 142 + #ifdef __cplusplus 143 + } 144 + #endif 145 + 146 + #endif
+94
src/frameworks/CoreServices/include/LaunchServices/UTType.h
··· 1 + #ifndef _UTTYPE_H 2 + #define _UTTYPE_H 3 + 4 + #include <CoreFoundation/CFString.h> 5 + #include <CoreFoundation/CFArray.h> 6 + #include <CoreServices/MacTypes.h> 7 + 8 + #ifdef __cplusplus 9 + extern "C" { 10 + #endif 11 + 12 + extern const CFStringRef kUTExportedTypeDeclarationsKey; 13 + 14 + extern const CFStringRef kUTImportedTypeDeclarationsKey; 15 + 16 + extern const CFStringRef kUTTypeIdentifierKey; 17 + 18 + extern const CFStringRef kUTTypeTagSpecificationKey; 19 + 20 + extern const CFStringRef kUTTypeConformsToKey; 21 + 22 + extern const CFStringRef kUTTypeDescriptionKey; 23 + 24 + extern const CFStringRef kUTTypeIconFileKey; 25 + 26 + extern const CFStringRef kUTTypeReferenceURLKey; 27 + 28 + extern const CFStringRef kUTTypeVersionKey; 29 + extern const CFStringRef kUTTagClassFilenameExtension; 30 + 31 + extern const CFStringRef kUTTagClassMIMEType; 32 + 33 + extern const CFStringRef kUTTagClassNSPboardType; 34 + 35 + extern const CFStringRef kUTTagClassOSType; 36 + 37 + extern _Nullable CFStringRef 38 + UTTypeCreatePreferredIdentifierForTag( 39 + CFStringRef inTagClass, 40 + CFStringRef inTag, 41 + _Nullable CFStringRef inConformingToUTI); 42 + 43 + extern _Nullable CFArrayRef 44 + UTTypeCreateAllIdentifiersForTag( 45 + CFStringRef inTagClass, 46 + CFStringRef inTag, 47 + _Nullable CFStringRef inConformingToUTI); 48 + 49 + extern _Nullable CFStringRef 50 + UTTypeCopyPreferredTagWithClass( 51 + CFStringRef inUTI, 52 + CFStringRef inTagClass); 53 + 54 + extern _Nullable CFArrayRef 55 + UTTypeCopyAllTagsWithClass( 56 + CFStringRef inUTI, 57 + CFStringRef inTagClass); 58 + 59 + extern Boolean 60 + UTTypeEqual( 61 + CFStringRef inUTI1, 62 + CFStringRef inUTI2); 63 + 64 + extern Boolean 65 + UTTypeConformsTo( 66 + CFStringRef inUTI, 67 + CFStringRef inConformsToUTI); 68 + 69 + extern _Nullable CFStringRef 70 + UTTypeCopyDescription(CFStringRef inUTI); 71 + 72 + extern Boolean 73 + UTTypeIsDeclared(CFStringRef inUTI); 74 + 75 + extern Boolean 76 + UTTypeIsDynamic(CFStringRef inUTI); 77 + 78 + extern _Nullable CFDictionaryRef 79 + UTTypeCopyDeclaration(CFStringRef inUTI); 80 + 81 + extern _Nullable CFURLRef 82 + UTTypeCopyDeclaringBundleURL(CFStringRef inUTI); 83 + 84 + extern CFStringRef 85 + UTCreateStringForOSType(OSType inOSType); 86 + 87 + extern OSType 88 + UTGetOSTypeFromString(CFStringRef inString); 89 + 90 + #ifdef __cplusplus 91 + } 92 + #endif 93 + 94 + #endif
-3
src/frameworks/CoreServices/src/FSEvents/FSEventsImpl.m
··· 132 132 } 133 133 if (queue) 134 134 { 135 - [self scheduleWithRunLoop: NULL 136 - mode: NULL]; 137 - 138 135 _queue = queue; 139 136 dispatch_retain(_queue); 140 137 }
+3 -1
src/frameworks/CoreServices/src/LaunchServices/CMakeLists.txt
··· 9 9 LaunchServices.cpp 10 10 LSApplicationProxy.m 11 11 LSApplicationWorkspace.m 12 - LaunchServicesNew.cpp 12 + LSRunning.m 13 13 constants.c 14 + LSInfo.m 15 + LSOpen.m 14 16 DEPENDENCIES 15 17 CoreFoundation 16 18 Foundation
+48
src/frameworks/CoreServices/src/LaunchServices/LSInfo.m
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + 21 + #include <LaunchServices/LaunchServices.h> 22 + #include <CoreServices/MacErrors.h> 23 + #include <stdio.h> 24 + 25 + OSStatus 26 + LSFindApplicationForInfo( 27 + OSType inCreator, 28 + CFStringRef inBundleID, 29 + CFStringRef inName, 30 + FSRef * outAppRef, 31 + CFURLRef * outAppURL) 32 + { 33 + puts("LSFindApplicationForInfo STUB"); 34 + return unimpErr; 35 + } 36 + 37 + OSStatus 38 + LSGetApplicationForInfo( 39 + OSType inType, 40 + OSType inCreator, 41 + CFStringRef inExtension, 42 + LSRolesMask inRoleMask, 43 + FSRef * outAppRef, 44 + CFURLRef * outAppURL) 45 + { 46 + puts("LSGetApplicationForInfo STUB"); 47 + return unimpErr; 48 + }
+36
src/frameworks/CoreServices/src/LaunchServices/LSOpen.m
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + 21 + #include <LaunchServices/LaunchServices.h> 22 + #include <CoreServices/MacErrors.h> 23 + #include <stdio.h> 24 + 25 + OSStatus 26 + LSOpenURLsWithRole( 27 + CFArrayRef inURLs, 28 + LSRolesMask inRole, 29 + const AEKeyDesc * inAEParam, 30 + const LSApplicationParameters * inAppParams, 31 + ProcessSerialNumber * outPSNs, 32 + CFIndex inMaxPSNCount) 33 + { 34 + puts("LSOpenURLsWithRole STUB"); 35 + return unimpErr; 36 + }
+1
src/frameworks/CoreServices/src/LaunchServices/LaunchServices.c
··· 18 18 */ 19 19 20 20 #include <LaunchServices/LaunchServices.h> 21 + #include <LaunchServices/LaunchServicesPriv.h> 21 22 #include <stdio.h> 22 23 #include <stdlib.h> 23 24 #include <launch_priv.h>
+1
src/frameworks/CoreServices/src/LaunchServices/LaunchServices.cpp
··· 1 1 #include <LaunchServices/LaunchServices.h> 2 + #include <LaunchServices/LaunchServicesPriv.h> 2 3 #include <CoreServices/MacErrors.h> 3 4 #include <unistd.h> 4 5 #include <string>
+26 -21
src/frameworks/CoreServices/src/LaunchServices/LaunchServicesNew.cpp src/frameworks/CoreServices/src/LaunchServices/LSRunning.m
··· 26 26 #include <CoreFoundation/CFDate.h> 27 27 #include <CoreServices/MacErrors.h> 28 28 #include <dispatch/dispatch.h> 29 - #include <cstdlib> 30 - #include <iostream> 29 + #include <stdlib.h> 30 + #include <stdio.h> 31 31 #include <Block.h> 32 32 33 33 static xpc_connection_t g_lsdConnection, g_endpointConnection; ··· 37 37 static mach_port_name_t deathPort(); 38 38 static CFTypeRef g_ourASN; 39 39 40 - static CFStringRef g_applicationType = _kLSApplicationForegroundTypeKey; 41 - static LSServerConnectionAllowedBlock g_connectionAllowedBlock = nullptr; 40 + static CFStringRef g_applicationType = NULL; 41 + static LSServerConnectionAllowedBlock g_connectionAllowedBlock = NULL; 42 42 43 43 CFDictionaryRef _LSApplicationCheckIn(int sessionID, CFDictionaryRef applicationInfo) 44 44 { 45 45 if (g_connectionAllowedBlock && !g_connectionAllowedBlock(applicationInfo)) 46 - return nullptr; 46 + return NULL; 47 47 48 - CFMutableDictionaryRef modAppInfo = CFDictionaryCreateMutableCopy(nullptr, 0, applicationInfo); 48 + CFMutableDictionaryRef modAppInfo = CFDictionaryCreateMutableCopy(NULL, 0, applicationInfo); 49 49 50 50 if (!CFDictionaryContainsValue(modAppInfo, _kLSArchitectureKey)) 51 51 { ··· 64 64 65 65 if (!CFDictionaryContainsValue(modAppInfo, _kLSExecutablePathKey)) 66 66 { 67 - CFStringRef path = CFStringCreateWithFileSystemRepresentation(nullptr, _CFProcessPath()); 67 + CFStringRef path = CFStringCreateWithFileSystemRepresentation(NULL, _CFProcessPath()); 68 68 CFDictionaryAddValue(modAppInfo, _kLSExecutablePathKey, path); 69 69 CFRelease(path); 70 70 } ··· 73 73 { 74 74 // Are we supposed to set this one if not present? 75 75 long pid = getpid(); 76 - CFNumberRef num = CFNumberCreate(nullptr, kCFNumberLongType, &pid); 76 + CFNumberRef num = CFNumberCreate(NULL, kCFNumberLongType, &pid); 77 77 CFDictionaryAddValue(modAppInfo, _kLSPIDKey, num); 78 78 CFRelease(num); 79 79 } ··· 87 87 88 88 if (!CFDictionaryContainsValue(modAppInfo, _kLSCheckInTimeKey)) 89 89 { 90 - CFDateRef now = CFDateCreate(nullptr, CFAbsoluteTimeGetCurrent()); 90 + CFDateRef now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()); 91 91 CFDictionaryAddValue(modAppInfo, _kLSCheckInTimeKey, now); 92 92 CFRelease(now); 93 93 } 94 94 95 95 if (!CFDictionaryContainsValue(modAppInfo, _kLSApplicationTypeKey)) 96 96 { 97 + if (!g_applicationType) 98 + g_applicationType = _kLSApplicationForegroundTypeKey; 97 99 CFDictionaryAddValue(modAppInfo, _kLSApplicationTypeKey, g_applicationType); 98 100 } 99 101 ··· 113 115 { 114 116 if (!xpc_dictionary_get_bool(reply, "success")) 115 117 { 116 - std::cerr << "LaunchServices: check-in failed\n"; 117 - return nullptr; 118 + fprintf(stderr, "LaunchServices: check-in failed\n"); 119 + return NULL; 118 120 } 119 121 120 122 CFDictionaryRef result = (CFDictionaryRef) _CFXPCCreateCFObjectFromXPCObject(xpc_dictionary_get_value(reply, "result")); ··· 126 128 } 127 129 else 128 130 { 129 - std::cerr << "LaunchServices: check-in operation didn't execute\n"; 131 + fprintf(stderr, "LaunchServices: check-in operation didn't execute\n"); 130 132 } 131 133 132 - return nullptr; 134 + return NULL; 133 135 } 134 136 135 137 CFTypeRef _LSGetCurrentApplicationASN(void) ··· 152 154 if (g_connectionAllowedBlock) 153 155 Block_release(g_connectionAllowedBlock); 154 156 155 - g_connectionAllowedBlock = nullptr; 157 + g_connectionAllowedBlock = NULL; 156 158 if (block) 157 159 g_connectionAllowedBlock = Block_copy(block); 158 160 } ··· 160 162 LSASNRef _LSASNCreateWithPid(CFAllocatorRef allocator, pid_t pid) 161 163 { 162 164 long lpid = pid; 163 - return CFNumberCreate(nullptr, kCFNumberLongType, &lpid); 165 + return CFNumberCreate(NULL, kCFNumberLongType, &lpid); 164 166 } 165 167 166 168 static mach_port_name_t deathPort() ··· 182 184 { 183 185 static dispatch_once_t once; 184 186 dispatch_once(&once, ^{ 185 - if (const char* env = getenv("SCDontUseServer"); env != nullptr && atoi(env) != 0) 187 + const char* env = getenv("SCDontUseServer"); 188 + if (env != NULL && atoi(env) != 0) 186 189 return; 187 190 188 191 const char* serviceName = "com.apple.coreservices.launchservicesd"; 189 - if (const char* altName = getenv("__LSXPCSERVICENAME"); altName != nullptr) 192 + const char* altName = getenv("__LSXPCSERVICENAME"); 193 + 194 + if (altName != NULL) 190 195 serviceName = altName; 191 196 192 197 xpc_connection_t master = xpc_connection_create_mach_service(serviceName, ··· 196 201 if (peer == 0) 197 202 { 198 203 // TODO: 199 - std::cerr << "LaunchServices: Cannot connect to lsd\n"; 204 + fprintf(stderr, "LaunchServices: Cannot connect to lsd\n"); 200 205 return; 201 206 } 202 207 g_lsdConnection = (xpc_connection_t) xpc_retain(peer); ··· 207 212 208 213 if (reply == XPC_ERROR_CONNECTION_INTERRUPTED || reply == XPC_ERROR_CONNECTION_INVALID) 209 214 { 210 - std::cerr << "LaunchServices: lsd connection broken\n"; 215 + fprintf(stderr, "LaunchServices: lsd connection broken\n"); 211 216 return; 212 217 } 213 218 if (!xpc_dictionary_get_bool(reply, "success")) 214 219 { 215 - std::cerr << "LaunchServices: lsd hello failed\n"; 220 + fprintf(stderr, "LaunchServices: lsd hello failed\n"); 216 221 return; 217 222 } 218 223 xpc_object_t result = xpc_dictionary_get_value(reply, "result"); ··· 238 243 239 244 static xpc_object_t createCommandDictionary(uint64_t command) 240 245 { 241 - xpc_object_t dict = xpc_dictionary_create(nullptr, nullptr, 0); 246 + xpc_object_t dict = xpc_dictionary_create(NULL, NULL, 0); 242 247 xpc_dictionary_set_int64(dict, "command", command); 243 248 return dict; 244 249 }
+143
src/frameworks/CoreServices/src/LaunchServices/constants.c
··· 23 23 const CFStringRef _kLSExecutableFormatCFMKey = CFSTR("LSExecutableCFMFormat"); 24 24 25 25 const CFStringRef _kLSASNKey = CFSTR("LSASN"); 26 + 27 + const CFStringRef kUTExportedTypeDeclarationsKey = CFSTR("UTExportedTypeDeclarations"); 28 + const CFStringRef kUTImportedTypeDeclarationsKey = CFSTR("UTImportedTypeDeclarations"); 29 + const CFStringRef kUTTypeIdentifierKey = CFSTR("UTTypeIdentifier"); 30 + const CFStringRef kUTTypeTagSpecificationKey = CFSTR("UTTypeTagSpecification"); 31 + const CFStringRef kUTTypeConformsToKey = CFSTR("UTTypeConformsTo"); 32 + const CFStringRef kUTTypeDescriptionKey = CFSTR("UTTypeDescription"); 33 + const CFStringRef kUTTypeIconFileKey = CFSTR("UTTypeIconFile"); 34 + const CFStringRef kUTTypeReferenceURLKey = CFSTR("UTTypeReferenceURL"); 35 + const CFStringRef kUTTypeVersionKey = CFSTR("UTTypeVersion"); 36 + const CFStringRef kUTTagClassFilenameExtension = CFSTR("public.filename-extension"); 37 + const CFStringRef kUTTagClassMIMEType = CFSTR("public.mime-type"); 38 + const CFStringRef kUTTagClassNSPboardType = CFSTR("com.apple.nspboard-type"); 39 + const CFStringRef kUTTagClassOSType = CFSTR("com.apple.ostype"); 40 + const CFStringRef kUTTypeItem = CFSTR("public.item"); 41 + const CFStringRef kUTTypeContent = CFSTR("public.content"); 42 + const CFStringRef kUTTypeCompositeContent = CFSTR("public.composite-content"); 43 + const CFStringRef kUTTypeMessage = CFSTR("public.message"); 44 + const CFStringRef kUTTypeContact = CFSTR("public.contact"); 45 + const CFStringRef kUTTypeArchive = CFSTR("public.archive"); 46 + const CFStringRef kUTTypeDiskImage = CFSTR("public.disk-image"); 47 + const CFStringRef kUTTypeData = CFSTR("public.data"); 48 + const CFStringRef kUTTypeDirectory = CFSTR("public.directory"); 49 + const CFStringRef kUTTypeResolvable = CFSTR("com.apple.resolvable"); 50 + const CFStringRef kUTTypeSymLink = CFSTR("public.symlink"); 51 + const CFStringRef kUTTypeExecutable = CFSTR("public.executable"); 52 + const CFStringRef kUTTypeMountPoint = CFSTR("com.apple.mount-point"); 53 + const CFStringRef kUTTypeAliasFile = CFSTR("com.apple.alias-file"); 54 + const CFStringRef kUTTypeAliasRecord = CFSTR("com.apple.alias-record"); 55 + const CFStringRef kUTTypeURLBookmarkData = CFSTR("com.apple.bookmark"); 56 + const CFStringRef kUTTypeURL = CFSTR("public.url"); 57 + const CFStringRef kUTTypeFileURL = CFSTR("public.file-url"); 58 + const CFStringRef kUTTypeText = CFSTR("public.text"); 59 + const CFStringRef kUTTypePlainText = CFSTR("public.plain-text"); 60 + const CFStringRef kUTTypeUTF8PlainText = CFSTR("public.utf8-plain-text"); 61 + const CFStringRef kUTTypeUTF16ExternalPlainText = CFSTR("public.utf16-external-plain-text"); 62 + const CFStringRef kUTTypeUTF16PlainText = CFSTR("public.utf16-plain-text"); 63 + const CFStringRef kUTTypeDelimitedText = CFSTR("public.delimited-values-text"); 64 + const CFStringRef kUTTypeCommaSeparatedText = CFSTR("public.comma-separated-values-text"); 65 + const CFStringRef kUTTypeTabSeparatedText = CFSTR("public.tab-separated-values-text"); 66 + const CFStringRef kUTTypeUTF8TabSeparatedText = CFSTR("public.utf8-tab-separated-values-text"); 67 + const CFStringRef kUTTypeRTF = CFSTR("public.rtf"); 68 + const CFStringRef kUTTypeHTML = CFSTR("public.html"); 69 + const CFStringRef kUTTypeXML = CFSTR("public.xml"); 70 + const CFStringRef kUTTypeSourceCode = CFSTR("public.source-code"); 71 + const CFStringRef kUTTypeAssemblyLanguageSource = CFSTR("public.assembly-source"); 72 + const CFStringRef kUTTypeCSource = CFSTR("public.c-source"); 73 + const CFStringRef kUTTypeObjectiveCSource = CFSTR("public.objective-c-source"); 74 + const CFStringRef kUTTypeSwiftSource = CFSTR("public.swift-source"); 75 + const CFStringRef kUTTypeCPlusPlusSource = CFSTR("public.c-plus-plus-source"); 76 + const CFStringRef kUTTypeObjectiveCPlusPlusSource = CFSTR("public.objective-c-plus-plus-source"); 77 + const CFStringRef kUTTypeCHeader = CFSTR("public.c-header"); 78 + const CFStringRef kUTTypeCPlusPlusHeader = CFSTR("public.c-plus-plus-header"); 79 + const CFStringRef kUTTypeJavaSource = CFSTR("com.sun.java-source"); 80 + const CFStringRef kUTTypeScript = CFSTR("public.script"); 81 + const CFStringRef kUTTypeAppleScript = CFSTR("com.apple.applescript.text"); 82 + const CFStringRef kUTTypeOSAScript = CFSTR("com.apple.applescript.script"); 83 + const CFStringRef kUTTypeOSAScriptBundle = CFSTR("com.apple.applescript.script-bundle"); 84 + const CFStringRef kUTTypeJavaScript = CFSTR("com.netscape.javascript-source"); 85 + const CFStringRef kUTTypeShellScript = CFSTR("public.shell-script"); 86 + const CFStringRef kUTTypePerlScript = CFSTR("public.perl-script"); 87 + const CFStringRef kUTTypePythonScript = CFSTR("public.python-script"); 88 + const CFStringRef kUTTypeRubyScript = CFSTR("public.ruby-script"); 89 + const CFStringRef kUTTypePHPScript = CFSTR("public.php-script"); 90 + const CFStringRef kUTTypeJSON = CFSTR("public.json"); 91 + const CFStringRef kUTTypePropertyList = CFSTR("com.apple.property-list"); 92 + const CFStringRef kUTTypeXMLPropertyList = CFSTR("com.apple.xml-property-list"); 93 + const CFStringRef kUTTypeBinaryPropertyList = CFSTR("com.apple.binary-property-list"); 94 + const CFStringRef kUTTypePDF = CFSTR("com.adobe.pdf"); 95 + const CFStringRef kUTTypeRTFD = CFSTR("com.apple.rtfd"); 96 + const CFStringRef kUTTypeFlatRTFD = CFSTR("com.apple.flat-rtfd"); 97 + const CFStringRef kUTTypeTXNTextAndMultimediaData = CFSTR("com.apple.txn.text-multimedia-data"); 98 + const CFStringRef kUTTypeWebArchive = CFSTR("com.apple.webarchive"); 99 + const CFStringRef kUTTypeImage = CFSTR("public.image"); 100 + const CFStringRef kUTTypeJPEG = CFSTR("public.jpeg"); 101 + const CFStringRef kUTTypeJPEG2000 = CFSTR("public.jpeg-2000"); 102 + const CFStringRef kUTTypeTIFF = CFSTR("public.tiff"); 103 + const CFStringRef kUTTypePICT = CFSTR("com.apple.pict"); 104 + const CFStringRef kUTTypeGIF = CFSTR("com.compuserve.gif"); 105 + const CFStringRef kUTTypePNG = CFSTR("public.png"); 106 + const CFStringRef kUTTypeQuickTimeImage = CFSTR("com.apple.quicktime-image"); 107 + const CFStringRef kUTTypeAppleICNS = CFSTR("com.apple.icns"); 108 + const CFStringRef kUTTypeBMP = CFSTR("com.microsoft.bmp"); 109 + const CFStringRef kUTTypeICO = CFSTR("com.microsoft.ico"); 110 + const CFStringRef kUTTypeRawImage = CFSTR("public.camera-raw-image"); 111 + const CFStringRef kUTTypeScalableVectorGraphics = CFSTR("public.svg-image"); 112 + const CFStringRef kUTTypeLivePhoto = CFSTR("com.apple.live-photo"); 113 + const CFStringRef kUTTypeAudiovisualContent = CFSTR("public.audiovisual-content"); 114 + const CFStringRef kUTTypeMovie = CFSTR("public.movie"); 115 + const CFStringRef kUTTypeVideo = CFSTR("public.video"); 116 + const CFStringRef kUTTypeAudio = CFSTR("public.audio"); 117 + const CFStringRef kUTTypeQuickTimeMovie = CFSTR("com.apple.quicktime-movie"); 118 + const CFStringRef kUTTypeMPEG = CFSTR("public.mpeg"); 119 + const CFStringRef kUTTypeMPEG2Video = CFSTR("public.mpeg-2-video"); 120 + const CFStringRef kUTTypeMPEG2TransportStream = CFSTR("public.mpeg-2-transport-stream"); 121 + const CFStringRef kUTTypeMP3 = CFSTR("public.mp3"); 122 + const CFStringRef kUTTypeMPEG4 = CFSTR("public.mpeg-4"); 123 + const CFStringRef kUTTypeMPEG4Audio = CFSTR("public.mpeg-4-audio"); 124 + const CFStringRef kUTTypeAppleProtectedMPEG4Audio = CFSTR("com.apple.protected-mpeg-4-audio"); 125 + const CFStringRef kUTTypeAppleProtectedMPEG4Video = CFSTR("com.apple.protected-mpeg-4-video"); 126 + const CFStringRef kUTTypeAVIMovie = CFSTR("public.avi"); 127 + const CFStringRef kUTTypeAudioInterchangeFileFormat = CFSTR("public.aiff-audio"); 128 + const CFStringRef kUTTypeWaveformAudio = CFSTR("com.microsoft.waveform-audio"); 129 + const CFStringRef kUTTypeMIDIAudio = CFSTR("public.midi-audio"); 130 + const CFStringRef kUTTypePlaylist = CFSTR("public.playlist"); 131 + const CFStringRef kUTTypeM3UPlaylist = CFSTR("public.m3u-playlist"); 132 + const CFStringRef kUTTypeFolder = CFSTR("public.folder"); 133 + const CFStringRef kUTTypeVolume = CFSTR("public.volume"); 134 + const CFStringRef kUTTypePackage = CFSTR("com.apple.package"); 135 + const CFStringRef kUTTypeBundle = CFSTR("com.apple.bundle"); 136 + const CFStringRef kUTTypePluginBundle = CFSTR("com.apple.plugin"); 137 + const CFStringRef kUTTypeSpotlightImporter = CFSTR("com.apple.metadata-importer"); 138 + const CFStringRef kUTTypeQuickLookGenerator = CFSTR("com.apple.quicklook-generator"); 139 + const CFStringRef kUTTypeXPCService = CFSTR("com.apple.xpc-service"); 140 + const CFStringRef kUTTypeFramework = CFSTR("com.apple.framework"); 141 + const CFStringRef kUTTypeApplication = CFSTR("com.apple.application"); 142 + const CFStringRef kUTTypeApplicationBundle = CFSTR("com.apple.application-bundle"); 143 + const CFStringRef kUTTypeApplicationFile = CFSTR("com.apple.application-file"); 144 + const CFStringRef kUTTypeUnixExecutable = CFSTR("public.unix-executable"); 145 + const CFStringRef kUTTypeWindowsExecutable = CFSTR("com.microsoft.windows-executable"); 146 + const CFStringRef kUTTypeJavaClass = CFSTR("com.sun.java-class"); 147 + const CFStringRef kUTTypeJavaArchive = CFSTR("com.sun.java-archive"); 148 + const CFStringRef kUTTypeSystemPreferencesPane = CFSTR("com.apple.systempreference.prefpane"); 149 + const CFStringRef kUTTypeGNUZipArchive = CFSTR("org.gnu.gnu-zip-archive"); 150 + const CFStringRef kUTTypeBzip2Archive = CFSTR("public.bzip2-archive"); 151 + const CFStringRef kUTTypeZipArchive = CFSTR("public.zip-archive"); 152 + const CFStringRef kUTTypeSpreadsheet = CFSTR("public.spreadsheet"); 153 + const CFStringRef kUTTypePresentation = CFSTR("public.presentation"); 154 + const CFStringRef kUTTypeDatabase = CFSTR("public.database"); 155 + const CFStringRef kUTTypeVCard = CFSTR("public.vcard"); 156 + const CFStringRef kUTTypeToDoItem = CFSTR("public.to-do-item"); 157 + const CFStringRef kUTTypeCalendarEvent = CFSTR("public.calendar-event"); 158 + const CFStringRef kUTTypeEmailMessage = CFSTR("public.email-message"); 159 + const CFStringRef kUTTypeInternetLocation = CFSTR("com.apple.internet-location"); 160 + const CFStringRef kUTTypeInkText = CFSTR("com.apple.ink.inktext"); 161 + const CFStringRef kUTTypeFont = CFSTR("public.font"); 162 + const CFStringRef kUTTypeBookmark = CFSTR("public.bookmark"); 163 + const CFStringRef kUTType3DContent = CFSTR("public.3d-content"); 164 + const CFStringRef kUTTypePKCS12 = CFSTR("com.rsa.pkcs-12"); 165 + const CFStringRef kUTTypeX509Certificate = CFSTR("public.x509-certificate"); 166 + const CFStringRef kUTTypeElectronicPublication = CFSTR("org.idpf.epub-container"); 167 + const CFStringRef kUTTypeLog = CFSTR("public.log"); 168 +
+9 -3
src/frameworks/CoreServices/src/LaunchServices/launchservicesd/CMakeLists.txt
··· 1 - project(lslaunchservicesdd) 1 + project(launchservicesd) 2 + 3 + include_directories( 4 + ${CMAKE_SOURCE_DIR}/src/external/fmdb/src 5 + ) 2 6 3 7 set(sources 4 - launchservicesd.cpp 8 + launchservicesd.m 9 + LSBundle.m 5 10 ) 6 11 7 12 add_darling_executable(launchservicesd ${sources}) 8 13 9 - target_link_libraries(launchservicesd system CoreServices sqlite3 cxx) 14 + target_link_libraries(launchservicesd system Foundation CoreFoundation CoreServices FMDB sqlite3 z) 10 15 install(TARGETS launchservicesd DESTINATION libexec/darling/System/Library/CoreServices) 16 + install(FILES schema.sql RENAME launchservicesd-schema.sql DESTINATION libexec/darling/System/Library/CoreServices)
+41
src/frameworks/CoreServices/src/LaunchServices/launchservicesd/LSBundle.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef _LSD_BUNDLE_H 21 + #define _LSD_BUNDLE_H 22 + #import <Foundation/NSObject.h> 23 + #include <CoreFoundation/CFBundle.h> 24 + 25 + @interface LSBundle : NSObject 26 + { 27 + CFBundleRef _bundle; 28 + int _bundleId; 29 + } 30 + -(id) initWithBundle:(CFBundleRef) bundle; 31 + -(void)dealloc; 32 + -(void)process; 33 + 34 + @property (readonly) int bundleId; 35 + 36 + +(void)scanForBundles; 37 + +(void)watchForBundles; 38 + @end 39 + 40 + #endif 41 +
+413
src/frameworks/CoreServices/src/LaunchServices/launchservicesd/LSBundle.m
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include "LSBundle.h" 21 + #include <FSEvents/FSEvents.h> 22 + #include <sqlite3.h> 23 + #import <Foundation/Foundation.h> 24 + #import <fmdb/FMDatabase.h> 25 + #include <zlib.h> 26 + #include <LaunchServices/UTType.h> 27 + 28 + #define DATABASE_VERSION 1 29 + 30 + static FMDatabase* g_database; 31 + extern dispatch_queue_t g_serverQueue; 32 + 33 + static void setupDBSchema(void); 34 + static void fsEventCallback(ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, 35 + void *eventPaths, const FSEventStreamEventFlags *eventFlags, const FSEventStreamEventId *eventIds); 36 + 37 + static NSArray<NSString*>* MONITORED_DIRECTORIES; 38 + static FSEventStreamRef g_eventStream; 39 + 40 + @implementation NSString (CRC32) 41 + -(uint32_t)crc32 42 + { 43 + const char* str = [self UTF8String]; 44 + return crc32(0, (const Bytef*) str, strlen(str)); 45 + } 46 + @end 47 + 48 + @implementation LSBundle 49 + 50 + @synthesize bundleId = _bundleId; 51 + 52 + -(id) initWithBundle:(CFBundleRef) bundle 53 + { 54 + _bundle = (CFBundleRef) CFRetain(bundle); 55 + 56 + return self; 57 + } 58 + 59 + -(void)dealloc 60 + { 61 + CFRelease(_bundle); 62 + [super dealloc]; 63 + } 64 + 65 + -(void)processUTIs:(NSArray<NSDictionary<NSString*,id>*>*)utis 66 + { 67 + NSNumber* ourBundleId = [NSNumber numberWithInt: _bundleId]; 68 + // Maintain a set of previously existing UTIs so that we know which ones need to be deleted 69 + NSMutableSet<NSString*>* previousUtis = [NSMutableSet setWithCapacity: 0]; 70 + 71 + FMResultSet* rs = [g_database executeQuery:@"select type_identifier from uti where bundle = ?", 72 + ourBundleId]; 73 + 74 + while ([rs next]) 75 + [previousUtis addObject: [rs stringForColumn: @"type_identifier"]]; 76 + [rs close]; 77 + 78 + for (NSDictionary<NSString*,id>* uti in utis) 79 + { 80 + NSNumber* utiId; 81 + NSString* typeId = uti[(NSString*) kUTTypeIdentifierKey]; 82 + 83 + if (![typeId isKindOfClass: [NSString class]]) 84 + continue; 85 + 86 + NSString* description = uti[(NSString*) kUTTypeDescriptionKey]; 87 + if (![description isKindOfClass: [NSString class]]) 88 + description = typeId; 89 + 90 + FMResultSet* rs = [g_database executeQuery:@"select id, description from uti where type_identifier = ? and bundle = ?", 91 + typeId, ourBundleId]; 92 + if ([rs next]) 93 + { 94 + // We already have this UTI record 95 + utiId = [NSNumber numberWithInt: [rs intForColumn:@"id"]]; 96 + NSString* oldDesc = [rs stringForColumn:@"description"]; 97 + 98 + // Update the description text if it changed 99 + if (![oldDesc isEqualToString: description]) 100 + { 101 + [g_database executeUpdate:@"update uti set description = ? where id = ?", oldDesc, utiId]; 102 + } 103 + } 104 + else 105 + { 106 + // Insert a new UTI record 107 + [g_database executeUpdate:@"insert into uti (type_identifier, description, bundle) values (?,?,?)", 108 + typeId, description, ourBundleId]; 109 + utiId = [NSNumber numberWithInt: [g_database lastInsertRowId]]; 110 + } 111 + [rs close]; 112 + 113 + [previousUtis removeObject: typeId]; 114 + 115 + // Process UTTypeConformsTo 116 + [g_database executeUpdate: @"delete from uti_conforms where uti = ?", utiId]; 117 + 118 + id conformsTo = uti[(NSString*) kUTTypeConformsToKey]; 119 + if ([conformsTo isKindOfClass: [NSString class]]) 120 + { 121 + [g_database executeUpdate:@"insert into uti_conforms (uti, conforms_to) values (?,?)", 122 + utiId, conformsTo]; 123 + } 124 + else if ([conformsTo isKindOfClass: [NSArray class]]) 125 + { 126 + for (NSString* ct in ((NSArray<NSString*>*) conformsTo)) 127 + { 128 + if (![ct isKindOfClass: [NSString class]]) 129 + continue; 130 + [g_database executeUpdate:@"insert into uti_conforms (uti, conforms_to) values (?,?)", 131 + utiId, ct]; 132 + } 133 + } 134 + 135 + // Process UTTypeIconFile / UTTypeIconFiles 136 + [g_database executeUpdate:@"delete from uti_icon where uti = ?", utiId]; 137 + NSString* icon = uti[(NSString*) kUTTypeIconFileKey]; 138 + if (icon != nil) 139 + { 140 + [g_database executeUpdate:@"insert into uti_icon (uti, file) values (?,?)", 141 + utiId, icon]; 142 + } 143 + NSArray<NSString*>* icons = uti[@"UTTypeIconFiles"]; 144 + if (icons != nil) 145 + { 146 + for (NSString* icon in icons) 147 + { 148 + if (![icon isKindOfClass: [NSString class]]) 149 + continue; 150 + [g_database executeUpdate:@"insert into uti_icon (uti, file) values (?,?)", 151 + utiId, icon]; 152 + } 153 + } 154 + 155 + // Process UTTypeTagSpecification 156 + [g_database executeUpdate:@"delete from uti_tag where uti = ?", utiId]; 157 + NSDictionary<NSString*, id>* tags = uti[(NSString*) kUTTypeTagSpecificationKey]; 158 + if (tags != nil) 159 + { 160 + for (NSString* tag in tags) 161 + { 162 + id tagValue = tags[tag]; 163 + if ([tagValue isKindOfClass: [NSString class]]) 164 + { 165 + [g_database executeUpdate:@"insert into uti_tag (uti, tag, value) values (?,?,?)", 166 + utiId, tag, tagValue]; 167 + } 168 + else if ([tagValue isKindOfClass: [NSArray class]]) 169 + { 170 + for (NSString* value in (NSArray<NSString*>*) tagValue) 171 + { 172 + if (![value isKindOfClass: [NSString class]]) 173 + continue; 174 + [g_database executeUpdate:@"insert into uti_tag (uti, tag, value) values (?,?,?)", 175 + utiId, tag, value]; 176 + } 177 + } 178 + } 179 + } 180 + } 181 + 182 + for (NSString* deletedId in previousUtis) 183 + { 184 + [g_database executeUpdate:@"delete from uti where type_identifier = ? and bundle = ?", 185 + deletedId, ourBundleId]; 186 + } 187 + } 188 + 189 + -(void)processFileAssociations 190 + { 191 + NSDictionary<NSString*,id>* infoDict = (NSDictionary*) CFBundleGetInfoDictionary(_bundle); 192 + 193 + NSArray<NSString*>* contentTypes = infoDict[@"LSItemContentTypes"]; 194 + } 195 + 196 + -(BOOL)setupBundleID 197 + { 198 + NSURL* url = (NSURL*) CFBundleCopyBundleURL(_bundle); 199 + NSString* path = [url path]; 200 + const uint32_t newChecksum = [[(NSDictionary*) CFBundleGetInfoDictionary(_bundle) description] crc32]; 201 + 202 + [url release]; 203 + FMResultSet* rs = [g_database executeQuery:@"select id, checksum from bundle where path = ?", path]; 204 + 205 + if ([rs next]) 206 + { 207 + _bundleId = [rs intForColumn:@"id"]; 208 + 209 + // Has the info dict changed? 210 + uint32_t dbChecksum = [rs intForColumn:@"checksum"]; 211 + if (dbChecksum == newChecksum) 212 + { 213 + NSLog(@"Bundle at '%@' hasn't changed\n", path); 214 + [rs close]; 215 + return FALSE; 216 + } 217 + } 218 + 219 + [rs close]; 220 + 221 + if (!_bundleId) 222 + { 223 + CFStringRef identifier = CFBundleGetIdentifier(_bundle); 224 + 225 + NSLog(@"Registering new bundle at '%@', identifier '%@'\n", path, identifier); 226 + 227 + [g_database executeUpdate:@"insert into bundle (path, bundle_id, checksum) values (?,?,?)", 228 + path, identifier, [NSNumber numberWithInt:newChecksum]]; 229 + 230 + _bundleId = [g_database lastInsertRowId]; 231 + } 232 + else 233 + { 234 + NSLog(@"Updating bundle at '%@'\n", path); 235 + 236 + // We're in a transaction, so it's OK to set the new checksum now 237 + [g_database executeUpdate:@"update bundle set checksum = ? where id = ?", 238 + [NSNumber numberWithInt:newChecksum], [NSNumber numberWithInt: _bundleId]]; 239 + } 240 + 241 + return TRUE; 242 + } 243 + 244 + -(void)process 245 + { 246 + BOOL needsProcessing; 247 + 248 + [g_database beginTransaction]; 249 + needsProcessing = [self setupBundleID]; 250 + 251 + if (!needsProcessing) 252 + { 253 + [g_database rollback]; 254 + return; 255 + } 256 + 257 + NSDictionary<NSString*,id>* infoDict = (NSDictionary*) CFBundleGetInfoDictionary(_bundle); 258 + 259 + NSArray<NSDictionary*>* utis = infoDict[@"UTExportedTypeDeclarations"]; 260 + if (utis != nil) 261 + { 262 + [self processUTIs:utis]; 263 + } 264 + 265 + if (infoDict[@"LSItemContentTypes"] != nil) 266 + { 267 + [self processFileAssociations]; 268 + } 269 + 270 + [g_database commit]; 271 + } 272 + 273 + +(void)initialize 274 + { 275 + if (self == [LSBundle class]) 276 + { 277 + MONITORED_DIRECTORIES = @[ 278 + @"/Applications", 279 + @"/System/Applications", 280 + // This path doesn't contain apps, but may still contain UTI definitions 281 + @"/System/Library/Frameworks", 282 + ]; 283 + 284 + FMDatabase* db = [FMDatabase databaseWithPath: @"/private/var/db/launchservices.db"]; 285 + if (![db open]) 286 + { 287 + NSLog(@"Cannot open LS database: %@", [db lastErrorMessage]); 288 + return; 289 + } 290 + g_database = [db retain]; 291 + 292 + setupDBSchema(); 293 + } 294 + } 295 + 296 + +(void)scanForBundles:(NSString*)dir 297 + { 298 + @autoreleasepool 299 + { 300 + NSURL* url = [NSURL fileURLWithPath:dir isDirectory:YES]; 301 + NSArray* bundles = (NSArray*) CFBundleCreateBundlesFromDirectory(NULL, (CFURLRef) url, NULL); 302 + 303 + for (id bundle in bundles) 304 + { 305 + // CFBundle is not exactly clever and gives us CFBundles of empty directories 306 + if (CFBundleGetIdentifier((CFBundleRef) bundle) == NULL) 307 + continue; 308 + 309 + @autoreleasepool 310 + { 311 + LSBundle* b = [[[LSBundle alloc] initWithBundle: (CFBundleRef) bundle] autorelease]; 312 + [b process]; 313 + } 314 + } 315 + } 316 + } 317 + 318 + +(void)scanForBundles 319 + { 320 + for (NSString* dir in MONITORED_DIRECTORIES) 321 + [LSBundle scanForBundles: dir]; 322 + } 323 + 324 + +(void)watchForBundles 325 + { 326 + g_eventStream = FSEventStreamCreate(NULL, fsEventCallback, NULL, (CFArrayRef) MONITORED_DIRECTORIES, 327 + kFSEventStreamEventIdSinceNow, 1, kFSEventStreamCreateFlagUseCFTypes); 328 + 329 + FSEventStreamSetDispatchQueue(g_eventStream, g_serverQueue); 330 + FSEventStreamStart(g_eventStream); 331 + } 332 + 333 + +(void)deleteBundleAtPath:(NSString*) path 334 + { 335 + // Delete DB entries referring to path 336 + [g_database beginTransaction]; 337 + [g_database executeQuery: @"delete from bundle where path = ?", path]; 338 + [g_database commit]; 339 + } 340 + 341 + @end 342 + 343 + static void createDBSchema(void) 344 + { 345 + NSString* sqlSchema = [NSString stringWithContentsOfFile: @"/System/Library/CoreServices/launchservicesd-schema.sql" 346 + encoding: NSUTF8StringEncoding 347 + error: nil]; 348 + 349 + const char* sql = [sqlSchema cStringUsingEncoding: NSUTF8StringEncoding]; 350 + char* errorMessage; 351 + 352 + sqlite3_exec(g_database.sqliteHandle, sql, NULL, NULL, &errorMessage); 353 + 354 + if (errorMessage != NULL) 355 + { 356 + NSLog(@"launchservicesd: createDBSchema error: %s\n", errorMessage); 357 + sqlite3_free(errorMessage); 358 + 359 + // TODO: abort_with_payload() instead? 360 + exit(1); 361 + } 362 + } 363 + 364 + static void setupDBSchema(void) 365 + { 366 + FMResultSet* rs = [g_database executeQuery:@"select value from `globals` where key = ?", @"version"]; 367 + if (![rs next]) 368 + { 369 + createDBSchema(); 370 + } 371 + else 372 + { 373 + if ([rs intForColumn: @"value"] != DATABASE_VERSION) 374 + { 375 + // TODO: This is where we'll do DB schema updates or possibly just delete everything and index from scratch 376 + } 377 + [rs close]; 378 + } 379 + } 380 + 381 + static void fsEventCallback(ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, 382 + void *eventPaths, const FSEventStreamEventFlags *eventFlags, const FSEventStreamEventId *eventIds) 383 + { 384 + NSArray<NSString*>* changes = (NSArray*) eventPaths; 385 + int index = 0; 386 + for (NSString* change in changes) 387 + { 388 + @autoreleasepool 389 + { 390 + if (eventFlags[index] & kFSEventStreamEventFlagItemIsFile) 391 + { 392 + if ([[change lastPathComponent] caseInsensitiveCompare: @"Info.plist"] == NSOrderedSame) 393 + { 394 + NSString* bundlePath = [[change stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]; 395 + CFBundleRef bundle = CFBundleCreate(NULL, (CFURLRef) [NSURL fileURLWithPath:bundlePath isDirectory:YES]); 396 + 397 + if (bundle != NULL) 398 + { 399 + LSBundle* lsb = [[[LSBundle alloc] initWithBundle: bundle] autorelease]; 400 + [lsb process]; 401 + 402 + CFRelease(bundle); 403 + } 404 + else 405 + { 406 + [LSBundle deleteBundleAtPath:bundlePath]; 407 + } 408 + } 409 + } 410 + } 411 + index++; 412 + } 413 + }
-65
src/frameworks/CoreServices/src/LaunchServices/launchservicesd/launchservicesd.cpp
··· 1 - #include <xpc/xpc.h> 2 - #include <FSEvents/FSEvents.h> 3 - #include <iostream> 4 - #include <dispatch/dispatch.h> 5 - #include <sqlite3.h> 6 - 7 - #define DATABASE_VERSION 1 8 - 9 - static void connectionCallback(xpc_connection_t connection); 10 - static void handleMessage(xpc_connection_t connection, xpc_object_t msg); 11 - 12 - sqlite3* g_database; 13 - 14 - static const char* MONITORED_DIRECTORIES[] = { 15 - "/Applications", 16 - "/System/Applications" 17 - "/System/Library/Frameworks" 18 - }; 19 - 20 - int main(int argc, const char** argv) 21 - { 22 - if (int err = sqlite3_open("/var/cache/launchservices.db", &g_database); err != SQLITE_OK) 23 - { 24 - std::cerr << "SQLite error: " << sqlite3_errstr(err) << std::endl; 25 - exit(1); 26 - } 27 - 28 - // xpc_main(connectionCallback); 29 - // Our xpc_main() isn't done yet, so we do this manually 30 - 31 - dispatch_queue_t server_queue = dispatch_queue_create("xpc service", NULL); 32 - 33 - xpc_connection_t listener = xpc_connection_create_mach_service("com.apple.coreservices.launchservicesd", 34 - server_queue, XPC_CONNECTION_MACH_SERVICE_LISTENER); 35 - 36 - xpc_connection_set_event_handler(listener, ^(xpc_object_t peer) { 37 - if (xpc_get_type(peer) == XPC_TYPE_CONNECTION) 38 - connectionCallback(xpc_connection_t(peer)); 39 - }); 40 - xpc_connection_resume(listener); 41 - 42 - dispatch_main(); 43 - return 0; 44 - } 45 - 46 - static void connectionCallback(xpc_connection_t connection) 47 - { 48 - pid_t pid = xpc_connection_get_pid(connection); 49 - xpc_connection_set_event_handler(connection, ^(xpc_object_t msg) { 50 - handleMessage(connection, msg); 51 - }); 52 - xpc_connection_resume(connection); 53 - } 54 - 55 - static void handleMessage(xpc_connection_t connection, xpc_object_t msg) 56 - { 57 - xpc_type_t type = xpc_get_type(msg); 58 - 59 - if (type == XPC_TYPE_DICTIONARY) 60 - { 61 - xpc_object_t reply = xpc_dictionary_create_reply(msg); 62 - 63 - xpc_connection_send_message(connection, reply); 64 - } 65 - }
+71
src/frameworks/CoreServices/src/LaunchServices/launchservicesd/launchservicesd.m
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include <xpc/xpc.h> 21 + #include <dispatch/dispatch.h> 22 + #include "LSBundle.h" 23 + 24 + static void connectionCallback(xpc_connection_t connection); 25 + static void handleMessage(xpc_connection_t connection, xpc_object_t msg); 26 + 27 + dispatch_queue_t g_serverQueue; 28 + 29 + int main(int argc, const char** argv) 30 + { 31 + g_serverQueue = dispatch_queue_create("service queue", NULL); 32 + 33 + [LSBundle scanForBundles]; 34 + [LSBundle watchForBundles]; 35 + 36 + // xpc_main(connectionCallback); 37 + // Our xpc_main() isn't done yet, so we do this manually 38 + 39 + xpc_connection_t listener = xpc_connection_create_mach_service("com.apple.coreservices.launchservicesd", 40 + g_serverQueue, XPC_CONNECTION_MACH_SERVICE_LISTENER); 41 + 42 + xpc_connection_set_event_handler(listener, ^(xpc_object_t peer) { 43 + if (xpc_get_type(peer) == XPC_TYPE_CONNECTION) 44 + connectionCallback((xpc_connection_t) peer); 45 + }); 46 + xpc_connection_resume(listener); 47 + 48 + dispatch_main(); 49 + return 0; 50 + } 51 + 52 + static void connectionCallback(xpc_connection_t connection) 53 + { 54 + pid_t pid = xpc_connection_get_pid(connection); 55 + xpc_connection_set_event_handler(connection, ^(xpc_object_t msg) { 56 + handleMessage(connection, msg); 57 + }); 58 + xpc_connection_resume(connection); 59 + } 60 + 61 + static void handleMessage(xpc_connection_t connection, xpc_object_t msg) 62 + { 63 + xpc_type_t type = xpc_get_type(msg); 64 + 65 + if (type == XPC_TYPE_DICTIONARY) 66 + { 67 + xpc_object_t reply = xpc_dictionary_create_reply(msg); 68 + 69 + xpc_connection_send_message(connection, reply); 70 + } 71 + }
+77
src/frameworks/CoreServices/src/LaunchServices/launchservicesd/schema.sql
··· 1 + CREATE TABLE `globals` (`key` TEXT PRIMARY KEY, `value` TEXT); 2 + INSERT INTO `globals` (`key`, `value`) VALUES ('version', '1'); 3 + 4 + CREATE TABLE `bundle` ( 5 + `id` INTEGER PRIMARY KEY AUTOINCREMENT, 6 + `path` TEXT NOT NULL, 7 + `bundle_id` TEXT NOT NULL, 8 + `checksum` INTEGER NOT NULL 9 + ); 10 + CREATE INDEX `bundle_id_index` ON `bundle`(`bundle_id`); 11 + CREATE INDEX `bundle_path_index` ON `bundle`(`path`); 12 + 13 + CREATE TABLE `uti` ( 14 + `id` INTEGER PRIMARY KEY AUTOINCREMENT, 15 + `type_identifier` TEXT NOT NULL, -- UTTypeIdentifier 16 + `description` TEXT, -- UTTypeDescription 17 + `bundle` INTEGER, 18 + FOREIGN KEY(`bundle`) REFERENCES `bundle`(`id`) ON DELETE CASCADE 19 + ); 20 + CREATE INDEX `uti_ident_index` ON `uti`(`type_identifier`); 21 + CREATE INDEX `uti_bundle_index` ON `uti`(`bundle`); 22 + 23 + -- UTTypeConformsTo 24 + CREATE TABLE `uti_conforms` ( 25 + `id` INTEGER PRIMARY KEY AUTOINCREMENT, 26 + `uti` INTEGER, 27 + `conforms_to` TEXT NOT NULL, 28 + FOREIGN KEY(`uti`) REFERENCES `uti`(`id`) ON DELETE CASCADE 29 + ); 30 + CREATE INDEX `uti_conforms_index` ON `uti_conforms`(`conforms_to`); 31 + CREATE INDEX `uti_conforms_uti_index` ON `uti_conforms`(`uti`); 32 + 33 + -- UTTypeIconFiles 34 + CREATE TABLE `uti_icon` ( 35 + `id` INTEGER PRIMARY KEY AUTOINCREMENT, 36 + `uti` INTEGER, 37 + `file` TEXT NOT NULL, 38 + FOREIGN KEY(`uti`) REFERENCES `uti`(`id`) ON DELETE CASCADE 39 + ); 40 + CREATE INDEX `uti_icon_uti_index` ON `uti_icon`(`uti`); 41 + 42 + -- UTTypeTagSpecification 43 + CREATE TABLE `uti_tag` ( 44 + `id` INTEGER PRIMARY KEY AUTOINCREMENT, 45 + `uti` INTEGER, 46 + `tag` TEXT NOT NULL, 47 + `value` TEXT NOT NULL, 48 + FOREIGN KEY(`uti`) REFERENCES `uti`(`id`) ON DELETE CASCADE 49 + ); 50 + CREATE INDEX `uti_tag_uti_index` ON `uti_tag`(`uti`); 51 + CREATE INDEX `uti_tag_index1` ON `uti_tag`(`tag`); 52 + CREATE INDEX `uti_tag_index2` ON `uti_tag`(`tag`, `value`); 53 + 54 + -- https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundledocumenttypes?language=objc 55 + 56 + CREATE TABLE `app_doc` ( 57 + `id` INTEGER PRIMARY KEY AUTOINCREMENT, 58 + `bundle` INTEGER, 59 + `icon` TEXT, -- CFBundleTypeIconFile 60 + `name` TEXT, -- CFBundleTypeName 61 + `role` TEXT, -- CFBundleTypeRole 62 + `rank` TEXT, -- LSHandlerRank 63 + `class` TEXT, -- NSDocumentClass 64 + FOREIGN KEY(`bundle`) REFERENCES `bundle`(`id`) ON DELETE CASCADE 65 + ); 66 + CREATE INDEX `app_doc_bundle_index` ON `app_doc`(`bundle`); 67 + 68 + -- LSItemContentTypes 69 + CREATE TABLE `app_doc_uti` ( 70 + `id` INTEGER PRIMARY KEY AUTOINCREMENT, 71 + `doc` INTEGER, 72 + `uti` INTEGER, 73 + FOREIGN KEY(`doc`) REFERENCES `app_doc`(`id`) ON DELETE CASCADE, 74 + FOREIGN KEY(`uti`) REFERENCES `uti`(`id`) ON DELETE CASCADE 75 + ); 76 + CREATE INDEX `app_doc_uti_doc_index` ON `app_doc_uti`(`doc`); 77 + CREATE INDEX `app_doc_uti_index` ON `app_doc_uti`(`uti`);
+2 -2
src/tools/CMakeLists.txt
··· 8 8 add_darling_executable(sw_vers sw_vers.c) 9 9 add_darling_executable(sudo sudo.c) 10 10 add_darling_executable(codesign codesign.c) 11 - add_darling_executable(open open.c) 11 + add_darling_executable(open open.m) 12 12 add_darling_executable(dsmemberutil dsmemberutil.c) 13 13 add_darling_executable(softwareupdate softwareupdate.c) 14 14 ··· 16 16 install(TARGETS softwareupdate DESTINATION libexec/darling/usr/sbin) 17 17 18 18 target_link_libraries(sw_vers CoreFoundation) 19 - target_link_libraries(open CoreFoundation ApplicationServices) 19 + target_link_libraries(open CoreServices Foundation AppKit)
-74
src/tools/open.c
··· 1 - /* 2 - This file is part of Darling. 3 - 4 - Copyright (C) 2019 Lubos Dolezel 5 - 6 - Darling is free software: you can redistribute it and/or modify 7 - it under the terms of the GNU General Public License as published by 8 - the Free Software Foundation, either version 3 of the License, or 9 - (at your option) any later version. 10 - 11 - Darling is distributed in the hope that it will be useful, 12 - but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - GNU General Public License for more details. 15 - 16 - You should have received a copy of the GNU General Public License 17 - along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 - */ 19 - 20 - #include <stdio.h> 21 - #include <string.h> 22 - #include <sys/types.h> 23 - #include <sys/stat.h> 24 - #include <unistd.h> 25 - #include <stdlib.h> 26 - 27 - #include <CoreFoundation/CoreFoundation.h> 28 - #include <ApplicationServices/ApplicationServices.h> 29 - 30 - static void usage(void); 31 - 32 - /* TODO: Options */ 33 - int main(int argc, char *argv[]) 34 - { 35 - CFStringRef url_or_path; 36 - CFURLRef url; 37 - struct stat path_stat; 38 - if (argc != 2) 39 - { 40 - usage(); 41 - return EXIT_FAILURE; 42 - } 43 - url_or_path = CFStringCreateWithFileSystemRepresentation(kCFAllocatorDefault, argv[1]); 44 - /* TODO: What is the URL is not a file URL? (http:, ftp:, etc) */ 45 - /* url = CFURLCreateWithString(kCFAllocatorDefault, url_or_path, NULL); */ 46 - url = NULL; 47 - 48 - if (url == NULL) 49 - { 50 - if (lstat(argv[1], &path_stat)) 51 - { 52 - perror(argv[1]); 53 - return EXIT_FAILURE; 54 - } 55 - url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, url_or_path, kCFURLPOSIXPathStyle, path_stat.st_mode & S_IFDIR); 56 - if (url == NULL) 57 - { 58 - printf("Failed to create file url: %s\n", argv[1]); 59 - return EXIT_FAILURE; 60 - } 61 - } 62 - 63 - LSOpenCFURLRef(url, NULL); 64 - 65 - CFRelease(url); 66 - 67 - return EXIT_SUCCESS; 68 - } 69 - 70 - static void usage(void) 71 - { 72 - printf("Usage: open [filenames]\n" 73 - "Help: Use open to open files, folders, and URLs from the command line.\n"); 74 - }
+235
src/tools/open.m
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2019-2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include <stdio.h> 21 + #include <string.h> 22 + #include <sys/types.h> 23 + #include <sys/stat.h> 24 + #include <unistd.h> 25 + #include <stdlib.h> 26 + #include <getopt.h> 27 + #include <stdbool.h> 28 + 29 + #import <Foundation/NSArray.h> 30 + #import <Foundation/NSString.h> 31 + #import <Foundation/NSURL.h> 32 + #import <AppKit/NSWorkspace.h> 33 + #include <CoreServices/CoreServices.h> 34 + 35 + static void usage(void); 36 + 37 + int main(int argc, char *argv[]) 38 + { 39 + bool fresh = false; 40 + bool reveal = false; 41 + bool wait = false; 42 + bool _new = false; 43 + bool hide = false; 44 + bool background = false; 45 + bool header = false; 46 + bool useDefTextEditor = false; 47 + bool readStdin = false; 48 + 49 + const char* sdk = NULL; 50 + const char* bundle = NULL; 51 + const char* appname = NULL; 52 + NSArray<NSString*>* arguments = nil; 53 + NSArray<NSURL*>* filenames = nil; 54 + FSRef fsref; 55 + bool hasFSRef = false; 56 + CFURLRef appURL = NULL; 57 + 58 + for (int i = 1; i < argc; i++) 59 + { 60 + if (strcmp(argv[i], "--args") == 0) 61 + { 62 + int count = argc-i-1; 63 + NSString** strings = (NSString**) malloc(count * sizeof(NSString*)); 64 + 65 + for (int j = 0; j < count; j++) 66 + strings[j] = [NSString stringWithCString: argv[j+i+1] encoding: NSUTF8StringEncoding]; 67 + 68 + arguments = [NSArray arrayWithObjects: strings count: count]; 69 + free(strings); 70 + 71 + argv[i] = NULL; 72 + argc = i; 73 + break; 74 + } 75 + } 76 + 77 + while (true) 78 + { 79 + static struct option long_options[] = { 80 + { "fresh", no_argument, 0, 'F' }, 81 + { "reveal", no_argument, 0, 'R' }, 82 + { "wait-apps", no_argument, 0, 'W' }, 83 + { "new", no_argument, 0, 'n' }, 84 + { "hide", no_argument, 0, 'j' }, 85 + { "background", no_argument, 0, 'g' }, 86 + { "header", no_argument, 0, 'h' }, 87 + { NULL, 0, 0, 0 } 88 + }; 89 + int c = getopt_long(argc, argv, "a:b:etfFRWnjghs:", long_options, NULL); 90 + 91 + if (c == -1) 92 + break; 93 + 94 + switch (c) 95 + { 96 + case 'a': 97 + appname = optarg; 98 + break; 99 + case 'b': 100 + bundle = optarg; 101 + break; 102 + case 'e': 103 + bundle = "com.apple.TextEdit"; 104 + break; 105 + case 't': 106 + useDefTextEditor = true; 107 + break; 108 + case 'f': 109 + readStdin = true; 110 + break; 111 + case 'F': 112 + fresh = true; 113 + break; 114 + case 'R': 115 + reveal = true; 116 + break; 117 + case 'W': 118 + wait = true; 119 + break; 120 + case 'n': 121 + _new = true; 122 + break; 123 + case 'j': 124 + hide = true; 125 + break; 126 + case 'g': 127 + background = true; 128 + break; 129 + case 'h': 130 + header = true; 131 + break; 132 + case 's': 133 + sdk = optarg; 134 + break; 135 + default: 136 + usage(); 137 + return EXIT_FAILURE; 138 + } 139 + } 140 + 141 + if (header || reveal || readStdin) 142 + { 143 + fprintf(stderr, "This operation is not implemented yet. Sorry.\n"); 144 + return EXIT_FAILURE; 145 + } 146 + 147 + if (optind < argc) 148 + { 149 + int count = argc - optind; 150 + NSURL** urls = (NSURL**) malloc(count * sizeof(NSURL*)); 151 + 152 + for (int i = 0; i < count; i++) 153 + urls[i] = [NSURL URLWithString:[NSString stringWithCString: argv[optind+i] encoding: NSUTF8StringEncoding]]; 154 + 155 + filenames = [NSArray arrayWithObjects: urls count: count]; 156 + free(urls); 157 + } 158 + 159 + OSStatus result = noErr; 160 + if (useDefTextEditor) 161 + { 162 + result = LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator, CFSTR("txt"), kLSRolesEditor, &fsref, &appURL); 163 + hasFSRef = true; 164 + } 165 + else if (bundle != NULL) 166 + { 167 + result = LSFindApplicationForInfo(kLSUnknownCreator, (CFStringRef) [NSString stringWithCString:bundle encoding:NSUTF8StringEncoding], NULL, &fsref, &appURL); 168 + hasFSRef = true; 169 + } 170 + else if (appname != NULL) 171 + { 172 + NSString* appPath = [[NSWorkspace sharedWorkspace] fullPathForApplication: [NSString stringWithCString:appname encoding:NSUTF8StringEncoding]]; 173 + if (appPath == nil) 174 + { 175 + fprintf(stderr, "Cannot find required application: %s\n", appname); 176 + return EXIT_FAILURE; 177 + } 178 + 179 + appURL = (CFURLRef) [NSURL URLWithString: appPath]; 180 + result = FSPathMakeRef((const UInt8*) [appPath UTF8String], &fsref, NULL); 181 + } 182 + 183 + if (result != noErr) 184 + { 185 + fprintf(stderr, "Cannot find required application: %d\n", result); 186 + return EXIT_FAILURE; 187 + } 188 + 189 + NSArray<NSURL*>* urlsToOpen; 190 + LSApplicationParameters params; 191 + 192 + memset(&params, 0, sizeof(params)); 193 + 194 + if (hasFSRef) 195 + params.application = &fsref; 196 + params.argv = (CFArrayRef) arguments; 197 + 198 + if (_new) 199 + params.flags |= kLSLaunchNewInstance; 200 + if (background) 201 + params.flags |= kLSLaunchDontSwitch; 202 + if (hide) 203 + params.flags |= kLSLaunchAndHide; 204 + 205 + if (filenames) 206 + { 207 + urlsToOpen = filenames; 208 + } 209 + else if (appURL) 210 + { 211 + urlsToOpen = [NSArray arrayWithObjects: (const id*) &appURL count: 1]; 212 + } 213 + else 214 + { 215 + usage(); 216 + return EXIT_FAILURE; 217 + } 218 + 219 + // TODO: Apple Events, PSNs (for waiting) 220 + result = LSOpenURLsWithRole((CFArrayRef) urlsToOpen, kLSRolesAll, NULL, &params, NULL, 0); 221 + 222 + if (result != noErr) 223 + { 224 + fprintf(stderr, "Failed to launch: %d\n", result); 225 + return EXIT_FAILURE; 226 + } 227 + 228 + return EXIT_SUCCESS; 229 + } 230 + 231 + static void usage(void) 232 + { 233 + printf("Usage: open [filenames]\n" 234 + "Help: Use open to open files, folders, and URLs from the command line.\n"); 235 + }