Exemple #1
0
void ToolManager::reloadTools(DesuraId id)
{
	//missing tools. Gather info again
	XML::gcXMLDocument doc;

	m_pUser->getWebCore()->getItemInfo(id, doc, MCFBranch(), MCFBuild());

	auto uNode = doc.GetRoot("iteminfo");

	if (!uNode.IsValid())
		return;

	uint32 ver = doc.ProcessStatus("iteminfo");

	if (ver == 1)
	{
		auto toolNode = uNode.FirstChildElement("toolinfo");

		if (toolNode.IsValid())
			parseXml(toolNode);
	}
	else
	{
		uNode.FirstChildElement("platforms").for_each_child("platform", [&](const XML::gcXMLElement &platform)
		{
			if (!m_pUser->platformFilter(platform, PlatformType::PT_Tool))
				parseXml(platform.FirstChildElement("toolinfo"));
		});
	}
}
void WebCoreClass::getInstalledItemList(XML::gcXMLDocument &xmlDocument)
{
	HttpHandle hh(getInstalledWizardUrl().c_str());
	setWCCookies(hh);
	hh->getWeb();

	if (hh->getDataSize() == 0)
		throw gcException(ERR_BADRESPONSE);

	if (strncmp(hh->getData(), "BZh", 3)==0)
	{
		uint32 bufSize = hh->getDataSize() *25;

		UTIL::MISC::Buffer buff(bufSize);
		UTIL::BZIP::BZ2DBuff(buff, &bufSize, const_cast<char*>(hh->getData()), hh->getDataSize());

		xmlDocument.LoadBuffer(buff, bufSize);
	}
	else
	{
		xmlDocument.LoadBuffer(const_cast<char*>(hh->getData()), hh->getDataSize());
	}

	xmlDocument.ProcessStatus("itemwizard");
}
const XML::gcXMLElement WebCoreClass::postToServer(std::string url, std::string resource, PostMap &postData, XML::gcXMLDocument &xmlDocument, bool useHTTPS)
{
	gcString httpOut;

	if (m_bDebuggingOut)
	{
		if (url.find('?') == std::string::npos)
			url += "?XDEBUG_SESSION_START=xdebug";
		else
			url += "&XDEBUG_SESSION_START=xdebug";
	}

	gcTrace("Hitting api {0}", url);

	{
		HttpHandle hh(url.c_str(), useHTTPS);

		if (useHTTPS)
		{
			hh->setUserAgent(getUserAgent());

			if (m_bValidateCert)
				hh->setCertFile(UTIL::STRING::toStr(UTIL::OS::getDataPath(L"ca-bundle.crt")).c_str());
		}
		else
		{
			setWCCookies(hh);
		}

		PostMap::iterator it = postData.begin();

		while (it != postData.end())
		{
			hh->addPostText(it->first.c_str(), it->second.c_str());
			it++;
		}

		hh->postWeb();
	
		if (hh->getDataSize() == 0)
			throw gcException(ERR_BADRESPONSE, "Data size was zero");

		xmlDocument.LoadBuffer(const_cast<char*>(hh->getData()), hh->getDataSize());

		if (m_bDebuggingOut)
			httpOut.assign(const_cast<char*>(hh->getData()), hh->getDataSize());
	}

	xmlDocument.ProcessStatus(resource);
	return xmlDocument.GetRoot(resource);
}
void InstalledWizardThread::doRun()
{
	m_szDbName = getCIBDb(getUserCore()->getAppDataPath());

	XML::gcXMLDocument doc;
	getWebCore()->getInstalledItemList(doc);


	int ver = doc.ProcessStatus("itemwizard");

	auto infoNode = doc.GetRoot("itemwizard");

	if (!infoNode.IsValid())
		throw gcException(ERR_BADXML);

	auto wMng = gcRefPtr<WildcardManager>::create();
	wMng->onNeedSpecialEvent += delegate(&onNeedWCEvent);
	wMng->onNeedSpecialEvent += delegate(&getUserCore()->getNeedWildCardEvent());


	if (isStopped())
		return;

	parseItemsQuick(infoNode);

	MCFCore::Misc::ProgressInfo pi = MCFCore::Misc::ProgressInfo();
	pi.percent = 0;
	onMcfProgressEvent(pi);

	if (ver == 1)
		parseItems1(infoNode, wMng);
	else
		parseItems2(infoNode, wMng);

	if (m_pTaskGroup)
	{
		m_pTaskGroup->finalize();
		m_pTaskGroup = nullptr;
	}

	try
	{
		createCIPDbTables(getUserCore()->getAppDataPath());

		sqlite3x::sqlite3_connection db(m_szDbName.c_str());
		sqlite3x::sqlite3_command cmd(db, "REPLACE INTO cipiteminfo (internalid, name) VALUES (?,?);");

		sqlite3x::sqlite3_transaction trans(db);

		for (size_t x=0; x<m_vGameList.size(); x++)
		{
			cmd.bind(1, (long long int)m_vGameList[x].getId().toInt64());
			cmd.bind(2, std::string(m_vGameList[x].getName()) );
			cmd.executenonquery();
		}

		trans.commit();
	}
	catch (std::exception &e)
	{
		Warning("Failed to update cip item list: {0}\n", e.what());
	}


	pi.percent = 100;
	onMcfProgressEvent(pi);

	uint32 prog = 0;
	onCompleteEvent(prog);
}
void UpdateThreadOld::parseXML(const XML::gcXMLDocument &doc)
{
	auto pUser = gcRefPtr<UserCore::User>::dyn_cast(m_pUser);

	if (!pUser)
		return;

	int version = 1;

	try
	{
		version = doc.ProcessStatus("updatepoll");
	}
	catch (gcException &e)
	{
		Warning("Update poll had bad status in xml! Status: {0}\n", e);
		return;
	}

	auto uNode = doc.GetRoot("updatepoll");

	if (!uNode.IsValid())
		return;

	auto tempNode = uNode.FirstChildElement("cookies");


	if (tempNode.IsValid())
	{
		gcString szSessCookie;
		tempNode.GetChild("session", szSessCookie);

		if (szSessCookie != "")
			m_pWebCore->setCookie(szSessCookie.c_str());
	}

	tempNode = uNode.FirstChildElement("messages");

	if (tempNode.IsValid())
	{
		int32 up = -1;
		int32 pm = -1;
		int32 cc = -1;
		int32 th = -1;

		tempNode.GetChild("updates", up);
		tempNode.GetChild("privatemessages", pm);
		tempNode.GetChild("cart", cc);
		tempNode.GetChild("threadwatch", th);

		pUser->setCounts(pm, up, th, cc);
	}

	if (!pUser->isAltProvider())
		checkAppUpdate(uNode);
	else
		Warning("Skipping app update check due to alt provider\n");

	tempNode = uNode.FirstChildElement("member");

	if (tempNode.IsValid())
	{
		tempNode = tempNode.FirstChildElement("avatar");

		if (tempNode.IsValid() && !tempNode.GetText().empty())
			m_pUser->setAvatarUrl(tempNode.GetText().c_str());
	}

	if (version == 1)
	{
		tempNode = uNode.FirstChildElement("items");

		if (tempNode.IsValid())
			pUser->getItemManager()->itemsNeedUpdate(tempNode);
	}
	else
	{
		tempNode = uNode.FirstChildElement("platforms");

		if (tempNode.IsValid())
			pUser->getItemManager()->itemsNeedUpdate2(tempNode);
	}

	tempNode = uNode.FirstChildElement("news");

	if (tempNode.IsValid())
		pUser->parseNews(tempNode);


	tempNode = uNode.FirstChildElement("gifts");

	if (tempNode.IsValid())
		pUser->parseGifts(tempNode);
}