mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-21 04:07:52 -05:00
refactor: use OutputPathFilesystem for writing fastfiles
This commit is contained in:
@ -51,12 +51,13 @@
|
||||
#include "Writing/WritingException.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <format>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
ContentWriter::ContentWriter()
|
||||
: varXAssetList(nullptr),
|
||||
ContentWriter::ContentWriter(const Zone& zone)
|
||||
: ContentWriterBase(zone),
|
||||
varXAssetList(nullptr),
|
||||
varXAsset(nullptr),
|
||||
varScriptStringList(nullptr)
|
||||
{
|
||||
@ -64,14 +65,14 @@ ContentWriter::ContentWriter()
|
||||
|
||||
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
|
||||
{
|
||||
if (!m_zone->m_script_strings.Empty())
|
||||
if (!m_zone.m_script_strings.Empty())
|
||||
{
|
||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||
xAssetList.stringList.count = static_cast<int>(m_zone->m_script_strings.Count());
|
||||
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone->m_script_strings.Count());
|
||||
assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||
xAssetList.stringList.count = static_cast<int>(m_zone.m_script_strings.Count());
|
||||
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone.m_script_strings.Count());
|
||||
|
||||
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
|
||||
xAssetList.stringList.strings[i] = m_zone->m_script_strings.CValue(i);
|
||||
for (auto i = 0u; i < m_zone.m_script_strings.Count(); i++)
|
||||
xAssetList.stringList.strings[i] = m_zone.m_script_strings.CValue(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -82,15 +83,15 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
||||
xAssetList.dependCount = 0;
|
||||
xAssetList.depends = nullptr;
|
||||
|
||||
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
||||
const auto assetCount = m_zone.m_pools->GetTotalAssetCount();
|
||||
if (assetCount > 0)
|
||||
{
|
||||
xAssetList.assetCount = static_cast<int>(assetCount);
|
||||
xAssetList.assets = memory.Alloc<XAsset>(assetCount);
|
||||
|
||||
const auto end = m_zone->m_pools->end();
|
||||
const auto end = m_zone.m_pools->end();
|
||||
auto index = 0u;
|
||||
for (auto i = m_zone->m_pools->begin(); i != end; ++i)
|
||||
for (auto i = m_zone.m_pools->begin(); i != end; ++i)
|
||||
{
|
||||
auto& asset = xAssetList.assets[index++];
|
||||
asset.type = static_cast<XAssetType>((*i)->m_type);
|
||||
@ -128,7 +129,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
||||
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, m_stream); \
|
||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, *m_stream); \
|
||||
writer.Write(&varXAsset->header.headerEntry); \
|
||||
break; \
|
||||
}
|
||||
@ -192,9 +193,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
||||
|
||||
default:
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Unsupported asset type: " << varXAsset->type << ".";
|
||||
throw WritingException(str.str());
|
||||
throw WritingException(std::format("Unsupported asset type: {}.", static_cast<unsigned>(varXAsset->type)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,10 +214,9 @@ void ContentWriter::WriteXAssetArray(const bool atStreamStart, const size_t coun
|
||||
}
|
||||
}
|
||||
|
||||
void ContentWriter::WriteContent(Zone* zone, IZoneOutputStream* stream)
|
||||
void ContentWriter::WriteContent(IZoneOutputStream& stream)
|
||||
{
|
||||
m_zone = zone;
|
||||
m_stream = stream;
|
||||
m_stream = &stream;
|
||||
|
||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||
|
||||
|
@ -7,10 +7,12 @@ namespace T6
|
||||
{
|
||||
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
||||
{
|
||||
XAssetList* varXAssetList;
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
public:
|
||||
explicit ContentWriter(const Zone& zone);
|
||||
|
||||
void WriteContent(IZoneOutputStream& stream) override;
|
||||
|
||||
private:
|
||||
void CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const;
|
||||
|
||||
void WriteScriptStringList(bool atStreamStart);
|
||||
@ -18,9 +20,8 @@ namespace T6
|
||||
void WriteXAsset(bool atStreamStart);
|
||||
void WriteXAssetArray(bool atStreamStart, size_t count);
|
||||
|
||||
public:
|
||||
ContentWriter();
|
||||
|
||||
void WriteContent(Zone* zone, IZoneOutputStream* stream) override;
|
||||
XAssetList* varXAssetList;
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
};
|
||||
} // namespace T6
|
||||
|
@ -95,7 +95,7 @@ namespace
|
||||
}
|
||||
}; // namespace
|
||||
|
||||
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
||||
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(const Zone& zone) const
|
||||
{
|
||||
auto writer = std::make_unique<ZoneWriter>();
|
||||
|
||||
@ -106,7 +106,7 @@ std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
||||
SetupBlocks(*writer);
|
||||
|
||||
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
|
||||
std::make_unique<ContentWriter>(), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
||||
std::make_unique<ContentWriter>(zone), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
||||
auto* contentInMemoryPtr = contentInMemory.get();
|
||||
writer->AddWritingStep(std::move(contentInMemory));
|
||||
|
||||
@ -116,7 +116,7 @@ std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
||||
// Setup loading XChunks from the zone from this point on.
|
||||
ICapturedDataProvider* dataToSignProvider;
|
||||
OutputProcessorXChunks* xChunksProcessor;
|
||||
AddXChunkProcessor(*writer, *zone, isEncrypted, &dataToSignProvider, &xChunksProcessor);
|
||||
AddXChunkProcessor(*writer, zone, isEncrypted, &dataToSignProvider, &xChunksProcessor);
|
||||
|
||||
// Start of the XFile struct
|
||||
// m_writer->AddWritingStep(std::make_unique<StepSkipBytes>(8)); // Skip size and externalSize fields since they are not interesting for us
|
||||
|
@ -8,9 +8,7 @@ namespace T6
|
||||
{
|
||||
class ZoneWriterFactory final : public IZoneWriterFactory
|
||||
{
|
||||
class Impl;
|
||||
|
||||
public:
|
||||
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
|
||||
[[nodiscard]] std::unique_ptr<ZoneWriter> CreateWriter(const Zone& zone) const override;
|
||||
};
|
||||
} // namespace T6
|
||||
|
Reference in New Issue
Block a user