From d3e9569cf0d74fe70a2ce04fc448d5d8d7cfe938 Mon Sep 17 00:00:00 2001 From: Dwayne Slater Date: Sat, 15 Apr 2017 13:53:53 -0400 Subject: [PATCH] VolumeDirectory: Compare case-insensitive file names as uppercase, not lowercase Fixes file ordering in games that use ASCII characters between lowercase 'z' and uppercase 'A' (underscores). MySims Kingdom has the files "terrainLightMapTinted.shader", "terrainLightMapTintedGrid.shader", and "terrainLightMapTinted_no_shadow.shader". In lowercase, "terrainLightMapTinted_no_shadow.shader" comes before "terrainLightMapTinted.shader" and "terrainLightMapTintedGrid.shader", which is invalid. --- Source/Core/DiscIO/VolumeDirectory.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/DiscIO/VolumeDirectory.cpp b/Source/Core/DiscIO/VolumeDirectory.cpp index 7f552e4195..b2ffe7f98d 100644 --- a/Source/Core/DiscIO/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/VolumeDirectory.cpp @@ -25,7 +25,7 @@ namespace DiscIO { static u32 ComputeNameSize(const File::FSTEntry& parent_entry); -static std::string ASCIIToLowercase(std::string str); +static std::string ASCIIToUppercase(std::string str); const size_t CVolumeDirectory::MAX_NAME_LENGTH; const size_t CVolumeDirectory::MAX_ID_LENGTH; @@ -455,9 +455,9 @@ void CVolumeDirectory::WriteDirectory(const File::FSTEntry& parent_entry, u32* f // Sort for determinism std::sort(sorted_entries.begin(), sorted_entries.end(), [](const File::FSTEntry& one, const File::FSTEntry& two) { - const std::string one_lower = ASCIIToLowercase(one.virtualName); - const std::string two_lower = ASCIIToLowercase(two.virtualName); - return one_lower == two_lower ? one.virtualName < two.virtualName : one_lower < two_lower; + const std::string one_upper = ASCIIToUppercase(one.virtualName); + const std::string two_upper = ASCIIToUppercase(two.virtualName); + return one_upper == two_upper ? one.virtualName < two.virtualName : one_upper < two_upper; }); for (const File::FSTEntry& entry : sorted_entries) @@ -500,10 +500,10 @@ static u32 ComputeNameSize(const File::FSTEntry& parent_entry) return name_size; } -static std::string ASCIIToLowercase(std::string str) +static std::string ASCIIToUppercase(std::string str) { std::transform(str.begin(), str.end(), str.begin(), - [](char c) { return std::tolower(c, std::locale::classic()); }); + [](char c) { return std::toupper(c, std::locale::classic()); }); return str; }