mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
GeckoCodeConfig: Use Curl instead of SFML::Http
This commit is contained in:
@ -2,19 +2,30 @@
|
|||||||
// Licensed under GPLv2+
|
// Licensed under GPLv2+
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "Core/GeckoCodeConfig.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <SFML/Network/Http.hpp>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
#include "Common/IniFile.h"
|
#include "Common/IniFile.h"
|
||||||
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
#include "Core/GeckoCodeConfig.h"
|
|
||||||
|
|
||||||
namespace Gecko
|
namespace Gecko
|
||||||
{
|
{
|
||||||
|
static size_t DownloadCodesWriteCallback(void* contents, size_t size, size_t nmemb,
|
||||||
|
std::string* body)
|
||||||
|
{
|
||||||
|
size_t realsize = size * nmemb;
|
||||||
|
body->insert(body->end(), reinterpret_cast<char*>(contents),
|
||||||
|
reinterpret_cast<char*>(contents) + realsize);
|
||||||
|
return realsize;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded)
|
std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded)
|
||||||
{
|
{
|
||||||
switch (gameid[0])
|
switch (gameid[0])
|
||||||
@ -29,17 +40,28 @@ std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Http::Request req;
|
std::unique_ptr<CURL, decltype(&curl_easy_cleanup)> curl{curl_easy_init(), curl_easy_cleanup};
|
||||||
req.setUri("/txt.php?txt=" + gameid);
|
|
||||||
|
|
||||||
sf::Http http;
|
std::string endpoint{"http://geckocodes.org/txt.php?txt=" + gameid};
|
||||||
http.setHost("geckocodes.org");
|
curl_easy_setopt(curl.get(), CURLOPT_URL, endpoint.c_str());
|
||||||
|
curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT, 5);
|
||||||
const sf::Http::Response resp = http.sendRequest(req, sf::seconds(5));
|
std::string response_body;
|
||||||
|
curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, DownloadCodesWriteCallback);
|
||||||
|
curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &response_body);
|
||||||
|
|
||||||
*succeeded = true;
|
*succeeded = true;
|
||||||
if (sf::Http::Response::Ok != resp.getStatus())
|
CURLcode res = curl_easy_perform(curl.get());
|
||||||
|
if (res != CURLE_OK)
|
||||||
{
|
{
|
||||||
|
ERROR_LOG(COMMON, "DownloadCodes: Curl error: %s", curl_easy_strerror(res));
|
||||||
|
*succeeded = false;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
long response_code{0};
|
||||||
|
curl_easy_getinfo(curl.get(), CURLINFO_RESPONSE_CODE, &response_code);
|
||||||
|
if (response_code != 200)
|
||||||
|
{
|
||||||
|
WARN_LOG(COMMON, "DownloadCodes: Curl response code: %li", response_code);
|
||||||
*succeeded = false;
|
*succeeded = false;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -48,7 +70,7 @@ std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded)
|
|||||||
std::vector<GeckoCode> gcodes;
|
std::vector<GeckoCode> gcodes;
|
||||||
|
|
||||||
// parse the codes
|
// parse the codes
|
||||||
std::istringstream ss(resp.getBody());
|
std::istringstream ss(response_body);
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user