diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index ede41c26..78e1351c 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -124,8 +124,8 @@ void setBgStatus(Context*, unsigned bg, bool status) noexcept { // Do NOT rely on Context in the GBA version of this function. ox::Error initConsole(Context *ctx) noexcept { - constexpr auto TilesheetAddr = "/TileSheets/Charset.ng"; - constexpr auto PaletteAddr = "/Palettes/Charset.npal"; + constexpr ox::FileAddress TilesheetAddr("/TileSheets/Charset.ng"); + constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal"); setBgStatus(ctx, 0b0001); if (!ctx) { ctx = new (ox_alloca(sizeof(Context))) Context(); @@ -174,14 +174,13 @@ ox::Error loadBgTileSheet(Context *ctx, } ox::Error loadSpriteTileSheet(Context *ctx, - unsigned cbb, const ox::FileAddress &tilesheetAddr, const ox::FileAddress &paletteAddr) noexcept { oxRequire(tsStat, ctx->rom->stat(tilesheetAddr)); oxRequire(ts, ctx->rom->directAccess(tilesheetAddr)); GbaTileMapTarget target; - target.pal.palette = &MEM_SPRITE_PALETTE[cbb]; - target.tileMap = &reinterpret_cast(MEM_SPRITE_TILES)[cbb * 512]; + target.pal.palette = MEM_SPRITE_PALETTE; + target.tileMap = MEM_SPRITE_TILES; oxReturnError(ox::readMC(ts, tsStat.size, &target)); // load external palette if available if (paletteAddr) { @@ -261,7 +260,7 @@ void setSprite(Context*, unsigned flipX) noexcept { oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow"); GbaSpriteAttrUpdate oa; - oa.attr0 = static_cast(y & ox::onMask(7)) + oa.attr0 = static_cast(y & ox::onMask(0b111)) | (static_cast(1) << 10) // enable alpha | (static_cast(spriteShape) << 14); oa.attr1 = (static_cast(x) & ox::onMask(8)) diff --git a/src/nostalgia/core/gba/media.cpp b/src/nostalgia/core/gba/media.cpp index 9b252bfd..4fd0a14d 100644 --- a/src/nostalgia/core/gba/media.cpp +++ b/src/nostalgia/core/gba/media.cpp @@ -31,6 +31,14 @@ ox::Result loadRom(const char*) noexcept { void unloadRom(char*) noexcept { } +ox::Result getPreloadAddr(Context *ctx, ox::CRStringView path) noexcept { + oxRequire(stat, ctx->rom->stat(path)); + oxRequire(buff, ctx->rom->directAccess(path)); + PreloadPtr p; + oxReturnError(ox::readMC(buff, stat.size, &p)); + return p.preloadAddr + ctx->preloadSectionOffset; +} + ox::Result getPreloadAddr(Context *ctx, const ox::FileAddress &file) noexcept { oxRequire(stat, ctx->rom->stat(file)); oxRequire(buff, ctx->rom->directAccess(file)); diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index 8bc1e478..3fd36e35 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -515,7 +515,6 @@ ox::Error loadBgTileSheet(Context *ctx, unsigned cbb, const ox::FileAddress &til const ox::FileAddress &palette = nullptr) noexcept; ox::Error loadSpriteTileSheet(Context *ctx, - unsigned section, const ox::FileAddress &tilesheetAddr, const ox::FileAddress &paletteAddr) noexcept; diff --git a/src/nostalgia/core/media.hpp b/src/nostalgia/core/media.hpp index a95cbf5c..523e6bfa 100644 --- a/src/nostalgia/core/media.hpp +++ b/src/nostalgia/core/media.hpp @@ -26,9 +26,10 @@ oxModelBegin(PreloadPtr) oxModelEnd() ox::Result getPreloadAddr(Context *ctx, const ox::FileAddress &file) noexcept; +ox::Result getPreloadAddr(Context *ctx, ox::CRStringView file) noexcept; template -ox::Result> readObj(Context *ctx, const ox::FileAddress &file, +ox::Result> readObj([[maybe_unused]] Context *ctx, [[maybe_unused]] ox::CRStringView path, [[maybe_unused]] bool forceLoad = false) noexcept { #ifndef OX_BARE_METAL constexpr auto readConvert = [](const ox::Buffer &buff) -> ox::Result { @@ -41,21 +42,36 @@ ox::Result> readObj(Context *ctx, const ox::FileAddress &file, } return std::move(obj); }; - oxRequire(path, file.getPath()); if (forceLoad) { - oxRequire(buff, ctx->rom->read(file)); + oxRequire(buff, ctx->rom->read(path)); oxRequire(obj, readConvert(buff)); oxRequire(cached, ctx->assetManager.setAsset(path, obj)); return std::move(cached); } else { auto [cached, err] = ctx->assetManager.getAsset(path); if (err) { - oxRequire(buff, ctx->rom->read(file)); + oxRequire(buff, ctx->rom->read(path)); oxRequire(obj, readConvert(buff)); oxReturnError(ctx->assetManager.setAsset(path, obj).moveTo(&cached)); } return std::move(cached); } +#else + if constexpr(ox::preloadable::value) { + oxRequire(addr, getPreloadAddr(ctx, path)); + return AssetRef(reinterpret_cast(addr)); + } else { + return OxError(1); + } +#endif +} + +template +ox::Result> readObj(Context *ctx, const ox::FileAddress &file, + [[maybe_unused]] bool forceLoad = false) noexcept { +#ifndef OX_BARE_METAL + oxRequire(path, file.getPath()); + return readObj(ctx, ox::StringView(path), forceLoad); #else if constexpr(ox::preloadable::value) { oxRequire(addr, getPreloadAddr(ctx, file)); diff --git a/src/nostalgia/core/studio/paletteeditor-imgui.cpp b/src/nostalgia/core/studio/paletteeditor-imgui.cpp index 3d50b4c3..dbf15833 100644 --- a/src/nostalgia/core/studio/paletteeditor-imgui.cpp +++ b/src/nostalgia/core/studio/paletteeditor-imgui.cpp @@ -19,7 +19,7 @@ ox::Result PaletteEditorImGui::make(Context *ctx, const ox: out->m_itemPath = path; const auto lastSlash = std::find(out->m_itemPath.rbegin(), out->m_itemPath.rend(), '/').offset(); out->m_itemName = out->m_itemPath.substr(lastSlash + 1); - oxRequire(pal, core::readObj(out->m_ctx, out->m_itemPath)); + oxRequire(pal, core::readObj(out->m_ctx, ox::FileAddress(out->m_itemPath.c_str()))); out->m_pal = *pal; return out.release(); } diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.cpp b/src/nostalgia/core/studio/tilesheeteditormodel.cpp index cd42d185..11a37a88 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.cpp @@ -511,7 +511,7 @@ class PaletteChangeCommand: public TileSheetCommand { m_idx = idx; m_img = img; m_oldPalette = m_img->defaultPalette; - m_newPalette = newPalette; + m_newPalette = ox::FileAddress(newPalette); } void redo() noexcept final { @@ -538,7 +538,7 @@ class PaletteChangeCommand: public TileSheetCommand { TileSheetEditorModel::TileSheetEditorModel(Context *ctx, ox::String path) { m_ctx = ctx; m_path = std::move(path); - oxRequireT(img, readObj(ctx, m_path.c_str())); + oxRequireT(img, readObj(ctx, m_path)); m_img = *img; if (m_img.defaultPalette) { oxThrowError(readObj(ctx, m_img.defaultPalette).moveTo(&m_pal)); @@ -709,7 +709,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(const studio::UndoCommand *cmd) m_updated = true; const auto cmdId = cmd->commandId(); if (static_cast(cmdId) == CommandId::PaletteChange) { - oxReturnError(readObj(m_ctx, m_img.defaultPalette.getPath().value).moveTo(&m_pal)); + oxReturnError(readObj(m_ctx, ox::StringView(m_img.defaultPalette.getPath().value)).moveTo(&m_pal)); } auto tsCmd = dynamic_cast(cmd); auto idx = m_img.validateSubSheetIdx(tsCmd->subsheetIdx()); diff --git a/src/nostalgia/core/userland/gfx.cpp b/src/nostalgia/core/userland/gfx.cpp index 84ca2600..ed715a0a 100644 --- a/src/nostalgia/core/userland/gfx.cpp +++ b/src/nostalgia/core/userland/gfx.cpp @@ -10,20 +10,13 @@ namespace nostalgia::core { ox::Error initConsole(Context *ctx) noexcept { - constexpr auto TilesheetAddr = "/TileSheets/Charset.ng"; - constexpr auto PaletteAddr = "/Palettes/Charset.npal"; + constexpr ox::FileAddress TilesheetAddr("/TileSheets/Charset.ng"); + constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal"); setBgStatus(ctx, 0b0001); setBgCbb(ctx, 0, 0); return loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr); } -ox::Error loadSpriteTileSheet(Context*, - unsigned, - const ox::FileAddress&, - const ox::FileAddress&) noexcept { - return OxError(0); -} - ox::Error loadBgTileSheet(Context *ctx, unsigned cbb, const ox::FileAddress &tilesheetPath, @@ -53,6 +46,12 @@ ox::Error loadBgTileSheet(Context *ctx, return OxError(0); } +ox::Error loadSpriteTileSheet(Context*, + const ox::FileAddress&, + const ox::FileAddress&) noexcept { + return OxError(0); +} + void puts(Context *ctx, int column, int row, const char *str) noexcept { for (int i = 0; str[i]; ++i) { setTile(ctx, 0, column + i, row, static_cast(charMap[static_cast(str[i])])); diff --git a/src/nostalgia/player/app.cpp b/src/nostalgia/player/app.cpp index a9965870..3adda211 100644 --- a/src/nostalgia/player/app.cpp +++ b/src/nostalgia/player/app.cpp @@ -42,15 +42,15 @@ static void keyEventHandler(core::Context *ctx, core::Key key, bool down) noexce } ox::Error run(ox::UniquePtr fs) noexcept { + oxTraceInitHook(); oxRequireM(ctx, core::init(std::move(fs))); - constexpr auto TileSheetAddr = "/TileSheets/Charset.ng"; - constexpr auto PaletteAddr = "/Palettes/Charset.npal"; + constexpr ox::FileAddress TileSheetAddr("/TileSheets/Charset.ng"); + constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal"); oxRequire(tsStat, ctx->rom->stat(PaletteAddr)); - oxReturnError(core::loadSpriteTileSheet(ctx.get(), 0, TileSheetAddr, PaletteAddr)); + oxReturnError(core::loadSpriteTileSheet(ctx.get(), TileSheetAddr, PaletteAddr)); oxReturnError(core::initConsole(ctx.get())); core::puts(ctx.get(), 10, 9, "DOPENESS!!!"); core::setUpdateHandler(ctx.get(), updateHandler); core::setKeyEventHandler(ctx.get(), keyEventHandler); return core::run(ctx.get()); -} - +} \ No newline at end of file diff --git a/src/nostalgia/studio/lib/editor.cpp b/src/nostalgia/studio/lib/editor.cpp index f61a3784..afba887e 100644 --- a/src/nostalgia/studio/lib/editor.cpp +++ b/src/nostalgia/studio/lib/editor.cpp @@ -2,6 +2,8 @@ * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. */ +#include + #include #include "editor.hpp" @@ -93,6 +95,11 @@ ox::Error BaseEditor::saveItem() noexcept { return OxError(0); } +ox::StringView BaseEditor::pathToItemName(ox::CRStringView path) noexcept { + const auto lastSlash = std::find(path.rbegin(), path.rend(), '/').offset(); + return path.substr(lastSlash + 1); +} + Editor::Editor() noexcept { m_undoStack.changeTriggered.connect(this, &Editor::markUnsavedChanges); } diff --git a/src/nostalgia/studio/lib/editor.hpp b/src/nostalgia/studio/lib/editor.hpp index b8a9f024..85cb0ea0 100644 --- a/src/nostalgia/studio/lib/editor.hpp +++ b/src/nostalgia/studio/lib/editor.hpp @@ -100,10 +100,7 @@ class NOSTALGIASTUDIO_EXPORT BaseEditor: public Widget { return nullptr; } - static constexpr auto pathToItemName(ox::CRStringView path) noexcept { - const auto lastSlash = std::find(path.rbegin(), path.rend(), '/').offset(); - return path.substr(lastSlash + 1); - } + static ox::StringView pathToItemName(ox::CRStringView path) noexcept; // signals public: diff --git a/src/nostalgia/studio/lib/project.cpp b/src/nostalgia/studio/lib/project.cpp index f1a8f1e4..5ae887fa 100644 --- a/src/nostalgia/studio/lib/project.cpp +++ b/src/nostalgia/studio/lib/project.cpp @@ -26,21 +26,21 @@ ox::FileSystem *Project::romFs() noexcept { return m_fs; } -ox::Error Project::mkdir(const ox::String &path) const noexcept { - oxReturnError(m_fs->mkdir(path.c_str(), true)); +ox::Error Project::mkdir(ox::CRStringView path) const noexcept { + oxReturnError(m_fs->mkdir(path, true)); fileUpdated.emit(path); return OxError(0); } -ox::Result Project::stat(const ox::String &path) const noexcept { - return m_fs->stat(path.c_str()); +ox::Result Project::stat(ox::CRStringView path) const noexcept { + return m_fs->stat(path); } -bool Project::exists(const ox::String &path) const noexcept { - return m_fs->stat(path.c_str()).error == 0; +bool Project::exists(ox::CRStringView path) const noexcept { + return m_fs->stat(path).error == 0; } -const ox::Vector &Project::fileList(const char *ext) noexcept { +const ox::Vector &Project::fileList(ox::CRStringView ext) noexcept { return m_fileExtFileMap[ext]; } @@ -59,7 +59,7 @@ void Project::buildFileIndex() noexcept { } } -void Project::indexFile(const ox::String &path) noexcept { +void Project::indexFile(ox::CRStringView path) noexcept { const auto [ext, err] = fileExt(path); if (err) { return; @@ -67,9 +67,9 @@ void Project::indexFile(const ox::String &path) noexcept { m_fileExtFileMap[ext].emplace_back(path); } -ox::Error Project::writeBuff(const ox::String &path, const ox::Buffer &buff) noexcept { - const auto newFile = m_fs->stat(path.c_str()).error != 0; - oxReturnError(m_fs->write(path.c_str(), buff.data(), buff.size())); +ox::Error Project::writeBuff(const ox::StringView &path, const ox::Buffer &buff) noexcept { + const auto newFile = m_fs->stat(path).error != 0; + oxReturnError(m_fs->write(path, buff.data(), buff.size(), ox::FileType::NormalFile)); if (newFile) { fileAdded.emit(path); indexFile(path); @@ -80,17 +80,17 @@ ox::Error Project::writeBuff(const ox::String &path, const ox::Buffer &buff) noe } ox::Result Project::loadBuff(const ox::String &path) const noexcept { - return m_fs->read(path.c_str()); + return m_fs->read(path); } -ox::Error Project::lsProcDir(ox::Vector *paths, const ox::String &path) const noexcept { - oxRequire(files, m_fs->ls(path.c_str())); +ox::Error Project::lsProcDir(ox::Vector *paths, ox::CRStringView path) const noexcept { + oxRequire(files, m_fs->ls(path)); for (const auto &name : files) { - const auto fullPath = path + "/" + name.c_str(); - oxRequire(stat, m_fs->stat(fullPath.c_str())); + auto fullPath = ox::sfmt("{}/{}", path, name); + oxRequire(stat, m_fs->stat(ox::StringView(fullPath))); switch (stat.fileType) { case ox::FileType::NormalFile: - paths->push_back(fullPath); + paths->emplace_back(std::move(fullPath)); break; case ox::FileType::Directory: oxReturnError(lsProcDir(paths, fullPath)); @@ -102,7 +102,7 @@ ox::Error Project::lsProcDir(ox::Vector *paths, const ox::String &pa return OxError(0); } -ox::Result> Project::listFiles(const ox::String &path) const noexcept { +ox::Result> Project::listFiles(ox::CRStringView path) const noexcept { ox::Vector paths; oxReturnError(lsProcDir(&paths, path)); return paths; diff --git a/src/nostalgia/studio/lib/project.hpp b/src/nostalgia/studio/lib/project.hpp index 4af1cc39..26d2d969 100644 --- a/src/nostalgia/studio/lib/project.hpp +++ b/src/nostalgia/studio/lib/project.hpp @@ -29,7 +29,7 @@ enum class ProjectEvent { }; [[nodiscard]] -constexpr ox::Result fileExt(const ox::String &path) noexcept { +constexpr ox::Result fileExt(ox::CRStringView path) noexcept { const auto extStart = ox::find(path.crbegin(), path.crend(), '.').offset(); if (!extStart) { return OxError(1, "Cannot open a file without valid extension."); @@ -52,7 +52,7 @@ class NOSTALGIASTUDIO_EXPORT Project { [[nodiscard]] ox::FileSystem *romFs() noexcept; - ox::Error mkdir(const ox::String &path) const noexcept; + ox::Error mkdir(ox::CRStringView path) const noexcept; /** * Writes a MetalClaw object to the project at the given path. @@ -63,40 +63,40 @@ class NOSTALGIASTUDIO_EXPORT Project { template ox::Result loadObj(const ox::String &path) const noexcept; - ox::Result stat(const ox::String &path) const noexcept; + ox::Result stat(ox::CRStringView path) const noexcept; [[nodiscard]] - bool exists(const ox::String& path) const noexcept; + bool exists(ox::CRStringView path) const noexcept; template ox::Error subscribe(ProjectEvent e, ox::SignalHandler *tgt, Functor &&slot) const noexcept; [[nodiscard]] - const ox::Vector &fileList(const char *ng) noexcept; + const ox::Vector &fileList(ox::CRStringView ext) noexcept; private: void buildFileIndex() noexcept; - void indexFile(const ox::String &path) noexcept; + void indexFile(ox::CRStringView path) noexcept; - ox::Error writeBuff(const ox::String &path, const ox::Buffer &buff) noexcept; + ox::Error writeBuff(const ox::StringView &path, const ox::Buffer &buff) noexcept; ox::Result loadBuff(const ox::String &path) const noexcept; - ox::Error lsProcDir(ox::Vector *paths, const ox::String &path) const noexcept; + ox::Error lsProcDir(ox::Vector *paths, ox::CRStringView path) const noexcept; - ox::Result> listFiles(const ox::String &path = "") const noexcept; + ox::Result> listFiles(ox::CRStringView path = "") const noexcept; // signals public: ox::Signal fileEvent; - ox::Signal fileAdded; + ox::Signal fileAdded; // FileRecognized is triggered for all matching files upon a new // subscription to a section of the project and upon the addition of a // file. - ox::Signal fileRecognized; - ox::Signal fileDeleted; - ox::Signal fileUpdated; + ox::Signal fileRecognized; + ox::Signal fileDeleted; + ox::Signal fileUpdated; }; diff --git a/src/nostalgia/studio/projectexplorer.cpp b/src/nostalgia/studio/projectexplorer.cpp index a5307054..c3fd7008 100644 --- a/src/nostalgia/studio/projectexplorer.cpp +++ b/src/nostalgia/studio/projectexplorer.cpp @@ -13,9 +13,9 @@ namespace nostalgia { static ox::Result> -buildProjectTreeModel(ProjectExplorer *explorer, const ox::String &name, const ox::String &path, ProjectTreeModel *parent) noexcept { +buildProjectTreeModel(ProjectExplorer *explorer, ox::CRStringView name, ox::CRStringView path, ProjectTreeModel *parent) noexcept { const auto fs = explorer->romFs(); - oxRequire(stat, fs->stat(path.c_str())); + oxRequire(stat, fs->stat(path)); auto out = ox::make_unique(explorer, name, parent); if (stat.fileType == ox::FileType::Directory) { oxRequireM(children, fs->ls(path)); @@ -58,7 +58,7 @@ void ProjectExplorer::setModel(ox::UniquePtr model) noexcept { m_treeModel = std::move(model); } -ox::Error ProjectExplorer::refreshProjectTreeModel(const ox::String&) noexcept { +ox::Error ProjectExplorer::refreshProjectTreeModel(ox::CRStringView) noexcept { oxRequireM(model, buildProjectTreeModel(this, "Project", "/", nullptr)); setModel(std::move(model)); return OxError(0); diff --git a/src/nostalgia/studio/projectexplorer.hpp b/src/nostalgia/studio/projectexplorer.hpp index ff45029e..522f54aa 100644 --- a/src/nostalgia/studio/projectexplorer.hpp +++ b/src/nostalgia/studio/projectexplorer.hpp @@ -23,7 +23,7 @@ class ProjectExplorer: public studio::Widget { void setModel(ox::UniquePtr model) noexcept; - ox::Error refreshProjectTreeModel(const ox::String& = {}) noexcept; + ox::Error refreshProjectTreeModel(ox::CRStringView = {}) noexcept; [[nodiscard]] constexpr ox::FileSystem *romFs() noexcept { diff --git a/src/nostalgia/studio/projecttreemodel.cpp b/src/nostalgia/studio/projecttreemodel.cpp index 6a7bfa5d..36335f89 100644 --- a/src/nostalgia/studio/projecttreemodel.cpp +++ b/src/nostalgia/studio/projecttreemodel.cpp @@ -9,10 +9,10 @@ namespace nostalgia { -ProjectTreeModel::ProjectTreeModel(ProjectExplorer *explorer, const ox::String &name, +ProjectTreeModel::ProjectTreeModel(ProjectExplorer *explorer, ox::String name, ProjectTreeModel *parent) noexcept { m_explorer = explorer; - m_name = name; + m_name = std::move(name); m_parent = parent; } @@ -23,7 +23,7 @@ ProjectTreeModel::ProjectTreeModel(ProjectTreeModel &&other) noexcept { void ProjectTreeModel::draw(core::Context *ctx) noexcept { constexpr auto dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick; - if (m_children.size()) { + if (!m_children.empty()) { if (ImGui::TreeNodeEx(m_name.c_str(), dirFlags)) { for (auto &child : m_children) { child->draw(ctx); diff --git a/src/nostalgia/studio/projecttreemodel.hpp b/src/nostalgia/studio/projecttreemodel.hpp index cc629282..1d45aab5 100644 --- a/src/nostalgia/studio/projecttreemodel.hpp +++ b/src/nostalgia/studio/projecttreemodel.hpp @@ -18,7 +18,7 @@ class ProjectTreeModel { ox::String m_name; ox::Vector> m_children; public: - explicit ProjectTreeModel(class ProjectExplorer *explorer, const ox::String &name, + explicit ProjectTreeModel(class ProjectExplorer *explorer, ox::String name, ProjectTreeModel *parent = nullptr) noexcept; ProjectTreeModel(ProjectTreeModel &&other) noexcept; diff --git a/src/nostalgia/tools/pack/pack.cpp b/src/nostalgia/tools/pack/pack.cpp index 0944d688..2533b9b0 100644 --- a/src/nostalgia/tools/pack/pack.cpp +++ b/src/nostalgia/tools/pack/pack.cpp @@ -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(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(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 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));