diff options
Diffstat (limited to 'src/common/file_util.cpp')
| -rw-r--r-- | src/common/file_util.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 16c3713e0..18fbfa25b 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -472,13 +472,14 @@ u64 ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry, | |||
| 472 | } | 472 | } |
| 473 | 473 | ||
| 474 | bool DeleteDirRecursively(const std::string& directory, unsigned int recursion) { | 474 | bool DeleteDirRecursively(const std::string& directory, unsigned int recursion) { |
| 475 | const auto callback = [recursion](u64* num_entries_out, const std::string& directory, | 475 | const auto callback = [recursion](u64*, const std::string& directory, |
| 476 | const std::string& virtual_name) -> bool { | 476 | const std::string& virtual_name) { |
| 477 | std::string new_path = directory + DIR_SEP_CHR + virtual_name; | 477 | const std::string new_path = directory + DIR_SEP_CHR + virtual_name; |
| 478 | 478 | ||
| 479 | if (IsDirectory(new_path)) { | 479 | if (IsDirectory(new_path)) { |
| 480 | if (recursion == 0) | 480 | if (recursion == 0) { |
| 481 | return false; | 481 | return false; |
| 482 | } | ||
| 482 | return DeleteDirRecursively(new_path, recursion - 1); | 483 | return DeleteDirRecursively(new_path, recursion - 1); |
| 483 | } | 484 | } |
| 484 | return Delete(new_path); | 485 | return Delete(new_path); |
| @@ -492,7 +493,8 @@ bool DeleteDirRecursively(const std::string& directory, unsigned int recursion) | |||
| 492 | return true; | 493 | return true; |
| 493 | } | 494 | } |
| 494 | 495 | ||
| 495 | void CopyDir(const std::string& source_path, const std::string& dest_path) { | 496 | void CopyDir([[maybe_unused]] const std::string& source_path, |
| 497 | [[maybe_unused]] const std::string& dest_path) { | ||
| 496 | #ifndef _WIN32 | 498 | #ifndef _WIN32 |
| 497 | if (source_path == dest_path) { | 499 | if (source_path == dest_path) { |
| 498 | return; | 500 | return; |
| @@ -553,7 +555,7 @@ std::optional<std::string> GetCurrentDir() { | |||
| 553 | std::string strDir = dir; | 555 | std::string strDir = dir; |
| 554 | #endif | 556 | #endif |
| 555 | free(dir); | 557 | free(dir); |
| 556 | return std::move(strDir); | 558 | return strDir; |
| 557 | } | 559 | } |
| 558 | 560 | ||
| 559 | bool SetCurrentDir(const std::string& directory) { | 561 | bool SetCurrentDir(const std::string& directory) { |
| @@ -772,21 +774,23 @@ std::size_t ReadFileToString(bool text_file, const std::string& filename, std::s | |||
| 772 | 774 | ||
| 773 | void SplitFilename83(const std::string& filename, std::array<char, 9>& short_name, | 775 | void SplitFilename83(const std::string& filename, std::array<char, 9>& short_name, |
| 774 | std::array<char, 4>& extension) { | 776 | std::array<char, 4>& extension) { |
| 775 | const std::string forbidden_characters = ".\"/\\[]:;=, "; | 777 | static constexpr std::string_view forbidden_characters = ".\"/\\[]:;=, "; |
| 776 | 778 | ||
| 777 | // On a FAT32 partition, 8.3 names are stored as a 11 bytes array, filled with spaces. | 779 | // On a FAT32 partition, 8.3 names are stored as a 11 bytes array, filled with spaces. |
| 778 | short_name = {{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\0'}}; | 780 | short_name = {{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\0'}}; |
| 779 | extension = {{' ', ' ', ' ', '\0'}}; | 781 | extension = {{' ', ' ', ' ', '\0'}}; |
| 780 | 782 | ||
| 781 | std::string::size_type point = filename.rfind('.'); | 783 | auto point = filename.rfind('.'); |
| 782 | if (point == filename.size() - 1) | 784 | if (point == filename.size() - 1) { |
| 783 | point = filename.rfind('.', point); | 785 | point = filename.rfind('.', point); |
| 786 | } | ||
| 784 | 787 | ||
| 785 | // Get short name. | 788 | // Get short name. |
| 786 | int j = 0; | 789 | int j = 0; |
| 787 | for (char letter : filename.substr(0, point)) { | 790 | for (char letter : filename.substr(0, point)) { |
| 788 | if (forbidden_characters.find(letter, 0) != std::string::npos) | 791 | if (forbidden_characters.find(letter, 0) != std::string::npos) { |
| 789 | continue; | 792 | continue; |
| 793 | } | ||
| 790 | if (j == 8) { | 794 | if (j == 8) { |
| 791 | // TODO(Link Mauve): also do that for filenames containing a space. | 795 | // TODO(Link Mauve): also do that for filenames containing a space. |
| 792 | // TODO(Link Mauve): handle multiple files having the same short name. | 796 | // TODO(Link Mauve): handle multiple files having the same short name. |
| @@ -794,14 +798,15 @@ void SplitFilename83(const std::string& filename, std::array<char, 9>& short_nam | |||
| 794 | short_name[7] = '1'; | 798 | short_name[7] = '1'; |
| 795 | break; | 799 | break; |
| 796 | } | 800 | } |
| 797 | short_name[j++] = toupper(letter); | 801 | short_name[j++] = static_cast<char>(std::toupper(letter)); |
| 798 | } | 802 | } |
| 799 | 803 | ||
| 800 | // Get extension. | 804 | // Get extension. |
| 801 | if (point != std::string::npos) { | 805 | if (point != std::string::npos) { |
| 802 | j = 0; | 806 | j = 0; |
| 803 | for (char letter : filename.substr(point + 1, 3)) | 807 | for (char letter : filename.substr(point + 1, 3)) { |
| 804 | extension[j++] = toupper(letter); | 808 | extension[j++] = static_cast<char>(std::toupper(letter)); |
| 809 | } | ||
| 805 | } | 810 | } |
| 806 | } | 811 | } |
| 807 | 812 | ||