[nostalgia] Cleanup

This commit is contained in:
Gary Talent 2021-05-11 00:43:07 -05:00
parent 0bcb78d3da
commit f5ff700bf3
5 changed files with 12 additions and 13 deletions

View File

@ -16,6 +16,7 @@ add_executable(
target_link_libraries( target_link_libraries(
nostalgia-studio nostalgia-studio
QDarkStyle QDarkStyle
OxClArgs
NostalgiaCore-Studio NostalgiaCore-Studio
NostalgiaStudio NostalgiaStudio
NostalgiaPack NostalgiaPack

View File

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

View File

@ -51,7 +51,7 @@ static ox::Error run(const ox::ClArgs &args) noexcept {
} }
int main(int argc, const char **args) { int main(int argc, const char **args) {
auto err = run(ox::ClArgs(argc, args)); const auto err = run(ox::ClArgs(argc, args));
oxAssert(err, "pack failed"); oxAssert(err, "pack failed");
return static_cast<int>(err); return static_cast<int>(err);
} }

View File

@ -6,10 +6,8 @@ add_library(
target_link_libraries( target_link_libraries(
NostalgiaPack PUBLIC NostalgiaPack PUBLIC
OxClArgs
OxClaw OxClaw
OxFS OxFS
OxStd
NostalgiaCommon NostalgiaCommon
NostalgiaCore NostalgiaCore
) )

View File

@ -19,15 +19,15 @@ namespace nostalgia {
* @return error * @return error
* stub for now * stub for now
*/ */
static ox::Error pathToInode(ox::Vector<uint8_t>*) noexcept { static ox::Error pathToInode(ox::Buffer*) noexcept {
return OxError(0); return OxError(0);
} }
// just strip header for now... // just strip header for now...
static ox::Error toMetalClaw(ox::Vector<uint8_t> *buff) noexcept { static ox::Error toMetalClaw(ox::Buffer *buff) noexcept {
oxRequire(mc, ox::stripClawHeader(ox::bit_cast<char*>(buff->data()), buff->size())); oxRequire(mc, ox::stripClawHeader(ox::bit_cast<char*>(buff->data()), buff->size()));
buff->resize(mc.size()); buff->resize(mc.size());
ox_memcpy(buff->data(), mc.data(), mc.size()); memcpy(buff->data(), mc.data(), mc.size());
return OxError(0); return OxError(0);
} }
@ -47,7 +47,7 @@ static ox::Error transformClaw(ox::FileSystem *dest, const ox::String &path) noe
// do transforms // do transforms
if (name.endsWith(".ng") || name.endsWith(".npal")) { if (name.endsWith(".ng") || name.endsWith(".npal")) {
// load file // load file
ox::Vector<uint8_t> buff(stat.size); ox::Buffer buff(stat.size);
oxReturnError(dest->read(filePath.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));
@ -60,15 +60,15 @@ static ox::Error transformClaw(ox::FileSystem *dest, const ox::String &path) noe
return OxError(0); return OxError(0);
} }
static ox::Error verifyFile(ox::FileSystem *fs, const ox::String &path, const ox::Vector<uint8_t> &expected) noexcept { static ox::Error verifyFile(ox::FileSystem *fs, const ox::String &path, const ox::Buffer &expected) noexcept {
ox::Vector<uint8_t> buff(expected.size()); ox::Buffer buff(expected.size());
oxReturnError(fs->read(path.c_str(), buff.data(), buff.size())); oxReturnError(fs->read(path.c_str(), buff.data(), buff.size()));
return OxError(buff == expected ? 0 : 1); return OxError(buff == expected ? 0 : 1);
} }
struct VerificationPair { struct VerificationPair {
ox::String path; ox::String path;
ox::Vector<uint8_t> buff; ox::Buffer buff;
}; };
static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, const ox::String &path) noexcept { static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, const ox::String &path) noexcept {
@ -87,15 +87,14 @@ static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, const ox::Strin
oxReturnError(dest->mkdir(currentFile.c_str(), true)); oxReturnError(dest->mkdir(currentFile.c_str(), true));
oxReturnError(copy(src, dest, currentFile + '/')); oxReturnError(copy(src, dest, currentFile + '/'));
} else { } else {
ox::Vector<uint8_t> buff; ox::Buffer buff(stat.size);
// load file // load file
buff.resize(stat.size);
oxReturnError(src->read(currentFile.c_str(), buff.data(), buff.size())); oxReturnError(src->read(currentFile.c_str(), buff.data(), buff.size()));
// write file to dest // write file to dest
oxOutf("writing {}\n", currentFile); oxOutf("writing {}\n", currentFile);
oxReturnError(dest->write(currentFile.c_str(), buff.data(), buff.size())); oxReturnError(dest->write(currentFile.c_str(), buff.data(), buff.size()));
oxReturnError(verifyFile(dest, currentFile, buff)); oxReturnError(verifyFile(dest, currentFile, buff));
verificationPairs.push_back({currentFile, buff}); verificationPairs.emplace_back(currentFile, buff);
} }
} }
// verify all at once in addition to right after the files are written // verify all at once in addition to right after the files are written