Skip to content

Commit

Permalink
Revert 132887 - Update lzma_sdk to 9.20
Browse files Browse the repository at this point in the history
Copied only C code required to open 7z archive files and
uncompress LZMA compression.
Updated chrome/installer/util/lzma_util.cc to follow API
changes.

BUG=None
TEST=installer_util_unittests --gtest_filter='LzmaUtilTest.*'

Review URL: http://codereview.chromium.org/10114005

TBR=bashi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10035048

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132895 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
bashi@chromium.org committed Apr 18, 2012
1 parent 2398108 commit 50cf47f
Show file tree
Hide file tree
Showing 58 changed files with 3,333 additions and 8,905 deletions.
129 changes: 54 additions & 75 deletions chrome/installer/util/lzma_util.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -9,68 +9,63 @@
#include "base/utf_string_conversions.h"

extern "C" {
#include "third_party/lzma_sdk/7z.h"
#include "third_party/lzma_sdk/7zAlloc.h"
#include "third_party/lzma_sdk/Archive/7z/7zExtract.h"
#include "third_party/lzma_sdk/Archive/7z/7zIn.h"
#include "third_party/lzma_sdk/7zCrc.h"
#include "third_party/lzma_sdk/7zFile.h"
}


namespace {

SRes LzmaReadFile(HANDLE file, void *data, size_t *size) {
if (*size == 0)
return SZ_OK;
typedef struct _CFileInStream {
ISzInStream InStream;
HANDLE File;
} CFileInStream;


size_t LzmaReadFile(HANDLE file, void *data, size_t size) {
if (size == 0)
return 0;

size_t processedSize = 0;
DWORD maxSize = *size;
do {
DWORD processedLoc = 0;
BOOL res = ReadFile(file, data, maxSize, &processedLoc, NULL);
BOOL res = ReadFile(file, data, (DWORD) size, &processedLoc, NULL);
data = (void *)((unsigned char *) data + processedLoc);
maxSize -= processedLoc;
size -= processedLoc;
processedSize += processedLoc;
if (processedLoc == 0) {
if (res)
return SZ_ERROR_READ;
else
break;
}
} while (maxSize > 0);
if (!res || processedLoc == 0)
break;
} while (size > 0);

*size = processedSize;
return SZ_OK;
return processedSize;
}

SRes SzFileSeekImp(void *object, Int64 *pos, ESzSeek origin) {
SZ_RESULT SzFileSeekImp(void *object, CFileSize pos) {
CFileInStream *s = (CFileInStream *) object;
LARGE_INTEGER value;
value.LowPart = (DWORD) *pos;
value.HighPart = (LONG) ((UInt64) *pos >> 32);
DWORD moveMethod;
switch (origin) {
case SZ_SEEK_SET:
moveMethod = FILE_BEGIN;
break;
case SZ_SEEK_CUR:
moveMethod = FILE_CURRENT;
break;
case SZ_SEEK_END:
moveMethod = FILE_END;
break;
default:
return SZ_ERROR_PARAM;
}
value.LowPart = SetFilePointer(s->file.handle, value.LowPart, &value.HighPart,
moveMethod);
*pos = ((Int64)value.HighPart << 32) | value.LowPart;
value.LowPart = (DWORD) pos;
value.HighPart = (LONG) ((UInt64) pos >> 32);
value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart,
FILE_BEGIN);
return ((value.LowPart == 0xFFFFFFFF) && (GetLastError() != NO_ERROR)) ?
SZ_ERROR_FAIL : SZ_OK;
SZE_FAIL : SZ_OK;
}

SRes SzFileReadImp(void *object, void *buffer, size_t *size) {
SZ_RESULT SzFileReadImp(void *object, void **buffer,
size_t maxRequiredSize, size_t *processedSize) {
const int kBufferSize = 1 << 12;
static Byte g_Buffer[kBufferSize];
if (maxRequiredSize > kBufferSize)
maxRequiredSize = kBufferSize;

CFileInStream *s = (CFileInStream *) object;
return LzmaReadFile(s->file.handle, buffer, size);
size_t processedSizeLoc;
processedSizeLoc = LzmaReadFile(s->File, g_Buffer, maxRequiredSize);
*buffer = g_Buffer;
if (processedSize != 0)
*processedSize = processedSizeLoc;
return SZ_OK;
}

} // namespace
Expand Down Expand Up @@ -127,66 +122,50 @@ DWORD LzmaUtil::UnPack(const std::wstring& location,
return ERROR_INVALID_HANDLE;

CFileInStream archiveStream;
CLookToRead lookStream;
CSzArEx db;
ISzAlloc allocImp;
ISzAlloc allocTempImp;
CArchiveDatabaseEx db;
DWORD ret = NO_ERROR;

archiveStream.file.handle = archive_handle_;
archiveStream.s.Read = SzFileReadImp;
archiveStream.s.Seek = SzFileSeekImp;
LookToRead_CreateVTable(&lookStream, false);
lookStream.realStream = &archiveStream.s;

archiveStream.File = archive_handle_;
archiveStream.InStream.Read = SzFileReadImp;
archiveStream.InStream.Seek = SzFileSeekImp;
allocImp.Alloc = SzAlloc;
allocImp.Free = SzFree;
allocTempImp.Alloc = SzAllocTemp;
allocTempImp.Free = SzFreeTemp;

CrcGenerateTable();
SzArEx_Init(&db);
if ((ret = SzArEx_Open(&db, &lookStream.s,
&allocImp, &allocTempImp)) != SZ_OK) {
SzArDbExInit(&db);
if ((ret = SzArchiveOpen(&archiveStream.InStream, &db,
&allocImp, &allocTempImp)) != SZ_OK) {
LOG(ERROR) << L"Error returned by SzArchiveOpen: " << ret;
return ERROR_INVALID_HANDLE;
return ret;
}

Byte *outBuffer = 0; // it must be 0 before first call for each new archive
UInt32 blockIndex = 0xFFFFFFFF; // can have any value if outBuffer = 0
size_t outBufferSize = 0; // can have any value if outBuffer = 0

for (unsigned int i = 0; i < db.db.NumFiles; i++) {
for (unsigned int i = 0; i < db.Database.NumFiles; i++) {
DWORD written;
size_t offset;
size_t outSizeProcessed;
CSzFileItem *f = db.db.Files + i;
CFileItem *f = db.Database.Files + i;

if ((ret = SzArEx_Extract(&db, &lookStream.s, i, &blockIndex,
if ((ret = SzExtract(&archiveStream.InStream, &db, i, &blockIndex,
&outBuffer, &outBufferSize, &offset, &outSizeProcessed,
&allocImp, &allocTempImp)) != SZ_OK) {
LOG(ERROR) << L"Error returned by SzExtract: " << ret;
ret = ERROR_INVALID_HANDLE;
break;
}

size_t file_name_length = SzArEx_GetFileNameUtf16(&db, i, NULL);
if (file_name_length < 1) {
LOG(ERROR) << L"Couldn't get file name";
ret = ERROR_INVALID_HANDLE;
break;
}
std::vector<UInt16> file_name(file_name_length);
SzArEx_GetFileNameUtf16(&db, i, &file_name[0]);
// |file_name| is NULL-terminated.
FilePath file_path = FilePath(location).Append(
FilePath::StringType(file_name.begin(), file_name.end() - 1));

FilePath file_path = FilePath(location).Append(UTF8ToWide(f->Name));
if (output_file)
*output_file = file_path.value();

// If archive entry is directory create it and move on to the next entry.
if (f->IsDir) {
if (f->IsDirectory) {
CreateDirectory(file_path);
continue;
}
Expand All @@ -211,9 +190,9 @@ DWORD LzmaUtil::UnPack(const std::wstring& location,
break;
}

if (f->MTimeDefined) {
if (f->IsLastWriteTimeDefined) {
if (!SetFileTime(hFile, NULL, NULL,
(const FILETIME *)&(f->MTime))) {
(const FILETIME *)&(f->LastWriteTime))) {
ret = GetLastError();
CloseHandle(hFile);
LOG(ERROR) << L"Error returned by SetFileTime: " << ret;
Expand All @@ -227,8 +206,8 @@ DWORD LzmaUtil::UnPack(const std::wstring& location,
}
} // for loop

IAlloc_Free(&allocImp, outBuffer);
SzArEx_Free(&db, &allocImp);
allocImp.Free(outBuffer);
SzArDbExFree(&db, allocImp.Free);
return ret;
}

Expand Down
Loading

0 comments on commit 50cf47f

Please sign in to comment.