From 93c1cedd304bb4b4ad987bb1be10e453536b9300 Mon Sep 17 00:00:00 2001 From: cdouglass Date: Fri, 2 Nov 2018 13:44:08 -0700 Subject: [PATCH] Fixes an issue where cartool crashed on Mohave due to an API change on CUIThemeFacet. -initWithURL:error: was moved by Apple to CUICatalog. --- cartool/main.m | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cartool/main.m b/cartool/main.m index 6aaf27b..6f4c856 100644 --- a/cartool/main.m +++ b/cartool/main.m @@ -60,6 +60,7 @@ @interface CUICatalog : NSObject @property(readonly) bool isVectorBased; +-(id)initWithURL:(NSURL *)URL error:(NSError **)error; -(id)initWithName:(NSString *)n fromBundle:(NSBundle *)b; -(id)allKeys; -(id)allImageNames; @@ -149,14 +150,19 @@ void exportCarFileAtPath(NSString * carPath, NSString *outputDirectoryPath) NSError *error = nil; outputDirectoryPath = [outputDirectoryPath stringByExpandingTildeInPath]; - - CUIThemeFacet *facet = [CUIThemeFacet themeWithContentsOfURL:[NSURL fileURLWithPath:carPath] error:&error]; - - CUICatalog *catalog = [[CUICatalog alloc] init]; - - /* Override CUICatalog to point to a file rather than a bundle */ - [catalog setValue:facet forKey:@"_storageRef"]; - + + CUICatalog *catalog = nil; + if ([CUICatalog instancesRespondToSelector:@selector(initWithURL:error:)]) { + /* If CUICatalog has the URL API (Mojave), use it. */ + catalog = [[CUICatalog alloc] initWithURL:[NSURL fileURLWithPath:carPath] error:&error]; + } else { + CUIThemeFacet *facet = [CUIThemeFacet themeWithContentsOfURL:[NSURL fileURLWithPath:carPath] error:&error]; + catalog = [[CUICatalog alloc] init]; + /* Override CUICatalog to point to a file rather than a bundle */ + [catalog setValue:facet forKey:@"_storageRef"]; + } + NSCAssert(!error, @"Error attempting to open asset catalog (%@): %@", carPath, error); + /* CUICommonAssetStorage won't link */ CUICommonAssetStorage *storage = [[NSClassFromString(@"CUICommonAssetStorage") alloc] initWithPath:carPath];