Mesen-SX/Core/RomFinder.h
NovaSquirrel c0e249e993 Revert "Merge branch 'reformat_code'"
This reverts commit daf3b57e89, reversing
changes made to 7a6e0b7d77.
2021-03-10 11:13:28 -05:00

49 lines
No EOL
1.5 KiB
C++

#pragma once
#include "stdafx.h"
#include "Console.h"
#include "BaseCartridge.h"
#include "../Utilities/VirtualFile.h"
#include "../Utilities/FolderUtilities.h"
class RomFinder
{
public:
static bool LoadMatchingRom(Console* console, string romName, string sha1Hash)
{
if(console->IsRunning() && console->GetCartridge()->GetSha1Hash() == sha1Hash) {
//Current game matches
return true;
}
string match = FindMatchingRom(console, romName, sha1Hash);
if(!match.empty()) {
return console->LoadRom(match, VirtualFile(""));
}
return false;
}
static string FindMatchingRom(Console* console, string romName, string sha1Hash)
{
if(console->IsRunning() && console->GetCartridge()->GetSha1Hash() == sha1Hash) {
//Current game matches
return console->GetRomInfo().RomFile;
}
string lcRomname = romName;
std::transform(lcRomname.begin(), lcRomname.end(), lcRomname.begin(), ::tolower);
std::transform(romName.begin(), romName.end(), romName.begin(), ::tolower);
vector<string> romFiles;
for(string folder : FolderUtilities::GetKnownGameFolders()) {
for(string romFilename : FolderUtilities::GetFilesInFolder(folder, VirtualFile::RomExtensions, true)) {
string lcRomFile = romFilename;
std::transform(lcRomFile.begin(), lcRomFile.end(), lcRomFile.begin(), ::tolower);
if(FolderUtilities::GetFilename(romName, false) == FolderUtilities::GetFilename(lcRomFile, false) && VirtualFile(romFilename).GetSha1Hash() == sha1Hash) {
return romFilename;
}
}
}
return "";
}
};