[nostalgia] Switch tools to use Claw
This commit is contained in:
parent
9a49761c01
commit
978dd70770
@ -19,7 +19,7 @@ target_link_libraries(
|
||||
NostalgiaStudio PUBLIC
|
||||
Qt5::Widgets
|
||||
OxFS
|
||||
OxMetalClaw
|
||||
OxClaw
|
||||
)
|
||||
|
||||
install(
|
||||
|
@ -56,8 +56,8 @@ void Project::writeBuff(QString path, uint8_t *buff, size_t buffLen) const {
|
||||
emit fileUpdated(path);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Project::loadBuff(QString path) const {
|
||||
std::vector<uint8_t> buff(stat(path).size);
|
||||
std::vector<char> Project::loadBuff(QString path) const {
|
||||
std::vector<char> buff(stat(path).size);
|
||||
const auto csPath = path.toUtf8();
|
||||
oxThrowError(m_fs.read(csPath.data(), buff.data(), buff.size()));
|
||||
return buff;
|
||||
|
@ -16,8 +16,10 @@
|
||||
#include <ox/mc/mc.hpp>
|
||||
#include <qnamespace.h>
|
||||
|
||||
#include "ox/claw/claw.hpp"
|
||||
#include <ox/fs/filesystem/passthroughfs.hpp>
|
||||
|
||||
#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<uint8_t> loadBuff(QString path) const;
|
||||
std::vector<char> loadBuff(QString path) const;
|
||||
|
||||
void procDir(QStringList &paths, QString path) const;
|
||||
|
||||
@ -91,12 +93,11 @@ class NOSTALGIASTUDIO_EXPORT Project: public QObject {
|
||||
|
||||
template<typename T>
|
||||
void Project::writeObj(QString path, T *obj) const {
|
||||
std::vector<uint8_t> 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<uint8_t*>(buff.data()), buff.size());
|
||||
emit fileUpdated(path);
|
||||
}
|
||||
|
||||
@ -104,7 +105,7 @@ template<typename T>
|
||||
std::unique_ptr<T> Project::loadObj(QString path) const {
|
||||
auto obj = std::make_unique<T>();
|
||||
auto buff = loadBuff(path);
|
||||
oxThrowError(ox::readMC<T>(buff.data(), buff.size(), obj.get()));
|
||||
oxThrowError(ox::readClaw<T>(buff.data(), buff.size(), obj.get()));
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -7,9 +7,9 @@ add_library(
|
||||
target_link_libraries(
|
||||
NostalgiaPack PUBLIC
|
||||
OxClArgs
|
||||
OxClaw
|
||||
OxFS
|
||||
OxStd
|
||||
OxMetalClaw
|
||||
NostalgiaCommon
|
||||
NostalgiaCore
|
||||
)
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <ox/claw/read.hpp>
|
||||
|
||||
#include "pack.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
@ -31,7 +33,12 @@ namespace {
|
||||
}
|
||||
|
||||
// stub for now
|
||||
[[nodiscard]] ox::Error toMetalClaw(std::vector<uint8_t>*) {
|
||||
[[nodiscard]] ox::Error toMetalClaw(std::vector<uint8_t> *buff) {
|
||||
auto [mc, err] = ox::stripClawHeader(ox::bit_cast<char*>(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<uint8_t> 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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user