Example #1
0
void UMcf::parseUpdateXml(const XML::gcXMLDocument &xmlDocument)
{
    auto uNode = xmlDocument.GetRoot("appupdate");

    if (!uNode.IsValid())
        return;

    auto mcfNode = uNode.FirstChildElement("mcf");

    if (!mcfNode.IsValid())
        return;


    const std::string appid = mcfNode.GetAtt("appid");

    if (!appid.empty())
        m_iAppId = Safe::atoi(appid.c_str());
    else
        m_iAppId = 100;

    const std::string build = mcfNode.GetAtt("build");

    if (!build.empty())
        m_iAppBuild = Safe::atoi(build.c_str());
    else
        m_iAppBuild = 0;

    mcfNode.GetChild("url", m_szUrl);
    parseXml(mcfNode.FirstChildElement("files"));
}
Example #2
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 UpdateThreadOld::loadLoginItems()
{
	auto im = gcRefPtr<UserCore::ItemManager>::dyn_cast(m_pUser->getItemManager());

	XML::gcXMLDocument doc;

	try
	{
		m_pWebCore->getLoginItems(doc);

		auto first = doc.GetRoot("memberdata");
		im->parseLoginXml2(first.FirstChildElement("games"), first.FirstChildElement("platforms"));
	}
	catch (gcException &e)
	{
		Warning("Failed to get login items: {0}\n", e);
	}

	im->enableSave();

#ifdef WIN32
	m_pUser->getThreadPool()->queueTask(gcRefPtr<UpdateUninstallTask>::create(m_pUser));
#endif

	m_pUser->getLoginItemsLoadedEvent()();
}
Example #4
0
gcString WebCoreClass::getAppUpdateDownloadUrl(uint32 &appId, uint32 &appBuild)
{
	gcAssert(appId);

	PostMap postData;

	postData["appid"] = appId;

	if (appBuild > 0)
		postData["build"] = appBuild;

	XML::gcXMLDocument doc;
	postToServer(getAppUpdateUrl(), "appupdate", postData, doc);

	auto mNode = doc.GetRoot("appupdate").FirstChildElement("mcf");

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

	mNode.GetAtt("appid", appId);
	mNode.GetAtt("build", appBuild);

	if (appId == 0 || appBuild == 0)
		throw gcException(ERR_BADXML);

	gcString url = mNode.GetChild("url");

	if (url.size() == 0)
		throw gcException(ERR_BADXML);

	return url;
}
		bool checkUpdate(uint32 appid, uint32 build)
		{
			XML::gcXMLDocument doc;
			doc.Create("apps");
			auto el = doc.GetRoot("apps").NewElement("app");
			el.SetAttribute("id", appid);
			el.SetText(gcString("{0}", build).c_str());

			bool bNeedsUpdate = false;

			std::function<void(uint32,uint32, bool)> callback = [&](uint32, uint32, bool)
			{
				bNeedsUpdate = true;
			};

			thread.checkAppUpdate(doc.GetRoot("apps"), callback);
			return bNeedsUpdate;
		}
Example #6
0
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 MCFDownloadProviders::processXml(XML::gcXMLDocument &doc)
{
	auto uNode = doc.GetRoot("itemdownloadurl");
	auto iNode = uNode.FirstChildElement("item");

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

	auto mNode = iNode.FirstChildElement("mcf");

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

	{
		const std::string szBuild = mNode.GetAtt("build");
		const std::string szBranch = mNode.GetAtt("branch");

		MCFBuild build;
		MCFBranch branch;

		if (!szBuild.empty())
			build = MCFBuild::BuildFromInt(Safe::atoi(szBuild.c_str()));

		if (!szBranch.empty())
			branch = MCFBranch::BranchFromInt(Safe::atoi(szBranch.c_str()));

		if (m_bInit)
		{
			if (m_Build != build)
				throw new gcException(ERR_BADRESPONSE, "Build didn't match expected build");

			if (m_Branch != branch)
				throw new gcException(ERR_BADRESPONSE, "Branch didn't match expected branch");
		}
		else
		{
			m_Branch = branch;
			m_Build = build;
		}
	}

	if (!m_bInit)
	{
		const std::string szAuthCode = mNode.GetChild("authhash");

		if (szAuthCode.empty())
			throw gcException(ERR_BADXML);

		auto temp = std::make_shared<MCFCore::Misc::GetFile_s>();

		Safe::strncpy(temp->authhash.data(), 33, szAuthCode.c_str(), szAuthCode.size());
		Safe::snprintf(temp->authkey.data(), 10, "%d", m_nUserId);

		m_DownloadAuth = temp;

		bool bAuthed = true;
		if (mNode.GetChild("authed", bAuthed))
			m_bUnAuthed = !bAuthed;
	}

	auto urlNode = mNode.FirstChildElement("urls");

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

	urlNode.for_each_child("url", [this](const XML::gcXMLElement &xmlChild)
	{
		auto p = std::make_shared<MCFCore::Misc::DownloadProvider>(xmlChild);

		auto bFound = false;

		for (auto x : m_vDownloadProviders)
		{
			if (gcString(p->getUrl()) == x->getUrl())
			{
				bFound = true;
				break;
			}
		}

		if (!bFound)
			m_vDownloadProviders.push_back(p);
	});

	if (!m_bInit)
		m_nFirstCount = m_vDownloadProviders.size();

	m_bInit = true;
}
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);
}