| Index: chrome/installer/util/lzma_util.cc
|
| ===================================================================
|
| --- chrome/installer/util/lzma_util.cc (revision 79843)
|
| +++ chrome/installer/util/lzma_util.cc (working copy)
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2011 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.
|
|
|
| @@ -9,67 +9,14 @@
|
| #include "base/utf_string_conversions.h"
|
|
|
| extern "C" {
|
| -#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/C/7z.h"
|
| +#include "third_party/lzma_sdk/C/7zAlloc.h"
|
| +#include "third_party/lzma_sdk/C/7zCrc.h"
|
| +#include "third_party/lzma_sdk/C/7zFile.h"
|
| +#include "third_party/lzma_sdk/C/7zVersion.h"
|
| }
|
|
|
|
|
| -namespace {
|
| -
|
| -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;
|
| - do {
|
| - DWORD processedLoc = 0;
|
| - BOOL res = ReadFile(file, data, (DWORD) size, &processedLoc, NULL);
|
| - data = (void *)((unsigned char *) data + processedLoc);
|
| - size -= processedLoc;
|
| - processedSize += processedLoc;
|
| - if (!res || processedLoc == 0)
|
| - break;
|
| - } while (size > 0);
|
| -
|
| - return processedSize;
|
| -}
|
| -
|
| -SZ_RESULT SzFileSeekImp(void *object, CFileSize pos) {
|
| - CFileInStream *s = (CFileInStream *) object;
|
| - LARGE_INTEGER value;
|
| - 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)) ?
|
| - SZE_FAIL : SZ_OK;
|
| -}
|
| -
|
| -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;
|
| - size_t processedSizeLoc;
|
| - processedSizeLoc = LzmaReadFile(s->File, g_Buffer, maxRequiredSize);
|
| - *buffer = g_Buffer;
|
| - if (processedSize != 0)
|
| - *processedSize = processedSizeLoc;
|
| - return SZ_OK;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| // static
|
| int32 LzmaUtil::UnPackArchive(const std::wstring& archive,
|
| const std::wstring& output_dir,
|
| @@ -121,51 +68,73 @@
|
| if (!archive_handle_)
|
| return ERROR_INVALID_HANDLE;
|
|
|
| - CFileInStream archiveStream;
|
| - ISzAlloc allocImp;
|
| - ISzAlloc allocTempImp;
|
| - CArchiveDatabaseEx db;
|
| + CFileInStream archive_stream;
|
| + CLookToRead look_stream;
|
| + ISzAlloc alloc_imp;
|
| + ISzAlloc alloc_temp_imp;
|
| + CSzArEx db;
|
| DWORD ret = NO_ERROR;
|
|
|
| - archiveStream.File = archive_handle_;
|
| - archiveStream.InStream.Read = SzFileReadImp;
|
| - archiveStream.InStream.Seek = SzFileSeekImp;
|
| - allocImp.Alloc = SzAlloc;
|
| - allocImp.Free = SzFree;
|
| - allocTempImp.Alloc = SzAllocTemp;
|
| - allocTempImp.Free = SzFreeTemp;
|
| + FileInStream_CreateVTable(&archive_stream);
|
| + archive_stream.file.handle = archive_handle_;
|
| + LookToRead_CreateVTable(&look_stream, False);
|
| + look_stream.realStream = &archive_stream.s;
|
| + LookToRead_Init(&look_stream);
|
|
|
| + alloc_imp.Alloc = SzAlloc;
|
| + alloc_imp.Free = SzFree;
|
| + alloc_temp_imp.Alloc = SzAllocTemp;
|
| + alloc_temp_imp.Free = SzFreeTemp;
|
| +
|
| CrcGenerateTable();
|
| - SzArDbExInit(&db);
|
| - if ((ret = SzArchiveOpen(&archiveStream.InStream, &db,
|
| - &allocImp, &allocTempImp)) != SZ_OK) {
|
| - LOG(ERROR) << L"Error returned by SzArchiveOpen: " << ret;
|
| - return ret;
|
| + SzArEx_Init(&db);
|
| + if ((ret = SzArEx_Open(&db, &look_stream.s,
|
| + &alloc_imp, &alloc_temp_imp)) != SZ_OK) {
|
| + LOG(ERROR) << L"Error returned by SzArEx_Open: " << ret;
|
| + return ERROR_INVALID_HANDLE;
|
| }
|
|
|
| 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.Database.NumFiles; i++) {
|
| + for (unsigned int i = 0; i < db.db.NumFiles; i++) {
|
| DWORD written;
|
| size_t offset;
|
| size_t outSizeProcessed;
|
| - CFileItem *f = db.Database.Files + i;
|
| + CSzFileItem* f = db.db.Files + i;
|
|
|
| - if ((ret = SzExtract(&archiveStream.InStream, &db, i, &blockIndex,
|
| - &outBuffer, &outBufferSize, &offset, &outSizeProcessed,
|
| - &allocImp, &allocTempImp)) != SZ_OK) {
|
| - LOG(ERROR) << L"Error returned by SzExtract: " << ret;
|
| + if ((ret = SzArEx_Extract(&db, &look_stream.s, i, &blockIndex,
|
| + &outBuffer, &outBufferSize, &offset,
|
| + &outSizeProcessed, &alloc_imp,
|
| + &alloc_temp_imp)) != SZ_OK) {
|
| + LOG(ERROR) << L"Error returned by SzArEx_Extract: " << ret;
|
| break;
|
| }
|
|
|
| - FilePath file_path = FilePath(location).Append(UTF8ToWide(f->Name));
|
| + UInt16* name = NULL;
|
| + size_t len = SzArEx_GetFileNameUtf16(&db, i, NULL);
|
| + name = reinterpret_cast<UInt16*>(SzAlloc(NULL, len * sizeof(UInt16)));
|
| + if (!name) {
|
| + ret = GetLastError();
|
| + LOG(ERROR) << L"Can't allocate memory for filename string.";
|
| + break;
|
| + }
|
| + SzArEx_GetFileNameUtf16(&db, i, name);
|
| + std::wstring wname;
|
| + if (!UTF16ToWide(reinterpret_cast<char16*>(name), len - 1, &wname)) {
|
| + ret = GetLastError();
|
| + LOG(ERROR) << L"Can't convert filename string.";
|
| + break;
|
| + }
|
| + SzFree(NULL, name);
|
| +
|
| + FilePath file_path = FilePath(location).Append(wname);
|
| if (output_file)
|
| *output_file = file_path.value();
|
|
|
| // If archive entry is directory create it and move on to the next entry.
|
| - if (f->IsDirectory) {
|
| + if (f->IsDir) {
|
| CreateDirectory(file_path);
|
| continue;
|
| }
|
| @@ -190,9 +159,9 @@
|
| break;
|
| }
|
|
|
| - if (f->IsLastWriteTimeDefined) {
|
| + if (f->MTimeDefined) {
|
| if (!SetFileTime(hFile, NULL, NULL,
|
| - (const FILETIME *)&(f->LastWriteTime))) {
|
| + reinterpret_cast<FILETIME*>(&(f->MTime)))) {
|
| ret = GetLastError();
|
| CloseHandle(hFile);
|
| LOG(ERROR) << L"Error returned by SetFileTime: " << ret;
|
| @@ -206,8 +175,7 @@
|
| }
|
| } // for loop
|
|
|
| - allocImp.Free(outBuffer);
|
| - SzArDbExFree(&db, allocImp.Free);
|
| + SzArEx_Free(&db, &alloc_imp);
|
| return ret;
|
| }
|
|
|
|
|