OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "third_party/zlib/google/zip_reader.h" | 5 #include "third_party/zlib/google/zip_reader.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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // Then Open the entry. | 185 // Then Open the entry. |
186 return OpenCurrentEntryInZip(); | 186 return OpenCurrentEntryInZip(); |
187 } | 187 } |
188 | 188 |
189 bool ZipReader::ExtractCurrentEntryToFilePath( | 189 bool ZipReader::ExtractCurrentEntryToFilePath( |
190 const base::FilePath& output_file_path) { | 190 const base::FilePath& output_file_path) { |
191 DCHECK(zip_file_); | 191 DCHECK(zip_file_); |
192 | 192 |
193 // If this is a directory, just create it and return. | 193 // If this is a directory, just create it and return. |
194 if (current_entry_info()->is_directory()) | 194 if (current_entry_info()->is_directory()) |
195 return file_util::CreateDirectory(output_file_path); | 195 return base::CreateDirectory(output_file_path); |
196 | 196 |
197 const int open_result = unzOpenCurrentFile(zip_file_); | 197 const int open_result = unzOpenCurrentFile(zip_file_); |
198 if (open_result != UNZ_OK) | 198 if (open_result != UNZ_OK) |
199 return false; | 199 return false; |
200 | 200 |
201 // We can't rely on parent directory entries being specified in the | 201 // We can't rely on parent directory entries being specified in the |
202 // zip, so we make sure they are created. | 202 // zip, so we make sure they are created. |
203 base::FilePath output_dir_path = output_file_path.DirName(); | 203 base::FilePath output_dir_path = output_file_path.DirName(); |
204 if (!file_util::CreateDirectory(output_dir_path)) | 204 if (!base::CreateDirectory(output_dir_path)) |
205 return false; | 205 return false; |
206 | 206 |
207 net::FileStream stream(NULL); | 207 net::FileStream stream(NULL); |
208 const int flags = (base::PLATFORM_FILE_CREATE_ALWAYS | | 208 const int flags = (base::PLATFORM_FILE_CREATE_ALWAYS | |
209 base::PLATFORM_FILE_WRITE); | 209 base::PLATFORM_FILE_WRITE); |
210 if (stream.OpenSync(output_file_path, flags) != 0) | 210 if (stream.OpenSync(output_file_path, flags) != 0) |
211 return false; | 211 return false; |
212 | 212 |
213 bool success = true; // This becomes false when something bad happens. | 213 bool success = true; // This becomes false when something bad happens. |
214 while (true) { | 214 while (true) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 } | 301 } |
302 | 302 |
303 void ZipReader::Reset() { | 303 void ZipReader::Reset() { |
304 zip_file_ = NULL; | 304 zip_file_ = NULL; |
305 num_entries_ = 0; | 305 num_entries_ = 0; |
306 reached_end_ = false; | 306 reached_end_ = false; |
307 current_entry_info_.reset(); | 307 current_entry_info_.reset(); |
308 } | 308 } |
309 | 309 |
310 } // namespace zip | 310 } // namespace zip |
OLD | NEW |