mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-08-26 12:16:20 +00:00
remove download gecko codes capability
This commit is contained in:
parent
4e00af9220
commit
c6c92764a8
4 changed files with 0 additions and 156 deletions
|
@ -16,113 +16,6 @@
|
||||||
|
|
||||||
namespace Gecko
|
namespace Gecko
|
||||||
{
|
{
|
||||||
std::vector<GeckoCode> DownloadCodes(std::string gametdb_id, bool* succeeded)
|
|
||||||
{
|
|
||||||
// codes.rc24.xyz is a mirror of the now defunct geckocodes.org.
|
|
||||||
std::string endpoint{"https://codes.rc24.xyz/txt.php?txt=" + gametdb_id};
|
|
||||||
Common::HttpRequest http;
|
|
||||||
|
|
||||||
// The server always redirects once to the same location.
|
|
||||||
http.FollowRedirects(1);
|
|
||||||
|
|
||||||
const Common::HttpRequest::Response response = http.Get(endpoint);
|
|
||||||
*succeeded = response.has_value();
|
|
||||||
if (!response)
|
|
||||||
return {};
|
|
||||||
|
|
||||||
// temp vector containing parsed codes
|
|
||||||
std::vector<GeckoCode> gcodes;
|
|
||||||
|
|
||||||
// parse the codes
|
|
||||||
std::istringstream ss(std::string(response->begin(), response->end()));
|
|
||||||
|
|
||||||
std::string line;
|
|
||||||
|
|
||||||
// seek past the header, get to the first code
|
|
||||||
std::getline(ss, line);
|
|
||||||
std::getline(ss, line);
|
|
||||||
std::getline(ss, line);
|
|
||||||
|
|
||||||
int read_state = 0;
|
|
||||||
GeckoCode gcode;
|
|
||||||
|
|
||||||
while ((std::getline(ss, line).good()))
|
|
||||||
{
|
|
||||||
// Remove \r at the end of the line for files using windows line endings, std::getline only
|
|
||||||
// removes \n
|
|
||||||
line = StripSpaces(line);
|
|
||||||
|
|
||||||
if (line.empty())
|
|
||||||
{
|
|
||||||
// add the code
|
|
||||||
if (!gcode.codes.empty())
|
|
||||||
gcodes.push_back(gcode);
|
|
||||||
gcode = GeckoCode();
|
|
||||||
read_state = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (read_state)
|
|
||||||
{
|
|
||||||
// read new code
|
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
std::istringstream ssline(line);
|
|
||||||
// stop at [ character (beginning of contributor name)
|
|
||||||
std::getline(ssline, gcode.name, '[');
|
|
||||||
gcode.name = StripSpaces(gcode.name);
|
|
||||||
gcode.user_defined = true;
|
|
||||||
// read the code creator name
|
|
||||||
std::getline(ssline, gcode.creator, ']');
|
|
||||||
read_state = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// read code lines
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
std::istringstream ssline(line);
|
|
||||||
std::string addr, data;
|
|
||||||
|
|
||||||
// Some locales (e.g. fr_FR.UTF-8) don't split the string stream on space
|
|
||||||
// Use the C locale to workaround this behavior
|
|
||||||
ssline.imbue(std::locale::classic());
|
|
||||||
|
|
||||||
ssline >> addr >> data;
|
|
||||||
ssline.seekg(0);
|
|
||||||
|
|
||||||
// check if this line a code, silly, but the dumb txt file comment lines can start with
|
|
||||||
// valid hex chars :/
|
|
||||||
if (8 == addr.length() && 8 == data.length())
|
|
||||||
{
|
|
||||||
GeckoCode::Code new_code;
|
|
||||||
new_code.original_line = line;
|
|
||||||
ssline >> std::hex >> new_code.address >> new_code.data;
|
|
||||||
gcode.codes.push_back(new_code);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gcode.notes.push_back(line);
|
|
||||||
read_state = 2; // start reading comments
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// read comment lines
|
|
||||||
case 2:
|
|
||||||
// append comment line
|
|
||||||
gcode.notes.push_back(line);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the last code
|
|
||||||
if (!gcode.codes.empty())
|
|
||||||
gcodes.push_back(gcode);
|
|
||||||
|
|
||||||
return gcodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localIni)
|
std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localIni)
|
||||||
{
|
{
|
||||||
std::vector<GeckoCode> gcodes;
|
std::vector<GeckoCode> gcodes;
|
||||||
|
|
|
@ -13,6 +13,5 @@ class IniFile;
|
||||||
namespace Gecko
|
namespace Gecko
|
||||||
{
|
{
|
||||||
std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localIni);
|
std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localIni);
|
||||||
std::vector<GeckoCode> DownloadCodes(std::string gametdb_id, bool* succeeded);
|
|
||||||
void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes);
|
void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes);
|
||||||
} // namespace Gecko
|
} // namespace Gecko
|
||||||
|
|
|
@ -75,11 +75,7 @@ void GeckoCodeWidget::CreateWidgets()
|
||||||
m_add_code = new QPushButton(tr("&Add New Code..."));
|
m_add_code = new QPushButton(tr("&Add New Code..."));
|
||||||
m_edit_code = new QPushButton(tr("&Edit Code..."));
|
m_edit_code = new QPushButton(tr("&Edit Code..."));
|
||||||
m_remove_code = new QPushButton(tr("&Remove Code"));
|
m_remove_code = new QPushButton(tr("&Remove Code"));
|
||||||
m_download_codes = new QPushButton(tr("Download Codes"));
|
|
||||||
|
|
||||||
m_download_codes->setToolTip(tr("Download Codes from the WiiRD Database"));
|
|
||||||
|
|
||||||
m_download_codes->setEnabled(!m_game_id.empty());
|
|
||||||
m_edit_code->setEnabled(false);
|
m_edit_code->setEnabled(false);
|
||||||
m_remove_code->setEnabled(false);
|
m_remove_code->setEnabled(false);
|
||||||
|
|
||||||
|
@ -111,7 +107,6 @@ void GeckoCodeWidget::CreateWidgets()
|
||||||
btn_layout->addWidget(m_add_code);
|
btn_layout->addWidget(m_add_code);
|
||||||
btn_layout->addWidget(m_edit_code);
|
btn_layout->addWidget(m_edit_code);
|
||||||
btn_layout->addWidget(m_remove_code);
|
btn_layout->addWidget(m_remove_code);
|
||||||
btn_layout->addWidget(m_download_codes);
|
|
||||||
|
|
||||||
layout->addLayout(btn_layout);
|
layout->addLayout(btn_layout);
|
||||||
|
|
||||||
|
@ -131,7 +126,6 @@ void GeckoCodeWidget::ConnectWidgets()
|
||||||
connect(m_add_code, &QPushButton::clicked, this, &GeckoCodeWidget::AddCode);
|
connect(m_add_code, &QPushButton::clicked, this, &GeckoCodeWidget::AddCode);
|
||||||
connect(m_remove_code, &QPushButton::clicked, this, &GeckoCodeWidget::RemoveCode);
|
connect(m_remove_code, &QPushButton::clicked, this, &GeckoCodeWidget::RemoveCode);
|
||||||
connect(m_edit_code, &QPushButton::clicked, this, &GeckoCodeWidget::EditCode);
|
connect(m_edit_code, &QPushButton::clicked, this, &GeckoCodeWidget::EditCode);
|
||||||
connect(m_download_codes, &QPushButton::clicked, this, &GeckoCodeWidget::DownloadCodes);
|
|
||||||
connect(m_warning, &CheatWarningWidget::OpenCheatEnableSettings, this,
|
connect(m_warning, &CheatWarningWidget::OpenCheatEnableSettings, this,
|
||||||
&GeckoCodeWidget::OpenGeneralSettings);
|
&GeckoCodeWidget::OpenGeneralSettings);
|
||||||
}
|
}
|
||||||
|
@ -295,43 +289,3 @@ void GeckoCodeWidget::UpdateList()
|
||||||
|
|
||||||
m_code_list->setDragDropMode(QAbstractItemView::InternalMove);
|
m_code_list->setDragDropMode(QAbstractItemView::InternalMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeckoCodeWidget::DownloadCodes()
|
|
||||||
{
|
|
||||||
bool success;
|
|
||||||
|
|
||||||
std::vector<Gecko::GeckoCode> codes = Gecko::DownloadCodes(m_gametdb_id, &success);
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
{
|
|
||||||
ModalMessageBox::critical(this, tr("Error"), tr("Failed to download codes."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (codes.empty())
|
|
||||||
{
|
|
||||||
ModalMessageBox::critical(this, tr("Error"), tr("File contained no codes."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t added_count = 0;
|
|
||||||
|
|
||||||
for (const auto& code : codes)
|
|
||||||
{
|
|
||||||
auto it = std::find(m_gecko_codes.begin(), m_gecko_codes.end(), code);
|
|
||||||
|
|
||||||
if (it == m_gecko_codes.end())
|
|
||||||
{
|
|
||||||
m_gecko_codes.push_back(code);
|
|
||||||
added_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateList();
|
|
||||||
SaveCodes();
|
|
||||||
|
|
||||||
ModalMessageBox::information(
|
|
||||||
this, tr("Download complete"),
|
|
||||||
tr("Downloaded %1 codes. (added %2)")
|
|
||||||
.arg(QString::number(codes.size()), QString::number(added_count)));
|
|
||||||
}
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ private:
|
||||||
void AddCode();
|
void AddCode();
|
||||||
void EditCode();
|
void EditCode();
|
||||||
void RemoveCode();
|
void RemoveCode();
|
||||||
void DownloadCodes();
|
|
||||||
void SaveCodes();
|
void SaveCodes();
|
||||||
void SortAlphabetically();
|
void SortAlphabetically();
|
||||||
|
|
||||||
|
@ -68,7 +67,6 @@ private:
|
||||||
QPushButton* m_add_code;
|
QPushButton* m_add_code;
|
||||||
QPushButton* m_edit_code;
|
QPushButton* m_edit_code;
|
||||||
QPushButton* m_remove_code;
|
QPushButton* m_remove_code;
|
||||||
QPushButton* m_download_codes;
|
|
||||||
std::vector<Gecko::GeckoCode> m_gecko_codes;
|
std::vector<Gecko::GeckoCode> m_gecko_codes;
|
||||||
bool m_restart_required;
|
bool m_restart_required;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue