Skip to content

Commit

Permalink
RMG-Core: make arguments to CoreGetCachedRomHeaderAndSettings() optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Feb 9, 2025
1 parent c0d81fd commit 428ef75
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
54 changes: 44 additions & 10 deletions Source/RMG-Core/CachedRomHeaderAndSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -316,18 +321,47 @@ 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
{
return false;
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion Source/RMG-Core/CachedRomHeaderAndSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions Source/RMG-Core/Cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/RMG/Thread/RomSearcherThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
3 changes: 2 additions & 1 deletion Source/RMG/UserInterface/Dialog/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions Source/RMG/UserInterface/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 428ef75

Please sign in to comment.