fix wolf2022 cheats download (#1173)

This commit is contained in:
DanielSvoboda 2024-10-01 01:53:20 -03:00 committed by GitHub
parent 348da93ee6
commit dda5cc411f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -456,10 +456,9 @@ void CheatsPatches::downloadCheats(const QString& source, const QString& gameSer
if (source == "GoldHEN") { if (source == "GoldHEN") {
url = "https://raw.githubusercontent.com/GoldHEN/GoldHEN_Cheat_Repository/main/json.txt"; url = "https://raw.githubusercontent.com/GoldHEN/GoldHEN_Cheat_Repository/main/json.txt";
} else if (source == "wolf2022") { } else if (source == "wolf2022") {
url = "https://wolf2022.ir/trainer/" + gameSerial + "_" + gameVersion + ".json"; url = "https://wolf2022.ir/trainer/list.json";
} else if (source == "shadPS4") { } else if (source == "shadPS4") {
url = "https://raw.githubusercontent.com/shadps4-emu/ps4_cheats/main/" url = "https://raw.githubusercontent.com/shadps4-emu/ps4_cheats/main/CHEATS_JSON.txt";
"CHEATS_JSON.txt";
} else { } else {
QMessageBox::warning(this, tr("Invalid Source"), QMessageBox::warning(this, tr("Invalid Source"),
QString(tr("The selected source is invalid.") + "\n%1").arg(source)); QString(tr("The selected source is invalid.") + "\n%1").arg(source));
@ -474,44 +473,32 @@ void CheatsPatches::downloadCheats(const QString& source, const QString& gameSer
QByteArray jsonData = reply->readAll(); QByteArray jsonData = reply->readAll();
bool foundFiles = false; bool foundFiles = false;
if (source == "GoldHEN" || source == "shadPS4") { if (source == "wolf2022") {
QString textContent(jsonData); QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
QRegularExpression regex( QJsonArray gamesArray = jsonDoc.object().value("games").toArray();
QString("%1_%2[^=]*\\.json").arg(gameSerial).arg(gameVersion));
QRegularExpressionMatchIterator matches = regex.globalMatch(textContent);
QString baseUrl;
if (source == "GoldHEN") { foreach (const QJsonValue& value, gamesArray) {
baseUrl = "https://raw.githubusercontent.com/GoldHEN/GoldHEN_Cheat_Repository/" QJsonObject gameObject = value.toObject();
"main/json/"; QString title = gameObject.value("title").toString();
} else { QString version = gameObject.value("version").toString();
baseUrl = "https://raw.githubusercontent.com/shadps4-emu/ps4_cheats/"
"main/CHEATS/";
}
while (matches.hasNext()) { if (title == gameSerial &&
QRegularExpressionMatch match = matches.next(); (version == gameVersion || version == gameVersion.mid(1))) {
QString fileName = match.captured(0); QString fileUrl =
"https://wolf2022.ir/trainer/" + gameObject.value("url").toString();
if (!fileName.isEmpty()) { QString localFileName = gameObject.value("url").toString();
QString newFileName = fileName; localFileName =
int dotIndex = newFileName.lastIndexOf('.'); localFileName.left(localFileName.lastIndexOf('.')) + "_wolf2022.json";
if (dotIndex != -1) {
if (source == "GoldHEN") { QString localFilePath = dir.filePath(localFileName);
newFileName.insert(dotIndex, "_GoldHEN");
} else {
newFileName.insert(dotIndex, "_shadPS4");
}
}
QString fileUrl = baseUrl + fileName;
QString localFilePath = dir.filePath(newFileName);
if (QFile::exists(localFilePath) && showMessageBox) { if (QFile::exists(localFilePath) && showMessageBox) {
QMessageBox::StandardButton reply; QMessageBox::StandardButton reply;
reply = QMessageBox::question( reply = QMessageBox::question(
this, tr("File Exists"), this, tr("File Exists"),
tr("File already exists. Do you want to replace it?"), tr("File already exists. Do you want to replace it?") + "\n" +
localFileName,
QMessageBox::Yes | QMessageBox::No); QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::No) { if (reply == QMessageBox::No) {
continue; continue;
@ -549,38 +536,81 @@ void CheatsPatches::downloadCheats(const QString& source, const QString& gameSer
if (!foundFiles && showMessageBox) { if (!foundFiles && showMessageBox) {
QMessageBox::warning(this, tr("Cheats Not Found"), tr("CheatsNotFound_MSG")); QMessageBox::warning(this, tr("Cheats Not Found"), tr("CheatsNotFound_MSG"));
} }
} else if (source == "wolf2022") { } else if (source == "GoldHEN" || source == "shadPS4") {
QString fileName = QFileInfo(QUrl(url).path()).fileName(); QString textContent(jsonData);
QString baseFileName = fileName; QRegularExpression regex(
int dotIndex = baseFileName.lastIndexOf('.'); QString("%1_%2[^=]*\\.json").arg(gameSerial).arg(gameVersion));
if (dotIndex != -1) { QRegularExpressionMatchIterator matches = regex.globalMatch(textContent);
baseFileName.insert(dotIndex, "_wolf2022"); QString baseUrl;
if (source == "GoldHEN") {
baseUrl = "https://raw.githubusercontent.com/GoldHEN/GoldHEN_Cheat_Repository/"
"main/json/";
} else {
baseUrl = "https://raw.githubusercontent.com/shadps4-emu/ps4_cheats/"
"main/CHEATS/";
} }
QString filePath;
Common::FS::PathToQString(filePath, while (matches.hasNext()) {
Common::FS::GetUserPath(Common::FS::PathType::CheatsDir)); QRegularExpressionMatch match = matches.next();
filePath += "/" + baseFileName; QString fileName = match.captured(0);
if (QFile::exists(filePath) && showMessageBox) {
QMessageBox::StandardButton reply2; if (!fileName.isEmpty()) {
reply2 = QString newFileName = fileName;
QMessageBox::question(this, tr("File Exists"), int dotIndex = newFileName.lastIndexOf('.');
tr("File already exists. Do you want to replace it?"), if (dotIndex != -1) {
QMessageBox::Yes | QMessageBox::No);
if (reply2 == QMessageBox::No) { if (source == "GoldHEN") {
reply->deleteLater(); newFileName.insert(dotIndex, "_GoldHEN");
return; } else {
newFileName.insert(dotIndex, "_shadPS4");
}
}
QString fileUrl = baseUrl + fileName;
QString localFilePath = dir.filePath(newFileName);
if (QFile::exists(localFilePath) && showMessageBox) {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(
this, tr("File Exists"),
tr("File already exists. Do you want to replace it?") + "\n" +
newFileName,
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::No) {
continue;
}
}
QNetworkRequest fileRequest(fileUrl);
QNetworkReply* fileReply = manager->get(fileRequest);
connect(fileReply, &QNetworkReply::finished, [=, this]() {
if (fileReply->error() == QNetworkReply::NoError) {
QByteArray fileData = fileReply->readAll();
QFile localFile(localFilePath);
if (localFile.open(QIODevice::WriteOnly)) {
localFile.write(fileData);
localFile.close();
} else {
QMessageBox::warning(
this, tr("Error"),
QString(tr("Failed to save file:") + "\n%1")
.arg(localFilePath));
}
} else {
QMessageBox::warning(this, tr("Error"),
QString(tr("Failed to download file:") +
"%1\n\n" + tr("Error:") + "%2")
.arg(fileUrl)
.arg(fileReply->errorString()));
}
fileReply->deleteLater();
});
foundFiles = true;
} }
} }
QFile cheatFile(filePath); if (!foundFiles && showMessageBox) {
if (cheatFile.open(QIODevice::WriteOnly)) { QMessageBox::warning(this, tr("Cheats Not Found"), tr("CheatsNotFound_MSG"));
cheatFile.write(jsonData);
cheatFile.close();
foundFiles = true;
populateFileListCheats();
} else {
QMessageBox::warning(
this, tr("Error"),
QString(tr("Failed to save file:") + "\n%1").arg(filePath));
} }
} }
if (foundFiles && showMessageBox) { if (foundFiles && showMessageBox) {
@ -910,11 +940,16 @@ void CheatsPatches::addCheatsToLayout(const QJsonArray& modsArray, const QJsonAr
void CheatsPatches::populateFileListCheats() { void CheatsPatches::populateFileListCheats() {
QString cheatsDir; QString cheatsDir;
Common::FS::PathToQString(cheatsDir, Common::FS::GetUserPath(Common::FS::PathType::CheatsDir)); Common::FS::PathToQString(cheatsDir, Common::FS::GetUserPath(Common::FS::PathType::CheatsDir));
QString pattern = m_gameSerial + "_" + m_gameVersion + "*.json";
QString fullGameVersion = m_gameVersion;
QString modifiedGameVersion = m_gameVersion.mid(1);
QString patternWithFirstChar = m_gameSerial + "_" + fullGameVersion + "*.json";
QString patternWithoutFirstChar = m_gameSerial + "_" + modifiedGameVersion + "*.json";
QDir dir(cheatsDir); QDir dir(cheatsDir);
QStringList filters; QStringList filters;
filters << pattern; filters << patternWithFirstChar << patternWithoutFirstChar;
dir.setNameFilters(filters); dir.setNameFilters(filters);
QFileInfoList fileList = dir.entryInfoList(QDir::Files); QFileInfoList fileList = dir.entryInfoList(QDir::Files);
@ -1248,4 +1283,4 @@ void CheatsPatches::onPatchCheckBoxHovered(QCheckBox* checkBox, bool hovered) {
} else { } else {
instructionsTextEdit->setText(defaultTextEdit); instructionsTextEdit->setText(defaultTextEdit);
} }
} }