コード例 #1
0
bool UIBranchServiceTask::initService()
{
	if (!UIBaseServiceTask::initService())
	{
		onComplete();
		return false;
	}

	if (!getItemInfo()->setInstalledMcf(getMcfBranch(), getMcfBuild()))
	{
		gcException eFailedBrchId(ERR_BADID, "Failed to set branch id.");
		onErrorEvent(eFailedBrchId);
		return false;
	}

	gcString oldBranchMcf = getBranchMcf(getItemInfo()->getId(), m_OldBranch, m_OldBuild);
	gcString newBranchMcf = getBranchMcf(getItemInfo()->getId(), getMcfBranch(), getMcfBuild());

	m_pIPCIM = getServiceMain()->newUninstallBranch();
			
	if (!m_pIPCIM)
	{
		gcException eFailCrtBrnch(ERR_NULLHANDLE, "Failed to create uninstall branch mcf service!\n");
		onErrorEvent(eFailCrtBrnch);
		return false;
	}

	m_pIPCIM->onCompleteEvent += delegate(this, &UIBranchServiceTask::onComplete);
	m_pIPCIM->onProgressEvent += delegate(&onMcfProgressEvent);
	m_pIPCIM->onErrorEvent += delegate((UIBaseServiceTask*)this, &UIBaseServiceTask::onServiceError);

	m_pIPCIM->start(oldBranchMcf.c_str(), newBranchMcf.c_str(), getItemInfo()->getPath(), getItemInfo()->getInstallScriptPath());

	return true;
}
コード例 #2
0
void ChangeDirThread::run()
{
	if (!m_pUser)
	{
		gcException gce(ERR_NULLHANDLE, "User Core is null!");
		onErrorEvent(gce);
		onCompleteEvent();
		return;
	}

	UTIL::FS::recMakeFolder(m_szDest);

	if (!UTIL::FS::isValidFolder(m_szDest))
	{
		gcException gce(ERR_BADPATH, "Could not create destination folder");
		onErrorEvent(gce);
		onCompleteEvent();
		return;
	}

	FileList vFileList;

	updateDb(vFileList);
	copyFiles(vFileList);
	
	if (!m_bStopped)
	{
		m_bCompleted = true;
	}

	onCompleteEvent();
}
コード例 #3
0
void UninstallProcess::run()
{
	if (m_szIPath == "" || m_szMCFPath == "")
	{
		gcException errPathNull(ERR_BADPATH, gcString("One of the paths for uninstall was nullptr [IP: {0} MCF: {1}].", m_szIPath, m_szMCFPath));
		onErrorEvent(errPathNull);
		return;
	}

	MCFCore::MCFI *mcfHandle = mcfFactory();
	m_pMcfHandle = mcfHandle;
	mcfHandle->getErrorEvent() += delegate(&onErrorEvent);
	mcfHandle->getProgEvent() += delegate(this, &UninstallProcess::onProgress);

	InstallScriptRunTime isrt(m_szInstallScript.c_str(), m_szIPath.c_str());

	try
	{
		mcfHandle->setFile(m_szMCFPath.c_str());
		mcfHandle->parseMCF();

		isrt.run("PreUninstall");
		mcfHandle->removeFiles(m_szIPath.c_str());
		isrt.run("PostUninstall");
	}
	catch (gcException &except)
	{
		onErrorEvent(except);
	}

	m_pMcfHandle=nullptr;
	mcfDelFactory(mcfHandle);

	onCompleteEvent();
}
コード例 #4
0
ファイル: SMTController.cpp プロジェクト: Alasaad/Desurium
bool SMTController::makeThreads()
{
	for (uint32 x=0; x<m_uiNumber; x++)
	{
		gcString file("{0}", m_szFile);

		UTIL::FS::FileHandle* fh = new UTIL::FS::FileHandle();

		if (x != 0)
			file += gcString(".part_{0}", x);

		try
		{
			fh->open(file.c_str(), UTIL::FS::FILE_WRITE);

			//due to the first thread being the proper MCF we have to allow for the header.
			if (x == 0)
				fh->seek(MCFCore::MCFHeader::getSizeS());
		}
		catch (gcException &except)
		{
			safe_delete(fh);
			onErrorEvent(except);
			return false;
		}

		SMTWorkerInfo* temp = new SMTWorkerInfo(this, x, fh, file.c_str());
		m_vWorkerList.push_back(temp);
		temp->workThread->start();

		m_iRunningWorkers++;
	}

	return true;
}
コード例 #5
0
ファイル: HGTController.cpp プロジェクト: boskee/Desurium-1
void HGTController::run()
{
	bool usingDiffs = false;

	fillDownloadList(usingDiffs);

	try
	{
		doDownload();

		//if we failed to expand the diffs, restart the download
		if (usingDiffs && !expandDiffs())
		{
			fillDownloadList(usingDiffs);

			if (usingDiffs)
				throw gcException(ERR_WEBDL_FAILED, "Diff download failed and shouldnt be trying again. :(");

			doDownload();
		}
	}
	catch (gcException &except)
	{
		onErrorEvent(except);
		return;
	}
}
コード例 #6
0
bool VSInstallMissing::doTask()
{
    const char* val = getUserCore()->getCVarValue("gc_corecount");
    gcException errFailMCFServ(ERR_NULLHANDLE, "Failed to create uninstall MCF service!\n");

    m_pIPCIM = getUserCore()->getServiceMain()->newInstallMcf();
    if (!m_pIPCIM)
    {
        onErrorEvent(errFailMCFServ);
        return false;
    }

    uint8 workers = 1;

    if (val)
        workers = atoi(val);

    if (workers == 0)
        workers = 1;

    m_pIPCIM->onCompleteEvent += delegate(this, &VSInstallMissing::onComplete);
    m_pIPCIM->onProgressEvent += delegate(&onProgressEvent);
    m_pIPCIM->onErrorEvent += delegate(&onErrorEvent);
    m_pIPCIM->start(m_hMcf->getFile(), getItemInfo()->getPath(), getItemInfo()->getInstallScriptPath(), workers);

    m_WaitCond.wait();

    m_bFinished = true;

    return isStopped() == false;
}
コード例 #7
0
ファイル: BaseItemTask.cpp プロジェクト: Alasaad/Desurium
void BaseItemTask::doTask()
{
	if (!m_pWebCore || !m_pUserCore)
	{
		gcException e(ERR_BADCLASS);
		onErrorEvent(e);
		return;
	}

	try
	{
		doRun();
	}
	catch (gcException& e)
	{
		onErrorEvent(e);
	}
}
コード例 #8
0
ファイル: SMTController.cpp プロジェクト: Alasaad/Desurium
void SMTController::reportError(uint32 id, gcException &e)
{
#ifdef WIN32
	SMTWorkerInfo* worker = findWorker(id);
	assert(worker);
#endif
	Warning(gcString("SMTControler {0} Error: {1}.\n", id, e));
	onErrorEvent(e);
}
コード例 #9
0
bool VSCheckInstall::checkInstall()
{
	try
	{
		return m_hMcf->verifyInstall(getItemInfo()->getPath(), true);
	}
	catch (gcException &except)
	{
		onErrorEvent(except);
		return false;
	}
}
コード例 #10
0
void DownloadToolTask::doTask()
{
	try
	{
		downloadTool();
		finish();
	}
	catch (gcException &except)
	{
		onErrorEvent(except);
	}
}
コード例 #11
0
void DownloadToolTask::finish()
{
	if (!m_bStopped)
	{
		m_pTool->setExePath(m_Path.getFullPath().c_str());
		onCompleteEvent();
	}
	else
	{
		gcException e(ERR_USERCANCELED);
		onErrorEvent(e);
		UTIL::FS::delFile(m_Path);
	}
}
コード例 #12
0
void VerifyServiceTask::onError(gcException& e)
{
	m_bError = true;

	Warning(gcString("Error in verify install: {0}\n", e));
	getItemHandle()->setPausable(false);

	if (!getItemHandle()->shouldPauseOnError())
		getItemHandle()->resetStage(true);
	else
		getItemHandle()->setPaused(true, true);

	onErrorEvent(e);
}
コード例 #13
0
void DownloadToolTask::onWrite(WriteMem_s& mem)
{
	try
	{
		m_fhFile.write((char*)mem.data, mem.size);
		mem.wrote = mem.size;
	}
	catch (gcException& e)
	{
		onErrorEvent(e);
		mem.stop = true;
	}

	mem.handled = true;
}
コード例 #14
0
ファイル: UserTasks.cpp プロジェクト: aromis/desura-app
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);
	}
}
コード例 #15
0
ファイル: UserTasks.cpp プロジェクト: aromis/desura-app
void DownloadAvatarTask::doTask()
{
	try
	{
		if (strncmp(m_szUrl.c_str(),"http://", 7)==0)
		{
			HttpHandle wc(m_szUrl.c_str());
			wc->getWeb();
			
			if (wc->getDataSize() != 0)
			{
				if (UTIL::MISC::isValidImage((const unsigned char*)wc->getData()) == IMAGE_VOID)
					throw gcException(ERR_INVALIDDATA, gcString("The url [{0}] is not an image format", m_szUrl));
				
				UTIL::FS::Path urlPath(m_szUrl, "", true);
				UTIL::FS::Path path(getUserCore()->getAppDataPath(), "", false);

				path += "users";
				path += gcString("{0}", m_uiUserId);
				path += urlPath.getFile();

				UTIL::FS::recMakeFolder(path);
				UTIL::FS::FileHandle fh(path, UTIL::FS::FILE_WRITE);

				fh.write(wc->getData(), wc->getDataSize());
				fh.close();

				getUserCore()->setAvatarUrl(path.getFullPath().c_str());
			}
			else
			{
				throw gcException(ERR_BADRESPONSE);
			}
		}
	}
	catch (gcException &e)
	{
		onErrorEvent(e);
	}
}
コード例 #16
0
void DownloadToolTask::onComplete()
{
	bool notComplete = isStopped() || m_bCancelled;

	getUserCore()->getToolManager()->removeTransaction(m_ToolTTID, notComplete);
	m_ToolTTID = UINT_MAX;

	std::vector<DesuraId> toolList;
	getItemInfo()->getCurrentBranch()->getToolList(toolList);

	if (!m_bCancelled && !getUserCore()->getToolManager()->areAllToolsDownloaded(toolList))
	{
		gcException e(ERR_INVALID, "Failed to download tools.");
		onErrorEvent(e);
		notComplete = true;
	}

	if (notComplete)
	{
		getItemHandle()->completeStage(true);
		return;
	}

	uint32 blank = 0;
	onCompleteEvent(blank);

	if (m_bInstallAfter)
	{
		getItemHandle()->goToStageInstallTools(m_bLaunch);
	}
	else
	{
		if (HasAllFlags(getItemInfo()->getStatus(), UserCore::Item::ItemInfoI::STATUS_INSTALLCOMPLEX))
			getItemHandle()->goToStageInstallComplex(getMcfBranch(), getMcfBuild());
		else
			getItemHandle()->goToStageInstall(m_szDownloadPath.c_str(), getMcfBranch());
	}
}
コード例 #17
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();
}
コード例 #18
0
ファイル: HGTController.cpp プロジェクト: boskee/Desurium-1
void HGTController::doDownload()
{
	//header should be saved all ready so appened to it
	m_hFile.open(m_szFile, UTIL::FS::FILE_APPEND);
	m_hFile.seek(0);

	HttpHandle wc(m_szUrl.c_str());

	//wc->getProgressEvent() += delegate(this, &HGTController::onProgress);
	wc->getWriteEvent() += delegate(this, &HGTController::onWriteMemory);

	for (size_t x=0; x<m_vSuperBlockList.size(); x++)
	{
		m_pCurBlock = m_vSuperBlockList[x];

		wc->cleanUp();
		wc->setDownloadRange(m_pCurBlock->offset, m_pCurBlock->size);

		try
		{
			m_hFile.seek(m_pCurBlock->vBlockList[0]->fileOffset);
			wc->getWeb();
		}
		catch (gcException &e)
		{
			onErrorEvent(e);
			nonBlockStop();
		}
	}

	size_t fsSize = m_rvFileList.size();
	for (size_t x=0; x<fsSize; x++)
	{
		if (!HasAllFlags(m_rvFileList[x]->getFlags(), MCFFileI::FLAG_CANUSEDIFF))
			m_rvFileList[x]->addFlag(MCFFileI::FLAG_COMPLETE);
	}
}
コード例 #19
0
ファイル: VSCheckMcf.cpp プロジェクト: EasyCoding/desura-app
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;
}
コード例 #20
0
ファイル: CDKProgress.cpp プロジェクト: EasyCoding/desura-app
void CDKProgress::onCDKeyError(DesuraId id, gcException& e)
{
	m_bOutstandingRequest = false;
	onErrorEvent(e);
}
コード例 #21
0
bool UIComplexModServiceTask::initService()
{
	m_OldBranch = getItemInfo()->getInstalledBranch();
	m_OldBuild = getItemInfo()->getInstalledBuild();

	UserCore::Item::ItemInfo* parentInfo = getParentItemInfo();

	if (getItemInfo()->getInstalledModId().isOk())
		parentInfo = getItemInfo();

	if (!parentInfo)
	{
		onComplete();
		return false;
	}

	m_idLastInstalledMod = parentInfo->getInstalledModId();
	getUserCore()->getItemManager()->setInstalledMod(parentInfo->getId(), DesuraId());

	if (!m_idLastInstalledMod.isOk())
	{
		onComplete();
		return false;
	}

	UserCore::Item::ItemInfo* modInfo = dynamic_cast<UserCore::Item::ItemInfo*>(getUserCore()->getItemManager()->findItemInfo(m_idLastInstalledMod));

	if (!modInfo)
	{
		gcException eModNoExist(ERR_NULLHANDLE, "Installed mod doesnt exist in database!\n");
		onErrorEvent(eModNoExist);
		return false;
	}

	m_pIPCCL = getServiceMain()->newComplexLaunch();

	if (!m_pIPCCL)
	{
		gcException eFailedUninstall (ERR_NULLHANDLE, "Failed to create uninstall complex branch mcf service!\n");
		onErrorEvent(eFailedUninstall);
		return false;
	}

	UserCore::MCFManager *mm = UserCore::GetMCFManager();

	gcString installPath = modInfo->getPath();
	gcString parPath = mm->getMcfBackup(parentInfo->getId(), m_idLastInstalledMod);
	gcString modMcfPath;

	if (m_idLastInstalledMod == getItemInfo()->getId())
		modMcfPath = getBranchMcf(modInfo->getId(), m_OldBranch, m_OldBuild);
	else
		modMcfPath = getBranchMcf(modInfo->getId(), modInfo->getInstalledBranch(), modInfo->getInstalledBuild());

	if (m_uiCompleteAction == CA_UNINSTALL)
		modInfo->resetInstalledMcf();

	m_pIPCCL->onCompleteEvent += delegate(this, &UIComplexModServiceTask::onComplete);
	m_pIPCCL->onProgressEvent += delegate(this, &UIComplexModServiceTask::onProgress);
	m_pIPCCL->onErrorEvent += delegate((UIBaseServiceTask*)this, &UIBaseServiceTask::onServiceError);
	m_pIPCCL->startRemove(modMcfPath.c_str(), parPath.c_str(), installPath.c_str(), getItemInfo()->getInstallScriptPath());	

	return true;
}
コード例 #22
0
ファイル: HGTController.cpp プロジェクト: boskee/Desurium-1
void HGTController::fillDownloadList(bool &usingDiffs)
{
	usingDiffs = false;
	safe_delete(m_vSuperBlockList);
	MCFCore::MCF *webMcf = new MCFCore::MCF();

	try
	{
		webMcf->dlHeaderFromHttp(m_szUrl.c_str());
	}
	catch (gcException &e)
	{
		onErrorEvent(e);
		safe_delete(webMcf);
		return;
	}

	webMcf->sortFileList();

	uint64 mcfOffset = m_pHeader->getSize();
	size_t fsSize = m_rvFileList.size();

	//find the last files offset
	for (size_t x=0; x< fsSize; x++)
	{
		if (!m_rvFileList[x]->isSaved())
			continue;

		if ((m_rvFileList[x]->isComplete() || m_rvFileList[x]->hasStartedDL()) && m_rvFileList[x]->getOffSet() > mcfOffset)
		{
			mcfOffset = m_rvFileList[x]->getOffSet() + m_rvFileList[x]->getCurSize();
		}
	}

	std::deque<Misc::WGTBlock*> vBlockList;
	std::sort(m_rvFileList.begin(), m_rvFileList.end(), SortByOffset);

	for (size_t x=0; x<fsSize; x++)
	{
		//dont download all ready downloaded items
		if (m_rvFileList[x]->isComplete())
			continue;

		//skip files that arnt "saved" in the MCF
		if (!m_rvFileList[x]->isSaved())
			continue;	

		uint32 index = webMcf->findFileIndexByHash(m_rvFileList[x]->getHash());
		MCFCore::MCFFile *webFile = webMcf->getFile(index);

		uint64 size = m_rvFileList[x]->getCurSize();
		bool started = m_rvFileList[x]->hasStartedDL();

		if (index == UNKNOWN_ITEM || !webFile || !webFile->isSaved())
		{
			Warning(gcString("File {0} is not in web MCF. Skipping download.\n", m_rvFileList[x]->getName()));

			if (!started)
				m_rvFileList[x]->delFlag(MCFCore::MCFFileI::FLAG_SAVE);

			continue;
		}	


		if (!started)
			m_rvFileList[x]->setOffSet(mcfOffset);


		Misc::WGTBlock* temp = new Misc::WGTBlock;

		temp->fileOffset = m_rvFileList[x]->getOffSet();
		temp->file = m_rvFileList[x];

		if (webFile->hasDiff() && HasAllFlags(m_rvFileList[x]->getFlags(), MCFFileI::FLAG_CANUSEDIFF))
		{
			temp->webOffset = webFile->getDiffOffSet();
			temp->size = webFile->getDiffSize();

			if (!started)
				mcfOffset += webFile->getSize();

			usingDiffs = true;
		}
		else
		{
			m_rvFileList[x]->delFlag(MCFFileI::FLAG_CANUSEDIFF);
			temp->webOffset = webFile->getOffSet();
			temp->size = size;

			if (!started)
				mcfOffset += size;
		}

		vBlockList.push_back(temp);
		m_uiTotal += temp->size;
	}


	std::sort(vBlockList.begin(), vBlockList.end(), &WGTBlockSort);

	while (vBlockList.size() > 0)
	{
		Misc::WGTSuperBlock* sb = new Misc::WGTSuperBlock();
		sb->offset = vBlockList[0]->webOffset;

		do
		{
			Misc::WGTBlock* block = vBlockList.front();
			vBlockList.pop_front();

			sb->size += block->size;
			sb->vBlockList.push_back(block);
		}
		while (vBlockList.size() > 0 && vBlockList[0]->webOffset == (sb->offset + sb->size));

		m_vSuperBlockList.push_back(sb);
	}
}