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.
This commit is contained in:
Dwayne Slater 2017-04-15 13:53:53 -04:00
parent 7908302782
commit d3e9569cf0
1 changed files with 6 additions and 6 deletions

View File

@ -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;
}