Esempio n. 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"));
		});
	}
}
Esempio n. 2
0
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()();
}
Esempio n. 3
0
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");
}
Esempio n. 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;
}
Esempio n. 5
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);
}
Esempio n. 6
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"));
}
Esempio n. 7
0
		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;
		}
Esempio n. 8
0
void UMcf::dumpXml(const wchar_t* path)
{
    if (!path)
        return;

    XML::gcXMLDocument doc;

    auto root = doc.Create("appupdate");
    auto mcfElFiles = root.NewElement("mcf");

    mcfElFiles.SetAttribute("build",  m_sHeader->getBuild());
    mcfElFiles.SetAttribute("appid",  m_sHeader->getId());

    auto filesElFiles = mcfElFiles.NewElement( "files" );

    for (auto file : m_pFileList)
    {
        auto el = filesElFiles.NewElement("file");
        file->genXml(el);
    }

    doc.SaveFile(gcString(path).c_str());
}
Esempio n. 9
0
gcWString GameExplorerInfo::generateXml()
{
	gcString szName = m_pItemInfo->getName();
	gcString szVersion("1.0.0.0"); //{0}.{1}", (int)m_pItemInfo->getInstalledBranch(), (int)m_pItemInfo->getInstalledBuild());
	gcString szDevUrl = m_pItemInfo->getDevProfile();
	gcString szDevName = m_pItemInfo->getDev();

	gcString szPub = m_pItemInfo->getPublisher();
	gcString szPubUrl = m_pItemInfo->getPublisherProfile();

	if (szPub.size() == 0)
		szPub = "Unknown";

	if (szPubUrl.size() == 0)
		szPubUrl = "http://";



	gcString szPlayLink("desura://launch/{0}/{1}", m_Id.getTypeString(), m_pItemInfo->getShortName());
	gcString szChangeLogLink("{0}/{1}/{2}/changelog", m_pUser->getWebCore()->getUrl(WebCore::Root), m_Id.getTypeString(), m_pItemInfo->getShortName());
	gcString szProfileLink = m_pItemInfo->getProfile();

	gcString szDescription = m_pItemInfo->getName();
	gcString szReleaseData = "2010-01-01";

	gcString szUninstallLink("desura://uninstall/{0}/{1}", m_Id.getTypeString(), m_pItemInfo->getShortName());
	gcString szVerifyLink("desura://verify/{0}/{1}", m_Id.getTypeString(), m_pItemInfo->getShortName());

	gcString szGenere(m_pItemInfo->getGenre());
	
	std::vector<gcRefPtr<UserCore::Item::Misc::ExeInfoI>> vExeList;
	m_pItemInfo->getExeList(vExeList);


	if (m_szGuid == "")
		m_szGuid = generateGuid();

	if (szGenere.size() == 0)
		szGenere = "Unknown";

	XML::gcXMLDocument doc;

	auto gameDefFile = doc.Create("GameDefinitionFile", "xml version=\"1.0\" encoding=\"utf-16\"");
	auto gameDef = gameDefFile.NewElement("GameDefinition");


	gameDefFile.SetAttribute("xmlns:baseTypes", "urn:schemas-microsoft-com:GamesExplorerBaseTypes.v1");
	gameDefFile.SetAttribute("xmlns", "urn:schemas-microsoft-com:GameDescription.v1");
	gameDef.SetAttribute("gameID", m_szGuid.c_str());


	gameDef.WriteChild("Name", szName);
	gameDef.WriteChild("Description", szDescription);
	gameDef.WriteChild("ReleaseDate", szReleaseData);

	auto genres = gameDef.NewElement("Genres");
	genres.WriteChild("Genre", szGenere);
		
	WriteChildWithChildAndAtt("Version", "VersionNumber", "versionNumber", szVersion.c_str(), gameDef);

	auto dev = gameDef.NewElement("Developers").NewElement("Developer");
	dev.SetAttribute("URI", szDevUrl.c_str());
	dev.SetText(szDevName.c_str());


	auto publisher = gameDef.NewElement("Publishers").NewElement("Publisher");
	publisher.SetAttribute("URI", szPubUrl.c_str());
	publisher.SetText(szPub.c_str());

	
	if (vExeList.size() > 0)
	{
		auto gameExecutables = gameDef.NewElement("GameExecutables");

		for (size_t x=0; x<vExeList.size(); x++)
		{
			gcString szGameExe(UTIL::FS::PathWithFile(vExeList[x]->getExe()).getFile().getFile());

			auto gameExe = gameExecutables.NewElement("GameExecutable");
			gameExe.SetAttribute("path", szGameExe.c_str());
		}
	}

	int i = 1;



	auto extProps = gameDef.NewElement("ExtendedProperties");
	auto gameTasks = extProps.NewElement("GameTasks");
	auto playTask = gameTasks.NewElement("Play");

	WriteChildWithChildAndAtt("Primary", "URLTask", "Link", szPlayLink.c_str(), playTask);

	if (vExeList.size() > 1)
	{
		for (size_t x=0; x<vExeList.size(); x++)
		{
			gcString play("Play: {0}", vExeList[x]->getName());
			gcString link("desura://launch/{0}/{1}/{2}", m_Id.getTypeString(), m_pItemInfo->getShortName(), vExeList[x]->getName());

			auto changeLog = WriteChildWithChildAndAtt("Task", "URLTask", "Link", link.c_str(), playTask);
			changeLog.SetAttribute("index", i);
			changeLog.SetAttribute("name", play.c_str());
			i++;
		}
	}

	if (m_pItemInfo->isDownloadable())
	{
		auto changeLog = WriteChildWithChildAndAtt("Task", "URLTask", "Link", szChangeLogLink.c_str(), playTask);
		changeLog.SetAttribute("index", i);
		changeLog.SetAttribute("name", "View Update History");
		i++;
	}
		
		
	auto profile = WriteChildWithChildAndAtt("Task", "URLTask", "Link", szProfileLink.c_str(), playTask);
	profile.SetAttribute("index", i);
	profile.SetAttribute("name", "View Profile");
	i++;
		

	uint32 count = 0;
	for (uint32 x=0; x<m_pItemInfo->getBranchCount(); x++)
	{
		auto bi = m_pItemInfo->getBranch(x);

		if (!bi)
			continue;

		if (bi->getBranchId() == m_pItemInfo->getInstalledBranch())
			continue;

		if (bi->getFlags()&UserCore::Item::BranchInfoI::BF_NORELEASES)
			continue;

		if (!(bi->getFlags()&UserCore::Item::BranchInfoI::BF_ONACCOUNT) && !(bi->getFlags()&UserCore::Item::BranchInfoI::BF_FREE))
			continue;

		gcString name("Install Branch: {0}", bi->getName());
		gcString link("desura://install/{0}/{1}/{2}", m_Id.getTypeString(), m_pItemInfo->getShortName(), bi->getBranchId());

		auto branch = WriteChildWithChildAndAtt("Task", "URLTask", "Link", link.c_str(), playTask);
		branch.SetAttribute("index", x+i);
		branch.SetAttribute("name", name.c_str());
			
	}


	auto supportTask = gameTasks.NewElement("Support");

	auto verify = WriteChildWithChildAndAtt("Task", "URLTask", "Link", szVerifyLink.c_str(), supportTask);
	verify.SetAttribute("index", 0);
	verify.SetAttribute("name", "Verify Files");

	auto uninstall = WriteChildWithChildAndAtt("Task", "URLTask", "Link", szUninstallLink.c_str(), supportTask);
	uninstall.SetAttribute("index", 1);
	uninstall.SetAttribute("name", "Uninstall");


	gcWString res;
	res.resize(1);

	res[0] = 0xFF + (0xFE<<8);
	res += doc.ToWString(false);

	return res;
}
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);
}
Esempio n. 11
0
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;
}
Esempio n. 12
0
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);
}