Exemple #1
0
bool User::platformFilter(const XML::gcXMLElement &platform, PlatformType type)
{
	if (!platform.IsValid())
		return true;

	uint32 id = 0;
	platform.GetAtt("id", id);

	if (id == 0)
		return true;

#ifdef WIN32
	return (id != 100);
#elif defined NIX
	if (type == PT_Tool)
		return (id != 110 && id != 120);
#ifdef NIX64
	if (id == 120)
		return false;
#endif
	//linux will have windows and nix
	return (id != 110); //id != 100 && 
#else
	return true;
#endif
}
void InstalledWizardThread::parseMod(DesuraId parId, DesuraId id, const XML::gcXMLElement &mod, gcRefPtr<WildcardManager> &pWildCard, const XML::gcXMLElement &info)
{
	gcString name = mod.GetChild("name");

	if (name == "" && info.IsValid())
		name = info.GetChild("name");

	if (name == "")
		return;

	if (m_bTriggerNewEvent)
		onNewItemEvent(name);

	triggerProgress();

	m_uiDone++;

	UserCore::Misc::InstallInfo temp(id, parId);

	try
	{
		temp.loadXmlData(mod, pWildCard);

		if (m_bTriggerNewEvent)
			onModFound(temp);
	}
	catch (gcException &except)
	{
		Warning("ItemWizard: Error in xml parsing (installed wizard, mods): {0}\n", except);
	}
}
Exemple #3
0
void BranchInfo::processInstallScript(const XML::gcXMLElement &xmlElement)
{
	uint32 crc = 0;
	xmlElement.GetAtt("crc", crc);

	if (UTIL::FS::isValidFile(m_szInstallScript))
	{
		if (crc != 0 && m_uiInstallScriptCRC == (uint32)crc)
			return;
	}
	else
	{
		m_szInstallScript = UTIL::OS::getAppDataPath(gcWString(L"{0}\\{1}\\install_script.js", m_ItemId.getFolderPathExtension(), getBranchId()).c_str());
	}

	gcString base64 = xmlElement.GetText();

	try
	{
		UTIL::FS::recMakeFolder(UTIL::FS::Path(m_szInstallScript, "", true));
		UTIL::FS::FileHandle fh(m_szInstallScript.c_str(), UTIL::FS::FILE_WRITE);
		UTIL::STRING::base64_decode(base64, [&fh](const unsigned char* data, uint32 size) -> bool
		{
			fh.write((const char*)data, size);
			return true;
		});

		m_uiInstallScriptCRC = crc;
	}
	catch (gcException &e)
	{
		Warning("Failed to save install script for {0} branch {1}: {2}\n", m_ItemId.toInt64(), m_uiBranchId, e);
		m_szInstallScript = "";
	}
}
void InstalledWizardThread::parseItemsQuick(const XML::gcXMLElement &fNode)
{
	if (!fNode.IsValid())
		return;

	auto platforms = fNode.FirstChildElement("platforms");

	if (platforms.IsValid())
	{
		platforms.for_each_child("platform", [&](const XML::gcXMLElement &platform)
		{
			if (isStopped())
				return;

			if (getUserCore()->platformFilter(platform, PlatformType::Item))
				return;

			parseItemsQuick(platform);
		});
	}
	else
	{
		fNode.FirstChildElement("games").for_each_child("game", [&](const XML::gcXMLElement &game)
		{
			if (isStopped())
				return;

			const std::string id = game.GetAtt("siteareaid");
			DesuraId gameId(id.c_str(), "games");

			if (gameId.isOk())
				parseGameQuick(game);
		});
	}
}
Exemple #5
0
void User::parseNewsAndGifts(const XML::gcXMLElement &xmlNode, const char* szChildName, Event<std::vector<UserCore::Misc::NewsItem*> > &onEvent)
{
	if (!xmlNode.IsValid())
		return;

	std::vector<UserCore::Misc::NewsItem*> itemList;

	xmlNode.for_each_child(szChildName, [&itemList](const XML::gcXMLElement &itemElem)
	{
		const std::string szId = itemElem.GetAtt("id");

		gcString szTitle;
		gcString szUrl;

		itemElem.GetChild("title", szTitle);
		itemElem.GetChild("url", szUrl);
			
		if (szId.empty() || szTitle.empty() || szUrl.empty())
			return;

		uint32 id = (uint32)Safe::atoi(szId.c_str());

		UserCore::Misc::NewsItem *temp = new UserCore::Misc::NewsItem(id, 0, szTitle.c_str(), szUrl.c_str());
		itemList.push_back(temp);
	});

	if (itemList.size() > 0)
		onEvent(itemList);

	safe_delete(itemList);
}
void InstalledWizardThread::parseItems1(const XML::gcXMLElement &fNode, gcRefPtr<WildcardManager> &pWildCard, std::map<uint64, XML::gcXMLElement> *vMap)
{
	gcAssert(pWildCard);

	if (!fNode.IsValid())
		return;

	fNode.FirstChildElement("games").for_each_child("game", [&](const XML::gcXMLElement &game)
	{
		if (isStopped())
			return;

		const std::string szId = game.GetAtt("siteareaid");
		DesuraId gameId(szId.c_str(), "games");

		if (!gameId.isOk())
			return;

		XML::gcXMLElement info;

		if (vMap)
			info = (*vMap)[gameId.toInt64()];

		parseGame(gameId, game, pWildCard, info);
	});
}
void InstalledWizardThread::parseGameQuick(const XML::gcXMLElement &game)
{
	if (!game.IsValid())
		return;

	m_uiTotal++;

	game.FirstChildElement("mods").for_each_child("mod", [&](const XML::gcXMLElement &)
	{
		m_uiTotal++;
	});
}
Exemple #8
0
void InstallInfo::loadXmlData(const XML::gcXMLElement &xmlNode, WildcardManager* pWildCard)
{
	WildcardManager lwc(pWildCard);

	auto wcNode = xmlNode.FirstChildElement("wcards");
	if (wcNode.IsValid())
	{
		lwc.parseXML(wcNode);
	}

	xmlNode.GetChild("name", m_szName);
	auto icsNode = xmlNode.FirstChildElement("settings").FirstChildElement("installlocations");

	if (!icsNode.IsValid())
		return;
		
	icsNode.for_each_child("installlocation", [&](const XML::gcXMLElement &xmlChild)
	{
		if (m_bInstalled)
			return;

		const std::string path = xmlChild.GetChild("path");
		const std::string check = xmlChild.GetChild("check");

		if (path.empty() || check.empty())
			return;

		char* CheckRes = nullptr;
		char* PathRes = nullptr;

		try
		{
			lwc.constructPath(check.c_str(), &CheckRes);
			lwc.constructPath(path.c_str(), &PathRes);

			if (CheckRes && PathRes && UTIL::FS::isValidFile(UTIL::FS::PathWithFile(CheckRes)))
			{
				m_szPath = PathRes;
				m_bInstalled = true;
			}
		}
		catch (gcException &e)
		{
			Debug(gcString("InstallInfo: Error parsing wildcards for installInfo: {0}\n", e));
		}

		safe_delete(CheckRes);
		safe_delete(PathRes);
	});
}
Exemple #9
0
uint8 UMcf::parseXml(const XML::gcXMLElement &xmlElement)
{
    if (!xmlElement.IsValid())
        return UMCF_ERR_XML_NOPRIMENODE;

    xmlElement.for_each_child("file", [this](const XML::gcXMLElement &xmlChild)
    {
        auto temp = std::make_shared<UMcfFile>();

        if (temp->loadXmlData(xmlChild) == UMCF_OK)
            m_pFileList.push_back(temp);
    });

    return UMCF_OK;
}
void BranchInstallInfo::extractInstallChecks(const XML::gcXMLElement &icsNode, gcRefPtr<WildcardManager> &pWildCard, std::vector<InsCheck> &vInsChecks)
{
	icsNode.for_each_child("installlocation", [&vInsChecks, pWildCard, this](const XML::gcXMLElement &icNode)
	{
		const gcString iCheck = icNode.GetChild("check");
		const gcString iPath = icNode.GetChild("path");

		if (iCheck.empty() || iPath.empty())
			return;

		try
		{
			gcString strCheckRes = pWildCard->constructPath(iCheck.c_str());

			if (isInstalled())
			{
				if (!updateInstallCheck(strCheckRes, iPath))
					return;

				vInsChecks.push_back(InsCheck(strCheckRes.c_str(), m_szPath.c_str()));
			}
			else
			{
				vInsChecks.push_back(InsCheck(strCheckRes.c_str(), iPath.c_str()));
			}
		}
		catch (...)
		{
		}
	});
}
uint8 WildcardManager::parseXML(const XML::gcXMLElement &xmlElement)
{
	if (!xmlElement.IsValid())
		return WCM_ERR_BADXML;

	xmlElement.for_each_child("wcard", [this](const XML::gcXMLElement &xmlChild)
	{
		const std::string name = xmlChild.GetAtt("name");
		const std::string type = xmlChild.GetAtt("type");
		const std::string string = xmlChild.GetText();
			
		if (!name.empty() && !type.empty() && !string.empty())
		{
			addItem(new WildcardInfo(name, string, type));
		}
	});

	return WCM_OK;
}
void InstalledWizardThread::parseItems2(const XML::gcXMLElement &fNode, gcRefPtr<WildcardManager> &pWildCard)
{
	gcAssert(pWildCard);

	if (!fNode.IsValid())
		return;

	std::map<uint64, XML::gcXMLElement> vMap;

	fNode.FirstChildElement("games").for_each_child("game", [&](const XML::gcXMLElement &game)
	{
		if (isStopped())
			return;

		const std::string szId = game.GetAtt("siteareaid");
		DesuraId gameId(szId.c_str(), "games");

		if (gameId.isOk())
			vMap[gameId.toInt64()] = game;
	});

	fNode.FirstChildElement("platforms").for_each_child("platform", [&](const XML::gcXMLElement &platform)
	{
		if (isStopped())
			return;

		if (getUserCore()->platformFilter(platform, PlatformType::Item))
			return;

		auto wm = gcRefPtr<WildcardManager>::create(pWildCard);
		auto wildCardNode = platform.FirstChildElement("wcards");

		if (wildCardNode.IsValid())
		{
			wm->parseXML(wildCardNode);
			wm->compactWildCards();
		}

		parseItems1(platform, wm, &vMap);
	});
}
Exemple #13
0
void Theme::LoadSprites(const XML::gcXMLElement &xmlEl)
{
	xmlEl.for_each_child("sprite", [this](const XML::gcXMLElement &xmlChild)
	{
		const std::string name = xmlChild.GetAtt("name");

		if (name.empty())
			return;

		auto sprite = SpriteList::findItem(name.c_str());

		if (!sprite)
		{
			sprite = gcRefPtr<ThemeSpriteInfo>::create(name.c_str());
			addItem(sprite);
		}

		xmlChild.for_each_child("rect", [sprite](const XML::gcXMLElement &xmlRect)
		{
			const std::string rName = xmlRect.GetAtt("name");

			const XML::gcXMLElement pos = xmlRect.FirstChildElement("pos");
			const XML::gcXMLElement size = xmlRect.FirstChildElement("size");

			if (rName.empty() || !pos.IsValid() || !size.IsValid())
				return;

			const std::string x = pos.GetAtt("x");
			const std::string y = pos.GetAtt("y");

			const std::string w = size.GetAtt("w");
			const std::string h = size.GetAtt("h");

			if (x.empty() || y.empty() || w.empty() || h.empty())
				return;

			auto rect = sprite->findItem(rName.c_str());

			if (!rect)
			{
				rect = gcRefPtr<SpriteRect>::create(rName.c_str());
				sprite->addItem(rect);
			}

			rect->x = Safe::atoi(x.c_str());
			rect->y = Safe::atoi(y.c_str());
			rect->w = Safe::atoi(w.c_str());
			rect->h = Safe::atoi(h.c_str());
		});
	});
}
Exemple #14
0
void Theme::LoadImages(const UTIL::FS::Path& path, const XML::gcXMLElement &xmlEl)
{
	xmlEl.for_each_child("image", [this, &path](const XML::gcXMLElement &xmlChild)
	{
		const std::string name = xmlChild.GetAtt("name");
		const std::string val = xmlChild.GetText();

		if (name.empty() || val.empty())
			return;

		std::string outVal = UTIL::STRING::sanitizeFileName(val);
		auto img = ImageList::findItem(name.c_str());

		if (!img)
		{
			img = gcRefPtr<ThemeImageInfo>::create(name.c_str());
			addItem(img);
		}

		gcString fullPath("{0}{2}images{2}app{2}{1}", path.getFolderPath(), outVal, DIRS_STR);
		img->path = fullPath;
	});
}
Exemple #15
0
void Theme::LoadControls(const XML::gcXMLElement &xmlEl)
{
	xmlEl.for_each_child("control", [this](const XML::gcXMLElement &xmlChild)
	{
		const std::string name = xmlChild.GetAtt("name");

		if (name.empty())
			return;

		auto control = ControlList::findItem(name.c_str());

		if (!control)
		{
			control = gcRefPtr<ThemeControlInfo>::create(name.c_str());
			addItem(control);
		}

		xmlChild.for_each_child("color", [control](const XML::gcXMLElement &xmlCol)
		{
			const std::string id = xmlCol.GetAtt("id");
			const std::string val = xmlCol.GetText();

			if (id.empty() || val.empty())
				return;

			auto col = control->findItem(id.c_str());

			if (!col)
			{
				col = gcRefPtr<ThemeColorInfo>::create(id.c_str());
				control->add(col);
			}

			col->color = Color(val.c_str());
		});
	});
}
Exemple #16
0
void Theme::LoadWeb(const UTIL::FS::Path& path, const XML::gcXMLElement &xmlEl)
{
	gcString urlPath(path.getFolderPath());

	for (size_t x=0; x<urlPath.size(); x++)
	{
		if (urlPath[x] == '\\')
			urlPath[x] = '/';
	}

	xmlEl.for_each_child("page", [this, urlPath](const XML::gcXMLElement &xmlChild)
	{
		const std::string name = xmlChild.GetAtt("name");
		const std::string val = xmlChild.GetText();

		if (name.empty() || val.empty())
			return;

		std::string outVal = UTIL::STRING::sanitizeFileName(val);

#ifdef WIN32
		gcString fullPath("file:///{0}/html/{1}", urlPath, outVal);
#else
		gcString fullPath("file://{0}/html/{1}", urlPath, outVal);
#endif

		auto web = WebList::findItem(name.c_str());

		if (!web)
		{
			web = gcRefPtr<ThemeWebInfo>::create(name.c_str());
			addItem(web);
		}

		web->path = fullPath;
	});
}
Exemple #17
0
void BranchInfo::loadXmlData(const XML::gcXMLElement &xmlNode)
{
	xmlNode.GetChild("name", m_szName);
	xmlNode.GetChild("price", m_szCost);
	xmlNode.GetChild("eula", m_szEulaUrl);

	auto eNode = xmlNode.FirstChildElement("eula");

	if (eNode.IsValid())
	{
		const std::string date = eNode.GetAtt("date");

		if (!date.empty() && m_szEulaDate != date)
		{
			m_uiFlags &= ~BF_ACCEPTED_EULA;
			m_szEulaDate = date;
		}
	}

	gcString preload;
	xmlNode.GetChild("preload", preload);

	if (m_szPreOrderDate.size() > 0 && (preload.size() == 0 || preload == "0"))
	{
		m_szPreOrderDate = "";
		m_uiFlags &= ~BF_PREORDER;

		onBranchInfoChangedEvent();
	}
	else if (preload != "0")
	{
		m_szPreOrderDate = preload;
		m_uiFlags |= BF_PREORDER;

		onBranchInfoChangedEvent();
	}


	bool nameon = false;
	bool free = false;
	bool onaccount = false;
	bool regionlock = false;
	bool memberlock = false;
	bool demo = false;
	bool test = false;
	bool cdkey = false;
	gcString cdkeyType;

	xmlNode.GetChild("nameon", nameon);
	xmlNode.GetChild("free", free);
	xmlNode.GetChild("onaccount", onaccount);
	xmlNode.GetChild("regionlock", regionlock);
	xmlNode.GetChild("inviteonly", memberlock);
	xmlNode.GetChild("demo", demo);
	xmlNode.GetChild("test", test);
	xmlNode.GetChild("cdkey", cdkey);
	xmlNode.FirstChildElement("cdkey").GetAtt("type", cdkeyType);

	uint32 global = -1;
	xmlNode.GetChild("global", global);

	if (global != -1)
		m_uiGlobalId = MCFBranch::BranchFromInt(global, true);

	if (nameon)
		m_uiFlags |= BF_DISPLAY_NAME;

	if (free)
		m_uiFlags |= BF_FREE;

	if (onaccount)
		m_uiFlags |= BF_ONACCOUNT;

	if (regionlock)
		m_uiFlags |= BF_REGIONLOCK;

	if (memberlock)
		m_uiFlags |= BF_MEMBERLOCK;

	if (demo)
		m_uiFlags |= BF_DEMO;

	if (test)
		m_uiFlags |= BF_TEST;

	if (cdkey)
		m_uiFlags |= BF_CDKEY;

	if (cdkeyType == "steam")
		m_uiFlags |= BF_STEAMGAME;

	//no mcf no release
	auto mcfNode = xmlNode.FirstChildElement("mcf");
	if (!mcfNode.IsValid())
	{
		m_uiFlags |= BF_NORELEASES;
	}
	else
	{
		m_uiFlags &= ~BF_NORELEASES;

		uint32 build = -1;
		mcfNode.GetChild("build", build);

		m_uiLatestBuild = MCFBuild::BuildFromInt(build);
	}

	auto toolsNode = xmlNode.FirstChildElement("tools");

	if (toolsNode.IsValid())
	{
		m_vToolList.clear();

		toolsNode.for_each_child("tool", [this](const XML::gcXMLElement &xmlTool)
		{
			const std::string id = xmlTool.GetText();

			if (!id.empty())
				m_vToolList.push_back(DesuraId(id.c_str(), "tools"));
		});
	}

	auto scriptNode = xmlNode.FirstChildElement("installscript");

	if (scriptNode.IsValid())
		processInstallScript(scriptNode);
}
void InstalledWizardThread::parseGame(DesuraId id, const XML::gcXMLElement &game, gcRefPtr<WildcardManager> &pWildCard, const XML::gcXMLElement &info)
{
	pWildCard->updateInstallWildcard("INSTALL_PATH", "INSTALL_PATH");
	pWildCard->updateInstallWildcard("PARENT_INSTALL_PATH", "%INSTALL_PATH%");


	gcString name = game.GetChild("name");

	if (name == "" && info.IsValid())
		name = info.GetChild("name");

	if (name == "")
		return;

	if (m_bTriggerNewEvent)
		onNewItemEvent(name);

	triggerProgress();
	m_uiDone++;

	UserCore::Misc::InstallInfo temp(id);

	try
	{
		if (info.IsValid())
			temp.loadXmlData(info, pWildCard);

		temp.loadXmlData(game, pWildCard);
	}
	catch (gcException &except)
	{
		Warning("ItemWizard: Error in xml parsing (installed wizard, games): {0}\n", except);
		return;
	}

	if (m_bTriggerNewEvent)
		onGameFound(temp);
	else
		m_vGameList.push_back(temp);

	pWildCard->updateInstallWildcard("INSTALL_PATH", "INSTALL_PATH");
	pWildCard->updateInstallWildcard("PARENT_INSTALL_PATH", temp.getPath());

	std::map<uint64, XML::gcXMLElement> mModMap;

	info.FirstChildElement("mods").for_each_child("mods", [&mModMap, this](const XML::gcXMLElement &mod)
	{
		if (isStopped())
			return;

		const std::string szId = mod.GetAtt("siteareaid");
		DesuraId internId(szId.c_str(), "mods");

		if (internId.isOk())
			mModMap[internId.toInt64()] = mod;
	});

	game.FirstChildElement("mods").for_each_child("mods", [&](const XML::gcXMLElement &mod)
	{
		if (isStopped())
			return;

		const std::string szId = mod.GetAtt("siteareaid");
		DesuraId internId(szId.c_str(), "mods");

		if (internId.isOk())
			parseMod(id, internId, mod, pWildCard, mModMap[internId.toInt64()]);
	});
}
Exemple #19
0
void ToolManager::parseXml(const XML::gcXMLElement &toolinfoNode)
{
	if (!toolinfoNode.IsValid())
		return;	

	auto toolsNode = toolinfoNode.FirstChildElement("tools");

	if (!toolsNode.IsValid())
		return;

	WildcardManager wcm;

	wcm.onNeedInstallSpecialEvent += delegate(this, &ToolManager::onSpecialCheck);
	wcm.onNeedSpecialEvent += delegate(m_pUser->getNeedWildCardEvent());

	auto wildcardNode = toolinfoNode.FirstChildElement("wcards");

	if (wildcardNode.IsValid())
		wcm.parseXML(wildcardNode);

	//clear the java path value
	WildcardInfo* temp = wcm.findItem("JAVA_EXE");

	if (temp)
	{
		temp->m_szPath = "";
		temp->m_bResolved = true;
	}

	bool is64OS = UTIL::OS::is64OS();

	toolsNode.for_each_child("tool", [this, is64OS, &wcm](const XML::gcXMLElement &toolEl)
	{
		bool isTool64 = false;
		toolEl.GetChild("bit64", isTool64);

		if (isTool64 && !is64OS)
			return;

		const std::string id = toolEl.GetAtt("siteareaid");

		if (id.empty())
			return;

		DesuraId tid(id.c_str(), "tools");
		ToolInfo* tool = this->findItem(tid.toInt64());

		bool bAdd = false;

		if (!tool)
		{
			tool = new ToolInfo(tid);
			bAdd = true;
		}

		tool->parseXml(toolEl, &wcm, m_pUser->getAppDataPath());

		if (bAdd)
			this->addItem(tool);
	});
	
	postParseXml();
}
void UpdateThreadOld::checkAppUpdate(const XML::gcXMLElement &uNode, std::function<void(uint32, uint32, bool)> &updateCallback)
{
	auto processAppVersion = [&](const char* szNodeName, uint32 &appid, uint32 &mcfversion)
	{
		appid = 0;
		mcfversion = 0;

		auto appEl = uNode.FirstChildElement(szNodeName);

		if (!appEl.IsValid())
			return false;

		auto id = appEl.GetAtt("id");
		auto ver = appEl.GetText();

		if (!id.empty())
			appid = Safe::atoi(id.c_str());

		if (!ver.empty())
			mcfversion = Safe::atoi(ver.c_str());

		return appid != 0 && mcfversion != 0;
	};

	auto isInternalApp = [](uint32 appid)
	{
		return appid >= 500 && appid < 600;
	};

	uint32 mcfversion = 0;
	uint32 appid = 0;
	bool bIsNewerVersion = false;
	bool bIsForced = false;

	bool bIsQa = false;

#ifdef DESURA_OFFICIAL_BUILD
	if (m_bInternalTesting)
	{
		Msg("Checking internal testing for app update...\n");

		if (!processAppVersion("apptesting", appid, mcfversion) || !isInternalApp(appid))
		{
			Warning("Failed to find qa testing build on update poll");

			if (!processAppVersion("app", appid, mcfversion))
				return;
		}
		else
		{
			Msg(gcString("Found qa app build {0}.{1}\n", appid, mcfversion));

			if (m_bForceTestingUpdate)
			{
				Msg("Forcing testing update..\n");

				bIsForced = true;
				bIsNewerVersion = true;
			}

			m_bForceTestingUpdate = false;
			bIsQa = true;
		}
	}
	else if (!processAppVersion("app", appid, mcfversion))
	{
		return;
	}
#else
	if (!processAppVersion("app", appid, mcfversion))
	{
		return;
	}
#endif

	auto bNewerOriginalBranch = (m_uiLastAppId == 0) && (appid == m_iAppId) && (mcfversion > m_iAppVersion);
	auto bNewerLastUpdateBranch = (appid == m_uiLastAppId) && (mcfversion > m_uiLastVersion);
	auto bDiffBranch = (appid != m_iAppId) && (appid != m_uiLastAppId);

	if (bNewerLastUpdateBranch || bNewerOriginalBranch || bDiffBranch)
		bIsNewerVersion = true;

	if (bIsNewerVersion)
	{

#ifdef WIN32
		if (bIsQa && mcfversion > 0)
		{
			//need to set appver back a build otherwise updater will ignore this build due to it being older than current
			gcString strAppid("{0}", appid);
			gcString strAppVer("{0}", mcfversion - 1);

			m_pUser->getInternal()->getServiceMain()->updateRegKey(APPID, strAppid.c_str());
			m_pUser->getInternal()->getServiceMain()->updateRegKey(APPBUILD, strAppVer.c_str());
		}
#endif

		updateCallback(appid, mcfversion, bIsForced);
		m_uiLastAppId = appid;
		m_uiLastVersion = mcfversion;
	}
}