Esempio n. 1
0
bool InternalLink::checkForPreorder(DesuraId id)
{
	UserCore::Item::ItemInfoI* item = GetUserCore()->getItemManager()->findItemInfo( id );

	if (!item)
		return false;

	if (item->getCurrentBranch())
		return item->getCurrentBranch()->isPreOrderAndNotPreload();


	for (size_t x=0; x<item->getBranchCount(); x++)
	{
		if (item->getBranch(x)->isPreOrderAndNotPreload())
			return true;
	}		

	return false;
}
Esempio n. 2
0
void InternalLink::showPreorderPrompt(DesuraId id, bool isPreload)
{
	UserCore::Item::ItemInfoI* item = GetUserCore()->getItemManager()->findItemInfo( id );

	if (!item)
		return;

	UserCore::Item::BranchInfoI* bi = item->getCurrentBranch();

	if (!bi)
	{
		for (size_t x=0; x<item->getBranchCount(); x++)
		{
			UserCore::Item::BranchInfoI *temp = item->getBranch(x);

			if (temp->isPreOrder())
			{
				bi = temp;
				break;
			}
		}
	}

	if (!bi)
		return;

	const char* str = bi->getPreOrderExpDate();

	uint32 days;
	uint32 hours;
	std::string time_available = UTIL::MISC::dateTimeToDisplay(str);

	UTIL::MISC::getTimeDiffFromNow(str, days, hours);

	gcString title(Managers::GetString("#IF_PRELOADLAUNCH_TITLE"), item->getName());
	gcString msg(Managers::GetString("#IF_PRELOADLAUNCH"), item->getName(), 
					days, 
						Managers::GetString(isPreload?"#IF_PRELOADLAUNCH_PRELOADED":"#IF_PRELOADLAUNCH_PREORDERED"), 
							time_available, 
								Managers::GetString(days == 1 ? "#IF_PRELOADLAUNCH_WORD_DAY":"#IF_PRELOADLAUNCH_WORD_DAYS"));

	PreloadButtonHelper pobh(id);

	if (pobh.m_bOtherBranches)
		msg += gcString(Managers::GetString("#IF_PRELOADLAUNCH_INSTALLOTHER_INFO"), item->getName());

	gcMessageBox(g_pMainApp->getMainWindow(), msg, title, wxICON_EXCLAMATION|wxCLOSE, &pobh);
}
Esempio n. 3
0
void CDKInfo::setInfo(DesuraId id, const char* key)
{
	BasePage::setInfo(id);

	UserCore::Item::ItemInfoI *info = getItemInfo();

	if (!info)
	{
		GetParent()->Close();
		return;
	}

	m_butLaunch->Enable(info->isLaunchable());

	if (checkForArma(id, key))
		return;

	m_tbCdKey->ChangeValue(key);
	tokenizeKey(key);

	UserCore::Item::BranchInfoI* cb = info->getCurrentBranch();

	if (cb && cb->isSteamGame())
	{
		m_labInfo->SetLabel(gcWString(Managers::GetString(L"#CDK_INFO_STEAM"), info->getName()));
		m_labInfo->Wrap(360);

		m_butActivate = new gcButton(this, wxID_ANY, Managers::GetString(L"#CDK_ACTIVATE"));

		m_pButtonSizer->Clear(false);
		m_pButtonSizer->Add( 0, 0, 1, wxEXPAND, 5 );
		m_pButtonSizer->Add(m_butActivate, 0, wxTOP|wxBOTTOM|wxLEFT, 5);
		m_pButtonSizer->Add(m_butLaunch, 0, wxTOP|wxBOTTOM|wxLEFT, 5);
		m_pButtonSizer->Add(m_butClose, 0, wxALL, 5);

		Layout();
		Refresh(false);

		setParentSize(-1, 140);
	}
}
Esempio n. 4
0
void InternalLink::launchItem(DesuraId id, Args args)
{
	bool cdKeyArg = args.containsArg("cdkey");
	bool noUpdateArg = args.containsArg("noupdate");
	bool exeNumArg = args.containsArg("exe");
	std::string exe = args.getArgValue("exe");

	if (exe == "")
		exeNumArg = false;

	g_pMainApp->showPlay();

	if (checkForPreorder(id))
		return;

	UserCore::Item::ItemInfoI* item = GetUserCore()->getItemManager()->findItemInfo(id);
	bool delFlag=false;

	if (!item || !item->isLaunchable())
	{
		installItem(id, Args());
		return;
	}

	if (!item->hasAcceptedEula())
	{
		showPrompt(id, FormatArgs("prompt=eula"));
		return;
	}

	if (!exeNumArg && item->getExeCount(true) > 1)
	{
		showExeSelect(id, cdKeyArg);
		return;
	}
	else if (exe.size() > 0)
	{
		item->setActiveExe(exe.c_str());
	}

	bool hasCDKey = item->getCurrentBranch() && item->getCurrentBranch()->hasCDKey();
	bool hasDLCDKey = item->getCurrentBranch() && item->getCurrentBranch()->isCDKeyValid();

	if (!cdKeyArg && ((item->isFirstLaunch() && hasCDKey) || (hasCDKey && !hasDLCDKey)))
	{
		showCDKey(id, FormatArgs("launch=true", std::string("exe=") + exe));
		return;
	}

	bool shouldShowGameDisk = false;

	if (args.containsArg("gamedisk") == false && HasAnyFlags(item->getOptions(), UserCore::Item::ItemInfoI::OPTION_DONTPROMPTGAMEDISK) == false)
	{
		size_t x=0; 
		while (g_GameDiskList[x].isOk())
		{
			if (item->getId() == g_GameDiskList[x] || item->getParentId() == g_GameDiskList[x])
			{
				shouldShowGameDisk = true;
				break;
			}

			x++;
		}
	}

	if (shouldShowGameDisk)
	{
		showGameDisk(id, exe.c_str(), cdKeyArg);
		return;
	}

	if (noUpdateArg && !HasAnyFlags(item->getOptions(), UserCore::Item::ItemInfoI::OPTION_NOTREMINDUPDATE))
	{
		item->addOFlag(UserCore::Item::ItemInfoI::OPTION_NOTREMINDUPDATE);
		delFlag = true;
	}

	UI::Forms::ItemForm* form = showItemForm(id, UI::Forms::INSTALL_ACTION::IA_LAUNCH);

	if (!form)
		Warning(gcString("Cant find item (or item not ready) for launch [{0}].\n", id.toInt64()));

	if (item && delFlag)
		item->delOFlag(UserCore::Item::ItemInfoI::OPTION_NOTREMINDUPDATE);
}
Esempio n. 5
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);
}