iw4x-client/src/Components/Modules/AssetInterfaces/IRawFile.cpp

62 lines
1.4 KiB
C++
Raw Normal View History

2022-02-27 07:53:44 -05:00
#include <STDInclude.hpp>
#include "IRawFile.hpp"
2017-01-19 16:23:59 -05:00
namespace Assets
{
2018-12-17 08:29:18 -05:00
void IRawFile::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
2017-01-19 16:23:59 -05:00
{
Components::FileSystem::File rawFile(name);
if (rawFile.exists())
{
Game::RawFile* asset = builder->getAllocator()->allocate<Game::RawFile>();
if (asset)
{
//std::string data = Utils::Compression::ZLib::Compress(rawFile.getBuffer());
asset->name = builder->getAllocator()->duplicateString(name);
2018-05-09 08:33:52 -04:00
asset->buffer = builder->getAllocator()->duplicateString(rawFile.getBuffer());
asset->compressedLen = 0;//data.size();
asset->len = rawFile.getBuffer().size();
2017-01-19 16:23:59 -05:00
header->rawfile = asset;
}
}
}
void IRawFile::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
AssertSize(Game::RawFile, 16);
Utils::Stream* buffer = builder->getBuffer();
Game::RawFile* asset = header.rawfile;
Game::RawFile* dest = buffer->dest<Game::RawFile>();
buffer->save(asset);
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->name)
{
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
}
2018-05-09 08:33:52 -04:00
if (asset->buffer)
2017-01-19 16:23:59 -05:00
{
2018-05-09 08:33:52 -04:00
if (asset->compressedLen)
2017-01-19 16:23:59 -05:00
{
2018-05-09 08:33:52 -04:00
buffer->save(asset->buffer, asset->compressedLen);
2017-01-19 16:23:59 -05:00
}
else
{
2018-05-09 08:33:52 -04:00
buffer->save(asset->buffer, asset->len + 1);
2017-01-19 16:23:59 -05:00
}
2018-05-09 08:33:52 -04:00
Utils::Stream::ClearPointer(&dest->buffer);
2017-01-19 16:23:59 -05:00
}
buffer->popBlock();
}
}