[nostalgia/tools/pack] Replace std types with ox types
This commit is contained in:
parent
db49361f8a
commit
022bc7e512
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <ox/claw/read.hpp>
|
#include <ox/claw/read.hpp>
|
||||||
|
|
||||||
@ -18,7 +17,8 @@ namespace nostalgia {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
[[nodiscard]] static constexpr bool endsWith(std::string_view str, std::string_view ending) {
|
[[nodiscard]]
|
||||||
|
static constexpr bool endsWith(std::string_view str, std::string_view ending) noexcept {
|
||||||
return str.size() >= ending.size() && str.substr(str.size() - ending.size()) == ending;
|
return str.size() >= ending.size() && str.substr(str.size() - ending.size()) == ending;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,12 +32,12 @@ static_assert(!endsWith("asdf", "eu"));
|
|||||||
* @return error
|
* @return error
|
||||||
* stub for now
|
* stub for now
|
||||||
*/
|
*/
|
||||||
ox::Error pathToInode(std::vector<uint8_t>*) {
|
ox::Error pathToInode(ox::Vector<uint8_t>*) {
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stub for now
|
// just strip header for now...
|
||||||
ox::Error toMetalClaw(std::vector<uint8_t> *buff) {
|
ox::Error toMetalClaw(ox::Vector<uint8_t> *buff) {
|
||||||
auto [mc, err] = ox::stripClawHeader(ox::bit_cast<char*>(buff->data()), buff->size());
|
auto [mc, err] = ox::stripClawHeader(ox::bit_cast<char*>(buff->data()), buff->size());
|
||||||
oxReturnError(err);
|
oxReturnError(err);
|
||||||
buff->resize(mc.size());
|
buff->resize(mc.size());
|
||||||
@ -47,7 +47,7 @@ ox::Error toMetalClaw(std::vector<uint8_t> *buff) {
|
|||||||
|
|
||||||
// claw file transformations are broken out because path to inode
|
// claw file transformations are broken out because path to inode
|
||||||
// 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
|
||||||
ox::Error transformClaw(ox::FileSystem32 *dest, std::string path) {
|
ox::Error transformClaw(ox::FileSystem32 *dest, ox::String path) {
|
||||||
// copy
|
// copy
|
||||||
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) {
|
||||||
@ -61,7 +61,7 @@ ox::Error transformClaw(ox::FileSystem32 *dest, std::string path) {
|
|||||||
// do transforms
|
// do transforms
|
||||||
if (endsWith(name, ".ng") || endsWith(name, ".npal")) {
|
if (endsWith(name, ".ng") || endsWith(name, ".npal")) {
|
||||||
// load file
|
// load file
|
||||||
std::vector<uint8_t> buff(stat.size);
|
ox::Vector<uint8_t> 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));
|
||||||
@ -74,53 +74,50 @@ ox::Error transformClaw(ox::FileSystem32 *dest, std::string path) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error verifyFile(ox::FileSystem32 *fs, const std::string &path, const std::vector<uint8_t> &expected) noexcept {
|
ox::Error verifyFile(ox::FileSystem32 *fs, const ox::String &path, const ox::Vector<uint8_t> &expected) noexcept {
|
||||||
std::vector<uint8_t> buff(expected.size());
|
ox::Vector<uint8_t> 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 {
|
||||||
std::string path;
|
ox::String path;
|
||||||
std::vector<uint8_t> buff;
|
ox::Vector<uint8_t> buff;
|
||||||
};
|
};
|
||||||
|
|
||||||
ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, std::string path) {
|
ox::Error copy(ox::PassThroughFS *src, ox::FileSystem32 *dest, ox::String path) {
|
||||||
std::cout << "copying directory: " << path << '\n';
|
std::cout << "copying directory: " << path.c_str() << '\n';
|
||||||
std::vector<VerificationPair> verficationPairs;
|
ox::Vector<VerificationPair> verificationPairs;
|
||||||
// copy
|
// copy
|
||||||
oxReturnError(src->ls(path.c_str(), [&verficationPairs, src, dest, path](std::string name, ox::InodeId_t) {
|
oxReturnError(src->ls(path.c_str(), [&verificationPairs, src, dest, path](ox::String name, ox::InodeId_t) {
|
||||||
auto currentFile = path + name;
|
auto currentFile = path + name;
|
||||||
if (currentFile == "/.nostalgia") {
|
if (currentFile == "/.nostalgia") {
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
std::cout << "reading " << name << '\n';
|
std::cout << "reading " << name.c_str() << '\n';
|
||||||
auto [stat, err] = src->stat((currentFile).c_str());
|
auto [stat, err] = src->stat((currentFile).c_str());
|
||||||
oxReturnError(err);
|
oxReturnError(err);
|
||||||
if (stat.fileType == ox::FileType_Directory) {
|
if (stat.fileType == ox::FileType_Directory) {
|
||||||
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 {
|
||||||
std::vector<uint8_t> buff;
|
ox::Vector<uint8_t> buff;
|
||||||
// do transforms
|
|
||||||
//const std::string OldExt = path.substr(path.find_last_of('.'));
|
|
||||||
// load file
|
// load file
|
||||||
buff.resize(stat.size);
|
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
|
||||||
std::cout << "writing " << currentFile << '\n';
|
std::cout << "writing " << currentFile.c_str() << '\n';
|
||||||
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));
|
||||||
verficationPairs.push_back({currentFile, buff});
|
verificationPairs.push_back({currentFile, buff});
|
||||||
}
|
}
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 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
|
||||||
for (auto v : verficationPairs) {
|
for (auto i = 0u; i < verificationPairs.size(); ++i) {
|
||||||
|
const auto &v = verificationPairs[i];
|
||||||
oxReturnError(verifyFile(dest, v.path, v.buff));
|
oxReturnError(verifyFile(dest, v.path, v.buff));
|
||||||
}
|
}
|
||||||
|
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user