예제 #1
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;
}
예제 #2
0
void ItemHandle::doLaunch(bool useXdgOpen, const char* globalExe, const char* globalArgs)
{
	preLaunchCheck();
	
	UserCore::Item::Misc::ExeInfoI* ei = getItemInfo()->getActiveExe();
	
	gcString e(globalExe);
	
	gcString args;
	gcString ea(ei->getExeArgs());
	gcString ua(ei->getUserArgs());
	gcString ga(globalArgs);
	gcString wdp(ei->getExe());
	
	if (!useXdgOpen)
	{
		//if we have a valid global exe need to append the local exe as the first arg
		if (e.size() > 0)
			args += gcString(ei->getExe());
		else
			globalExe = ei->getExe();
	}
	
	auto AppendArgs = [&args](const std::string& a)
	{
		if (a.size() == 0)
			return;
		
		if (args.size() > 0)
			args += " ";
			
		args += a;
	};

	AppendArgs(ea);
	AppendArgs(ua);
	
	if (!useXdgOpen)
		AppendArgs(ga);
	
	bool res = false;

	if (useXdgOpen && args.size() != 0)
		Warning(gcString("Arguments '{1}' are not being passed to non-executable file '{0}'.", ei->getExe(), args));

	UserCore::Item::BranchInfoI* branch = getItemInfo()->getCurrentBranch();

#ifdef NIX64
	if (!useXdgOpen && branch && branch->is32Bit())
	{
		#ifdef USE_BITTEST
			int testRet = system("desura_bittest");
			
			if (testRet != 0)
				throw gcException(ERR_NO32LIBS);
		#else
			throw gcException(ERR_NOBITTEST);
		#endif
		
	}
#endif

	gcString libPathA;
	gcString libPathB;
	gcString libPath;
	
	if (branch)
	{
		libPathA = gcString("{0}/{1}/{2}/lib", UTIL::OS::getAppDataPath(), branch->getItemId().getFolderPathExtension(), (uint32)branch->getBranchId());
		libPathB = gcString("{0}/lib{1}", getItemInfo()->getPath(), branch->is32Bit()?"32":"64");

		libPath = libPathA;
		
		if (UTIL::FS::isValidFolder(libPathB.c_str()))
		{
			libPath += ":";
			libPath += libPathB;
		}
	}

	if (useXdgOpen)
	{
		res = UTIL::LIN::launchProcessXDG(ei->getExe(), libPath.c_str());
	}
	else
	{
		if (libPathA.size() > 0)
		{
			std::vector<DesuraId> toolList;
			branch->getToolList(toolList);
			
			getUserCore()->getToolManager()->symLinkTools(toolList, libPathA.c_str());
		}
	
		std::map<std::string, std::string> info;
		
		info["cla"] = args;
		info["lp"] = libPath;
		info["wd"] = UTIL::FS::PathWithFile(wdp.c_str()).getFolderPath();
		
		res = UTIL::LIN::launchProcess(globalExe, info);
	}

	if (!res)
	{
		ERROR_OUTPUT(gcString("Failed to create {0} process. [{1}: {2}].\n", getItemInfo()->getName(), errno, ei->getExe()).c_str());
		throw gcException(ERR_LAUNCH, errno, gcString("Failed to create {0} process. [{1}: {2}].\n", getItemInfo()->getName(), errno, ei->getExe()));
	}
}