Io: Apply VFAT hack only to dirs <= 8 chars long.

Fixes Mega Drops 2, which relies on the lowercase name at about 10
characters.
This commit is contained in:
Unknown W. Brackets 2020-03-21 22:49:00 -07:00
parent 0d2acb6d73
commit 08b6275bc7

View file

@ -795,10 +795,17 @@ static std::string SimulateVFATBug(std::string filename) {
// These are the characters allowed in DOS filenames.
static const char *FAT_UPPER_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&'(){}-_`~";
static const char *FAT_LOWER_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&'(){}-_`~";
static const char *LOWER_CHARS = "abcdefghijklmnopqrstuvwxyz";
// To avoid logging/comparing, skip all this if it has no lowercase chars to begin with.
size_t lowerchar = filename.find_first_of(LOWER_CHARS);
if (lowerchar == filename.npos) {
return filename;
}
bool apply_hack = false;
size_t dot_pos = filename.find('.');
if (dot_pos == filename.npos) {
if (dot_pos == filename.npos && filename.length() <= 8) {
size_t badchar = filename.find_first_not_of(FAT_LOWER_CHARS);
if (badchar == filename.npos) {
// It's all lowercase. Convert to upper.
@ -825,6 +832,7 @@ static std::string SimulateVFATBug(std::string filename) {
}
if (apply_hack) {
VERBOSE_LOG(FILESYS, "Applying VFAT hack to filename: %s", filename.c_str());
// In this situation, NT would write UPPERCASE, and just set a flag to say "actually lowercase".
// That VFAT flag isn't read by the PSP firmware, so let's pretend to "not read it."
std::transform(filename.begin(), filename.end(), filename.begin(), toupper);