Example #1
0
bool VerifyServiceTask::checkBranch()
{
	UserCore::Item::ItemInfo* pItem = getItemInfo();
	UserCore::Item::BranchInfoI* pBranch = pItem->getCurrentBranch();
	
	if (!pBranch)
		return false;

	if (pBranch && pItem->isDownloadable() && !pBranch->isDownloadable())
	{
		finishVerify(UserCore::Misc::VerifyComplete::V_RESET);
		return true;
	}

	if (m_McfBranch != 0 && pBranch && pBranch->getBranchId() != m_McfBranch)
	{
		finishVerify(UserCore::Misc::VerifyComplete::V_SWITCHBRANCH);
		return true;
	}

	m_McfBranch = pItem->getCurrentBranch()->getBranchId();
	return false;
}
Example #2
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;
}
Example #3
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()));
	}
}
Example #4
0
void ItemHandle::installLaunchScripts()
{
	UserCore::Item::ItemInfoI* item = getItemInfo();
	
	if (!item)
		return;
		
	UserCore::Item::BranchInfoI* branch = item->getCurrentBranch();
	
	if (!branch)
		return;
		
	std::vector<UserCore::Item::Misc::ExeInfoI*> exeList;
	item->getExeList(exeList);
	
	char* scriptBin = NULL;
	char* scriptXdg = NULL;
	
	try
	{
		UTIL::FS::readWholeFile(UTIL::STRING::toStr(
			UTIL::OS::getDataPath(L"scripts/launch_bin_template.sh")), &scriptBin);
		UTIL::FS::readWholeFile(UTIL::STRING::toStr(
			UTIL::OS::getDataPath(L"scripts/launch_xdg_template.sh")), &scriptXdg);
	}
	catch (gcException &e)
	{
		safe_delete(scriptBin);
		safe_delete(scriptXdg);		
		
		Warning(gcString("Failed to read launch script template: {0}\n", e));
		return;
	}
	
	gcString globalArgs = getUserCore()->getCVarValue("gc_linux_launch_globalargs");
	gcString globalExe = getUserCore()->getCVarValue("gc_linux_launch_globalbin");
	
	if (!UTIL::FS::isValidFile(globalExe.c_str()))
		globalExe = "";
	
	for (size_t x=0; x<exeList.size(); x++)
	{
		UserCore::Item::Misc::ExeInfoI* exe = exeList[x];
		
		if (!exe || !UTIL::FS::isValidFile(exe->getExe()))
			continue;
			
		gcString path("{0}/desura_launch_{1}.sh", item->getPath(), UTIL::LIN::sanitiseFileName(exe->getName()));
			
		char magicBytes[5] = {0};
			
		try
		{
			UTIL::FS::FileHandle fh(exe->getExe(), UTIL::FS::FILE_READ);
			fh.read(magicBytes, 5);
		}
		catch (gcException& e)
		{
			continue;
		}
		
		UTIL::LIN::BinType type = UTIL::LIN::getFileType(magicBytes, 5);
		
		try
		{
			UTIL::FS::FileHandle fh(path.c_str(), UTIL::FS::FILE_WRITE);
			
			if (type == UTIL::LIN::BT_UNKNOWN)
			{
				gcString lcmd(scriptXdg, exe->getExe());
				fh.write(lcmd.c_str(), lcmd.size());
			}
			else
			{
				gcString libPath("\"{0}/{1}/{2}/lib\"", UTIL::OS::getAppDataPath(), branch->getItemId().getFolderPathExtension(), (uint32)branch->getBranchId());
				gcString libPathB("{0}/lib{1}", item->getPath(), branch->is32Bit()?"32":"64");
				
				if (UTIL::FS::isValidFolder(libPathB.c_str()))
				{
					libPath += ":";
					libPath += "\"" + libPathB + "\"";
				}

				const char* exePath = exe->getExe();
				
				gcString args;
				gcString ea(exe->getExeArgs());
				
				if (globalExe.size() > 0)
				{
					args += gcString(exePath);
					exePath = globalExe.c_str();
				}
				
				if (ea.size() > 0)
				{
					if (args.size() > 0)
						args += " ";
						
					args += ea;
				}
				
				if (globalArgs.size() > 0)
				{
					if (args.size() > 0)
						args += " ";
						
					args += globalArgs;
				}			
					
				gcString lcmd(scriptBin, exePath, args, libPath);
				fh.write(lcmd.c_str(), lcmd.size());
			}
		}
		catch (gcException &e)
		{
		}
		
		chmod(path.c_str(), S_IRWXU|S_IRGRP|S_IROTH);
	}
	
	safe_delete(scriptBin);
	safe_delete(scriptXdg);
}