Allow editing the cheats URL via the config file

This commit is contained in:
wiidev 2021-08-01 18:00:17 +01:00
parent 34149ea92c
commit f0fef6fe56
3 changed files with 27 additions and 8 deletions

View File

@ -1459,11 +1459,14 @@ int CodeDownload(const char *id)
char txtpath[250]; char txtpath[250];
int txtLen = snprintf(txtpath, sizeof(txtpath), "%s%s.txt", Settings.TxtCheatcodespath, id); int txtLen = snprintf(txtpath, sizeof(txtpath), "%s%s.txt", Settings.TxtCheatcodespath, id);
char codeurl[80]; char codeurl[300];
snprintf(codeurl, sizeof(codeurl), "https://codes.rc24.xyz/txt.php?txt=%s", id);
struct download file = {}; struct download file = {};
downloadfile(codeurl, &file); std::string url(Settings.URL_Cheats);
if(url.find("{gameid}") != url.npos)
{
url.replace(url.find("{gameid}"), 8, id);
downloadfile(url.c_str(), &file);
}
if (file.size <= 0) { if (file.size <= 0) {
gprintf("Trying backup...\n"); gprintf("Trying backup...\n");
snprintf(codeurl, sizeof(codeurl), "https://web.archive.org/web/202009if_/geckocodes.org/txt.php?txt=%s", id); snprintf(codeurl, sizeof(codeurl), "https://web.archive.org/web/202009if_/geckocodes.org/txt.php?txt=%s", id);

View File

@ -88,6 +88,7 @@ void CSettings::SetDefault()
strlcpy(URL_Discs, "https://art.gametdb.com/wii/disc/", sizeof(URL_Discs)); strlcpy(URL_Discs, "https://art.gametdb.com/wii/disc/", sizeof(URL_Discs));
strlcpy(URL_DiscsCustom, "https://art.gametdb.com/wii/disccustom/", sizeof(URL_DiscsCustom)); strlcpy(URL_DiscsCustom, "https://art.gametdb.com/wii/disccustom/", sizeof(URL_DiscsCustom));
strlcpy(URL_GameTDB, "https://www.gametdb.com/wiitdb.zip", sizeof(URL_GameTDB)); strlcpy(URL_GameTDB, "https://www.gametdb.com/wiitdb.zip", sizeof(URL_GameTDB));
strlcpy(URL_Cheats, "https://codes.rc24.xyz/txt.php?txt={gameid}", sizeof(URL_Cheats));
ProxyUsername[0] = 0; ProxyUsername[0] = 0;
ProxyPassword[0] = 0; ProxyPassword[0] = 0;
ProxyAddress[0] = 0; ProxyAddress[0] = 0;
@ -508,6 +509,7 @@ bool CSettings::Save()
fprintf(file, "URL_Discs = %s\n", URL_Discs); fprintf(file, "URL_Discs = %s\n", URL_Discs);
fprintf(file, "URL_DiscsCustom = %s\n", URL_DiscsCustom); fprintf(file, "URL_DiscsCustom = %s\n", URL_DiscsCustom);
fprintf(file, "URL_GameTDB = %s\n", URL_GameTDB); fprintf(file, "URL_GameTDB = %s\n", URL_GameTDB);
fprintf(file, "URL_Cheats = %s\n", URL_Cheats);
fprintf(file, "ProxyUseSystem = %d\n", ProxyUseSystem); fprintf(file, "ProxyUseSystem = %d\n", ProxyUseSystem);
fprintf(file, "ProxyUsername = %s\n", ProxyUsername); fprintf(file, "ProxyUsername = %s\n", ProxyUsername);
fprintf(file, "ProxyPassword = %s\n", ProxyPassword); fprintf(file, "ProxyPassword = %s\n", ProxyPassword);
@ -518,15 +520,22 @@ bool CSettings::Save()
return true; return true;
} }
bool CSettings::ValidateURL(char *value, bool zip) bool CSettings::ValidateURL(char *value, int type)
{ {
if (strlen(value) >= 12 && (strncmp(value, "https://", 8) == 0 || strncmp(value, "http://", 7) == 0)) if (strlen(value) >= 12 && (strncmp(value, "https://", 8) == 0 || strncmp(value, "http://", 7) == 0))
{ {
if (zip) // GameTDB
if (type == 1)
{ {
if (strncmp(value + strlen(value) -4, ".zip", 4) == 0) // The URL must end with .zip to be valid if (strncmp(value + strlen(value) -4, ".zip", 4) == 0) // The URL must end with .zip to be valid
return true; return true;
} }
// Cheats
else if (type == 2)
{
if (strstr(value, "{gameid}") != NULL)
return true;
}
else else
{ {
if (strncmp(value + strlen(value) -1, "/", 1) == 0) // The URL must end with / to be valid if (strncmp(value + strlen(value) -1, "/", 1) == 0) // The URL must end with / to be valid
@ -1346,10 +1355,16 @@ bool CSettings::SetSetting(char *name, char *value)
} }
else if (strcmp(name, "URL_GameTDB") == 0) else if (strcmp(name, "URL_GameTDB") == 0)
{ {
if (ValidateURL(value, true)) if (ValidateURL(value, 1))
strlcpy(URL_GameTDB, value, sizeof(URL_GameTDB)); strlcpy(URL_GameTDB, value, sizeof(URL_GameTDB));
return true; return true;
} }
else if (strcmp(name, "URL_Cheats") == 0)
{
if (ValidateURL(value, 2))
strlcpy(URL_Cheats, value, sizeof(URL_Cheats));
return true;
}
else if (strcmp(name, "ProxyUseSystem") == 0) else if (strcmp(name, "ProxyUseSystem") == 0)
{ {
ProxyUseSystem = atoi(value); ProxyUseSystem = atoi(value);

View File

@ -99,6 +99,7 @@ class CSettings
char URL_Discs[300]; char URL_Discs[300];
char URL_DiscsCustom[300]; char URL_DiscsCustom[300];
char URL_GameTDB[300]; char URL_GameTDB[300];
char URL_Cheats[300];
char ProxyUsername[33]; char ProxyUsername[33];
char ProxyPassword[33]; char ProxyPassword[33];
char ProxyAddress[256]; char ProxyAddress[256];
@ -242,7 +243,7 @@ class CSettings
bool FirstTimeRun; bool FirstTimeRun;
protected: protected:
bool ValidVersion(FILE * file); bool ValidVersion(FILE * file);
bool ValidateURL(char *value, bool zip = false); bool ValidateURL(char *value, int type = 0);
bool SetSetting(char *name, char *value); bool SetSetting(char *name, char *value);
//!Find the config file in the default paths //!Find the config file in the default paths
bool FindConfig(); bool FindConfig();