Exemplo n.º 1
0
void UploadPrepThread::doRun()
{
	UTIL::FS::Path path = UTIL::FS::PathWithFile(m_szFile);

	if (!UTIL::FS::isValidFile(path))
		throw gcException(ERR_INVALIDFILE);


	McfHandle mcfHandle;;

	bool validMcf = false;

	mcfHandle->setFile(m_szFile.c_str());
	mcfHandle->parseMCF();

	MCFCore::MCFHeaderI* mcfHead = mcfHandle->getHeader();

	DesuraId mcfId = mcfHead->getDesuraId();
	DesuraId itemId =  getItemId();

	validMcf = (mcfHead->isValid() && (!mcfId.isOk() || mcfId == itemId));

	if (!validMcf)
		throw gcException(ERR_INVALIDMCF);


	std::string hash = UTIL::MISC::hashFile(path.getFullPath().c_str());
	uint64 fileSize = UTIL::FS::getFileSize(path);

	char* key = NULL;

	try
	{
		getWebCore()->newUpload(getItemId(), hash.c_str(), fileSize, &key);
	}
	catch (gcException &)
	{
		safe_delete(key);
		throw;
	}

	getUploadManager()->addUpload(getItemId(), key, m_szFile.c_str());
	m_szKey = gcString(key);
	safe_delete(key);

	onCompleteStrEvent(m_szKey);
}
Exemplo n.º 2
0
void GameExplorerManager::addItem(DesuraId item)
{
	if (!shouldInstallItems())
		return;

	if (!item.isOk())
		return;
	
	Misc::GameExplorerInfo* gei = BaseManager::findItem(item.toInt64());

	if (!gei)
	{
		gei = new Misc::GameExplorerInfo(item, m_pUser);
		BaseManager<Misc::GameExplorerInfo>::addItem(gei);
	}

	if (!gei->isInstallable() || !gei->needsInstall())
		return;

	gei->generateDll();
	gei->installDll();
}
Exemplo n.º 3
0
int InstallBranch::setInfo(DesuraId id, bool selectBranch)
{
	m_bSelectBranch = selectBranch;
	UserCore::Item::ItemInfoI* pItemInfo = GetUserCore()->getItemManager()->findItemInfo(id);

	if (!pItemInfo)
		return 1;

	m_bIsMod = id.getType() == DesuraId::TYPE_MOD;
	m_bIsExpansion = m_bIsMod == false && pItemInfo->getParentId().getType() == DesuraId::TYPE_GAME;

	m_Item = id;

	gcWString parName;
	gcWString itemName = pItemInfo->getName();
	
	DesuraId par = pItemInfo->getParentId();
	UserCore::Item::ItemInfoI *parInfo = NULL;
	if (par.isOk())
	{
		parInfo = GetUserCore()->getItemManager()->findItemInfo(par);

		if (parInfo)
			parName = gcWString(parInfo->getName());
	}

	fixName(parName);
	fixName(itemName);

	if (selectBranch == false && m_bIsMod)
	{
		m_labInfo->SetLabel(gcWString(Managers::GetString(L"#IF_NOTFOUND"), itemName, parName));
		m_labInfo->Wrap( 350 );
	}
	else if (selectBranch == false && m_bIsExpansion)
	{
		m_labInfo->SetLabel(gcWString(Managers::GetString(L"#IF_NOTFOUND_GAME"), itemName, parName));
		m_labInfo->Wrap( 350 );
	}
	else
	{
		m_labInfo->SetLabel(gcWString(Managers::GetString(L"#IF_BRANCHINFO"), itemName));
		m_labInfo->Wrap( 350 );
	}

	uint32 count = 0;
	int32 full = -1;
	uint32 fullReadyCount = 0;
	m_bBuy = true;

	UserCore::Item::ItemInfoI *i = pItemInfo;

	bool isCheckingParent = (m_bIsMod || m_bIsExpansion) && !selectBranch;

	if (isCheckingParent)
	{
		if (!parInfo)
		{
			gcMessageBox(GetParent(), Managers::GetString(L"#IF_IIPARENT"), Managers::GetString(L"#IF_IIERRTITLE"));
			return 1;
		}

		i = parInfo;
	}

	std::vector<UserCore::Item::BranchInfoI*> bList;

	for (uint32 x=0; x<i->getBranchCount(); x++)
	{
		UserCore::Item::BranchInfoI* bi = i->getBranch(x);

		if (!bi)
			continue;

		uint32 flags = bi->getFlags();

		bool noRelease = HasAllFlags(flags, UserCore::Item::BranchInfoI::BF_NORELEASES);
		bool isPreorder = bi->isPreOrder();
		bool isDemo = HasAnyFlags(flags, UserCore::Item::BranchInfoI::BF_DEMO);
		bool onAccount = HasAllFlags(flags, UserCore::Item::BranchInfoI::BF_ONACCOUNT);
		bool locked = HasAnyFlags(flags, UserCore::Item::BranchInfoI::BF_MEMBERLOCK|UserCore::Item::BranchInfoI::BF_REGIONLOCK);
		bool test = HasAnyFlags(flags, UserCore::Item::BranchInfoI::BF_TEST);
		bool free = HasAnyFlags(flags, UserCore::Item::BranchInfoI::BF_FREE);

		if (noRelease && !isPreorder)
			continue;

		if (!onAccount && locked)
			continue;
		
		if (!selectBranch && (isDemo || test))
			continue;

		if ((free || onAccount) && isPreorder && !selectBranch)
			continue;

		bool globalFound = false;

		for (size_t x=0; x<bList.size(); x++)
		{
			if (bList[x]->getGlobalId() == bi->getGlobalId())
			{
				globalFound = true;
				break;
			}
		}

		if (globalFound)
			continue;

		if (isDemo || test)
		{
		}
		else if (full == -1 || ((!m_bBuy || onAccount) && !free))
		{
			if (full == -1 || m_bBuy)
			{
				//if this is the first full game or this is the first full game that you dont have to buy
				m_bBuy = (!onAccount && !free);
				full = count;
			}
			
			if (onAccount || free)
				fullReadyCount++;
		}

		bList.push_back(bi);
		count++;
	}

	for (size_t x=0; x<bList.size(); x++)
	{
		UserCore::Item::BranchInfoI* bi = bList[x];
		gcString name = bi->getName();
		gcWString title;
		
		uint32 flags = bi->getFlags();

		bool noRelease = HasAllFlags(flags, UserCore::Item::BranchInfoI::BF_NORELEASES);
		bool isPreorder = bi->isPreOrder();
		bool onAccount = HasAllFlags(flags, UserCore::Item::BranchInfoI::BF_ONACCOUNT);
		bool free = HasAnyFlags(flags, UserCore::Item::BranchInfoI::BF_FREE);

		if (!free)
			title = gcString("{0} - {1}", name, Managers::GetString("#IF_BROUGHT"));
		else
			title = gcString("{0} - {1}", name, Managers::GetString("#IF_FREE"));
		
		if (!free && !onAccount)
		{
			gcWString cost(bi->getCost());

			if (cost == "")
				cost = gcString(Managers::GetString("#TBA"));

			title = gcString("{0} - {1}", name, cost.c_str());
		}
		else if (isPreorder)
		{
			if (noRelease)
				title = gcString("{0} - {1}", name, Managers::GetString("#IF_PREORDERED_NORELEASE"));
			else
				title = gcString("{0} - {1}", name, Managers::GetString("#IF_PREORDERED"));
		}

		m_cbBranchList->Append(title, new BranchData(bi->getBranchId(), bi->getGlobalId()));
	}

	count = bList.size();

	if (full == -1)
		full = 0;

#ifdef WIN32
	if (HasAnyFlags(i->getStatus(), UserCore::Item::ItemInfoI::STATUS_ONCOMPUTER))
		m_cbBranchList->Append(Managers::GetString("#IF_ONCOMPUTER"), new BranchData(MCFBranch::BranchFromInt(-1), MCFBranch::BranchFromInt(-1)));
	else
		m_cbBranchList->Append(Managers::GetString("#IF_FINDONCOMPUTER"), new BranchData(MCFBranch::BranchFromInt(-2), MCFBranch::BranchFromInt(-2)));
#endif

	m_cbBranchList->SetSelection(full);

	if (pItemInfo->getIcon() && UTIL::FS::isValidFile(UTIL::FS::PathWithFile(pItemInfo->getIcon())))
		setIcon(pItemInfo->getIcon());

	SetTitle(gcWString(Managers::GetString(L"#IF_BRANCHTITLE"), itemName));


	uint32 ret = 0;

	if (count == 0)
	{
		if (!isCheckingParent)
			gcMessageBox(GetParent(), Managers::GetString(L"#IF_IINOBRANCHES"), Managers::GetString(L"#IF_IIERRTITLE"));
		else if (selectBranch)
			ret = 1;
	}
	else if ((count == 1 || fullReadyCount == 1) && !m_bBuy)
	{	
		ret =  1;
	}
	else
	{
		wxCommandEvent e;
		onChoice(e);
	}

	return ret;
}
Exemplo n.º 4
0
uint32 GatherInfoTask::validate()
{
	UserCore::Item::ItemInfoI* pItemInfo = getItemHandle()->getItemInfo();
	uint32 isValid = 0;

	if (!pItemInfo)
		return UserCore::Item::Helper::V_BADINFO;

	DesuraId par = pItemInfo->getParentId();
	UserCore::Item::ItemInfoI *parInfo = nullptr;

	if (par.isOk())
	{
		parInfo = getUserCore()->getItemManager()->findItemInfo(par);

		if (!parInfo || !(parInfo->getStatus() & UserCore::Item::ItemInfoI::STATUS_INSTALLED))
			isValid |= UserCore::Item::Helper::V_PARENT;
	}

	const char* path = pItemInfo->getPath(getMcfBranch());

	if (!path)
	{
		isValid |= UserCore::Item::Helper::V_BADPATH;
	}
	else
	{
		const char *comAppPath = getUserCore()->getAppDataPath();

		uint64 inFreeSpace = UTIL::OS::getFreeSpace(path);
		uint64 dlFreeSpace = UTIL::OS::getFreeSpace(comAppPath);

		//if they are on the same drive:
		if (strncmp(comAppPath, path, 3) == 0)
		{
			if ((inFreeSpace+dlFreeSpace) < (pItemInfo->getDownloadSize()+pItemInfo->getInstallSize()))
			{
				isValid |= (UserCore::Item::Helper::V_FREESPACE|UserCore::Item::Helper::V_FREESPACE_DL|UserCore::Item::Helper::V_FREESPACE_INS);
			}
		}
		else
		{
			if (dlFreeSpace < pItemInfo->getDownloadSize())
				isValid |= UserCore::Item::Helper::V_FREESPACE|UserCore::Item::Helper::V_FREESPACE_DL;

			if (inFreeSpace < pItemInfo->getInstallSize())
				isValid |= UserCore::Item::Helper::V_FREESPACE|UserCore::Item::Helper::V_FREESPACE_INS;
		}

		if (pItemInfo->getStatus() & UserCore::Item::ItemInfoI::STATUS_INSTALLCOMPLEX)
		{
			const char* primPath = pItemInfo->getInsPrimary();

			if (primPath && strcmp(primPath, "") != 0 && UTIL::FS::isValidFolder(primPath) && !UTIL::FS::isFolderEmpty(primPath))
				isValid |= UserCore::Item::Helper::V_NONEMPTY;
		}
		else if (pItemInfo->getStatus() & UserCore::Item::ItemInfoI::STATUS_DLC)
		{
			if (!parInfo || gcString(path) != gcString(parInfo->getPath()))
			{
				if (!UTIL::FS::isFolderEmpty(path))
					isValid |= UserCore::Item::Helper::V_NONEMPTY;
			}
		}
		else if (!UTIL::FS::isFolderEmpty(path))
		{
			isValid |= UserCore::Item::Helper::V_NONEMPTY;
		}
	}

#ifdef NIX
	UserCore::Item::BranchInfoI* bi = pItemInfo->getBranchById(getMcfBranch());
	
	std::vector<DesuraId> toolList;
	bi->getToolList(toolList);

	uint32 res = getUserCore()->getToolManager()->hasNonInstallableTool(toolList);
	
	switch (res)
	{
	case 0:
		isValid |= UserCore::Item::Helper::V_JAVA_SUN;
		break;		
		
	case 1:
		isValid |= UserCore::Item::Helper::V_JAVA;
		break;		
	
	case 2:
		isValid |= UserCore::Item::Helper::V_MONO;
		break;
		
	case 3:
		isValid |= UserCore::Item::Helper::V_AIR;
		break;		
	};
#endif

	return isValid;
}
Exemplo n.º 5
0
bool InternalLink::processItemLink(bool &badLink, std::vector<gcString> &list, const char* link)
{
	if (list.size() < 3)
	{
		badLink = true;
		return true;
	}

	std::string key = list[1] + list[2];

	std::map<gcString, gcFrame*>::iterator it = m_mWaitingItemFromMap.find(key);

	if (it != m_mWaitingItemFromMap.end())
	{
		it->second->Raise();
		return false;
	}

	UI::Forms::ItemForm *form = new UI::Forms::ItemForm(m_pParent, list[0].c_str(), list[2].c_str());
	m_mWaitingItemFromMap[key] = form;

	form->Show();

	DesuraId id;

	try
	{
		id = GetWebCore()->nameToId(list[2].c_str(), list[1].c_str());
	}
	catch (gcException &e)
	{
		DesuraId idAsNum(list[2].c_str(), list[1].c_str());

		if (idAsNum.getItem() == 0)
		{
			Warning(gcString("Failed to resolve item name {0} for link {2}: {1}\n", list[2], e, link));
			gcErrorBox(form, Managers::GetString("#MF_ERRTITLE"), Managers::GetString("#MF_NAMERESOLVE"), e);

			m_mWaitingItemFromMap.erase(m_mWaitingItemFromMap.find(key));

			form->Show(false);
			form->Destroy();
			return false;
		}
		else
		{
			id = idAsNum;
		}
	}

	m_mWaitingItemFromMap.erase(m_mWaitingItemFromMap.find(key));

	bool destroyForm = false;
	std::vector<std::string> argList;

	if (id.isOk())
	{
		UI::Forms::ItemForm *formFind = findForm<UI::Forms::ItemForm>(id, m_vSubForms);

		if (!formFind)
		{
			form->setItemId(id);
			regForm(id, form);
		}
		else
		{
			formFind->SetPosition(form->GetPosition());
			form->Show(false);
			destroyForm = true;
		}

		if (list[0] == "install" || list[0] == "launch")
		{
			std::string branch;

			if (list.size() >= 4)
				branch = list[3];

			if (branch.size() > 0)
			{
				argList.push_back(std::string("global=") + branch);
				handleInternalLink(id, ACTION_INSTALL, argList);	
			}
			else
			{
				bool isInstall = (list[0] == "install");
				handleInternalLink(id, isInstall?ACTION_INSTALL:ACTION_LAUNCH, argList);	
			}
		}
		else if (list[0] == "uninstall" || list[0] == "remove")
		{
			handleInternalLink(id, ACTION_UNINSTALL);
		}
		else if (list[0] == "verify")
		{
			handleInternalLink(id, ACTION_VERIFY);
		}
		else if (list[0] == "upload")
		{
			destroyForm = true;
			handleInternalLink(id,  ACTION_UPLOAD);
		}
		else if (list[0] == "resumeupload" && list.size() >= 4)
		{
			destroyForm = true;
			argList.push_back(std::string("key=") + list[3]);
			handleInternalLink(id, ACTION_RESUPLOAD, argList);	//
		}
		else if (list[0] == "makemcf")
		{
			destroyForm = true;
			handleInternalLink(id, ACTION_CREATE);
		}
		else if (list[0] == "test" && list.size() >= 5)
		{
			argList.push_back(std::string("branch=") + list[3]);
			argList.push_back(std::string("build=") + list[4]);
			handleInternalLink(id, ACTION_TEST, argList);
		}
		else
		{
			badLink = true;
		}
	}
	else
	{
		badLink = true;
	}

	if (badLink || destroyForm)
	{
		closeForm(form->GetId());
		form->Show(false);
		form->Destroy();
	}

	return true;
}