Qt: Don't use hash cheat list when PPFs exist

This commit is contained in:
Stenzek
2025-10-12 13:21:00 +10:00
parent c4c6357be3
commit ec96dd70f9
5 changed files with 27 additions and 2 deletions

View File

@@ -238,7 +238,7 @@ std::string GameCheatSettingsWidget::getPathForSavingCheats() const
{
// Check for the path without the hash first. If we have one of those, keep using it.
std::string path = Cheats::GetChtFilename(m_dialog->getGameSerial(), std::nullopt, true);
if (!FileSystem::FileExists(path.c_str()))
if (!FileSystem::FileExists(path.c_str()) && m_dialog->isGameHashStable())
path = Cheats::GetChtFilename(m_dialog->getGameSerial(), m_dialog->getGameHash(), true);
return path;
}

View File

@@ -51,7 +51,8 @@ SettingsWindow::SettingsWindow() : QWidget()
}
SettingsWindow::SettingsWindow(const GameList::Entry* entry, std::unique_ptr<INISettingsInterface> sif)
: QWidget(), m_sif(std::move(sif)), m_database_entry(entry->dbentry), m_serial(entry->serial), m_hash(entry->hash)
: QWidget(), m_sif(std::move(sif)), m_database_entry(entry->dbentry), m_serial(entry->serial), m_hash(entry->hash),
m_path(entry->path)
{
m_ui.setupUi(this);
setGameTitle(entry->GetDisplayTitle(GameList::ShouldShowLocalizedTitles()));
@@ -662,6 +663,11 @@ bool SettingsWindow::hasGameTrait(GameDatabase::Trait trait)
m_sif->GetBoolValue("Main", "ApplyCompatibilitySettings", true));
}
bool SettingsWindow::isGameHashStable() const
{
return (m_path.empty() || !CDImage::HasOverlayablePatch(m_path.c_str()));
}
SettingsWindow* SettingsWindow::openGamePropertiesDialog(const GameList::Entry* entry,
const char* category /* = nullptr */)
{

View File

@@ -65,6 +65,7 @@ public:
ALWAYS_INLINE const std::string& getGameTitle() const { return m_title; }
ALWAYS_INLINE const std::string& getGameSerial() const { return m_serial; }
ALWAYS_INLINE const std::optional<GameHash>& getGameHash() const { return m_hash; }
ALWAYS_INLINE const std::string& getGamePath() const { return m_path; }
ALWAYS_INLINE const GameDatabase::Entry* getDatabaseEntry() const { return m_database_entry; }
ALWAYS_INLINE bool hasDatabaseEntry() const { return (m_database_entry != nullptr); }
@@ -107,6 +108,7 @@ public:
void setGameTitle(std::string_view title);
bool hasGameTrait(GameDatabase::Trait trait);
bool isGameHashStable() const;
void setCategory(const char* category);
void setCategoryRow(int index);
@@ -165,4 +167,5 @@ private:
std::string m_title;
std::string m_serial;
std::optional<GameHash> m_hash;
std::string m_path;
};

View File

@@ -129,6 +129,19 @@ std::unique_ptr<CDImage> CDImage::Open(const char* path, bool allow_patches, Err
return image;
}
bool CDImage::HasOverlayablePatch(const char* path)
{
// Annoying handling because of storage access framework.
#ifdef __ANDROID__
const std::string ppf_path =
Path::BuildRelativePath(path, Path::ReplaceExtension(FileSystem::GetDisplayNameFromPath(path), "ppf"));
#else
const std::string ppf_path = Path::BuildRelativePath(path, Path::ReplaceExtension(Path::GetFileName(path), "ppf"));
#endif
return FileSystem::FileExists(ppf_path.c_str());
}
CDImage::LBA CDImage::GetTrackStartPosition(u8 track) const
{
Assert(track > 0 && track <= m_tracks.size());

View File

@@ -221,6 +221,9 @@ public:
/// Returns true if the specified filename is a CD-ROM device name.
static bool IsDeviceName(const char* filename);
/// Returns true if an overlayable patch file exists for the specified image path.
static bool HasOverlayablePatch(const char* path);
// Opening disc image.
static std::unique_ptr<CDImage> Open(const char* path, bool allow_patches, Error* error);
static std::unique_ptr<CDImage> OpenBinImage(const char* path, Error* error);