[nostalgia] Replace C strings with StringViews
This commit is contained in:
@@ -32,7 +32,7 @@ static ox::Error pathToInode(ox::FileSystem *dest, ox::ModelObject *obj) noexcep
|
||||
case ox::FileAddressType::None:
|
||||
return {};
|
||||
}
|
||||
oxRequire(s, dest->stat(path.c_str()));
|
||||
oxRequire(s, dest->stat(ox::StringView(path)));
|
||||
oxReturnError(o["type"].set(static_cast<int8_t>(ox::FileAddressType::Inode)));
|
||||
return data.set(2, s.inode);
|
||||
}
|
||||
@@ -58,12 +58,12 @@ static ox::Error transformObj(ox::FileSystem *dest, ox::ModelObject *obj) noexce
|
||||
return {};
|
||||
}
|
||||
|
||||
static ox::Error doTransformations(core::TypeStore *ts, ox::FileSystem *dest, ox::CRString filePath) noexcept {
|
||||
if (filePath.endsWith(".ng") || filePath.endsWith(".npal")) {
|
||||
static ox::Error doTransformations(core::TypeStore *ts, ox::FileSystem *dest, ox::CRStringView filePath) noexcept {
|
||||
if (endsWith(filePath, ".ng") || endsWith(filePath, ".npal")) {
|
||||
// load file
|
||||
oxRequire(s, dest->stat(filePath.c_str()));
|
||||
oxRequire(s, dest->stat(filePath));
|
||||
oxRequireM(buff, dest->read(s.inode));
|
||||
if (filePath.endsWith(".ng")) {
|
||||
if (endsWith(filePath, ".ng")) {
|
||||
oxReturnError(core::convertBuffToBuff<core::CompactTileSheet>(buff, ox::ClawFormat::Metal).moveTo(&buff));
|
||||
}
|
||||
oxRequireM(obj, ox::readClaw(ts, buff));
|
||||
@@ -78,15 +78,15 @@ static ox::Error doTransformations(core::TypeStore *ts, ox::FileSystem *dest, ox
|
||||
|
||||
// claw file transformations are broken out because path to inode
|
||||
// transformations need to be done after the copy to the new FS is complete
|
||||
static ox::Error transformClaw(core::TypeStore *ts, ox::FileSystem *dest, ox::CRString path) noexcept {
|
||||
static ox::Error transformClaw(core::TypeStore *ts, ox::FileSystem *dest, ox::CRStringView path) noexcept {
|
||||
// copy
|
||||
oxTracef("pack::transformClaw", "path: {}", path);
|
||||
oxRequire(fileList, dest->ls(path));
|
||||
for (const auto &name : fileList) {
|
||||
const auto filePath = path + name;
|
||||
oxRequire(stat, dest->stat(filePath.c_str()));
|
||||
const auto filePath = ox::sfmt("{}{}", path, name);
|
||||
oxRequire(stat, dest->stat(filePath));
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
const auto dir = path + name + '/';
|
||||
const auto dir = ox::sfmt("{}{}/", path, name);
|
||||
oxReturnError(transformClaw(ts, dest, dir));
|
||||
} else {
|
||||
oxReturnError(doTransformations(ts, dest, filePath));
|
||||
@@ -95,9 +95,9 @@ static ox::Error transformClaw(core::TypeStore *ts, ox::FileSystem *dest, ox::CR
|
||||
return {};
|
||||
}
|
||||
|
||||
static ox::Error verifyFile(ox::FileSystem *fs, ox::CRString path, const ox::Buffer &expected) noexcept {
|
||||
static ox::Error verifyFile(ox::FileSystem *fs, ox::CRStringView path, const ox::Buffer &expected) noexcept {
|
||||
ox::Buffer buff(expected.size());
|
||||
oxReturnError(fs->read(path.c_str(), buff.data(), buff.size()));
|
||||
oxReturnError(fs->read(path, buff.data(), buff.size()));
|
||||
return OxError(buff == expected ? 0 : 1);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ struct VerificationPair {
|
||||
}
|
||||
};
|
||||
|
||||
static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, ox::CRString path) noexcept {
|
||||
static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, ox::CRStringView path) noexcept {
|
||||
oxOutf("copying directory: {}\n", path);
|
||||
ox::Vector<VerificationPair> verificationPairs;
|
||||
// copy
|
||||
@@ -121,16 +121,16 @@ static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, ox::CRString pa
|
||||
continue;
|
||||
}
|
||||
oxOutf("reading {}\n", currentFile);
|
||||
oxRequire(stat, src->stat(currentFile.c_str()));
|
||||
oxRequire(stat, src->stat(ox::StringView(currentFile)));
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
oxReturnError(dest->mkdir(currentFile.c_str(), true));
|
||||
oxReturnError(copy(src, dest, currentFile + '/'));
|
||||
} else {
|
||||
// load file
|
||||
oxRequireM(buff, src->read(currentFile.c_str()));
|
||||
oxRequireM(buff, src->read(currentFile));
|
||||
// write file to dest
|
||||
oxOutf("writing {}\n", currentFile);
|
||||
oxReturnError(dest->write(currentFile.c_str(), buff.data(), buff.size()));
|
||||
oxReturnError(dest->write(currentFile, buff.data(), buff.size()));
|
||||
oxReturnError(verifyFile(dest, currentFile, buff));
|
||||
verificationPairs.emplace_back(std::move(currentFile), std::move(buff));
|
||||
}
|
||||
@@ -143,9 +143,9 @@ static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, ox::CRString pa
|
||||
}
|
||||
|
||||
// transformations need to be done after the copy to the new FS is complete
|
||||
static ox::Error preloadObj(core::TypeStore *ts, ox::FileSystem *romFs, GbaPreloader *pl, ox::CRString path) noexcept {
|
||||
static ox::Error preloadObj(core::TypeStore *ts, ox::FileSystem *romFs, GbaPreloader *pl, ox::CRStringView path) noexcept {
|
||||
// load file
|
||||
oxRequireM(buff, romFs->read(path.c_str()));
|
||||
oxRequireM(buff, romFs->read(path));
|
||||
oxRequireM(obj, ox::readClaw(ts, buff));
|
||||
if (obj.type()->preloadable) {
|
||||
// preload
|
||||
@@ -159,21 +159,21 @@ static ox::Error preloadObj(core::TypeStore *ts, ox::FileSystem *romFs, GbaPrelo
|
||||
// strip the Claw header (it is not needed after preloading) and write back out to dest fs
|
||||
oxReturnError(ox::writeMC(&obj).moveTo(&buff));
|
||||
}
|
||||
oxReturnError(romFs->write(path.c_str(), buff.data(), buff.size()));
|
||||
oxReturnError(romFs->write(path, buff.data(), buff.size()));
|
||||
return {};
|
||||
}
|
||||
|
||||
// claw file transformations are broken out because path to inode
|
||||
// transformations need to be done after the copy to the new FS is complete
|
||||
static ox::Error preloadDir(core::TypeStore *ts, ox::FileSystem *romFs, GbaPreloader *pl, ox::CRString path) noexcept {
|
||||
static ox::Error preloadDir(core::TypeStore *ts, ox::FileSystem *romFs, GbaPreloader *pl, ox::CRStringView path) noexcept {
|
||||
// copy
|
||||
oxTracef("pack::preload", "path: {}", path);
|
||||
oxRequire(fileList, romFs->ls(path));
|
||||
for (const auto &name : fileList) {
|
||||
const auto filePath = path + name;
|
||||
oxRequire(stat, romFs->stat(filePath.c_str()));
|
||||
const auto filePath = ox::sfmt("{}{}", path, name);
|
||||
oxRequire(stat, romFs->stat(ox::StringView(filePath)));
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
const auto dir = path + name + '/';
|
||||
const auto dir = ox::sfmt("{}{}/", path, name);
|
||||
oxReturnError(preloadDir(ts, romFs, pl, dir));
|
||||
} else {
|
||||
oxReturnError(preloadObj(ts, romFs, pl, filePath));
|
||||
|
||||
Reference in New Issue
Block a user