fix wolf2022 cheats download ()

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));
QRegularExpressionMatchIterator matches = regex.globalMatch(textContent);
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/";
}
while (matches.hasNext()) {
QRegularExpressionMatch match = matches.next();
QString fileName = match.captured(0);
if (!fileName.isEmpty()) {
QString newFileName = fileName;
int dotIndex = newFileName.lastIndexOf('.');
if (dotIndex != -1) { if (dotIndex != -1) {
baseFileName.insert(dotIndex, "_wolf2022");
if (source == "GoldHEN") {
newFileName.insert(dotIndex, "_GoldHEN");
} else {
newFileName.insert(dotIndex, "_shadPS4");
} }
QString filePath; }
Common::FS::PathToQString(filePath, QString fileUrl = baseUrl + fileName;
Common::FS::GetUserPath(Common::FS::PathType::CheatsDir)); QString localFilePath = dir.filePath(newFileName);
filePath += "/" + baseFileName;
if (QFile::exists(filePath) && showMessageBox) { if (QFile::exists(localFilePath) && showMessageBox) {
QMessageBox::StandardButton reply2; QMessageBox::StandardButton reply;
reply2 = reply = QMessageBox::question(
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" +
newFileName,
QMessageBox::Yes | QMessageBox::No); QMessageBox::Yes | QMessageBox::No);
if (reply2 == QMessageBox::No) { if (reply == QMessageBox::No) {
reply->deleteLater(); continue;
return;
} }
} }
QFile cheatFile(filePath); QNetworkRequest fileRequest(fileUrl);
if (cheatFile.open(QIODevice::WriteOnly)) { QNetworkReply* fileReply = manager->get(fileRequest);
cheatFile.write(jsonData);
cheatFile.close(); connect(fileReply, &QNetworkReply::finished, [=, this]() {
foundFiles = true; if (fileReply->error() == QNetworkReply::NoError) {
populateFileListCheats(); QByteArray fileData = fileReply->readAll();
QFile localFile(localFilePath);
if (localFile.open(QIODevice::WriteOnly)) {
localFile.write(fileData);
localFile.close();
} else { } else {
QMessageBox::warning( QMessageBox::warning(
this, tr("Error"), this, tr("Error"),
QString(tr("Failed to save file:") + "\n%1").arg(filePath)); 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;
}
}
if (!foundFiles && showMessageBox) {
QMessageBox::warning(this, tr("Cheats Not Found"), tr("CheatsNotFound_MSG"));
} }
} }
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);