mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Move GeckoCodeDiag download logic to GeckoCodeConfig
This commit is contained in:
@ -7,12 +7,131 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <SFML/Network/Http.hpp>
|
||||
|
||||
#include "Common/IniFile.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Core/GeckoCodeConfig.h"
|
||||
|
||||
namespace Gecko
|
||||
{
|
||||
std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded)
|
||||
{
|
||||
switch (gameid[0])
|
||||
{
|
||||
case 'R':
|
||||
case 'S':
|
||||
case 'G':
|
||||
break;
|
||||
default:
|
||||
// All channels (WiiWare, VirtualConsole, etc) are identified by their first four characters
|
||||
gameid = gameid.substr(0, 4);
|
||||
break;
|
||||
}
|
||||
|
||||
sf::Http::Request req;
|
||||
req.setUri("/txt.php?txt=" + gameid);
|
||||
|
||||
sf::Http http;
|
||||
http.setHost("geckocodes.org");
|
||||
|
||||
const sf::Http::Response resp = http.sendRequest(req, sf::seconds(5));
|
||||
|
||||
*succeeded = true;
|
||||
if (sf::Http::Response::Ok != resp.getStatus())
|
||||
{
|
||||
*succeeded = false;
|
||||
return {};
|
||||
}
|
||||
|
||||
// temp vector containing parsed codes
|
||||
std::vector<GeckoCode> gcodes;
|
||||
|
||||
// parse the codes
|
||||
std::istringstream ss(resp.getBody());
|
||||
|
||||
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.size())
|
||||
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;
|
||||
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.size())
|
||||
gcodes.push_back(gcode);
|
||||
|
||||
return gcodes;
|
||||
}
|
||||
|
||||
std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localIni)
|
||||
{
|
||||
std::vector<GeckoCode> gcodes;
|
||||
|
Reference in New Issue
Block a user