From 281eae913c1c05fc60a90a21e689ef73c033d8e4 Mon Sep 17 00:00:00 2001 From: OlehKulykov Date: Tue, 24 Nov 2015 11:44:43 +0100 Subject: [PATCH] Release 0.0.9 --- src/LzmaSDKObjC.h | 9 ++++-- src/LzmaSDKObjCCommon.cpp | 20 ++++++++++-- src/LzmaSDKObjCCommon.h | 2 ++ src/LzmaSDKObjCExtractCallback.mm | 54 ++++++++++++++++++------------- src/LzmaSDKObjCReader.h | 2 +- tests/ios/ios/ViewController.m | 2 +- 6 files changed, 60 insertions(+), 29 deletions(-) diff --git a/src/LzmaSDKObjC.h b/src/LzmaSDKObjC.h index 6014e27..1575b07 100644 --- a/src/LzmaSDKObjC.h +++ b/src/LzmaSDKObjC.h @@ -28,12 +28,15 @@ /* * Lzma SDK for Objective-C based on extended functionality of the C++ LZMA code * - * Changes on version 0.0.8 (current): + * Changes on version 0.0.9 (current): + * - Extract empty archive folders + * + * Changes on version 0.0.8: * - Update LZMA SDK to version 15.12. * Note: If you use XZ code from LZMA SDK, it's recommended to upgrade to new XZ code from 7-Zip 15.12. * That new code fixes some bugs. * - * Changes on version 0.0.7 (current): + * Changes on version 0.0.7: * - Enabled test functionality. * * Changes on version 0.0.6: @@ -63,7 +66,7 @@ #define LZMASDKOBJC_VERSION_MAJOR 0 #define LZMASDKOBJC_VERSION_MINOR 0 -#define LZMASDKOBJC_VERSION_PATCH 8 +#define LZMASDKOBJC_VERSION_PATCH 9 #include "LzmaSDKObjCTypes.h" diff --git a/src/LzmaSDKObjCCommon.cpp b/src/LzmaSDKObjCCommon.cpp index fb85516..8cc4192 100644 --- a/src/LzmaSDKObjCCommon.cpp +++ b/src/LzmaSDKObjCCommon.cpp @@ -33,16 +33,32 @@ uint64_t LzmaSDKObjCPROPVARIANTGetUInt64(PROPVARIANT * prop) switch (prop->vt) { case VT_UI8: return prop->uhVal.QuadPart; - case VT_UI4: return prop->ulVal; + + case VT_HRESULT: + case VT_UI4: + return prop->ulVal; + case VT_UINT: return prop->uintVal; case VT_I8: return prop->hVal.QuadPart; case VT_UI1: return prop->bVal; case VT_I4: return prop->lVal; - default:break; + case VT_INT: return prop->intVal; + + default: break; } return 0; } +bool LzmaSDKObjCPROPVARIANTGetBool(PROPVARIANT * prop) +{ + switch (prop->vt) + { + case VT_BOOL: return (prop->boolVal == 0) ? false : true; + default: break; + } + return (LzmaSDKObjCPROPVARIANTGetUInt64(prop) == 0) ? false : true; +} + time_t LzmaSDKObjCFILETIMEToUnixTime(const FILETIME filetime) { long long int t = filetime.dwHighDateTime; diff --git a/src/LzmaSDKObjCCommon.h b/src/LzmaSDKObjCCommon.h index 44593b4..a7f0cf2 100644 --- a/src/LzmaSDKObjCCommon.h +++ b/src/LzmaSDKObjCCommon.h @@ -36,6 +36,8 @@ LZMASDKOBJC_EXTERN const GUID LzmaSDKObjCCLSIDFormatXz; LZMASDKOBJC_EXTERN uint64_t LzmaSDKObjCPROPVARIANTGetUInt64(PROPVARIANT * prop); +LZMASDKOBJC_EXTERN bool LzmaSDKObjCPROPVARIANTGetBool(PROPVARIANT * prop); + LZMASDKOBJC_EXTERN time_t LzmaSDKObjCFILETIMEToUnixTime(const FILETIME filetime); #endif diff --git a/src/LzmaSDKObjCExtractCallback.mm b/src/LzmaSDKObjCExtractCallback.mm index d152bc8..df1e8ed 100644 --- a/src/LzmaSDKObjCExtractCallback.mm +++ b/src/LzmaSDKObjCExtractCallback.mm @@ -139,25 +139,45 @@ fullPath = [fullPath stringByAppendingPathComponent:fileName]; - LzmaSDKObjC::OutFile * outFile = new LzmaSDKObjC::OutFile(); - if (!outFile) + PROPVARIANT isDirProp; + HRESULT res = _archive->GetProperty(index, kpidIsDir, &isDirProp); + if (res != S_OK) { - this->setLastError(E_ABORT, __LINE__, __FILE__, "Can't create out file stream"); - return E_ABORT; + this->setLastError(res, __LINE__, __FILE__, "Can't get property of the item by index: %u", (unsigned int)index); + return res; } - if (!outFile->open([fullPath UTF8String])) + if (LzmaSDKObjCPROPVARIANTGetBool(&isDirProp)) { - delete outFile; - this->setLastError(E_ABORT, __LINE__, __FILE__, "Can't open destination for write: [%s]", [fullPath UTF8String]); - return E_ABORT; + NSError * error = nil; + if (![[NSFileManager defaultManager] createDirectoryAtPath:fullPath withIntermediateDirectories:YES attributes:nil error:&error] || error) + { + this->setLastError(S_FALSE, __LINE__, __FILE__, "Can't create directory: [%s]", [fullPath UTF8String]); + return E_ABORT; + } } + else + { + LzmaSDKObjC::OutFile * outFile = new LzmaSDKObjC::OutFile(); + if (!outFile) + { + this->setLastError(E_ABORT, __LINE__, __FILE__, "Can't create out file stream"); + return E_ABORT; + } - _outFileStreamRef = outFile; - CMyComPtr outStreamLoc = _outFileStreamRef; + if (!outFile->open([fullPath UTF8String])) + { + delete outFile; + this->setLastError(E_ABORT, __LINE__, __FILE__, "Can't open destination for write: [%s]", [fullPath UTF8String]); + return E_ABORT; + } - _outFileStream = outStreamLoc; - *outStream = outStreamLoc.Detach(); + _outFileStreamRef = outFile; + CMyComPtr outStreamLoc = _outFileStreamRef; + + _outFileStream = outStreamLoc; + *outStream = outStreamLoc.Detach(); + } return S_OK; } @@ -176,16 +196,6 @@ return E_ABORT; } - PROPVARIANT isDirProp; - HRESULT res = _archive->GetProperty(index, kpidIsDir, &isDirProp); - if (res != S_OK) - { - this->setLastError(res, __LINE__, __FILE__, "Can't get property of the item by index: %u", (unsigned int)index); - return res; - } - - if (isDirProp.vt != VT_BOOL || isDirProp.boolVal) return S_OK; - switch (_mode) { case NArchive::NExtract::NAskMode::kExtract: diff --git a/src/LzmaSDKObjCReader.h b/src/LzmaSDKObjCReader.h index 4a804fb..bdb6154 100644 --- a/src/LzmaSDKObjCReader.h +++ b/src/LzmaSDKObjCReader.h @@ -150,7 +150,7 @@ LZMASDKOBJC_EXTERN NSString * const _Nonnull kLzmaSDKObjCErrorDomain; */ - (BOOL) extract:(nullable NSArray *) items toPath:(nullable NSString *) path - withFullPaths:(BOOL) isFullPaths; + withFullPaths:(BOOL) isFullPaths; /** diff --git a/tests/ios/ios/ViewController.m b/tests/ios/ios/ViewController.m index 6af0dfd..5f55dfa 100644 --- a/tests/ios/ios/ViewController.m +++ b/tests/ios/ios/ViewController.m @@ -44,7 +44,7 @@ - (IBAction) on1:(id)sender NSString * archivePath = [@"/Volumes/Data/Documents/LzmaSDK-ObjC/tests/files/" stringByAppendingPathComponent:testFile]; -// archivePath = @"/Volumes/Data/1/example.7Z"; +// archivePath = @"/Volumes/Data/1/2.7z"; self.reader = [[LzmaSDKObjCReader alloc] initWithFileURL:[NSURL fileURLWithPath:archivePath]];