2011-06-18 09:00:42 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2011
|
|
|
|
* by Dimok
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any
|
|
|
|
* damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any
|
|
|
|
* purpose, including commercial applications, and to alter it and
|
|
|
|
* redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you
|
|
|
|
* must not claim that you wrote the original software. If you use
|
|
|
|
* this software in a product, an acknowledgment in the product
|
|
|
|
* documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
|
|
|
***************************************************************************/
|
|
|
|
#include "Wiinnertag.h"
|
|
|
|
#include "FileOperations/fileops.h"
|
|
|
|
#include "settings/CSettings.h"
|
|
|
|
#include "network/networkops.h"
|
2019-11-11 18:09:59 +01:00
|
|
|
#include "network/https.h"
|
2011-06-18 09:00:42 +02:00
|
|
|
#include "utils/StringTools.h"
|
2016-11-06 16:01:54 +01:00
|
|
|
#include "xml/tinyxml2.h"
|
2011-06-18 09:00:42 +02:00
|
|
|
#include "gecko.h"
|
|
|
|
|
2016-11-06 16:01:54 +01:00
|
|
|
using namespace tinyxml2;
|
|
|
|
|
2021-08-01 19:00:15 +02:00
|
|
|
Wiinnertag::Wiinnertag(const std::string &filepath)
|
2011-06-18 09:00:42 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
ReadXML(filepath);
|
2011-06-18 09:00:42 +02:00
|
|
|
}
|
|
|
|
|
2021-08-01 19:00:15 +02:00
|
|
|
bool Wiinnertag::ReadXML(const std::string &filepath)
|
2011-06-18 09:00:42 +02:00
|
|
|
{
|
2016-11-06 16:01:54 +01:00
|
|
|
XMLDocument xmlDoc;
|
|
|
|
if(xmlDoc.LoadFile(filepath.c_str()) != 0)
|
2011-07-26 00:28:22 +02:00
|
|
|
return false;
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2016-11-06 16:01:54 +01:00
|
|
|
XMLElement * node = xmlDoc.FirstChildElement("Tag");
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
while(node != NULL)
|
|
|
|
{
|
|
|
|
const char * URL = node->Attribute("URL");
|
|
|
|
const char * Key = node->Attribute("Key");
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if(URL && Key)
|
|
|
|
{
|
|
|
|
int size = tagList.size();
|
|
|
|
tagList.resize(size+1);
|
|
|
|
tagList[size].first = URL;
|
|
|
|
tagList[size].second = Key;
|
|
|
|
}
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
node = node->NextSiblingElement();
|
|
|
|
}
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return true;
|
2011-06-18 09:00:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Wiinnertag::Send(const char *gameID)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if(!IsNetworkInit())
|
|
|
|
return false;
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
char sendURL[1024];
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
for(u32 i = 0; i < tagList.size(); ++i)
|
|
|
|
{
|
|
|
|
strcpy(sendURL, tagList[i].first.c_str());
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
replaceString(sendURL, "{ID6}", gameID);
|
|
|
|
replaceString(sendURL, "{KEY}", tagList[i].second.c_str());
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2019-11-11 18:09:59 +01:00
|
|
|
struct download file = {};
|
2020-11-08 22:29:44 +01:00
|
|
|
file.skip_response = true;
|
2019-11-11 18:09:59 +01:00
|
|
|
downloadfile(sendURL, &file);
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return true;
|
2011-06-18 09:00:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Wiinnertag::TagGame(const char *gameID)
|
|
|
|
{
|
2021-08-01 19:00:15 +02:00
|
|
|
std::string fullpath = Settings.WiinnertagPath;
|
2011-07-26 00:28:22 +02:00
|
|
|
if(fullpath.size() == 0)
|
|
|
|
return false;
|
2011-06-22 19:57:37 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if(fullpath[fullpath.size()-1] != '/')
|
|
|
|
fullpath += '/';
|
|
|
|
fullpath += "Wiinnertag.xml";
|
2011-06-22 19:57:37 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
Wiinnertag Tag(fullpath);
|
|
|
|
return Tag.Send(gameID);
|
2011-06-18 09:00:42 +02:00
|
|
|
}
|
|
|
|
|
2021-08-01 19:00:15 +02:00
|
|
|
bool Wiinnertag::CreateExample(const std::string &filepath)
|
2011-06-18 09:00:42 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if(filepath.size() == 0)
|
|
|
|
return false;
|
2011-06-22 19:57:37 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
CreateSubfolder(filepath.c_str());
|
2011-06-25 21:50:57 +02:00
|
|
|
|
2021-08-01 19:00:15 +02:00
|
|
|
std::string fullpath = filepath;
|
2011-07-26 00:28:22 +02:00
|
|
|
if(fullpath[fullpath.size()-1] != '/')
|
|
|
|
fullpath += '/';
|
|
|
|
fullpath += "Wiinnertag.xml";
|
2011-06-22 19:57:37 +02:00
|
|
|
|
2016-11-06 16:01:54 +01:00
|
|
|
XMLDocument xmlDoc;
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2016-11-06 16:01:54 +01:00
|
|
|
XMLDeclaration * declaration = xmlDoc.NewDeclaration();
|
2011-07-26 00:28:22 +02:00
|
|
|
xmlDoc.InsertEndChild(declaration);
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2016-11-06 16:01:54 +01:00
|
|
|
XMLElement *Tag = xmlDoc.NewElement("Tag");
|
2020-07-09 03:10:05 +02:00
|
|
|
Tag->SetAttribute("URL", "https://tag.rc24.xyz/wii?game={ID6}&key={KEY}");
|
2016-11-06 16:01:54 +01:00
|
|
|
Tag->SetAttribute("Key", "1234567890");
|
2011-06-25 21:50:57 +02:00
|
|
|
xmlDoc.InsertEndChild(Tag);
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2016-11-06 16:01:54 +01:00
|
|
|
xmlDoc.SaveFile(fullpath.c_str());
|
2011-06-18 09:00:42 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return true;
|
2011-06-18 09:00:42 +02:00
|
|
|
}
|