From 8927451fae0132c6a1b31aaafcabf527cd38719a Mon Sep 17 00:00:00 2001 From: Stephen Lind Date: Thu, 6 Nov 2014 12:58:56 -0800 Subject: [PATCH] Fix issue parsing iWork '14 format, Fixes #3 --- .../iWorkFileInspector/Bundle/IWBundle.m | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/iWorkFileInspector/iWorkFileInspector/Bundle/IWBundle.m b/iWorkFileInspector/iWorkFileInspector/Bundle/IWBundle.m index 702921e..585a2ef 100644 --- a/iWorkFileInspector/iWorkFileInspector/Bundle/IWBundle.m +++ b/iWorkFileInspector/iWorkFileInspector/Bundle/IWBundle.m @@ -31,18 +31,33 @@ @implementation IWBundle - (instancetype)initWithURL:(NSURL *)fileURL decryptionKey:(NSData *)decryptionKey { - self = [super init]; - if (self == nil) { - return nil; - } - - _objectArchive = [[IWZipArchive alloc] initWithURL:[fileURL URLByAppendingPathComponent:IWBundleComponentZipFileName]]; - if (_objectArchive == nil) { - return nil; - } - - _decryptionKey = decryptionKey; - + self = [super init]; + if (self) { + _decryptionKey = decryptionKey; + + /* + The object archive can be in one of two places, depending + on which version of iWork was used: + + 1. The top level file (iWork '14) + 2. In the bundle zip component file (iWork '13) + */ + + + // Start with iWork '13 structure + _objectArchive = [[IWZipArchive alloc] initWithURL:[fileURL URLByAppendingPathComponent:IWBundleComponentZipFileName]]; + if (_objectArchive == nil) { + // Try again with iWork '14 + _objectArchive = [[IWZipArchive alloc] initWithURL:fileURL]; + } + + + if (_objectArchive == nil) { + return nil; + } + } + + return self; }