OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/installer/util/lzma_util.h" | 5 #include "chrome/installer/util/lzma_util.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 | 10 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 size_t outSizeProcessed; | 151 size_t outSizeProcessed; |
152 CFileItem *f = db.Database.Files + i; | 152 CFileItem *f = db.Database.Files + i; |
153 | 153 |
154 if ((ret = SzExtract(&archiveStream.InStream, &db, i, &blockIndex, | 154 if ((ret = SzExtract(&archiveStream.InStream, &db, i, &blockIndex, |
155 &outBuffer, &outBufferSize, &offset, &outSizeProcessed, | 155 &outBuffer, &outBufferSize, &offset, &outSizeProcessed, |
156 &allocImp, &allocTempImp)) != SZ_OK) { | 156 &allocImp, &allocTempImp)) != SZ_OK) { |
157 LOG(ERROR) << L"Error returned by SzExtract: " << ret; | 157 LOG(ERROR) << L"Error returned by SzExtract: " << ret; |
158 break; | 158 break; |
159 } | 159 } |
160 | 160 |
161 // Append location to the file path in archive, to get full path. | 161 FilePath file_path = FilePath(location).Append(UTF8ToWide(f->Name)); |
162 std::wstring wfileName(location); | |
163 file_util::AppendToPath(&wfileName, UTF8ToWide(f->Name)); | |
164 if (output_file) | 162 if (output_file) |
165 *output_file = wfileName; | 163 *output_file = file_path.value(); |
166 | 164 |
167 // If archive entry is directory create it and move on to the next entry. | 165 // If archive entry is directory create it and move on to the next entry. |
168 if (f->IsDirectory) { | 166 if (f->IsDirectory) { |
169 file_util::CreateDirectory(FilePath(wfileName)); | 167 file_util::CreateDirectory(file_path); |
170 continue; | 168 continue; |
171 } | 169 } |
172 | 170 |
| 171 file_util::CreateDirectory(file_path.DirName()); |
| 172 |
173 HANDLE hFile; | 173 HANDLE hFile; |
174 std::wstring directory = file_util::GetDirectoryFromPath(wfileName); | 174 hFile = CreateFile(file_path.value().c_str(), GENERIC_WRITE, 0, NULL, |
175 file_util::CreateDirectory(FilePath(directory)); | |
176 | |
177 hFile = CreateFile(wfileName.c_str(), GENERIC_WRITE, 0, NULL, | |
178 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | 175 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
179 if (hFile == INVALID_HANDLE_VALUE) { | 176 if (hFile == INVALID_HANDLE_VALUE) { |
180 ret = GetLastError(); | 177 ret = GetLastError(); |
181 LOG(ERROR) << L"Error returned by CreateFile: " << ret; | 178 LOG(ERROR) << L"Error returned by CreateFile: " << ret; |
182 break; | 179 break; |
183 } | 180 } |
184 | 181 |
185 if ((!WriteFile(hFile, outBuffer + offset, (DWORD) outSizeProcessed, | 182 if ((!WriteFile(hFile, outBuffer + offset, (DWORD) outSizeProcessed, |
186 &written, NULL)) || | 183 &written, NULL)) || |
187 (written != outSizeProcessed)) { | 184 (written != outSizeProcessed)) { |
(...skipping 23 matching lines...) Expand all Loading... |
211 SzArDbExFree(&db, allocImp.Free); | 208 SzArDbExFree(&db, allocImp.Free); |
212 return ret; | 209 return ret; |
213 } | 210 } |
214 | 211 |
215 void LzmaUtil::CloseArchive() { | 212 void LzmaUtil::CloseArchive() { |
216 if (archive_handle_) { | 213 if (archive_handle_) { |
217 CloseHandle(archive_handle_); | 214 CloseHandle(archive_handle_); |
218 archive_handle_ = NULL; | 215 archive_handle_ = NULL; |
219 } | 216 } |
220 } | 217 } |
OLD | NEW |