summaryrefslogtreecommitdiff
path: root/src/common/file_util.cpp
diff options
context:
space:
mode:
authorGravatar Emmanuel Gil Peyrot2014-09-29 08:34:37 +0000
committerGravatar Emmanuel Gil Peyrot2014-10-06 19:58:43 +0200
commitfbd72fd6bf0f02a13be207c9d61f630c594e3156 (patch)
tree766620c93a936e767cc073382573660041c2e193 /src/common/file_util.cpp
parentFileSys: Add static asserts for the Directory struct, and fix its fields posi... (diff)
downloadyuzu-fbd72fd6bf0f02a13be207c9d61f630c594e3156.tar.gz
yuzu-fbd72fd6bf0f02a13be207c9d61f630c594e3156.tar.xz
yuzu-fbd72fd6bf0f02a13be207c9d61f630c594e3156.zip
Common: Add a helper function to generate a 8.3 filename from a long one.
Core: Fix the SDMC Directory implementation to make blargSnes work.
Diffstat (limited to 'src/common/file_util.cpp')
-rw-r--r--src/common/file_util.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 9292a1cd6..5fd155222 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -780,6 +780,48 @@ size_t ReadFileToString(bool text_file, const char *filename, std::string &str)
780 return file.ReadArray(&str[0], str.size()); 780 return file.ReadArray(&str[0], str.size());
781} 781}
782 782
783/**
784 * Splits the filename into 8.3 format
785 * Loosely implemented following https://en.wikipedia.org/wiki/8.3_filename
786 * @param filename The normal filename to use
787 * @param short_name A 9-char array in which the short name will be written
788 * @param extension A 4-char array in which the extension will be written
789 */
790void SplitFilename83(const std::string& filename, std::array<char, 9>& short_name,
791 std::array<char, 4>& extension) {
792 const std::string forbidden_characters = ".\"/\\[]:;=, ";
793
794 // On a FAT32 partition, 8.3 names are stored as a 11 bytes array, filled with spaces.
795 short_name = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\0'};
796 extension = {' ', ' ', ' ', '\0'};
797
798 std::string::size_type point = filename.rfind('.');
799 if (point == filename.size() - 1)
800 point = filename.rfind('.', point);
801
802 // Get short name.
803 int j = 0;
804 for (char letter : filename.substr(0, point)) {
805 if (forbidden_characters.find(letter, 0) != std::string::npos)
806 continue;
807 if (j == 8) {
808 // TODO(Link Mauve): also do that for filenames containing a space.
809 // TODO(Link Mauve): handle multiple files having the same short name.
810 short_name[6] = '~';
811 short_name[7] = '1';
812 break;
813 }
814 short_name[j++] = toupper(letter);
815 }
816
817 // Get extension.
818 if (point != std::string::npos) {
819 j = 0;
820 for (char letter : filename.substr(point + 1, 3))
821 extension[j++] = toupper(letter);
822 }
823}
824
783IOFile::IOFile() 825IOFile::IOFile()
784 : m_file(NULL), m_good(true) 826 : m_file(NULL), m_good(true)
785{} 827{}