diff --git a/README.md b/README.md index 0879841..a977714 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,8 @@ cartool ======= Export images from OS X / iOS .car CoreUI archives. Very rough code, probably tons wrong with it, but still useful. + +changelog +======= + +2016.06.15 create output directory automatically, otherwise it raises a segfault error \ No newline at end of file diff --git a/cartool/main.m b/cartool/main.m index 4ad7da6..7890930 100644 --- a/cartool/main.m +++ b/cartool/main.m @@ -60,12 +60,29 @@ void CGImageWriteToFile(CGImageRef image, NSString *path) CFRelease(destination); } - void exportCarFileAtPath(NSString * carPath, NSString *outputDirectoryPath) { NSError *error = nil; - + BOOL isDir; + NSFileManager *fileManager = [NSFileManager defaultManager]; + outputDirectoryPath = [outputDirectoryPath stringByExpandingTildeInPath]; + + // mkdir + if ([fileManager fileExistsAtPath:outputDirectoryPath isDirectory:&isDir]) { + if (! isDir) { + NSLog(@"Error: output directory %@ exists and is not a directory", outputDirectoryPath); + exit(1); + } + } else { + if (![fileManager createDirectoryAtPath:outputDirectoryPath + withIntermediateDirectories:NO + attributes:nil + error:&error]) + { + NSLog(@"Error: %@ while trying to create directory %@", error, outputDirectoryPath); + } + } CUIThemeFacet *facet = [CUIThemeFacet themeWithContentsOfURL:[NSURL fileURLWithPath:carPath] error:&error];