mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-12 07:48:16 -05:00
refactor: use OutputPathFilesystem for writing fastfiles
This commit is contained in:
@ -28,12 +28,13 @@
|
||||
#include "Writing/WritingException.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <format>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
ContentWriter::ContentWriter()
|
||||
: varXAssetList(nullptr),
|
||||
ContentWriter::ContentWriter(const Zone& zone)
|
||||
: ContentWriterBase(zone),
|
||||
varXAssetList(nullptr),
|
||||
varXAsset(nullptr),
|
||||
varScriptStringList(nullptr)
|
||||
{
|
||||
@ -41,14 +42,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
|
||||
{
|
||||
@ -56,15 +57,15 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
||||
xAssetList.stringList.strings = 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);
|
||||
@ -102,7 +103,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; \
|
||||
}
|
||||
@ -147,9 +148,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)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,10 +170,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 IW3
|
||||
{
|
||||
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 IW3
|
||||
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 IW3
|
||||
|
@ -45,14 +45,14 @@ 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>();
|
||||
|
||||
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));
|
||||
|
||||
|
@ -9,6 +9,6 @@ namespace IW3
|
||||
class ZoneWriterFactory final : public IZoneWriterFactory
|
||||
{
|
||||
public:
|
||||
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
|
||||
[[nodiscard]] std::unique_ptr<ZoneWriter> CreateWriter(const Zone& zone) const override;
|
||||
};
|
||||
} // namespace IW3
|
||||
|
@ -38,12 +38,13 @@
|
||||
#include "Writing/WritingException.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <format>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
ContentWriter::ContentWriter()
|
||||
: varXAssetList(nullptr),
|
||||
ContentWriter::ContentWriter(const Zone& zone)
|
||||
: ContentWriterBase(zone),
|
||||
varXAssetList(nullptr),
|
||||
varXAsset(nullptr),
|
||||
varScriptStringList(nullptr)
|
||||
{
|
||||
@ -51,14 +52,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
|
||||
{
|
||||
@ -66,15 +67,15 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
||||
xAssetList.stringList.strings = 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);
|
||||
@ -112,7 +113,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; \
|
||||
}
|
||||
@ -167,9 +168,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)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,10 +190,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 IW4
|
||||
{
|
||||
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 IW4
|
||||
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 IW4
|
||||
|
@ -57,7 +57,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>();
|
||||
|
||||
@ -67,7 +67,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));
|
||||
|
||||
|
@ -9,6 +9,6 @@ namespace IW4
|
||||
class ZoneWriterFactory final : public IZoneWriterFactory
|
||||
{
|
||||
public:
|
||||
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
|
||||
[[nodiscard]] std::unique_ptr<ZoneWriter> CreateWriter(const Zone& zone) const override;
|
||||
};
|
||||
} // namespace IW4
|
||||
|
@ -43,12 +43,13 @@
|
||||
#include "Writing/WritingException.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <format>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
ContentWriter::ContentWriter()
|
||||
: varXAssetList(nullptr),
|
||||
ContentWriter::ContentWriter(const Zone& zone)
|
||||
: ContentWriterBase(zone),
|
||||
varXAssetList(nullptr),
|
||||
varXAsset(nullptr),
|
||||
varScriptStringList(nullptr)
|
||||
{
|
||||
@ -56,14 +57,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
|
||||
{
|
||||
@ -71,15 +72,15 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
||||
xAssetList.stringList.strings = 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);
|
||||
@ -117,7 +118,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; \
|
||||
}
|
||||
@ -175,9 +176,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)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,10 +198,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 IW5
|
||||
{
|
||||
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 IW5
|
||||
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 IW5
|
||||
|
@ -58,7 +58,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>();
|
||||
|
||||
@ -68,7 +68,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));
|
||||
|
||||
|
@ -9,6 +9,6 @@ namespace IW5
|
||||
class ZoneWriterFactory final : public IZoneWriterFactory
|
||||
{
|
||||
public:
|
||||
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
|
||||
[[nodiscard]] std::unique_ptr<ZoneWriter> CreateWriter(const Zone& zone) const override;
|
||||
};
|
||||
} // namespace IW5
|
||||
|
@ -35,12 +35,13 @@
|
||||
#include "Writing/WritingException.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <format>
|
||||
|
||||
using namespace T5;
|
||||
|
||||
ContentWriter::ContentWriter()
|
||||
: varXAssetList(nullptr),
|
||||
ContentWriter::ContentWriter(const Zone& zone)
|
||||
: ContentWriterBase(zone),
|
||||
varXAssetList(nullptr),
|
||||
varXAsset(nullptr),
|
||||
varScriptStringList(nullptr)
|
||||
{
|
||||
@ -48,14 +49,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
|
||||
{
|
||||
@ -63,15 +64,15 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
||||
xAssetList.stringList.strings = 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);
|
||||
@ -109,7 +110,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; \
|
||||
}
|
||||
@ -160,9 +161,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)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,10 +183,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 T5
|
||||
{
|
||||
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
||||
{
|
||||
XAssetList* varXAssetList;
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
public:
|
||||
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 T5
|
||||
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 T5
|
||||
|
@ -43,14 +43,14 @@ 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>();
|
||||
|
||||
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));
|
||||
|
||||
|
@ -8,9 +8,7 @@ namespace T5
|
||||
{
|
||||
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 T5
|
||||
|
@ -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