[nostalgia/tools/pack] Add Bullock integration and cleanup FS access

This commit is contained in:
Gary Talent 2023-02-01 22:41:04 -06:00
parent 1cc3549d00
commit fad8837ad1
3 changed files with 15 additions and 4 deletions

View File

@ -3,6 +3,7 @@ add_executable(nost-pack pack.cpp)
target_link_libraries(
nost-pack
OxClArgs
OxLogConn
NostalgiaPack
)

View File

@ -6,6 +6,7 @@
#include <ox/clargs/clargs.hpp>
#include <ox/fs/fs.hpp>
#include <ox/logconn/logconn.hpp>
#include <nostalgia/core/typestore.hpp>
@ -42,7 +43,6 @@ static ox::Result<ox::Buffer> readFileBuff(ox::CRStringView path) noexcept {
}
static ox::Error run(const ox::ClArgs &args) noexcept {
ox::trace::init();
const auto argSrc = args.getString("src", "");
const auto argRomBin = args.getString("rom-bin", "");
if (argSrc == "") {
@ -78,6 +78,16 @@ static ox::Error run(const ox::ClArgs &args) noexcept {
}
int main(int argc, const char **args) {
ox::trace::init();
#ifdef DEBUG
ox::LoggerConn loggerConn;
const auto loggerErr = loggerConn.initConn("nost-pack");
if (loggerErr) {
oxErrf("Could not connect to logger: {} ({}:{})\n", toStr(loggerErr), loggerErr.file, loggerErr.line);
} else {
ox::trace::setLogger(&loggerConn);
}
#endif
const auto err = run(ox::ClArgs(argc, args));
oxAssert(err, "pack failed");
return static_cast<int>(err);

View File

@ -32,7 +32,7 @@ static ox::Error pathToInode(ox::FileSystem *dest, ox::ModelObject *obj) noexcep
case ox::FileAddressType::None:
return {};
}
oxRequire(s, dest->stat(ox::StringView(path)));
oxRequire(s, dest->stat(path));
oxReturnError(o["type"].set(static_cast<int8_t>(ox::FileAddressType::Inode)));
return data.set(2, s.inode);
}
@ -121,7 +121,7 @@ static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, ox::CRStringVie
continue;
}
oxOutf("reading {}\n", currentFile);
oxRequire(stat, src->stat(ox::StringView(currentFile)));
oxRequire(stat, src->stat(currentFile));
if (stat.fileType == ox::FileType::Directory) {
oxReturnError(dest->mkdir(currentFile, true));
oxReturnError(copy(src, dest, currentFile + '/'));
@ -171,7 +171,7 @@ static ox::Error preloadDir(core::TypeStore *ts, ox::FileSystem *romFs, GbaPrelo
oxRequire(fileList, romFs->ls(path));
for (const auto &name : fileList) {
const auto filePath = ox::sfmt("{}{}", path, name);
oxRequire(stat, romFs->stat(ox::StringView(filePath)));
oxRequire(stat, romFs->stat(filePath));
if (stat.fileType == ox::FileType::Directory) {
const auto dir = ox::sfmt("{}{}/", path, name);
oxReturnError(preloadDir(ts, romFs, pl, dir));