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 // Download utility implementation | 5 // Download utility implementation |
6 | 6 |
7 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 else | 483 else |
484 taskbar->SetProgressValue(frame, (int)(progress * 100), 100); | 484 taskbar->SetProgressValue(frame, (int)(progress * 100), 100); |
485 } | 485 } |
486 #endif | 486 #endif |
487 } | 487 } |
488 #endif | 488 #endif |
489 | 489 |
490 // Appends the passed the number between parenthesis the path before the | 490 // Appends the passed the number between parenthesis the path before the |
491 // extension. | 491 // extension. |
492 void AppendNumberToPath(FilePath* path, int number) { | 492 void AppendNumberToPath(FilePath* path, int number) { |
493 file_util::InsertBeforeExtension(path, | 493 *path = path->InsertBeforeExtensionASCII(StringPrintf(" (%d)", number)); |
494 StringPrintf(FILE_PATH_LITERAL(" (%d)"), number)); | |
495 } | 494 } |
496 | 495 |
497 // Attempts to find a number that can be appended to that path to make it | 496 // Attempts to find a number that can be appended to that path to make it |
498 // unique. If |path| does not exist, 0 is returned. If it fails to find such | 497 // unique. If |path| does not exist, 0 is returned. If it fails to find such |
499 // a number, -1 is returned. | 498 // a number, -1 is returned. |
500 int GetUniquePathNumber(const FilePath& path) { | 499 int GetUniquePathNumber(const FilePath& path) { |
501 const int kMaxAttempts = 100; | 500 const int kMaxAttempts = 100; |
502 | 501 |
503 if (!file_util::PathExists(path)) | 502 if (!file_util::PathExists(path)) |
504 return 0; | 503 return 0; |
505 | 504 |
506 FilePath new_path; | 505 FilePath new_path; |
507 for (int count = 1; count <= kMaxAttempts; ++count) { | 506 for (int count = 1; count <= kMaxAttempts; ++count) { |
508 new_path = FilePath(path); | 507 new_path = FilePath(path); |
509 AppendNumberToPath(&new_path, count); | 508 AppendNumberToPath(&new_path, count); |
510 | 509 |
511 if (!file_util::PathExists(new_path)) | 510 if (!file_util::PathExists(new_path)) |
512 return count; | 511 return count; |
513 } | 512 } |
514 | 513 |
515 return -1; | 514 return -1; |
516 } | 515 } |
517 | 516 |
518 } // namespace download_util | 517 } // namespace download_util |
OLD | NEW |