Пример #1
0
void ToolManager::addJSTool(UserCore::Item::ItemInfo* item, uint32 branchId, gcString name, gcString exe, gcString args, gcString res)
{
	if (!item)
		return;

	UserCore::Item::BranchInfoI* branch = item->getBranchById(branchId);

	if (!branch)
		return;

	UserCore::Item::BranchInfo* realBranch = dynamic_cast<UserCore::Item::BranchInfo*>(branch);

	if (!realBranch)
		return;

	bool found = false;


	JSToolInfo* jsinfo = nullptr;

	BaseManager<ToolInfo>::for_each([&](ToolInfo* info)
	{
		auto temp = dynamic_cast<JSToolInfo*>(info);

		if (!temp)
			return;

		if (item->getId() == temp->getItemId() && name == info->getName() && temp->getBranchId() == branchId)
		{
			jsinfo = temp;
			found = true;
		}
	});

	if (found)
	{
		if (!jsinfo->isRealyInstalled())
			jsinfo->setExePath(exe.c_str());

		return;
	}


	DesuraId toolId(m_iLastCustomToolId, DesuraId::TYPE_TOOL);
	m_iLastCustomToolId--;

	JSToolInfo* tool = new JSToolInfo(item->getId(), realBranch->getBranchId(), toolId, name, exe, args, res);
	realBranch->addJSTool(toolId);
	addItem(tool);
}
Пример #2
0
void CreateMCFThread::processBranches(std::vector<UserCore::Item::BranchInfo*> &outList, TiXmlElement* item)
{
	XML::for_each_child("branch", item->FirstChildElement("branches"), [this, &outList](TiXmlElement* branch)
	{
		uint32 id = 0;
		XML::GetAtt("id", id, branch);

		if (id == 0)
			return;

		UserCore::Item::BranchInfo *bi = new UserCore::Item::BranchInfo(MCFBranch::BranchFromInt(id), this->getItemId(), NULL);
		bi->loadXmlData(branch);

		if (!HasAnyFlags(bi->getFlags(), UserCore::Item::BranchInfoI::BF_NORELEASES))
			outList.push_back(bi);
		else
			safe_delete(bi);
	});
}
Пример #3
0
void ToolManager::addJSTool(UserCore::Item::ItemInfo* item, uint32 branchId, gcString name, gcString exe, gcString args, gcString res)
{
	if (!item)
		return;

	UserCore::Item::BranchInfoI* branch = item->getBranchById(branchId);

	if (!branch)
		return;

	UserCore::Item::BranchInfo* realBranch = dynamic_cast<UserCore::Item::BranchInfo*>(branch);

	if (!realBranch)
		return;

	bool found = false;

	BaseManager<ToolInfo>::for_each([&](ToolInfo* info)
	{
		JSToolInfo* jsinfo = dynamic_cast<JSToolInfo*>(info);

		if (!jsinfo)
			return;

		if (item->getId() == jsinfo->getItemId() && name == info->getName() && jsinfo->getBranchId() == branchId)
			found = true;
	});

	if (found)
		return;

	DesuraId toolId(m_iLastCustomToolId, DesuraId::TYPE_TOOL);
	m_iLastCustomToolId--;

	JSToolInfo* tool = new JSToolInfo(item->getId(), realBranch->getBranchId(), toolId, name, exe, args, res);
	realBranch->addJSTool(toolId);
	addItem(tool);
}
Пример #4
0
void CreateMCFThread::compareBranches(std::vector<UserCore::Item::BranchInfo*> &vBranchList)
{
	uint64 lastSize = 0;
	//uint32 lastIndex = 0;                    unused variable

	McfHandle lastMcf;

	m_hMCFile->setHeader(getItemId(), MCFBranch(), MCFBuild());
	m_hMCFile->getHeader()->setParent(0);


	for (size_t x=0; x<vBranchList.size(); x++)
	{
		if (isStopped())
			return;

		UserCore::Item::BranchInfo* bi = vBranchList[x];

		McfHandle tempMcf;
		tempMcf->setHeader(getItemId(), bi->getBranchId(), MCFBuild());
		tempMcf->getErrorEvent() += delegate(&onErrorEvent);
	
		try
		{
			MCFCore::Misc::UserCookies uc;
			getWebCore()->setMCFCookies(&uc); 
			tempMcf->getDownloadProviders(getWebCore()->getMCFDownloadUrl(), &uc);
		}
		catch (gcException &except)
		{
			Warning(gcString("CreateMCF: Failed to get download providers for mcf: {0}\n", except));
			continue;
		}

		if (tempMcf->getHeader()->getBuild() > 0)
		{
			try
			{
				tempMcf->dlHeaderFromWeb();
			}
			catch (gcException &except)
			{
				Warning(gcString("CreateMCF: Failed to get dlHeaderFromWeb for mcf: {0}\n", except));
				continue;
			}

			uint64 totalSize = 0;
			uint32 fileCount = 0;
			m_hMCFile->getPatchStats(tempMcf.handle(), &totalSize, &fileCount);

			if (lastSize == 0 || totalSize < lastSize)
			{
				lastSize = totalSize;
				//lastIndex = x;
				lastMcf.setHandle(tempMcf.releaseHandle());

				// if there are no files just use this one
				if (fileCount == 0)
					break;
			}
		}
	}

	MCFBuild build = lastMcf->getHeader()->getBuild();
	MCFBranch branch = lastMcf->getHeader()->getBranch();

	m_hMCFile->setHeader(getItemId(), branch, build);

	if (build > 0)
		m_hMCFile->getHeader()->addFlags( MCFCore::MCFHeaderI::FLAG_PARTFILE );
	else
		m_hMCFile->getHeader()->delFlags( MCFCore::MCFHeaderI::FLAG_PARTFILE );

	m_hMCFile->getHeader()->setParent(lastMcf->getHeader()->getBuild());
	m_hMCFile->makePatch(lastMcf.handle());
}