├── .gitignore ├── README.md ├── cartool.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── steven.xcuserdatad │ └── xcschemes │ ├── cartool.xcscheme │ └── xcschememanagement.plist └── cartool ├── cartool-Prefix.pch ├── cartool.1 └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | xcuserdata/ 3 | *.xccheckout 4 | 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cartool 2 | ======= 3 | 4 | Export images from OS X / iOS .car CoreUI archives. Very rough code, probably tons wrong with it, but still useful. 5 | -------------------------------------------------------------------------------- /cartool.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B06C818B17934BA30082BD37 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B06C818A17934BA30082BD37 /* Foundation.framework */; }; 11 | B06C818E17934BA30082BD37 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B06C818D17934BA30082BD37 /* main.m */; }; 12 | B06C819217934BA30082BD37 /* cartool.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = B06C819117934BA30082BD37 /* cartool.1 */; }; 13 | B06C819917934BCC0082BD37 /* CoreUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B06C819817934BCC0082BD37 /* CoreUI.framework */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXCopyFilesBuildPhase section */ 17 | B06C818517934BA30082BD37 /* CopyFiles */ = { 18 | isa = PBXCopyFilesBuildPhase; 19 | buildActionMask = 2147483647; 20 | dstPath = /usr/share/man/man1/; 21 | dstSubfolderSpec = 0; 22 | files = ( 23 | B06C819217934BA30082BD37 /* cartool.1 in CopyFiles */, 24 | ); 25 | runOnlyForDeploymentPostprocessing = 1; 26 | }; 27 | /* End PBXCopyFilesBuildPhase section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | B06C818717934BA30082BD37 /* cartool */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = cartool; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | B06C818A17934BA30082BD37 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 32 | B06C818D17934BA30082BD37 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 33 | B06C819017934BA30082BD37 /* cartool-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "cartool-Prefix.pch"; sourceTree = ""; }; 34 | B06C819117934BA30082BD37 /* cartool.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = cartool.1; sourceTree = ""; }; 35 | B06C819817934BCC0082BD37 /* CoreUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreUI.framework; path = ../../../../../../System/Library/PrivateFrameworks/CoreUI.framework; sourceTree = ""; }; 36 | /* End PBXFileReference section */ 37 | 38 | /* Begin PBXFrameworksBuildPhase section */ 39 | B06C818417934BA30082BD37 /* Frameworks */ = { 40 | isa = PBXFrameworksBuildPhase; 41 | buildActionMask = 2147483647; 42 | files = ( 43 | B06C819917934BCC0082BD37 /* CoreUI.framework in Frameworks */, 44 | B06C818B17934BA30082BD37 /* Foundation.framework in Frameworks */, 45 | ); 46 | runOnlyForDeploymentPostprocessing = 0; 47 | }; 48 | /* End PBXFrameworksBuildPhase section */ 49 | 50 | /* Begin PBXGroup section */ 51 | B06C817E17934BA30082BD37 = { 52 | isa = PBXGroup; 53 | children = ( 54 | B06C818C17934BA30082BD37 /* cartool */, 55 | B06C818917934BA30082BD37 /* Frameworks */, 56 | B06C818817934BA30082BD37 /* Products */, 57 | ); 58 | sourceTree = ""; 59 | }; 60 | B06C818817934BA30082BD37 /* Products */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | B06C818717934BA30082BD37 /* cartool */, 64 | ); 65 | name = Products; 66 | sourceTree = ""; 67 | }; 68 | B06C818917934BA30082BD37 /* Frameworks */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | B06C819817934BCC0082BD37 /* CoreUI.framework */, 72 | B06C818A17934BA30082BD37 /* Foundation.framework */, 73 | ); 74 | name = Frameworks; 75 | sourceTree = ""; 76 | }; 77 | B06C818C17934BA30082BD37 /* cartool */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | B06C818D17934BA30082BD37 /* main.m */, 81 | B06C819117934BA30082BD37 /* cartool.1 */, 82 | B06C818F17934BA30082BD37 /* Supporting Files */, 83 | ); 84 | path = cartool; 85 | sourceTree = ""; 86 | }; 87 | B06C818F17934BA30082BD37 /* Supporting Files */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | B06C819017934BA30082BD37 /* cartool-Prefix.pch */, 91 | ); 92 | name = "Supporting Files"; 93 | sourceTree = ""; 94 | }; 95 | /* End PBXGroup section */ 96 | 97 | /* Begin PBXNativeTarget section */ 98 | B06C818617934BA30082BD37 /* cartool */ = { 99 | isa = PBXNativeTarget; 100 | buildConfigurationList = B06C819517934BA30082BD37 /* Build configuration list for PBXNativeTarget "cartool" */; 101 | buildPhases = ( 102 | B06C818317934BA30082BD37 /* Sources */, 103 | B06C818417934BA30082BD37 /* Frameworks */, 104 | B06C818517934BA30082BD37 /* CopyFiles */, 105 | ); 106 | buildRules = ( 107 | ); 108 | dependencies = ( 109 | ); 110 | name = cartool; 111 | productName = cartool; 112 | productReference = B06C818717934BA30082BD37 /* cartool */; 113 | productType = "com.apple.product-type.tool"; 114 | }; 115 | /* End PBXNativeTarget section */ 116 | 117 | /* Begin PBXProject section */ 118 | B06C817F17934BA30082BD37 /* Project object */ = { 119 | isa = PBXProject; 120 | attributes = { 121 | LastUpgradeCheck = 0800; 122 | ORGANIZATIONNAME = "High Caffeine Content"; 123 | }; 124 | buildConfigurationList = B06C818217934BA30082BD37 /* Build configuration list for PBXProject "cartool" */; 125 | compatibilityVersion = "Xcode 3.2"; 126 | developmentRegion = English; 127 | hasScannedForEncodings = 0; 128 | knownRegions = ( 129 | en, 130 | ); 131 | mainGroup = B06C817E17934BA30082BD37; 132 | productRefGroup = B06C818817934BA30082BD37 /* Products */; 133 | projectDirPath = ""; 134 | projectRoot = ""; 135 | targets = ( 136 | B06C818617934BA30082BD37 /* cartool */, 137 | ); 138 | }; 139 | /* End PBXProject section */ 140 | 141 | /* Begin PBXSourcesBuildPhase section */ 142 | B06C818317934BA30082BD37 /* Sources */ = { 143 | isa = PBXSourcesBuildPhase; 144 | buildActionMask = 2147483647; 145 | files = ( 146 | B06C818E17934BA30082BD37 /* main.m in Sources */, 147 | ); 148 | runOnlyForDeploymentPostprocessing = 0; 149 | }; 150 | /* End PBXSourcesBuildPhase section */ 151 | 152 | /* Begin XCBuildConfiguration section */ 153 | B06C819317934BA30082BD37 /* Debug */ = { 154 | isa = XCBuildConfiguration; 155 | buildSettings = { 156 | ALWAYS_SEARCH_USER_PATHS = NO; 157 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 158 | CLANG_CXX_LIBRARY = "libc++"; 159 | CLANG_ENABLE_MODULES = YES; 160 | CLANG_ENABLE_OBJC_ARC = YES; 161 | CLANG_WARN_BOOL_CONVERSION = YES; 162 | CLANG_WARN_CONSTANT_CONVERSION = YES; 163 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 164 | CLANG_WARN_EMPTY_BODY = YES; 165 | CLANG_WARN_ENUM_CONVERSION = YES; 166 | CLANG_WARN_INFINITE_RECURSION = YES; 167 | CLANG_WARN_INT_CONVERSION = YES; 168 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 169 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 170 | CLANG_WARN_UNREACHABLE_CODE = YES; 171 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 172 | COPY_PHASE_STRIP = NO; 173 | ENABLE_STRICT_OBJC_MSGSEND = YES; 174 | ENABLE_TESTABILITY = YES; 175 | GCC_C_LANGUAGE_STANDARD = gnu99; 176 | GCC_DYNAMIC_NO_PIC = NO; 177 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 178 | GCC_NO_COMMON_BLOCKS = YES; 179 | GCC_OPTIMIZATION_LEVEL = 0; 180 | GCC_PREPROCESSOR_DEFINITIONS = ( 181 | "DEBUG=1", 182 | "$(inherited)", 183 | ); 184 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 185 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 186 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 187 | GCC_WARN_UNDECLARED_SELECTOR = YES; 188 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 189 | GCC_WARN_UNUSED_FUNCTION = YES; 190 | GCC_WARN_UNUSED_VARIABLE = YES; 191 | MACOSX_DEPLOYMENT_TARGET = 10.9; 192 | ONLY_ACTIVE_ARCH = YES; 193 | SDKROOT = macosx; 194 | }; 195 | name = Debug; 196 | }; 197 | B06C819417934BA30082BD37 /* Release */ = { 198 | isa = XCBuildConfiguration; 199 | buildSettings = { 200 | ALWAYS_SEARCH_USER_PATHS = NO; 201 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 202 | CLANG_CXX_LIBRARY = "libc++"; 203 | CLANG_ENABLE_MODULES = YES; 204 | CLANG_ENABLE_OBJC_ARC = YES; 205 | CLANG_WARN_BOOL_CONVERSION = YES; 206 | CLANG_WARN_CONSTANT_CONVERSION = YES; 207 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 208 | CLANG_WARN_EMPTY_BODY = YES; 209 | CLANG_WARN_ENUM_CONVERSION = YES; 210 | CLANG_WARN_INFINITE_RECURSION = YES; 211 | CLANG_WARN_INT_CONVERSION = YES; 212 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 213 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 214 | CLANG_WARN_UNREACHABLE_CODE = YES; 215 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 216 | COPY_PHASE_STRIP = YES; 217 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 218 | ENABLE_NS_ASSERTIONS = NO; 219 | ENABLE_STRICT_OBJC_MSGSEND = YES; 220 | GCC_C_LANGUAGE_STANDARD = gnu99; 221 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 222 | GCC_NO_COMMON_BLOCKS = YES; 223 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 224 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 225 | GCC_WARN_UNDECLARED_SELECTOR = YES; 226 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 227 | GCC_WARN_UNUSED_FUNCTION = YES; 228 | GCC_WARN_UNUSED_VARIABLE = YES; 229 | MACOSX_DEPLOYMENT_TARGET = 10.9; 230 | SDKROOT = macosx; 231 | }; 232 | name = Release; 233 | }; 234 | B06C819617934BA30082BD37 /* Debug */ = { 235 | isa = XCBuildConfiguration; 236 | buildSettings = { 237 | FRAMEWORK_SEARCH_PATHS = ( 238 | "$(inherited)", 239 | "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks", 240 | ); 241 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 242 | GCC_PREFIX_HEADER = "cartool/cartool-Prefix.pch"; 243 | PRODUCT_NAME = "$(TARGET_NAME)"; 244 | }; 245 | name = Debug; 246 | }; 247 | B06C819717934BA30082BD37 /* Release */ = { 248 | isa = XCBuildConfiguration; 249 | buildSettings = { 250 | FRAMEWORK_SEARCH_PATHS = ( 251 | "$(inherited)", 252 | "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks", 253 | ); 254 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 255 | GCC_PREFIX_HEADER = "cartool/cartool-Prefix.pch"; 256 | PRODUCT_NAME = "$(TARGET_NAME)"; 257 | }; 258 | name = Release; 259 | }; 260 | /* End XCBuildConfiguration section */ 261 | 262 | /* Begin XCConfigurationList section */ 263 | B06C818217934BA30082BD37 /* Build configuration list for PBXProject "cartool" */ = { 264 | isa = XCConfigurationList; 265 | buildConfigurations = ( 266 | B06C819317934BA30082BD37 /* Debug */, 267 | B06C819417934BA30082BD37 /* Release */, 268 | ); 269 | defaultConfigurationIsVisible = 0; 270 | defaultConfigurationName = Release; 271 | }; 272 | B06C819517934BA30082BD37 /* Build configuration list for PBXNativeTarget "cartool" */ = { 273 | isa = XCConfigurationList; 274 | buildConfigurations = ( 275 | B06C819617934BA30082BD37 /* Debug */, 276 | B06C819717934BA30082BD37 /* Release */, 277 | ); 278 | defaultConfigurationIsVisible = 0; 279 | defaultConfigurationName = Release; 280 | }; 281 | /* End XCConfigurationList section */ 282 | }; 283 | rootObject = B06C817F17934BA30082BD37 /* Project object */; 284 | } 285 | -------------------------------------------------------------------------------- /cartool.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /cartool.xcodeproj/xcuserdata/steven.xcuserdatad/xcschemes/cartool.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /cartool.xcodeproj/xcuserdata/steven.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | cartool.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | B06C818617934BA30082BD37 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /cartool/cartool-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /cartool/cartool.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 14/07/2013 \" DATE 7 | .Dt cartool 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm cartool, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner -------------------------------------------------------------------------------- /cartool/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // cartool 4 | // 5 | // Created by Steven Troughton-Smith on 14/07/2013. 6 | // Copyright (c) 2013 High Caffeine Content. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef enum _kCoreThemeIdiom { 12 | kCoreThemeIdiomUniversal, 13 | kCoreThemeIdiomPhone, 14 | kCoreThemeIdiomPad, 15 | kCoreThemeIdiomTV, 16 | kCoreThemeIdiomCar, 17 | kCoreThemeIdiomWatch, 18 | kCoreThemeIdiomMarketing 19 | } kCoreThemeIdiom; 20 | 21 | typedef NS_ENUM(NSInteger, UIUserInterfaceSizeClass) { 22 | UIUserInterfaceSizeClassUnspecified = 0, 23 | UIUserInterfaceSizeClassCompact = 1, 24 | UIUserInterfaceSizeClassRegular = 2, 25 | }; 26 | 27 | @interface CUICommonAssetStorage : NSObject 28 | 29 | -(NSArray *)allAssetKeys; 30 | -(NSArray *)allRenditionNames; 31 | 32 | -(id)initWithPath:(NSString *)p; 33 | 34 | -(NSString *)versionString; 35 | 36 | @end 37 | 38 | @interface CUINamedImage : NSObject 39 | 40 | @property(readonly) CGSize size; 41 | @property(readonly) CGFloat scale; 42 | @property(readonly) kCoreThemeIdiom idiom; 43 | @property(readonly) UIUserInterfaceSizeClass sizeClassHorizontal; 44 | @property(readonly) UIUserInterfaceSizeClass sizeClassVertical; 45 | 46 | -(CGImageRef)image; 47 | 48 | @end 49 | 50 | @interface CUIRenditionKey : NSObject 51 | @end 52 | 53 | @interface CUIThemeFacet : NSObject 54 | 55 | +(CUIThemeFacet *)themeWithContentsOfURL:(NSURL *)u error:(NSError **)e; 56 | 57 | @end 58 | 59 | @interface CUICatalog : NSObject 60 | 61 | @property(readonly) bool isVectorBased; 62 | 63 | -(id)initWithName:(NSString *)n fromBundle:(NSBundle *)b; 64 | -(id)allKeys; 65 | -(id)allImageNames; 66 | -(CUINamedImage *)imageWithName:(NSString *)n scaleFactor:(CGFloat)s; 67 | -(CUINamedImage *)imageWithName:(NSString *)n scaleFactor:(CGFloat)s deviceIdiom:(int)idiom; 68 | -(NSArray *)imagesWithName:(NSString *)n; 69 | 70 | @end 71 | 72 | 73 | 74 | void CGImageWriteToFile(CGImageRef image, NSString *path) 75 | { 76 | CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path]; 77 | CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL); 78 | CGImageDestinationAddImage(destination, image, nil); 79 | 80 | if (!CGImageDestinationFinalize(destination)) { 81 | NSLog(@"Failed to write image to %@", path); 82 | } 83 | 84 | CFRelease(destination); 85 | } 86 | 87 | NSString *idiomSuffixForCoreThemeIdiom(kCoreThemeIdiom idiom) 88 | { 89 | switch (idiom) { 90 | case kCoreThemeIdiomUniversal: 91 | return @""; 92 | break; 93 | case kCoreThemeIdiomPhone: 94 | return @"~iphone"; 95 | break; 96 | case kCoreThemeIdiomPad: 97 | return @"~ipad"; 98 | break; 99 | case kCoreThemeIdiomTV: 100 | return @"~tv"; 101 | break; 102 | case kCoreThemeIdiomCar: 103 | return @"~carplay"; 104 | break; 105 | case kCoreThemeIdiomWatch: 106 | return @"~watch"; 107 | break; 108 | case kCoreThemeIdiomMarketing: 109 | return @"~marketing"; 110 | break; 111 | default: 112 | break; 113 | } 114 | 115 | return @""; 116 | } 117 | 118 | NSString *sizeClassSuffixForSizeClass(UIUserInterfaceSizeClass sizeClass) 119 | { 120 | switch (sizeClass) 121 | { 122 | case UIUserInterfaceSizeClassCompact: 123 | return @"C"; 124 | break; 125 | case UIUserInterfaceSizeClassRegular: 126 | return @"R"; 127 | break; 128 | default: 129 | return @"A"; 130 | } 131 | } 132 | 133 | NSMutableArray *getImagesArray(CUICatalog *catalog, NSString *key) 134 | { 135 | NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:5]; 136 | 137 | for (NSNumber *scaleFactor in @[@1, @2, @3]) 138 | { 139 | CUINamedImage *image = [catalog imageWithName:key scaleFactor:scaleFactor.doubleValue]; 140 | 141 | if (image && image.scale == scaleFactor.floatValue) [images addObject:image]; 142 | } 143 | 144 | return images; 145 | } 146 | 147 | void exportCarFileAtPath(NSString * carPath, NSString *outputDirectoryPath) 148 | { 149 | NSError *error = nil; 150 | 151 | outputDirectoryPath = [outputDirectoryPath stringByExpandingTildeInPath]; 152 | 153 | CUIThemeFacet *facet = [CUIThemeFacet themeWithContentsOfURL:[NSURL fileURLWithPath:carPath] error:&error]; 154 | 155 | CUICatalog *catalog = [[CUICatalog alloc] init]; 156 | 157 | /* Override CUICatalog to point to a file rather than a bundle */ 158 | [catalog setValue:facet forKey:@"_storageRef"]; 159 | 160 | /* CUICommonAssetStorage won't link */ 161 | CUICommonAssetStorage *storage = [[NSClassFromString(@"CUICommonAssetStorage") alloc] initWithPath:carPath]; 162 | 163 | for (NSString *key in [storage allRenditionNames]) 164 | { 165 | printf("%s\n", [key UTF8String]); 166 | 167 | NSArray* pathComponents = [key pathComponents]; 168 | if (pathComponents.count > 1) 169 | { 170 | // Create subdirectories for namespaced assets (those with names like "some/namespace/image-name") 171 | NSArray* subdirectoryComponents = [pathComponents subarrayWithRange:NSMakeRange(0, pathComponents.count - 1)]; 172 | 173 | NSString* subdirectoryPath = [outputDirectoryPath copy]; 174 | for (NSString* pathComponent in subdirectoryComponents) 175 | { 176 | subdirectoryPath = [subdirectoryPath stringByAppendingPathComponent:pathComponent]; 177 | } 178 | 179 | [[NSFileManager defaultManager] createDirectoryAtPath:subdirectoryPath 180 | withIntermediateDirectories:YES 181 | attributes:nil 182 | error:&error]; 183 | } 184 | 185 | NSMutableArray *images = getImagesArray(catalog, key); 186 | for( CUINamedImage *image in images ) 187 | { 188 | if( CGSizeEqualToSize(image.size, CGSizeZero) ) 189 | printf("\tnil image?\n"); 190 | else 191 | { 192 | CGImageRef cgImage = [image image]; 193 | NSString *idiomSuffix = idiomSuffixForCoreThemeIdiom(image.idiom); 194 | 195 | NSString *sizeClassSuffix = @""; 196 | 197 | if (image.sizeClassHorizontal || image.sizeClassVertical) 198 | { 199 | sizeClassSuffix = [NSString stringWithFormat:@"-%@x%@", sizeClassSuffixForSizeClass(image.sizeClassHorizontal), sizeClassSuffixForSizeClass(image.sizeClassVertical)]; 200 | } 201 | 202 | NSString *scale = image.scale > 1.0 ? [NSString stringWithFormat:@"@%dx", (int)floor(image.scale)] : @""; 203 | NSString *name = [NSString stringWithFormat:@"%@%@%@%@.png", key, idiomSuffix, sizeClassSuffix, scale]; 204 | printf("\t%s\n", [name UTF8String]); 205 | if( outputDirectoryPath ) 206 | CGImageWriteToFile(cgImage, [outputDirectoryPath stringByAppendingPathComponent:name]); 207 | } 208 | } 209 | } 210 | } 211 | 212 | int main(int argc, const char * argv[]) 213 | { 214 | @autoreleasepool { 215 | 216 | if (argc < 2) 217 | { 218 | printf("Usage: cartool [outputDirectory]\n"); 219 | return -1; 220 | } 221 | 222 | exportCarFileAtPath([NSString stringWithUTF8String:argv[1]], argc > 2 ? [NSString stringWithUTF8String:argv[2]] : nil); 223 | } 224 | return 0; 225 | } 226 | --------------------------------------------------------------------------------