OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/common/zip.h" | 5 #include "chrome/common/zip.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "net/base/file_stream.h" | 9 #include "net/base/file_stream.h" |
10 #include "third_party/zlib/contrib/minizip/unzip.h" | 10 #include "third_party/zlib/contrib/minizip/unzip.h" |
11 #include "third_party/zlib/contrib/minizip/zip.h" | 11 #include "third_party/zlib/contrib/minizip/zip.h" |
12 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
13 #include "third_party/zlib/contrib/minizip/iowin32.h" | 13 #include "third_party/zlib/contrib/minizip/iowin32.h" |
14 #endif | 14 #endif |
15 | 15 |
16 static const int kZipMaxPath = 256; | 16 static const int kZipMaxPath = 256; |
17 static const int kZipBufSize = 8192; | 17 static const int kZipBufSize = 8192; |
18 | 18 |
19 // Extract the 'current' selected file from the zip into dest_dir. | 19 // Extract the 'current' selected file from the zip into dest_dir. |
20 // Output filename is stored in out_file. Returns true on success. | 20 // Output filename is stored in out_file. Returns true on success. |
21 static bool ExtractCurrentFile(unzFile zip_file, | 21 static bool ExtractCurrentFile(unzFile zip_file, |
22 const FilePath& dest_dir) { | 22 const FilePath& dest_dir) { |
23 char filename_inzip[kZipMaxPath] = {0}; | 23 char filename_inzip[kZipMaxPath] = {0}; |
24 unz_file_info file_info; | 24 unz_file_info file_info; |
25 int err = unzGetCurrentFileInfo(zip_file, &file_info, filename_inzip, | 25 int err = unzGetCurrentFileInfo(zip_file, &file_info, filename_inzip, |
26 sizeof(filename_inzip), NULL, 0, NULL, 0); | 26 sizeof(filename_inzip) - 1, NULL, 0, NULL, 0); |
27 if (err != UNZ_OK) | 27 if (err != UNZ_OK) |
28 return false; | 28 return false; |
29 if (filename_inzip[0] == '\0') | 29 if (filename_inzip[0] == '\0') |
30 return false; | 30 return false; |
31 | 31 |
32 err = unzOpenCurrentFile(zip_file); | 32 err = unzOpenCurrentFile(zip_file); |
33 if (err != UNZ_OK) | 33 if (err != UNZ_OK) |
34 return false; | 34 return false; |
35 | 35 |
36 FilePath::StringType filename; | 36 FilePath::StringType filename; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 if (ZIP_OK != zipClose(zip_file, NULL)) { // global comment | 295 if (ZIP_OK != zipClose(zip_file, NULL)) { // global comment |
296 LOG(ERROR) << "Error closing zip file " << dest_file_str; | 296 LOG(ERROR) << "Error closing zip file " << dest_file_str; |
297 return false; | 297 return false; |
298 } | 298 } |
299 | 299 |
300 return success; | 300 return success; |
301 } | 301 } |
OLD | NEW |