mirror of
				https://git.zaroz.cloud/nintendo-back-up/yuzu/yuzu.git
				synced 2025-05-12 00:45:25 +00:00 
			
		
		
		
	loader.cpp: improved file extension checking, made Upper/LowerStr useful
Instead of forcibly taking the last 4 characters, it now finds the last extension separator (the period) and takes a substr of its location.
This commit is contained in:
		
							parent
							
								
									335082e74e
								
							
						
					
					
						commit
						4ed24a0619
					
				@ -18,19 +18,15 @@
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Make a string lowercase
 | 
					/// Make a string lowercase
 | 
				
			||||||
void LowerStr(char* str) {
 | 
					std::string LowerStr(std::string str) {
 | 
				
			||||||
    for (int i = 0; str[i]; i++) {
 | 
					    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
 | 
				
			||||||
        str[i] = tolower(str[ i ]);
 | 
					    return str;
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Make a string uppercase
 | 
					/// Make a string uppercase
 | 
				
			||||||
void UpperStr(char* str) {
 | 
					std::string UpperStr(std::string str) {
 | 
				
			||||||
    for (int i=0; i < strlen(str); i++) {
 | 
					    std::transform(str.begin(), str.end(), str.begin(), ::toupper);
 | 
				
			||||||
        if(str[i] >= 'a' && str[i] <= 'z') {
 | 
					    return str;
 | 
				
			||||||
            str[i] &= 0xDF;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// faster than sscanf
 | 
					// faster than sscanf
 | 
				
			||||||
 | 
				
			|||||||
@ -13,10 +13,11 @@
 | 
				
			|||||||
#include "common/common.h"
 | 
					#include "common/common.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Make a string lowercase
 | 
					/// Make a string lowercase
 | 
				
			||||||
void LowerStr(char* str);
 | 
					
 | 
				
			||||||
 | 
					std::string LowerStr(std::string str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Make a string uppercase
 | 
					/// Make a string uppercase
 | 
				
			||||||
void UpperStr(char* str);
 | 
					std::string UpperStr(std::string str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::string StringFromFormat(const char* format, ...);
 | 
					std::string StringFromFormat(const char* format, ...);
 | 
				
			||||||
// Cheap!
 | 
					// Cheap!
 | 
				
			||||||
 | 
				
			|||||||
@ -26,21 +26,23 @@ FileType IdentifyFile(const std::string &filename) {
 | 
				
			|||||||
        ERROR_LOG(LOADER, "invalid filename %s", filename.c_str());
 | 
					        ERROR_LOG(LOADER, "invalid filename %s", filename.c_str());
 | 
				
			||||||
        return FileType::Error;
 | 
					        return FileType::Error;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    std::string extension = filename.size() >= 5 ? filename.substr(filename.size() - 4) : "";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!strcasecmp(extension.c_str(), ".elf")) {
 | 
					    size_t extension_loc = filename.find_last_of('.');
 | 
				
			||||||
 | 
					    std::string extension = extension_loc != std::string::npos ? filename.substr(extension_loc) : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (LowerStr(extension) == ".elf") {
 | 
				
			||||||
        return FileType::ELF; // TODO(bunnei): Do some filetype checking :p
 | 
					        return FileType::ELF; // TODO(bunnei): Do some filetype checking :p
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (!strcasecmp(extension.c_str(), ".axf")) {
 | 
					    else if (LowerStr(extension) == ".axf") {
 | 
				
			||||||
        return FileType::ELF; // TODO(bunnei): Do some filetype checking :p
 | 
					        return FileType::ELF; // TODO(bunnei): Do some filetype checking :p
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (!strcasecmp(extension.c_str(), ".cxi")) {
 | 
					    else if (LowerStr(extension) == ".cxi") {
 | 
				
			||||||
        return FileType::CXI; // TODO(bunnei): Do some filetype checking :p
 | 
					        return FileType::CXI; // TODO(bunnei): Do some filetype checking :p
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (!strcasecmp(extension.c_str(), ".cci")) {
 | 
					    else if (LowerStr(extension) == ".cci") {
 | 
				
			||||||
        return FileType::CCI; // TODO(bunnei): Do some filetype checking :p
 | 
					        return FileType::CCI; // TODO(bunnei): Do some filetype checking :p
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (!strcasecmp(extension.c_str(), ".bin")) {
 | 
					    else if (LowerStr(extension) == ".bin") {
 | 
				
			||||||
        return FileType::BIN; // TODO(bunnei): Do some filetype checking :p
 | 
					        return FileType::BIN; // TODO(bunnei): Do some filetype checking :p
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return FileType::Unknown;
 | 
					    return FileType::Unknown;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user