[nostalgia] Restore GBA support

This commit is contained in:
2019-11-03 21:32:40 -06:00
parent deaa293c67
commit 758907ab5a
9 changed files with 152 additions and 108 deletions

View File

@@ -1,6 +1,3 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
add_executable(nost-pack pack.cpp)
target_link_libraries(

View File

@@ -66,21 +66,21 @@ using namespace nostalgia::common;
oxReturnError(ox::FileSystem32::format(buff.data(), buff.size()));
ox::PassThroughFS src(argSrc.c_str());
ox::FileSystem32 dst(ox::FileStore32(buff.data(), buff.size()));
auto err = nostalgia::pack(&src, &dst);
if (err) {
std::cerr << "pack failed...";
}
oxReturnError(nostalgia::pack(&src, &dst));
oxReturnError(dst.resize());
std::cout << "new size: " << dst.size() << '\n';
buff.resize(dst.size());
oxReturnError(writeFileBuff(argDst, buff));
return err;
return OxError(0);
}
int main(int argc, const char **args) {
auto err = run(ClArgs(argc, args));
oxAssert(err, "pack failed");
if (err) {
std::cerr << "pack failed...\n";
}
return static_cast<int>(err);
}

View File

@@ -39,6 +39,7 @@ 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
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());
oxReturnError(err);
@@ -68,10 +69,16 @@ namespace {
return OxError(buff == expected ? 0 : 1);
}
struct VerificationPair {
std::string path;
std::vector<uint8_t> buff;
};
[[nodiscard]] ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, std::string path) {
std::cout << "copying directory: " << path << '\n';
std::vector<VerificationPair> verficationPairs;
// copy
return src->ls(path.c_str(), [src, dest, path](const char *name, ox::InodeId_t) {
oxReturnError(src->ls(path.c_str(), [&verficationPairs, src, dest, path](const char *name, ox::InodeId_t) {
std::cout << "reading " << name << '\n';
auto currentFile = path + name;
auto [stat, err] = src->stat((currentFile).c_str());
@@ -90,16 +97,26 @@ namespace {
std::cout << "writing " << currentFile << '\n';
oxReturnError(dest->write(currentFile.c_str(), buff.data(), buff.size()));
oxReturnError(verifyFile(dest, currentFile, buff));
verficationPairs.push_back({currentFile, buff});
}
return OxError(0);
});
}
}));
}
// verify all at once in addition to right after the files are written
for (auto v : verficationPairs) {
oxReturnError(verifyFile(dest, v.path, v.buff));
}
[[nodiscard]] ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest, std::string path) {
oxReturnError(copy(src, dest, path));
oxReturnError(transformClaw(dest, path));
return OxError(0);
}
}
[[nodiscard]] ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest) {
oxReturnError(copy(src, dest, "/"));
oxReturnError(dest->stat("/TileSheets/Charset.ng").error);
oxReturnError(dest->stat("/Palettes/Charset.npal").error);
oxReturnError(transformClaw(dest, "/"));
return OxError(0);
}

View File

@@ -12,6 +12,6 @@
namespace nostalgia {
ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest, std::string path = "/");
ox::Error pack(ox::PassThroughFS *src, ox::FileSystem32 *dest);
}