Skip to content

Commit

Permalink
Patch compatible version notice (shadps4-emu#1407)
Browse files Browse the repository at this point in the history
* Patch compatible version notice

* +
  • Loading branch information
DanielSvoboda authored Oct 18, 2024
1 parent a13d1d1 commit 47ba6c6
Show file tree
Hide file tree
Showing 28 changed files with 629 additions and 38 deletions.
91 changes: 81 additions & 10 deletions src/qt_gui/cheats_patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#include "common/path_util.h"
#include "core/module.h"

using namespace Common::FS;

CheatsPatches::CheatsPatches(const QString& gameName, const QString& gameSerial,
const QString& gameVersion, const QString& gameSize,
const QPixmap& gameImage, QWidget* parent)
Expand Down Expand Up @@ -776,6 +774,7 @@ void CheatsPatches::downloadPatches(const QString repository, const bool showMes
// Create the files.json file with the identification of which file to open
createFilesJson(repository);
populateFileListPatches();
compatibleVersionNotice(repository);
} else {
if (showMessageBox) {
QMessageBox::warning(this, tr("Error"),
Expand All @@ -787,6 +786,84 @@ void CheatsPatches::downloadPatches(const QString repository, const bool showMes
});
}

void CheatsPatches::compatibleVersionNotice(const QString repository) {
QDir patchesDir(Common::FS::GetUserPath(Common::FS::PathType::PatchesDir));
QDir dir = patchesDir.filePath(repository);

QStringList xmlFiles = dir.entryList(QStringList() << "*.xml", QDir::Files);
QSet<QString> appVersionsSet;

foreach (const QString& xmlFile, xmlFiles) {
QFile file(dir.filePath(xmlFile));
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::warning(this, tr("ERROR"),
QString(tr("Failed to open file:") + "\n%1").arg(xmlFile));
continue;
}

QXmlStreamReader xmlReader(&file);
bool foundMatchingID = false;

while (!xmlReader.atEnd() && !xmlReader.hasError()) {
QXmlStreamReader::TokenType token = xmlReader.readNext();
if (token == QXmlStreamReader::StartElement) {
if (xmlReader.name() == QStringLiteral("ID")) {
QString id = xmlReader.readElementText();
if (id == m_gameSerial) {
foundMatchingID = true;
}
} else if (xmlReader.name() == QStringLiteral("Metadata")) {
if (foundMatchingID) {
QString appVer = xmlReader.attributes().value("AppVer").toString();
if (!appVer.isEmpty()) {
appVersionsSet.insert(appVer);
}
}
}
}
}

if (xmlReader.hasError()) {
QMessageBox::warning(this, tr("ERROR"),
QString(tr("XML ERROR:") + "\n%1").arg(xmlReader.errorString()));
}

if (foundMatchingID) {
QStringList incompatibleVersions;
bool hasMatchingVersion = false;

foreach (const QString& appVer, appVersionsSet) {
if (appVer != m_gameVersion) {
incompatibleVersions.append(appVer);
} else {
hasMatchingVersion = true;
}
}

if (!incompatibleVersions.isEmpty() ||
(hasMatchingVersion && incompatibleVersions.isEmpty())) {
QString message;

if (!incompatibleVersions.isEmpty()) {
QString versionsList = incompatibleVersions.join(", ");
message += QString(tr("The game is in version: %1")).arg(m_gameVersion) + "\n" +
QString(tr("The downloaded patch only works on version: %1"))
.arg(versionsList);

if (hasMatchingVersion) {
message += QString(", %1").arg(m_gameVersion);
}
message += QString("\n" + tr("You may need to update your game."));
}

if (!message.isEmpty()) {
QMessageBox::information(this, tr("Incompatibility Notice"), message);
}
}
}
}
}

void CheatsPatches::createFilesJson(const QString& repository) {

QDir dir(Common::FS::GetUserPath(Common::FS::PathType::PatchesDir));
Expand Down Expand Up @@ -1126,8 +1203,8 @@ void CheatsPatches::addPatchesToLayout(const QString& filePath) {
}
}

// Remove the item from the list view if no patches were added (the game has patches, but not
// for the current version)
// Remove the item from the list view if no patches were added
// (the game has patches, but not for the current version)
if (!patchAdded) {
QStringListModel* model = qobject_cast<QStringListModel*>(patchesListView->model());
if (model) {
Expand All @@ -1154,12 +1231,6 @@ void CheatsPatches::updateNoteTextEdit(const QString& patchName) {
QString type = lineObject["Type"].toString();
QString address = lineObject["Address"].toString();
QString patchValue = lineObject["Value"].toString();

// add the values ​​to be modified in instructionsTextEdit
// text.append(QString("\nType: %1\nAddress: %2\n\nValue: %3")
// .arg(type)
// .arg(address)
// .arg(patchValue));
}
text.replace("\\n", "\n");
instructionsTextEdit->setText(text);
Expand Down
2 changes: 1 addition & 1 deletion src/qt_gui/cheats_patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class CheatsPatches : public QWidget {
const QString& gameSize, const QPixmap& gameImage, QWidget* parent = nullptr);
~CheatsPatches();

// Public Methods
void downloadCheats(const QString& source, const QString& m_gameSerial,
const QString& m_gameVersion, bool showMessageBox);
void downloadPatches(const QString repository, const bool showMessageBox);
void createFilesJson(const QString& repository);
void compatibleVersionNotice(const QString repository);

signals:
void downloadFinished();
Expand Down
22 changes: 21 additions & 1 deletion src/qt_gui/translations/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@
<message>
<location filename="../cheats_patches.cpp" line="763"/>
<source>DownloadComplete_MSG</source>
<translation>تم تنزيل التصحيحات بنجاح! تم تنزيل جميع التصحيحات لجميع الألعاب، ولا داعي لتنزيلها بشكل فردي لكل لعبة كما هو الحال مع الغش. إذا لم يظهر التحديث، قد يكون السبب أنه غير متوفر للإصدار وسيريال اللعبة المحدد. قد تحتاج إلى تحديث اللعبة.</translation>
<translation>تم تنزيل التصحيحات بنجاح! تم تنزيل جميع التصحيحات لجميع الألعاب، ولا داعي لتنزيلها بشكل فردي لكل لعبة كما هو الحال مع الغش. إذا لم يظهر التحديث، قد يكون السبب أنه غير متوفر للإصدار وسيريال اللعبة المحدد.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="773"/>
Expand All @@ -1038,6 +1038,26 @@
<source>Failed to retrieve HTML page.</source>
<translation>.HTML فشل في استرجاع صفحة</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="850"/>
<source>The game is in version: %1</source>
<translation>اللعبة في الإصدار: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="851"/>
<source>The downloaded patch only works on version: %1</source>
<translation>الباتش الذي تم تنزيله يعمل فقط على الإصدار: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="856"/>
<source>You may need to update your game.</source>
<translation>قد تحتاج إلى تحديث لعبتك.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="860"/>
<source>Incompatibility Notice</source>
<translation>إشعار عدم التوافق</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="801"/>
<source>Failed to open file:</source>
Expand Down
22 changes: 21 additions & 1 deletion src/qt_gui/translations/da_DK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@
<message>
<location filename="../cheats_patches.cpp" line="763"/>
<source>DownloadComplete_MSG</source>
<translation>Patcher hentet med succes! Alle patches til alle spil er blevet hentet, der er ikke behov for at hente dem individuelt for hvert spil, som det sker med snyd. Hvis opdateringen ikke vises, kan det være, at den ikke findes for den specifikke serie og version af spillet. Det kan være nødvendigt at opdatere spillet.</translation>
<translation>Patcher hentet med succes! Alle patches til alle spil er blevet hentet, der er ikke behov for at hente dem individuelt for hvert spil, som det sker med snyd. Hvis opdateringen ikke vises, kan det være, at den ikke findes for den specifikke serie og version af spillet.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="773"/>
Expand All @@ -1038,6 +1038,26 @@
<source>Failed to retrieve HTML page.</source>
<translation>Kunne ikke hente HTML-side.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="850"/>
<source>The game is in version: %1</source>
<translation>Spillet er i version: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="851"/>
<source>The downloaded patch only works on version: %1</source>
<translation>Den downloadede patch fungerer kun på version: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="856"/>
<source>You may need to update your game.</source>
<translation>Du skal muligvis opdatere dit spil.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="860"/>
<source>Incompatibility Notice</source>
<translation>Uforenelighedsmeddelelse</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="801"/>
<source>Failed to open file:</source>
Expand Down
22 changes: 21 additions & 1 deletion src/qt_gui/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@
<message>
<location filename="../cheats_patches.cpp" line="763"/>
<source>DownloadComplete_MSG</source>
<translation>Patches erfolgreich heruntergeladen! Alle Patches für alle Spiele wurden heruntergeladen, es ist nicht notwendig, sie einzeln für jedes Spiel herunterzuladen, wie es bei Cheats der Fall ist. Wenn der Patch nicht angezeigt wird, könnte es sein, dass er für die spezifische Seriennummer und Version des Spiels nicht existiert. Möglicherweise müssen Sie das Spiel aktualisieren.</translation>
<translation>Patches erfolgreich heruntergeladen! Alle Patches für alle Spiele wurden heruntergeladen, es ist nicht notwendig, sie einzeln für jedes Spiel herunterzuladen, wie es bei Cheats der Fall ist. Wenn der Patch nicht angezeigt wird, könnte es sein, dass er für die spezifische Seriennummer und Version des Spiels nicht existiert.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="773"/>
Expand All @@ -1038,6 +1038,26 @@
<source>Failed to retrieve HTML page.</source>
<translation>Fehler beim Abrufen der HTML-Seite.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="850"/>
<source>The game is in version: %1</source>
<translation>Das Spiel ist in der Version: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="851"/>
<source>The downloaded patch only works on version: %1</source>
<translation>Der heruntergeladene Patch funktioniert nur in der Version: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="856"/>
<source>You may need to update your game.</source>
<translation>Sie müssen möglicherweise Ihr Spiel aktualisieren.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="860"/>
<source>Incompatibility Notice</source>
<translation>Inkompatibilitätsbenachrichtigung</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="801"/>
<source>Failed to open file:</source>
Expand Down
22 changes: 21 additions & 1 deletion src/qt_gui/translations/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@
<message>
<location filename="../cheats_patches.cpp" line="763"/>
<source>DownloadComplete_MSG</source>
<translation>Τα Patches κατεβάστηκαν επιτυχώς! Όλα τα Patches για όλα τα παιχνίδια έχουν κατέβει, δεν είναι απαραίτητο να τα κατεβάσετε ένα-ένα για κάθε παιχνίδι, όπως με τα Cheats. Εάν η ενημέρωση δεν εμφανίζεται, μπορεί να μην υπάρχει για τον συγκεκριμένο σειριακό αριθμό και έκδοση του παιχνιδιού. Μπορεί να χρειαστεί να ενημερώσετε το παιχνίδι.</translation>
<translation>Τα Patches κατεβάστηκαν επιτυχώς! Όλα τα Patches για όλα τα παιχνίδια έχουν κατέβει, δεν είναι απαραίτητο να τα κατεβάσετε ένα-ένα για κάθε παιχνίδι, όπως με τα Cheats. Εάν η ενημέρωση δεν εμφανίζεται, μπορεί να μην υπάρχει για τον συγκεκριμένο σειριακό αριθμό και έκδοση του παιχνιδιού.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="773"/>
Expand All @@ -1038,6 +1038,26 @@
<source>Failed to retrieve HTML page.</source>
<translation>Αποτυχία ανάκτησης σελίδας HTML.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="850"/>
<source>The game is in version: %1</source>
<translation>Το παιχνίδι είναι στην έκδοση: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="851"/>
<source>The downloaded patch only works on version: %1</source>
<translation>Η ληφθείσα ενημέρωση λειτουργεί μόνο στην έκδοση: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="856"/>
<source>You may need to update your game.</source>
<translation>Μπορεί να χρειαστεί να ενημερώσετε το παιχνίδι σας.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="860"/>
<source>Incompatibility Notice</source>
<translation>Ειδοποίηση ασυμβατότητας</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="801"/>
<source>Failed to open file:</source>
Expand Down
22 changes: 21 additions & 1 deletion src/qt_gui/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@
<message>
<location filename="../cheats_patches.cpp" line="763"/>
<source>DownloadComplete_MSG</source>
<translation>Patches Downloaded Successfully! All Patches available for all games have been downloaded, there is no need to download them individually for each game as happens in Cheats. If the patch does not appear, it may be that it does not exist for the specific serial and version of the game. It may be necessary to update the game.</translation>
<translation>Patches Downloaded Successfully! All Patches available for all games have been downloaded, there is no need to download them individually for each game as happens in Cheats. If the patch does not appear, it may be that it does not exist for the specific serial and version of the game.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="773"/>
Expand All @@ -1038,6 +1038,26 @@
<source>Failed to retrieve HTML page.</source>
<translation>Failed to retrieve HTML page.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="850"/>
<source>The game is in version: %1</source>
<translation>The game is in version: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="851"/>
<source>The downloaded patch only works on version: %1</source>
<translation>The downloaded patch only works on version: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="856"/>
<source>You may need to update your game.</source>
<translation>You may need to update your game.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="860"/>
<source>Incompatibility Notice</source>
<translation>Incompatibility Notice</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="801"/>
<source>Failed to open file:</source>
Expand Down
22 changes: 21 additions & 1 deletion src/qt_gui/translations/es_ES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@
<message>
<location filename="../cheats_patches.cpp" line="763"/>
<source>DownloadComplete_MSG</source>
<translation>¡Parches descargados exitosamente! Todos los parches disponibles para todos los juegos han sido descargados, no es necesario descargarlos individualmente para cada juego como ocurre con los trucos. Si el parche no aparece, puede ser que no exista para el número de serie y versión específicos del juego. Puede ser necesario actualizar el juego.</translation>
<translation>¡Parches descargados exitosamente! Todos los parches disponibles para todos los juegos han sido descargados, no es necesario descargarlos individualmente para cada juego como ocurre con los trucos. Si el parche no aparece, puede ser que no exista para el número de serie y versión específicos del juego.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="773"/>
Expand All @@ -1038,6 +1038,26 @@
<source>Failed to retrieve HTML page.</source>
<translation>Error al recuperar la página HTML.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="850"/>
<source>The game is in version: %1</source>
<translation>El juego está en la versión: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="851"/>
<source>The downloaded patch only works on version: %1</source>
<translation>El parche descargado solo funciona en la versión: %1</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="856"/>
<source>You may need to update your game.</source>
<translation>Puede que necesites actualizar tu juego.</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="860"/>
<source>Incompatibility Notice</source>
<translation>Aviso de incompatibilidad</translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="801"/>
<source>Failed to open file:</source>
Expand Down
Loading

0 comments on commit 47ba6c6

Please sign in to comment.