[nostalgia] Switch tools to use Claw
This commit is contained in:
parent
9a49761c01
commit
978dd70770
@ -19,7 +19,7 @@ target_link_libraries(
|
|||||||
NostalgiaStudio PUBLIC
|
NostalgiaStudio PUBLIC
|
||||||
Qt5::Widgets
|
Qt5::Widgets
|
||||||
OxFS
|
OxFS
|
||||||
OxMetalClaw
|
OxClaw
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
|
@ -56,8 +56,8 @@ void Project::writeBuff(QString path, uint8_t *buff, size_t buffLen) const {
|
|||||||
emit fileUpdated(path);
|
emit fileUpdated(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> Project::loadBuff(QString path) const {
|
std::vector<char> Project::loadBuff(QString path) const {
|
||||||
std::vector<uint8_t> buff(stat(path).size);
|
std::vector<char> buff(stat(path).size);
|
||||||
const auto csPath = path.toUtf8();
|
const auto csPath = path.toUtf8();
|
||||||
oxThrowError(m_fs.read(csPath.data(), buff.data(), buff.size()));
|
oxThrowError(m_fs.read(csPath.data(), buff.data(), buff.size()));
|
||||||
return buff;
|
return buff;
|
||||||
|
@ -16,8 +16,10 @@
|
|||||||
#include <ox/mc/mc.hpp>
|
#include <ox/mc/mc.hpp>
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
|
|
||||||
|
#include "ox/claw/claw.hpp"
|
||||||
|
#include <ox/fs/filesystem/passthroughfs.hpp>
|
||||||
|
|
||||||
#include "nostalgiastudio_export.h"
|
#include "nostalgiastudio_export.h"
|
||||||
#include "ox/fs/filesystem/passthroughfs.hpp"
|
|
||||||
|
|
||||||
namespace nostalgia::studio {
|
namespace nostalgia::studio {
|
||||||
|
|
||||||
@ -71,7 +73,7 @@ class NOSTALGIASTUDIO_EXPORT Project: public QObject {
|
|||||||
private:
|
private:
|
||||||
void writeBuff(QString path, uint8_t *buff, size_t buffLen) const;
|
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;
|
void procDir(QStringList &paths, QString path) const;
|
||||||
|
|
||||||
@ -91,12 +93,11 @@ class NOSTALGIASTUDIO_EXPORT Project: public QObject {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Project::writeObj(QString path, T *obj) const {
|
void Project::writeObj(QString path, T *obj) const {
|
||||||
std::vector<uint8_t> buff(10 * ox::units::MB, 0);
|
|
||||||
// write MetalClaw
|
// write MetalClaw
|
||||||
size_t mcSize = 0;
|
auto [buff, err] = ox::writeClaw(obj, ox::ClawFormat::Metal);
|
||||||
oxThrowError(ox::writeMC(buff.data(), buff.size(), obj, &mcSize));
|
oxThrowError(err);
|
||||||
// write to FS
|
// write to FS
|
||||||
writeBuff(path, buff.data(), mcSize);
|
writeBuff(path, ox::bit_cast<uint8_t*>(buff.data()), buff.size());
|
||||||
emit fileUpdated(path);
|
emit fileUpdated(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +105,7 @@ template<typename T>
|
|||||||
std::unique_ptr<T> Project::loadObj(QString path) const {
|
std::unique_ptr<T> Project::loadObj(QString path) const {
|
||||||
auto obj = std::make_unique<T>();
|
auto obj = std::make_unique<T>();
|
||||||
auto buff = loadBuff(path);
|
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;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@ add_library(
|
|||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
NostalgiaPack PUBLIC
|
NostalgiaPack PUBLIC
|
||||||
OxClArgs
|
OxClArgs
|
||||||
|
OxClaw
|
||||||
OxFS
|
OxFS
|
||||||
OxStd
|
OxStd
|
||||||
OxMetalClaw
|
|
||||||
NostalgiaCommon
|
NostalgiaCommon
|
||||||
NostalgiaCore
|
NostalgiaCore
|
||||||
)
|
)
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <ox/claw/read.hpp>
|
||||||
|
|
||||||
#include "pack.hpp"
|
#include "pack.hpp"
|
||||||
|
|
||||||
namespace nostalgia {
|
namespace nostalgia {
|
||||||
@ -31,7 +33,12 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// stub for now
|
// 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);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,24 +46,27 @@ namespace {
|
|||||||
// transformations need to be done after the copy to the new FS is complete
|
// transformations need to be done after the copy to the new FS is complete
|
||||||
[[nodiscard]] ox::Error transformClaw(ox::FileSystem32 *dest, std::string path) {
|
[[nodiscard]] ox::Error transformClaw(ox::FileSystem32 *dest, std::string path) {
|
||||||
// copy
|
// copy
|
||||||
|
std::cout << "transformClaw: path: " << path << '\n';
|
||||||
oxTrace("pack::transformClaw") << "path:" << path.c_str();
|
oxTrace("pack::transformClaw") << "path:" << path.c_str();
|
||||||
return dest->ls(path.c_str(), [dest, path](const char *name, ox::InodeId_t) {
|
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);
|
oxReturnError(err);
|
||||||
if (stat.fileType == ox::FileType_Directory) {
|
if (stat.fileType == ox::FileType_Directory) {
|
||||||
const auto dir = path + name + '/';
|
const auto dir = path + name + '/';
|
||||||
oxReturnError(transformClaw(dest, dir));
|
oxReturnError(transformClaw(dest, dir));
|
||||||
} else {
|
} else {
|
||||||
|
std::cout << filePath << '\n';
|
||||||
// do transforms
|
// do transforms
|
||||||
if (endsWith(path, ".claw")) {
|
if (endsWith(name, ".ng") || endsWith(name, ".npal")) {
|
||||||
// load file
|
// load file
|
||||||
std::vector<uint8_t> buff(stat.size);
|
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
|
// do transformations
|
||||||
oxReturnError(pathToInode(&buff));
|
oxReturnError(pathToInode(&buff));
|
||||||
oxReturnError(toMetalClaw(&buff));
|
oxReturnError(toMetalClaw(&buff));
|
||||||
// write file to dest
|
// 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);
|
return OxError(0);
|
||||||
@ -114,6 +124,7 @@ struct VerificationPair {
|
|||||||
|
|
||||||
[[nodiscard]] ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest) {
|
[[nodiscard]] ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest) {
|
||||||
oxReturnError(copy(src, dest, "/"));
|
oxReturnError(copy(src, dest, "/"));
|
||||||
|
std::cout << '\n';
|
||||||
oxReturnError(transformClaw(dest, "/"));
|
oxReturnError(transformClaw(dest, "/"));
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user