mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-16 03:38:38 +12:00
Qt: move ReadJSON in game compat to its own function
This commit is contained in:
parent
dab82b70f7
commit
a96a8a9db0
2 changed files with 69 additions and 66 deletions
|
@ -15,74 +15,73 @@ game_compatibility::game_compatibility(std::shared_ptr<gui_settings> settings) :
|
||||||
RequestCompatibility();
|
RequestCompatibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool game_compatibility::ReadJSON(const QJsonObject& json_data, bool after_download)
|
||||||
|
{
|
||||||
|
int return_code = json_data["return_code"].toInt();
|
||||||
|
|
||||||
|
if (return_code < 0)
|
||||||
|
{
|
||||||
|
if (after_download)
|
||||||
|
{
|
||||||
|
std::string error_message;
|
||||||
|
switch (return_code)
|
||||||
|
{
|
||||||
|
case -1:
|
||||||
|
error_message = "Server Error - Internal Error";
|
||||||
|
break;
|
||||||
|
case -2:
|
||||||
|
error_message = "Server Error - Maintenance Mode";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error_message = "Server Error - Unknown Error";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
LOG_ERROR(GENERAL, "Compatibility error: { %s: return code %d }", error_message, return_code);
|
||||||
|
Q_EMIT DownloadError(qstr(error_message) + " " + QString::number(return_code));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_ERROR(GENERAL, "Compatibility error: { Database Error - Invalid: return code %d }", return_code);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!json_data["results"].isObject())
|
||||||
|
{
|
||||||
|
LOG_ERROR(GENERAL, "Compatibility error: { Database Error - No Results found }");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_compat_database.clear();
|
||||||
|
|
||||||
|
QJsonObject json_results = json_data["results"].toObject();
|
||||||
|
|
||||||
|
// Retrieve status data for every valid entry
|
||||||
|
for (const auto& key : json_results.keys())
|
||||||
|
{
|
||||||
|
if (!json_results[key].isObject())
|
||||||
|
{
|
||||||
|
LOG_ERROR(GENERAL, "Compatibility error: { Database Error - Unusable object %s }", sstr(key));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject json_result = json_results[key].toObject();
|
||||||
|
|
||||||
|
// Retrieve compatibility information from json
|
||||||
|
compat_status status = Status_Data.at(json_result.value("status").toString("NoResult"));
|
||||||
|
|
||||||
|
// Add date if possible
|
||||||
|
status.date = json_result.value("date").toString();
|
||||||
|
|
||||||
|
// Add status to map
|
||||||
|
m_compat_database.emplace(std::pair<std::string, compat_status>(sstr(key), status));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void game_compatibility::RequestCompatibility(bool online)
|
void game_compatibility::RequestCompatibility(bool online)
|
||||||
{
|
{
|
||||||
// Creates new map from database
|
|
||||||
auto ReadJSON = [=](const QJsonObject& json_data, bool after_download)
|
|
||||||
{
|
|
||||||
int return_code = json_data["return_code"].toInt();
|
|
||||||
|
|
||||||
if (return_code < 0)
|
|
||||||
{
|
|
||||||
if (after_download)
|
|
||||||
{
|
|
||||||
std::string error_message;
|
|
||||||
switch (return_code)
|
|
||||||
{
|
|
||||||
case -1:
|
|
||||||
error_message = "Server Error - Internal Error";
|
|
||||||
break;
|
|
||||||
case -2:
|
|
||||||
error_message = "Server Error - Maintenance Mode";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
error_message = "Server Error - Unknown Error";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
LOG_ERROR(GENERAL, "Compatibility error: { %s: return code %d }", error_message, return_code);
|
|
||||||
Q_EMIT DownloadError(qstr(error_message) + " " + QString::number(return_code));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG_ERROR(GENERAL, "Compatibility error: { Database Error - Invalid: return code %d }", return_code);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_data["results"].isObject())
|
|
||||||
{
|
|
||||||
LOG_ERROR(GENERAL, "Compatibility error: { Database Error - No Results found }");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_compat_database.clear();
|
|
||||||
|
|
||||||
QJsonObject json_results = json_data["results"].toObject();
|
|
||||||
|
|
||||||
// Retrieve status data for every valid entry
|
|
||||||
for (const auto& key : json_results.keys())
|
|
||||||
{
|
|
||||||
if (!json_results[key].isObject())
|
|
||||||
{
|
|
||||||
LOG_ERROR(GENERAL, "Compatibility error: { Database Error - Unusable object %s }", sstr(key));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject json_result = json_results[key].toObject();
|
|
||||||
|
|
||||||
// Retrieve compatibility information from json
|
|
||||||
compat_status status = Status_Data.at(json_result.value("status").toString("NoResult"));
|
|
||||||
|
|
||||||
// Add date if possible
|
|
||||||
status.date = json_result.value("date").toString();
|
|
||||||
|
|
||||||
// Add status to map
|
|
||||||
m_compat_database.emplace(std::pair<std::string, compat_status>(sstr(key), status));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!online)
|
if (!online)
|
||||||
{
|
{
|
||||||
// Retrieve database from file
|
// Retrieve database from file
|
||||||
|
|
|
@ -28,6 +28,7 @@ class game_compatibility : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
const std::map<QString, compat_status> Status_Data =
|
const std::map<QString, compat_status> Status_Data =
|
||||||
{
|
{
|
||||||
{ "Playable", { 0, "", "#1ebc61", QObject::tr("Playable"), QObject::tr("Games that can be properly played from start to finish") } },
|
{ "Playable", { 0, "", "#1ebc61", QObject::tr("Playable"), QObject::tr("Games that can be properly played from start to finish") } },
|
||||||
|
@ -49,6 +50,9 @@ class game_compatibility : public QObject
|
||||||
std::unique_ptr<QNetworkAccessManager> m_network_access_manager;
|
std::unique_ptr<QNetworkAccessManager> m_network_access_manager;
|
||||||
std::map<std::string, compat_status> m_compat_database;
|
std::map<std::string, compat_status> m_compat_database;
|
||||||
|
|
||||||
|
/** Creates new map from the database */
|
||||||
|
bool ReadJSON(const QJsonObject& json_data, bool after_download);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Handles reads, writes and downloads for the compatibility database */
|
/** Handles reads, writes and downloads for the compatibility database */
|
||||||
game_compatibility(std::shared_ptr<gui_settings> settings);
|
game_compatibility(std::shared_ptr<gui_settings> settings);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue