Esempio n. 1
0
void DownloadImgTask::doTask()
{
	if (!m_pItem)
		return;

	gcString path;

	if (m_Image == ICON)
		path = m_pItem->getIconUrl();
	else
		path = m_pItem->getLogoUrl();

	if (path == "")
		return;

	WebCore::Misc::DownloadImageInfo dii(m_pItem->getId(), path);

	try
	{
		getWebCore()->downloadImage(&dii, m_bStopped);

		if (m_Image == ICON)
			m_pItem->setIcon(dii.outPath.c_str());
		else
			m_pItem->setLogo(dii.outPath.c_str());
	}
	catch (gcException &e)
	{
		Warning("Failed to download image {0}: {1}\n", path, e);
	}
}
Esempio n. 2
0
void UploadResumeThread::doRun()
{
	assert(m_pUpInfo);

	getWebCore()->resumeUpload(getItemId(), m_szKey.c_str(), *m_pUpInfo);

	const char* localFilePath = getUploadManager()->findUpload(m_szKey.c_str());
	gcString sLocalFP(localFilePath);

	if (localFilePath && validFile(localFilePath))
	{
		onCompleteStrEvent(sLocalFP);
		return;
	}

	//gona try and search for the file in the data/mods/id folder
	const char* appDataPath = getUserCore()->getAppDataPath();
	gcString searchPath("{0}{1}{2}", appDataPath, DIRS_STR, getItemId().getFolderPathExtension());
	gcString sNull("NULL");

	if (doSearch(searchPath.c_str()))
		return;

	if (getUserCore()->isAdmin())
	{
		searchPath = gcString("{0}{1}temp{1}", appDataPath, DIRS_STR);
		
		if (doSearch(searchPath.c_str()))
			return;
	}

	onCompleteStrEvent(sNull);
}
Esempio n. 3
0
void MainApp::logOut(bool bShowLogin, bool autoLogin, bool webLoggedOut)
{
	gcTrace("");

	m_pInternalLink->closeAll();
	safe_delete(m_pInternalLink);

	closeMainForm();
	wxTheApp->ProcessIdle();

	{
		std::lock_guard<std::mutex> a(m_UserLock);
		if (g_pUserHandle)
		{
			auto user = g_pUserHandle;

			g_pUserHandle = nullptr;
			DesuraJSBinding::gs_pItemManager = nullptr;

			user->getPipeDisconnectEvent() -= guiDelegate(this, &MainApp::onPipeDisconnect);
			user->logOut(!autoLogin);

			user->getAppUpdateProgEvent()				-= guiDelegate(this, &MainApp::onAppUpdateProg);
			user->getAppUpdateCompleteEvent()			-= guiDelegate(this, &MainApp::onAppUpdate);
			user->getWebCore()->getCookieUpdateEvent() -= guiDelegate(this, &MainApp::onCookieUpdate);
			user->getWebCore()->getLoggedOutEvent()		-= delegate(&onLoggedOutEvent);

			user->destroy();
		}
	}

	GetCVarManager()->saveAll();
	GetCVarManager()->cleanUserCvars();

	m_bLoggedIn = false;
	m_iMode = APP_MODE::MODE_UNINT;

	if (bShowLogin)
		showLogin(!autoLogin, webLoggedOut);

	HideLogForm();

	DeleteCookies();
	SetCrashDumpSettings(nullptr, true);
}
Esempio n. 4
0
void VerifyServiceTask::setupCurTask()
{
	m_pCurTask->onErrorEvent += delegate(this, &VerifyServiceTask::onError);

	m_pCurTask->setItemHandle(getItemHandle());
	m_pCurTask->setMcfBuild(m_McfBuild);
	m_pCurTask->setMcfBranch(m_McfBranch);

	m_pCurTask->setUserCore(getUserCore());
	m_pCurTask->setWebCore(getWebCore());

	m_pCurTask->setMcfHandle(m_hMcf.handle());
}
Esempio n. 5
0
bool VSDownloadMissing::doTask()
{
	m_hMcf->getNewProvider() += delegate(this, &VSDownloadMissing::onNewProvider);

	try
	{
		MCFCore::Misc::UserCookies uc;
		getWebCore()->setMCFCookies(&uc); 

		m_hMcf->getDownloadProviders(getWebCore()->getMCFDownloadUrl(), &uc);
		m_hMcf->dlFilesFromWeb();
	}
	catch (gcException &except)
	{
		onErrorEvent(except);
		return false;
	}

	if (isStopped())
		return false;

	return checkComplex();
}
Esempio n. 6
0
void ChangeAccountTask::doTask()
{
	auto pItem = getItemInfo();

	if (!pItem || !getWebCore())
		return;

	try
	{
		if (m_Action == ACCOUNT_ADD)
		{
			getWebCore()->updateAccountItem(pItem->getId(), true);
			pItem->addSFlag(ItemInfoI::STATUS_ONACCOUNT);
		}
		else
		{
			getWebCore()->updateAccountItem(pItem->getId(), false);
			pItem->delSFlag(ItemInfoI::STATUS_ONACCOUNT);

			if (!(pItem->getStatus() & (ItemInfoI::STATUS_INSTALLED|
										ItemInfoI::STATUS_ONCOMPUTER|
										ItemInfoI::STATUS_DOWNLOADING|
										ItemInfoI::STATUS_INSTALLING|
										ItemInfoI::STATUS_UPLOADING|
										ItemInfoI::STATUS_VERIFING)))
			{
				getUserCore()->getItemManager()->removeItem(pItem->getId());
			}
		}
	}
	catch (gcException &except)
	{
		if (except.getSecErrId() != 107)
			Warning("Error in Change Account task: {0}.\n", except);
	}
}
Esempio n. 7
0
void CDKeyTask::doTask()
{
	if (!getItemInfo() || !getWebCore())
	{
		CDKeyEventInfo<gcException> cdei;
		cdei.task = this;
		cdei.t = gcException(ERR_NULLHANDLE, "Item info or web core are null");
		cdei.id = getItemId();

		onErrorEvent(cdei);
		return;
	}

	MCFBranch branch = getItemInfo()->getInstalledBranch();

	try
	{
		gcString key = getWebCore()->getCDKey(getItemId(), branch);

		CDKeyEventInfo<gcString> cdei;
		cdei.task = this;
		cdei.t = key;
		cdei.id = getItemId();

		onCompleteEvent(cdei);
	}
	catch (gcException &e)
	{
		CDKeyEventInfo<gcException> cdei;
		cdei.task = this;
		cdei.t = e;
		cdei.id = getItemId();

		onErrorEvent(cdei);
	}
}
Esempio n. 8
0
bool VerifyServiceTask::checkUnAuthed()
{
	UserCore::Item::ItemInfo* pItem = getItemInfo();

	if (m_McfBuild != 0 || HasAllFlags(pItem->getStatus(), UserCore::Item::ItemInfoI::STATUS_UNAUTHED) == false)
		return false;

	McfHandle hMcf;
	hMcf->setHeader(getItemId(), m_McfBranch, m_McfBuild);

	try
	{
		MCFCore::Misc::UserCookies uc;
		getWebCore()->setMCFCookies(&uc); 
		hMcf->getDownloadProviders(getWebCore()->getMCFDownloadUrl(), &uc);
	}
	catch (gcException &except)
	{
		onError(except);
		return true;
	}		

	m_McfBuild = hMcf->getHeader()->getBuild();

	if (m_McfBuild == 0)
	{
		//cant remove this as this is the first version
		finishVerify();
		return true;
	}

	pItem->overideInstalledBuild(m_McfBuild);
	pItem->delSFlag(UserCore::Item::ItemInfoI::STATUS_UNAUTHED);
	
	return false;
}
Esempio n. 9
0
void CreateMCFThread::retrieveBranchList(std::vector<UserCore::Item::BranchInfo*> &outList)
{
	TiXmlDocument doc;
	getWebCore()->getItemInfo(getItemId(), doc, MCFBranch(), MCFBuild());

	TiXmlNode *uNode = doc.FirstChild("iteminfo");

	if (!uNode)
		throw gcException(ERR_BADXML);

	XML::for_each_child("platform", uNode->FirstChildElement("platforms"), [this, &outList](TiXmlElement* platform)
	{
		this->processGames(outList, platform);
	});
}
Esempio n. 10
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);
}
Esempio n. 11
0
void GetItemListThread::doRun()
{
	m_szDbName = getCIBDb(getUserCore()->getAppDataPath());

	tinyxml2::XMLDocument doc;
	getWebCore()->getInstalledItemList(doc);

	int ver = XML::processStatus(doc, "itemwizard");

	tinyxml2::XMLElement *infoNode = doc.FirstChildElement("itemwizard");

	if (!infoNode)
		throw gcException(ERR_BADXML);

	if (isStopped())
		return;

	WildcardManager wMng = WildcardManager();

	if (ver == 1)
		parseItems1(infoNode, &wMng);
	else
		parseItems2(infoNode, &wMng);

	try
	{
		createCIPDbTables(getUserCore()->getAppDataPath());

		sqlite3x::sqlite3_connection db(m_szDbName.c_str());
		sqlite3x::sqlite3_command cmd(db, "REPLACE INTO cipiteminfo (internalid, name) VALUES (?,?);");

		for (size_t x=0; x<m_vGameList.size(); x++)
		{
			cmd.bind(1, (long long int)m_vGameList[x].getId().toInt64());
			cmd.bind(2, std::string(m_vGameList[x].getName()) ); 
			cmd.executenonquery();
		}
	}
	catch (std::exception &e)
	{
		Warning(gcString("Failed to update cip item list: {0}\n", e.what()));
	}

	uint32 prog=0;
	onCompleteEvent(prog);
}
Esempio n. 12
0
void DownloadBannerTask::doTask()
{
	BannerCompleteInfo dpinfo(this, m_DownloadProvider);

	try
	{
		UTIL::FS::Path path(getUserCore()->getAppDataPath(), "", false);

		path += "temp";
		UTIL::FS::recMakeFolder(path);

		getWebCore()->downloadBanner(&m_DownloadProvider, path.getFullPath().c_str());
		dpinfo.complete = true;
	}
	catch (gcException &e)
	{
		Warning("Failed to download banner: {0}\n", e);
		dpinfo.complete = false;
	}

	onDLCompleteEvent(dpinfo);
}
Esempio n. 13
0
gcString VSCheckMcf::downloadMCFHeader()
{
	if (isStopped())
		return "";

	auto mm = getUserCore()->getInternal()->getMCFManager();
	gcString path = mm->getMcfPath(getItemId(), getMcfBranch(), getMcfBuild());

	if (path == "")
		path = mm->newMcfPath(getItemId(), getMcfBranch(), getMcfBuild());

	m_hTempMcf->setHeader(getItemId(), getMcfBranch(), getMcfBuild());

	try
	{
		auto dp = std::make_shared<MCFDownloadProviders>(getWebCore(), getUserCore()->getUserId());
		MCFDownloadProviders::forceLoad(m_hTempMcf, dp);

		m_hTempMcf->dlHeaderFromWeb();
	}
	catch (gcException &except)
	{
		onErrorEvent(except);
		return "";
	}

	m_hTempMcf->setFile(path.c_str());
	m_hTempMcf->markFiles(m_hTempMcf.handle(), false, false, false, false);
	m_hTempMcf->saveMCFHeader();

	if (isStopped())
		return "";

	m_hTempMcf = McfHandle();

	return path;
}
Esempio n. 14
0
void DownloadToolTask::validateTools()
{
	std::vector<DesuraId> toolList;
	getItemInfo()->getCurrentBranch()->getToolList(toolList);

	if (toolList.size() == 0)
		return;

	if (!getUserCore()->getToolManager()->areAllToolsValid(toolList))
	{
		//missing tools. Gather info again
		TiXmlDocument doc;

		getWebCore()->getItemInfo(getItemId(), doc, MCFBranch(), MCFBuild());

		TiXmlNode *uNode = doc.FirstChild("iteminfo");

		if (!uNode)
			throw gcException(ERR_BADXML);

		TiXmlNode *toolNode = uNode->FirstChild("toolinfo");

		if (toolNode)
			getUserCore()->getToolManager()->parseXml(toolNode);

		TiXmlNode *gameNode = uNode->FirstChild("games");

		if (!gameNode)
			throw gcException(ERR_BADXML);

		getItemInfo()->getCurrentBranch()->getToolList(toolList);
	}

	if (!getUserCore()->getToolManager()->areAllToolsValid(toolList))
		throw gcException(ERR_INVALID, "Tool ids cannot be resolved into tools.");
}
Esempio n. 15
0
void UpdateThread::doRun()
{
	m_pBaseTask->setInfo(getUserCore(), getWebCore());
	m_pBaseTask->doRun();
}
Esempio n. 16
0
void CreateMCFThread::compareBranches(std::vector<UserCore::Item::BranchInfo*> &vBranchList)
{
	uint64 lastSize = 0;
	//uint32 lastIndex = 0;                    unused variable

	McfHandle lastMcf;

	m_hMCFile->setHeader(getItemId(), MCFBranch(), MCFBuild());
	m_hMCFile->getHeader()->setParent(0);


	for (size_t x=0; x<vBranchList.size(); x++)
	{
		if (isStopped())
			return;

		UserCore::Item::BranchInfo* bi = vBranchList[x];

		McfHandle tempMcf;
		tempMcf->setHeader(getItemId(), bi->getBranchId(), MCFBuild());
		tempMcf->getErrorEvent() += delegate(&onErrorEvent);
	
		try
		{
			MCFCore::Misc::UserCookies uc;
			getWebCore()->setMCFCookies(&uc); 
			tempMcf->getDownloadProviders(getWebCore()->getMCFDownloadUrl(), &uc);
		}
		catch (gcException &except)
		{
			Warning(gcString("CreateMCF: Failed to get download providers for mcf: {0}\n", except));
			continue;
		}

		if (tempMcf->getHeader()->getBuild() > 0)
		{
			try
			{
				tempMcf->dlHeaderFromWeb();
			}
			catch (gcException &except)
			{
				Warning(gcString("CreateMCF: Failed to get dlHeaderFromWeb for mcf: {0}\n", except));
				continue;
			}

			uint64 totalSize = 0;
			uint32 fileCount = 0;
			m_hMCFile->getPatchStats(tempMcf.handle(), &totalSize, &fileCount);

			if (lastSize == 0 || totalSize < lastSize)
			{
				lastSize = totalSize;
				//lastIndex = x;
				lastMcf.setHandle(tempMcf.releaseHandle());

				// if there are no files just use this one
				if (fileCount == 0)
					break;
			}
		}
	}

	MCFBuild build = lastMcf->getHeader()->getBuild();
	MCFBranch branch = lastMcf->getHeader()->getBranch();

	m_hMCFile->setHeader(getItemId(), branch, build);

	if (build > 0)
		m_hMCFile->getHeader()->addFlags( MCFCore::MCFHeaderI::FLAG_PARTFILE );
	else
		m_hMCFile->getHeader()->delFlags( MCFCore::MCFHeaderI::FLAG_PARTFILE );

	m_hMCFile->getHeader()->setParent(lastMcf->getHeader()->getBuild());
	m_hMCFile->makePatch(lastMcf.handle());
}
//this is a feature of webcore but we need it here in case we need to shutdown during a download
void DownloadUpdateTask::downloadUpdate()
{
#ifdef DEBUG
	return;
#endif

	uint32 appver = m_uiAppVer;
	uint32 appbuild = m_uiAppBuild;


	HttpHandle wc(PRIMUPDATE);
	getWebCore()->setWCCookies(wc);
	
	wc->addPostText("appid", appver);
	wc->postWeb();


	if (wc->getDataSize() == 0)
		throw gcException(ERR_INVALIDDATA);


	XML::gcXMLDocument doc(const_cast<char*>(wc->getData()), wc->getDataSize());
	doc.ProcessStatus("appupdate");

	auto mNode = doc.GetRoot("appupdate").FirstChildElement("mcf");

	if (!mNode.IsValid())
		throw gcException(ERR_BADXML);

	uint32 version = 0;
	uint32 build = 0;
	
	mNode.GetAtt("appid", version);
	mNode.GetAtt("build", build);

	if (version == 0 || build == 0)
		throw gcException(ERR_BADXML);

	//check to see if its newer than last
	if (appbuild != 0 && build <= appbuild && appver == version)
		return;

	gcString url = mNode.GetChild("url");

	if (url.size() == 0)
		throw gcException(ERR_BADXML);

#ifdef WIN32
	const char *comAppPath = getUserCore()->getAppDataPath();
	m_szPath = gcString("{0}{1}{2}", comAppPath, DIRS_STR, UPDATEFILE);
#else
	m_szPath = gcString("{0}", UPDATEFILE);
#endif

	m_hMcfHandle->setFile(m_szPath.c_str());
	m_hMcfHandle->setWorkerCount(1);
	
	try
	{
		m_hMcfHandle->dlHeaderFromHttp(url.c_str());

#ifdef WIN32
		const char* dir = ".\\";
#else
		const char* dir = "./";
#endif

		//Dont use courgette for non admins for now
		bool useCourgette = false;

#ifdef WIN32
		if (getUserCore()->isAdmin())
			useCourgette = true;
#endif

		bool res = m_hMcfHandle->verifyInstall(dir, true, useCourgette);

		m_hMcfHandle->getProgEvent() += delegate(this, &DownloadUpdateTask::onDownloadProgress);

		UserCore::Misc::update_s info;
		info.build = build;

		if (!res)
		{
			Msg(gcString("Downloading " PRODUCT_NAME " update: Ver {0} build {1}\n", appver, build));
			info.alert = true;

			onDownloadStartEvent(info);

			if (useCourgette)
				m_hMcfHandle->dlFilesFromHttp(url.c_str(), dir);
			else
				m_hMcfHandle->dlFilesFromHttp(url.c_str());

			if (!isStopped())
				onDownloadCompleteEvent(info);
		}
		else
		{
			//sometimes this gets called after shutdown and causes major problems
			if (!getUserCore() || !getUserCore()->getServiceMain())
				return;

			gcString av("{0}", appver);
			gcString ab("{0}", build);
			info.alert = false;

			try
			{
				getUserCore()->getServiceMain()->updateRegKey(APPID, av.c_str());
				getUserCore()->getServiceMain()->updateRegKey(APPBUILD, ab.c_str());
			}
			catch (gcException &e)
			{
				Warning(gcString("Failed to update reg key: {0}\n", e));
			}

			onDownloadCompleteEvent(info);
		}
	}
	catch (gcException &e)
	{
		Warning(gcString("Download update failed: {0}\n", e));
	}
}