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);
}
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);
}