Пример #1
0
ALERROR CExtension::CreateExtension (SDesignLoadCtx &Ctx, CXMLElement *pDesc, EFolderTypes iFolder, CExternalEntityTable *pEntities, CExtension **retpExtension)

//	CreateExtension
//
//	Loads the given extension or adventure. We take ownership of pEntities.

	{
	ALERROR error;
	int i;

	//	Create an extension object

	CExtension *pExtension;
	if (error = CreateExtensionFromRoot(Ctx.sResDb, pDesc, iFolder, pEntities, Ctx.dwInheritAPIVersion, &pExtension, &Ctx.sError))
		return error;

	//	Set up context

	Ctx.pExtension = pExtension;

	//	Load all the design elements

	for (i = 0; i < pDesc->GetContentElementCount(); i++)
		{
		CXMLElement *pItem = pDesc->GetContentElement(i);

		if (error = pExtension->LoadDesignElement(Ctx, pItem))
			{
			pExtension->m_pEntities = NULL;	//	Let our parent clean up.
			delete pExtension;
			return error;
			}
		}

	//	If this is an adventure and we have no adventure descriptor then we
	//	fail.

	if (pExtension->m_iType == extAdventure && pExtension->m_pAdventureDesc == NULL)
		{
		pExtension->m_pEntities = NULL;	//	Let our parent clean up.
		delete pExtension;
		Ctx.sError = CONSTLIT("Adventure must have an AdventureDesc type.");
		return ERR_FAIL;
		}

	pExtension->AddDefaultLibraryReferences(Ctx);

	//	Restore

	Ctx.pExtension = NULL;

	//	Done

	pExtension->m_iLoadState = (Ctx.bLoadAdventureDesc ? loadAdventureDesc : loadComplete);
	*retpExtension = pExtension;

	return NOERROR;
	}
Пример #2
0
ALERROR CExtension::CreateBaseFile (SDesignLoadCtx &Ctx, EGameTypes iGame, CXMLElement *pDesc, CExternalEntityTable *pEntities, CExtension **retpBase, TArray<CXMLElement *> *retEmbedded)

//	CreateBaseFile
//
//	Loads a new extension from the base file.

	{
	ALERROR error;
	int i;

	//	Create an extension object

	CExtension *pExtension = new CExtension;
	pExtension->m_sFilespec = Ctx.sResDb;
	pExtension->m_dwUNID = 0;	//	Base is the only extension with 0 UNID.
	pExtension->m_iGame = iGame;
	pExtension->m_iType = extBase;
	pExtension->m_iLoadState = loadEntities;
	pExtension->m_iFolderType = folderBase;
	pExtension->m_pEntities = pEntities;
	pExtension->m_ModifiedTime = fileGetModifiedTime(Ctx.sResDb);
	pExtension->m_bRegistered = true;
	pExtension->m_bPrivate = true;
	pExtension->m_bAutoInclude = true;
	pExtension->m_bUsesXML = false;
	pExtension->m_bUsesCompatibilityLibrary = false;

	//	Load the apiVersion

	CString sAPIVersion;
	if (pDesc->FindAttribute(API_VERSION_ATTRIB, &sAPIVersion))
		{
		pExtension->m_dwAPIVersion = (DWORD)strToInt(sAPIVersion, 0);
		if (pExtension->m_dwAPIVersion < 12)
			pExtension->m_dwAPIVersion = 0;
		}

	//	If this version is later than what we expect, then we fail.

	if (pExtension->m_dwAPIVersion > API_VERSION)
		{
		pExtension->m_pEntities = NULL;	//	Let our parent clean up
		delete pExtension;
		Ctx.sError = CONSTLIT("Newer version of the Transcendence engine is required.");
		return ERR_FAIL;
		}

	//	We return the base extension

	*retpBase = pExtension;

	//	Set up context

	Ctx.pExtension = pExtension;

	//	Load the Main XML file

	for (i = 0; i < pDesc->GetContentElementCount(); i++)
		{
		CXMLElement *pItem = pDesc->GetContentElement(i);

		//	<Images>

		if (strEquals(pItem->GetTag(), IMAGES_TAG))
			error = pExtension->LoadImagesElement(Ctx, pItem);

		//	<Sounds>

		else if (strEquals(pItem->GetTag(), SOUNDS_TAG))
			error = pExtension->LoadSoundsElement(Ctx, pItem);

		//	<SystemTypes>

		else if (strEquals(pItem->GetTag(), SYSTEM_TYPES_TAG))
			error = pExtension->LoadSystemTypesElement(Ctx, pItem);

		//	<TranscendenceAdventure>

		else if (strEquals(pItem->GetTag(), TRANSCENDENCE_ADVENTURE_TAG)
				|| strEquals(pItem->GetTag(), TRANSCENDENCE_LIBRARY_TAG)
				|| strEquals(pItem->GetTag(), CORE_LIBRARY_TAG))
			{
			//	Return this as an embedded extension

			retEmbedded->Insert(pItem);
			error = NOERROR;
			}

		//	Other types

		else
			error = pExtension->LoadDesignElement(Ctx, pItem);

		//	Check for error

		if (error)
			{
			pExtension->m_pEntities = NULL;	//	Let our parent clean up
			delete pExtension;
			return error;
			}
		}

	//	Restore

	Ctx.pExtension = NULL;

	//	Done

	pExtension->m_iLoadState = loadComplete;

	return NOERROR;
	}