mirror of
https://github.com/Rosalie241/RMG.git
synced 2026-11-15 18:39:22 +01:00
RMG-Core: make arguments to CoreGetCachedRomHeaderAndSettings() optional
This commit is contained in:
1 parent
c0d81fdc9f
commit
428ef7549a
6 files changed
+50
-19
No files matched your search
@@ -292,21 +292,26 @@ bool CoreSaveRomHeaderAndSettingsCache(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CoreGetCachedRomHeaderAndSettings(std::filesystem::path file, CoreRomType& type, CoreRomHeader& header, CoreRomSettings& defaultSettings, CoreRomSettings& settings)
|
||||
bool CoreGetCachedRomHeaderAndSettings(std::filesystem::path file, CoreRomType* type, CoreRomHeader* header, CoreRomSettings* defaultSettings, CoreRomSettings* settings)
|
||||
{
|
||||
bool ret = false;
|
||||
auto iter = get_cache_entry_iter(file);
|
||||
if (iter == l_CacheEntries.end())
|
||||
{
|
||||
CoreRomType romType;
|
||||
CoreRomHeader romHeader;
|
||||
CoreRomSettings romSettings;
|
||||
CoreRomSettings romDefaultSettings;
|
||||
|
||||
// when we haven't found a cached entry,
|
||||
// we're gonna attempt to retrieve the
|
||||
// rom header and settings and add it
|
||||
// to the cache
|
||||
ret = CoreOpenRom(file) &&
|
||||
CoreGetRomType(type) &&
|
||||
CoreGetCurrentRomHeader(header) &&
|
||||
CoreGetCurrentDefaultRomSettings(defaultSettings) &&
|
||||
CoreGetCurrentRomSettings(settings);
|
||||
CoreGetRomType(romType) &&
|
||||
CoreGetCurrentRomHeader(romHeader) &&
|
||||
CoreGetCurrentRomSettings(romSettings) &&
|
||||
CoreGetCurrentDefaultRomSettings(romDefaultSettings);
|
||||
// always close ROM
|
||||
if (CoreHasRomOpen() && !CoreCloseRom())
|
||||
{
|
||||
@@ -316,7 +321,24 @@ bool CoreGetCachedRomHeaderAndSettings(std::filesystem::path file, CoreRomType&
|
||||
// the info successfully
|
||||
if (ret)
|
||||
{
|
||||
return CoreAddCachedRomHeaderAndSettings(file, type, header, defaultSettings, settings);
|
||||
if (type != nullptr)
|
||||
{
|
||||
*type = romType;
|
||||
}
|
||||
if (header != nullptr)
|
||||
{
|
||||
*header = romHeader;
|
||||
}
|
||||
if (settings != nullptr)
|
||||
{
|
||||
*settings = romSettings;
|
||||
}
|
||||
if (defaultSettings != nullptr)
|
||||
{
|
||||
*defaultSettings = romDefaultSettings;
|
||||
}
|
||||
|
||||
return CoreAddCachedRomHeaderAndSettings(file, romType, romHeader, romDefaultSettings, romSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -324,10 +346,22 @@ bool CoreGetCachedRomHeaderAndSettings(std::filesystem::path file, CoreRomType&
|
||||
}
|
||||
}
|
||||
|
||||
type = (*iter).type;
|
||||
header = (*iter).header;
|
||||
settings = (*iter).settings;
|
||||
defaultSettings = (*iter).defaultSettings;
|
||||
if (type != nullptr)
|
||||
{
|
||||
*type = (*iter).type;
|
||||
}
|
||||
if (header != nullptr)
|
||||
{
|
||||
*header = (*iter).header;
|
||||
}
|
||||
if (settings != nullptr)
|
||||
{
|
||||
*settings = (*iter).settings;
|
||||
}
|
||||
if (defaultSettings != nullptr)
|
||||
{
|
||||
*defaultSettings = (*iter).defaultSettings;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ bool CoreSaveRomHeaderAndSettingsCache(void);
|
||||
// returns whether retrieving the rom header & settings
|
||||
// for given filename succeeds, it also attempts to add
|
||||
// an entry if there's no cached entry found
|
||||
bool CoreGetCachedRomHeaderAndSettings(std::filesystem::path file, CoreRomType& type, CoreRomHeader& header, CoreRomSettings& defaultSettings, CoreRomSettings& settings);
|
||||
bool CoreGetCachedRomHeaderAndSettings(std::filesystem::path file, CoreRomType* type, CoreRomHeader* header, CoreRomSettings* defaultSettings, CoreRomSettings* settings);
|
||||
|
||||
// returns whether adding cached rom header & settings
|
||||
// for given filename succeeds
|
||||
|
||||
@@ -565,9 +565,7 @@ static bool get_romheader_and_romsettings(const std::filesystem::path& file, Cor
|
||||
}
|
||||
else
|
||||
{
|
||||
CoreRomType romType;
|
||||
CoreRomSettings defaultSettings;
|
||||
return CoreGetCachedRomHeaderAndSettings(file, romType, romHeader, defaultSettings, romSettings);
|
||||
return CoreGetCachedRomHeaderAndSettings(file, nullptr, &romHeader, nullptr, &romSettings);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -100,7 +100,7 @@ void RomSearcherThread::searchDirectory(QString directory)
|
||||
{
|
||||
QString file = roms.at(i);
|
||||
|
||||
if (CoreGetCachedRomHeaderAndSettings(file.toStdU32String(), type, header, defaultSettings, settings))
|
||||
if (CoreGetCachedRomHeaderAndSettings(file.toStdU32String(), &type, &header, nullptr, &settings))
|
||||
{
|
||||
data.push_back(
|
||||
{
|
||||
|
||||
@@ -82,7 +82,8 @@ SettingsDialog::SettingsDialog(QWidget *parent, QString file) : QDialog(parent)
|
||||
else if (!file.isEmpty())
|
||||
{
|
||||
// only show game tab once retrieving cached entry succeeds
|
||||
this->showGameSettings = CoreGetCachedRomHeaderAndSettings(file.toStdU32String(), this->currentGameType, this->currentGameHeader, this->defaultGameSettings, this->currentGameSettings);
|
||||
this->showGameSettings = CoreGetCachedRomHeaderAndSettings(file.toStdU32String(), &this->currentGameType,
|
||||
&this->currentGameHeader, &this->defaultGameSettings, &this->currentGameSettings);
|
||||
if (this->showGameSettings)
|
||||
{
|
||||
this->currentGameFile = file;
|
||||
|
||||
@@ -2160,12 +2160,10 @@ void MainWindow::on_RomBrowser_RomInformation(QString file)
|
||||
this->ui_Widget_RomBrowser->StopRefreshRomList();
|
||||
}
|
||||
|
||||
CoreRomType romType;
|
||||
CoreRomHeader romHeader;
|
||||
CoreRomSettings romDefaultSettings;
|
||||
CoreRomSettings romSettings;
|
||||
|
||||
if (!CoreGetCachedRomHeaderAndSettings(file.toStdU32String(), romType, romHeader, romDefaultSettings, romSettings))
|
||||
if (!CoreGetCachedRomHeaderAndSettings(file.toStdU32String(), nullptr, &romHeader, nullptr, &romSettings))
|
||||
{
|
||||
this->showErrorMessage("CoreGetCachedRomHeaderAndSettings() Failed", QString::fromStdString(CoreGetError()));
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user