Beispiel #1
0
ALERROR WriteHeader (CTDBCompiler &Ctx, int iGameFile, CDataFile &Out)
	{
	ALERROR error;
	CMemoryWriteStream Stream;

	if (error = Stream.Create())
		{
		Ctx.ReportError(CONSTLIT("Out of memory"));
		return error;
		}

	//	Write it

	CString sError;
	if (!Ctx.WriteHeader(Stream, iGameFile, &sError))
		{
		Ctx.ReportError(strPatternSubst(CONSTLIT("Unable to write header: %s"), sError));
		return ERR_FAIL;
		}

	//	Write out the header

	Stream.Close();
	CString sData(Stream.GetPointer(), Stream.GetLength(), TRUE);
	int iEntry;
	if (error = Out.AddEntry(sData, &iEntry))
		{
		Ctx.ReportError(CONSTLIT("Unable to write header"));
		return error;
		}

	Out.SetDefaultEntry(iEntry);

	return NOERROR;
	}
Beispiel #2
0
ALERROR WriteResource (const CString &sFilename, const CString &sFolder, CSymbolTable &Resources, CDataFile &Out)
	{
	ALERROR error;
	CString sFilespec = pathAddComponent(sFolder, sFilename);

	CFileReadBlock theFile(sFilespec);
	if (error = theFile.Open())
		{
		printf("Unable to open '%s'\n", sFilespec.GetASCIIZPointer());
		return error;
		}

	CString sData(theFile.GetPointer(0, -1), theFile.GetLength(), TRUE);
	int iEntry;
	if (error = Out.AddEntry(sData, &iEntry))
		{
		printf("Unable to store '%s'\n", sFilespec.GetASCIIZPointer());
		return error;
		}

	Resources.AddEntry(sFilespec, (CObject *)iEntry);
	printf("   %s\n", sFilespec.GetASCIIZPointer());

	return NOERROR;
	}
Beispiel #3
0
ALERROR WriteHeader (int iGameFile, CSymbolTable &Resources, CDataFile &Out)
	{
	ALERROR error;
	CMemoryWriteStream Stream;
	DWORD dwSave;

	if (error = Stream.Create())
		{
		printf("Out of memory\n");
		return error;
		}

	//	Signature

	dwSave = TDB_SIGNATURE;
	Stream.Write((char *)&dwSave, sizeof(dwSave));

	//	Version

	dwSave = TDB_VERSION;
	Stream.Write((char *)&dwSave, sizeof(dwSave));

	//	Game file entry

	dwSave = iGameFile;
	Stream.Write((char *)&dwSave, sizeof(dwSave));

	//	Game title

	CString sGameTitle = CONSTLIT("Transcendence: The March of the Heretic");
	sGameTitle.WriteToStream(&Stream);

	//	Resource map

	CString sSave;
	if (error = CObject::Flatten(&Resources, &sSave))
		{
		printf("Unable to flatten resources map\n");
		return error;
		}

	sSave.WriteToStream(&Stream);

	//	Write out the header

	Stream.Close();
	CString sData(Stream.GetPointer(), Stream.GetLength(), TRUE);
	int iEntry;
	if (error = Out.AddEntry(sData, &iEntry))
		{
		printf("Unable to write out header\n");
		return error;
		}

	Out.SetDefaultEntry(iEntry);

	return NOERROR;
	}
Beispiel #4
0
ALERROR WriteResource (CTDBCompiler &Ctx, const CString &sFilename, const CString &sFolder, bool bCompress, CDataFile &Out)
	{
	ALERROR error;
	CString sFilespec = pathAddComponent(sFolder, sFilename);

	CFileReadBlock theFile(pathAddComponent(Ctx.GetRootPath(), sFilespec));
	if (error = theFile.Open())
		{
		Ctx.ReportError(strPatternSubst(CONSTLIT("Unable to open '%s'."), sFilespec));
		return error;
		}

	CString sData(theFile.GetPointer(0, -1), theFile.GetLength(), TRUE);

	if (bCompress)
		{
		CBufferReadBlock Input(sData);

		CMemoryWriteStream Output;
		if (error = Output.Create())
			return ERR_FAIL;

		CString sError;
		if (!zipCompress(Input, compressionZlib, Output, &sError))
			{
			Ctx.ReportError(sError);
			return ERR_FAIL;
			}

		sData = CString(Output.GetPointer(), Output.GetLength());
		}

	int iEntry;
	if (error = Out.AddEntry(sData, &iEntry))
		{
		Ctx.ReportError(strPatternSubst(CONSTLIT("Unable to store '%s'."), sFilespec));
		return error;
		}

	Ctx.AddResource(sFilespec, iEntry, bCompress);

	printf("   %s\n", sFilespec.GetASCIIZPointer());

	return NOERROR;
	}
Beispiel #5
0
ALERROR WriteGameFile (const CString &sFilespec, CDataFile &Out, int *retiGameFile)
	{
	ALERROR error;

	CFileReadBlock theFile(sFilespec);
	if (error = theFile.Open())
		{
		printf("Unable to open '%s'\n", sFilespec.GetASCIIZPointer());
		return error;
		}

	CString sData(theFile.GetPointer(0, -1), theFile.GetLength(), TRUE);
	if (error = Out.AddEntry(sData, retiGameFile))
		{
		printf("Unable to store '%s'\n", sFilespec.GetASCIIZPointer());
		return error;
		}

	printf("%s\n", sFilespec.GetASCIIZPointer());

	return NOERROR;
	}