OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #include <time.h> | 10 #include <time.h> |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 wchar_t temp_path[MAX_PATH + 1]; | 369 wchar_t temp_path[MAX_PATH + 1]; |
370 DWORD path_len = ::GetTempPath(MAX_PATH, temp_path); | 370 DWORD path_len = ::GetTempPath(MAX_PATH, temp_path); |
371 if (path_len >= MAX_PATH || path_len <= 0) | 371 if (path_len >= MAX_PATH || path_len <= 0) |
372 return false; | 372 return false; |
373 path->assign(temp_path); | 373 path->assign(temp_path); |
374 TrimTrailingSeparator(path); | 374 TrimTrailingSeparator(path); |
375 return true; | 375 return true; |
376 } | 376 } |
377 | 377 |
378 bool CreateTemporaryFileName(std::wstring* temp_file) { | 378 bool CreateTemporaryFileName(std::wstring* temp_file) { |
379 wchar_t temp_name[MAX_PATH + 1]; | |
380 std::wstring temp_path; | 379 std::wstring temp_path; |
381 | 380 |
382 if (!GetTempDir(&temp_path)) | 381 if (!GetTempDir(&temp_path)) |
383 return false; | 382 return false; |
384 | 383 |
385 if (!GetTempFileName(temp_path.c_str(), L"", 0, temp_name)) | 384 return CreateTemporaryFileNameInDir(temp_path, temp_file); |
| 385 } |
| 386 |
| 387 bool CreateTemporaryFileNameInDir(const std::wstring& dir, |
| 388 std::wstring* temp_file) { |
| 389 wchar_t temp_name[MAX_PATH + 1]; |
| 390 |
| 391 if (!GetTempFileName(dir.c_str(), L"", 0, temp_name)) |
386 return false; // fail! | 392 return false; // fail! |
387 | 393 |
388 DWORD path_len = GetLongPathName(temp_name, temp_name, MAX_PATH); | 394 DWORD path_len = GetLongPathName(temp_name, temp_name, MAX_PATH); |
389 if (path_len > MAX_PATH + 1 || path_len == 0) | 395 if (path_len > MAX_PATH + 1 || path_len == 0) |
390 return false; // fail! | 396 return false; // fail! |
391 | 397 |
392 temp_file->assign(temp_name, path_len); | 398 temp_file->assign(temp_name, path_len); |
393 return true; | 399 return true; |
394 } | 400 } |
395 | 401 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); | 662 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); |
657 } | 663 } |
658 | 664 |
659 if ((file_type_ & FileEnumerator::DIRECTORIES) == 0) | 665 if ((file_type_ & FileEnumerator::DIRECTORIES) == 0) |
660 return Next(); | 666 return Next(); |
661 } | 667 } |
662 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); | 668 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); |
663 } | 669 } |
664 | 670 |
665 } // namespace file_util | 671 } // namespace file_util |
OLD | NEW |