From 978dd707705e226d62fbcf810a4d91c9a2dd128f Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 15 Jun 2020 01:40:21 -0500 Subject: [PATCH] [nostalgia] Switch tools to use Claw --- src/nostalgia/studio/lib/CMakeLists.txt | 2 +- src/nostalgia/studio/lib/project.cpp | 4 ++-- src/nostalgia/studio/lib/project.hpp | 15 ++++++++------- src/nostalgia/tools/pack/CMakeLists.txt | 2 +- src/nostalgia/tools/pack/pack.cpp | 21 ++++++++++++++++----- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/nostalgia/studio/lib/CMakeLists.txt b/src/nostalgia/studio/lib/CMakeLists.txt index 7114b6a8..850ad522 100644 --- a/src/nostalgia/studio/lib/CMakeLists.txt +++ b/src/nostalgia/studio/lib/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries( NostalgiaStudio PUBLIC Qt5::Widgets OxFS - OxMetalClaw + OxClaw ) install( diff --git a/src/nostalgia/studio/lib/project.cpp b/src/nostalgia/studio/lib/project.cpp index 2a407f3c..ab8244f4 100644 --- a/src/nostalgia/studio/lib/project.cpp +++ b/src/nostalgia/studio/lib/project.cpp @@ -56,8 +56,8 @@ void Project::writeBuff(QString path, uint8_t *buff, size_t buffLen) const { emit fileUpdated(path); } -std::vector Project::loadBuff(QString path) const { - std::vector buff(stat(path).size); +std::vector Project::loadBuff(QString path) const { + std::vector buff(stat(path).size); const auto csPath = path.toUtf8(); oxThrowError(m_fs.read(csPath.data(), buff.data(), buff.size())); return buff; diff --git a/src/nostalgia/studio/lib/project.hpp b/src/nostalgia/studio/lib/project.hpp index 6e00fd77..a970e644 100644 --- a/src/nostalgia/studio/lib/project.hpp +++ b/src/nostalgia/studio/lib/project.hpp @@ -16,8 +16,10 @@ #include #include +#include "ox/claw/claw.hpp" +#include + #include "nostalgiastudio_export.h" -#include "ox/fs/filesystem/passthroughfs.hpp" namespace nostalgia::studio { @@ -71,7 +73,7 @@ class NOSTALGIASTUDIO_EXPORT Project: public QObject { private: void writeBuff(QString path, uint8_t *buff, size_t buffLen) const; - std::vector loadBuff(QString path) const; + std::vector loadBuff(QString path) const; void procDir(QStringList &paths, QString path) const; @@ -91,12 +93,11 @@ class NOSTALGIASTUDIO_EXPORT Project: public QObject { template void Project::writeObj(QString path, T *obj) const { - std::vector buff(10 * ox::units::MB, 0); // write MetalClaw - size_t mcSize = 0; - oxThrowError(ox::writeMC(buff.data(), buff.size(), obj, &mcSize)); + auto [buff, err] = ox::writeClaw(obj, ox::ClawFormat::Metal); + oxThrowError(err); // write to FS - writeBuff(path, buff.data(), mcSize); + writeBuff(path, ox::bit_cast(buff.data()), buff.size()); emit fileUpdated(path); } @@ -104,7 +105,7 @@ template std::unique_ptr Project::loadObj(QString path) const { auto obj = std::make_unique(); auto buff = loadBuff(path); - oxThrowError(ox::readMC(buff.data(), buff.size(), obj.get())); + oxThrowError(ox::readClaw(buff.data(), buff.size(), obj.get())); return obj; } diff --git a/src/nostalgia/tools/pack/CMakeLists.txt b/src/nostalgia/tools/pack/CMakeLists.txt index ea0c5567..d3293bbd 100644 --- a/src/nostalgia/tools/pack/CMakeLists.txt +++ b/src/nostalgia/tools/pack/CMakeLists.txt @@ -7,9 +7,9 @@ add_library( target_link_libraries( NostalgiaPack PUBLIC OxClArgs + OxClaw OxFS OxStd - OxMetalClaw NostalgiaCommon NostalgiaCore ) diff --git a/src/nostalgia/tools/pack/pack.cpp b/src/nostalgia/tools/pack/pack.cpp index 8d51d99a..f9162aff 100644 --- a/src/nostalgia/tools/pack/pack.cpp +++ b/src/nostalgia/tools/pack/pack.cpp @@ -10,6 +10,8 @@ #include #include +#include + #include "pack.hpp" namespace nostalgia { @@ -31,7 +33,12 @@ namespace { } // stub for now -[[nodiscard]] ox::Error toMetalClaw(std::vector*) { +[[nodiscard]] ox::Error toMetalClaw(std::vector *buff) { + auto [mc, err] = ox::stripClawHeader(ox::bit_cast(buff->data()), buff->size()); + std::cout << "buff size: " << buff->size() << '\n'; + oxReturnError(err); + buff->resize(mc.size()); + ox_memcpy(buff->data(), mc.data(), mc.size()); return OxError(0); } @@ -39,24 +46,27 @@ namespace { // transformations need to be done after the copy to the new FS is complete [[nodiscard]] ox::Error transformClaw(ox::FileSystem32 *dest, std::string path) { // copy + std::cout << "transformClaw: path: " << path << '\n'; oxTrace("pack::transformClaw") << "path:" << path.c_str(); return dest->ls(path.c_str(), [dest, path](const char *name, ox::InodeId_t) { - auto [stat, err] = dest->stat(path.c_str()); + auto filePath = path + name; + auto [stat, err] = dest->stat(filePath.c_str()); oxReturnError(err); if (stat.fileType == ox::FileType_Directory) { const auto dir = path + name + '/'; oxReturnError(transformClaw(dest, dir)); } else { + std::cout << filePath << '\n'; // do transforms - if (endsWith(path, ".claw")) { + if (endsWith(name, ".ng") || endsWith(name, ".npal")) { // load file std::vector buff(stat.size); - oxReturnError(dest->read(path.c_str(), buff.data(), buff.size())); + oxReturnError(dest->read(filePath.c_str(), buff.data(), buff.size())); // do transformations oxReturnError(pathToInode(&buff)); oxReturnError(toMetalClaw(&buff)); // write file to dest - oxReturnError(dest->write(path.c_str(), buff.data(), buff.size())); + oxReturnError(dest->write(filePath.c_str(), buff.data(), buff.size())); } } return OxError(0); @@ -114,6 +124,7 @@ struct VerificationPair { [[nodiscard]] ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest) { oxReturnError(copy(src, dest, "/")); + std::cout << '\n'; oxReturnError(transformClaw(dest, "/")); return OxError(0); }