diff --git a/src/keel/typestore.cpp b/src/keel/typestore.cpp index 4e2028eb..b267d019 100644 --- a/src/keel/typestore.cpp +++ b/src/keel/typestore.cpp @@ -6,14 +6,14 @@ namespace keel { -TypeStore::TypeStore(ox::FileSystem *fs, ox::String descPath) noexcept: +TypeStore::TypeStore(ox::FileSystem &fs, ox::String descPath) noexcept: m_fs(fs), m_descPath(std::move(descPath)) { } ox::Result> TypeStore::loadDescriptor(ox::CRStringView typeId) noexcept { auto path = ox::sfmt("{}/{}", m_descPath, typeId); - oxRequire(buff, m_fs->read(path)); + oxRequire(buff, m_fs.read(path)); auto dt = ox::make_unique(); oxReturnError(ox::readClaw(buff, dt.get())); return dt; diff --git a/src/keel/typestore.hpp b/src/keel/typestore.hpp index 94f79133..84524e43 100644 --- a/src/keel/typestore.hpp +++ b/src/keel/typestore.hpp @@ -12,11 +12,11 @@ namespace keel { class TypeStore: public ox::TypeStore { private: - ox::FileSystem *m_fs = nullptr; + ox::FileSystem &m_fs; ox::String m_descPath; public: - explicit TypeStore(ox::FileSystem *fs, ox::String descPath) noexcept; + explicit TypeStore(ox::FileSystem &fs, ox::String descPath) noexcept; protected: ox::Result> loadDescriptor(ox::CRStringView typeId) noexcept override; diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index 42218c1d..557cbffc 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -65,7 +65,7 @@ static ox::Error run(const ox::ClArgs &args) noexcept { oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size())); ox::FileSystem32 dst(dstBuff); oxRequire(ctx, keel::init(ox::make_unique(argSrc), "nost-pack")); - keel::TypeStore ts(ctx->rom.get(), "/.nostalgia/type_descriptors"); + keel::TypeStore ts(*ctx->rom, "/.nostalgia/type_descriptors"); oxReturnError(generateTypes(&ts)); oxReturnError(keel::pack(*ctx, ts, dst)); oxRequireM(pl, keel::GbaPreloader::make()); diff --git a/src/studio/applib/src/newmenu.cpp b/src/studio/applib/src/newmenu.cpp index bbd1e695..bae6216b 100644 --- a/src/studio/applib/src/newmenu.cpp +++ b/src/studio/applib/src/newmenu.cpp @@ -106,8 +106,7 @@ void NewMenu::drawLastPageButtons(turbine::Context *ctx) noexcept { } void NewMenu::finish(turbine::Context *ctx) noexcept { - const auto itemName = ox::String(m_itemName); - const auto err = m_types[static_cast(m_selectedType)]->write(ctx, itemName); + const auto err = m_types[static_cast(m_selectedType)]->write(ctx, m_itemName); if (err) { oxLogError(err); return; diff --git a/src/studio/applib/src/studioapp.cpp b/src/studio/applib/src/studioapp.cpp index 54a6d177..4cc341d3 100644 --- a/src/studio/applib/src/studioapp.cpp +++ b/src/studio/applib/src/studioapp.cpp @@ -305,7 +305,7 @@ ox::Error StudioUI::openProject(ox::CRStringView path) noexcept { oxRequireM(fs, keel::loadRomFs(path)); oxReturnError(keel::setRomFs(&m_ctx->keelCtx, std::move(fs))); turbine::setWindowTitle(*m_ctx, ox::sfmt("{} - {}", m_ctx->keelCtx.appName, path)); - m_project = ox::make_unique(&m_ctx->keelCtx, ox::String(path), m_projectDir); + m_project = ox::make_unique(m_ctx->keelCtx, ox::String(path), m_projectDir); auto sctx = applicationData(*m_ctx); sctx->project = m_project.get(); m_project->fileAdded.connect(m_projectExplorer.get(), &ProjectExplorer::refreshProjectTreeModel); @@ -324,9 +324,7 @@ ox::Error StudioUI::openFile(ox::CRStringView path) noexcept { } ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab) noexcept { - // Warning: StringView to String - auto const pathStr = ox::String(path); - if (m_openFiles.contains(pathStr)) { + if (m_openFiles.contains(path)) { for (auto &e : m_editors) { if (makeActiveTab && e->itemName() == path) { m_activeEditor = e.get(); @@ -365,7 +363,7 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab) } // save to config studio::editConfig(&m_ctx->keelCtx, [&](StudioConfig *config) { - if (!config->openFiles.contains(pathStr)) { + if (!config->openFiles.contains(path)) { config->openFiles.emplace_back(path); } }); diff --git a/src/studio/modlib/include/studio/project.hpp b/src/studio/modlib/include/studio/project.hpp index ccd3ecf5..86759087 100644 --- a/src/studio/modlib/include/studio/project.hpp +++ b/src/studio/modlib/include/studio/project.hpp @@ -42,11 +42,11 @@ class Project { ox::String m_path; ox::String m_projectDataDir; mutable keel::TypeStore m_typeStore; - mutable ox::FileSystem *m_fs = nullptr; + ox::FileSystem &m_fs; ox::HashMap> m_fileExtFileMap; public: - explicit Project(keel::Context *ctx, ox::String path, ox::CRStringView projectDir) noexcept; + explicit Project(keel::Context &ctx, ox::String path, ox::CRStringView projectDataDir) noexcept; ox::Error create() noexcept; @@ -93,14 +93,14 @@ class Project { // signals public: - ox::Signal fileEvent; + ox::Signal fileEvent; 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; }; @@ -133,7 +133,7 @@ ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat f template ox::Result Project::loadObj(ox::CRStringView path) const noexcept { oxRequire(buff, loadBuff(path)); - if constexpr (ox::is_same_v) { + if constexpr(ox::is_same_v) { return keel::readAsset(&m_typeStore, buff); } else { return keel::readAsset(buff); diff --git a/src/studio/modlib/src/project.cpp b/src/studio/modlib/src/project.cpp index 90f44a95..7693691f 100644 --- a/src/studio/modlib/src/project.cpp +++ b/src/studio/modlib/src/project.cpp @@ -21,12 +21,12 @@ static void generateTypes(ox::TypeStore *ts) noexcept { } } -Project::Project(keel::Context *ctx, ox::String path, ox::CRStringView projectDataDir) noexcept: - m_ctx(*ctx), +Project::Project(keel::Context &ctx, ox::String path, ox::CRStringView projectDataDir) noexcept: + m_ctx(ctx), m_path(std::move(path)), m_projectDataDir(projectDataDir), - m_typeStore(ctx->rom.get(), ox::sfmt("/.{}/type_descriptors", projectDataDir)), - m_fs(ctx->rom.get()) { + m_typeStore(*m_ctx.rom, ox::sfmt("/.{}/type_descriptors", projectDataDir)), + m_fs(*m_ctx.rom) { oxTracef("studio", "Project: {}", m_path); generateTypes(&m_typeStore); buildFileIndex(); @@ -39,21 +39,21 @@ ox::Error Project::create() noexcept { } ox::FileSystem *Project::romFs() noexcept { - return m_fs; + return &m_fs; } ox::Error Project::mkdir(ox::CRStringView path) const noexcept { - oxReturnError(m_fs->mkdir(path, true)); + oxReturnError(m_fs.mkdir(path, true)); fileUpdated.emit(path); return {}; } ox::Result Project::stat(ox::CRStringView path) const noexcept { - return m_fs->stat(path); + return m_fs.stat(path); } bool Project::exists(ox::CRStringView path) const noexcept { - return m_fs->stat(path).error == 0; + return m_fs.stat(path).error == 0; } const ox::Vector &Project::fileList(ox::CRStringView ext) noexcept { @@ -88,13 +88,13 @@ ox::Error Project::writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexc ox::Buffer outBuff; outBuff.reserve(buff.size() + HdrSz); ox::BufferWriter writer(&outBuff); - const auto [uuid, err] = m_ctx.pathToUuid.at(path); + const auto [uuid, err] = m_ctx.pathToUuid.at(path); if (!err) { oxReturnError(keel::writeUuidHeader(writer, *uuid)); } oxReturnError(writer.write(buff.data(), buff.size())); - const auto newFile = m_fs->stat(path).error != 0; - oxReturnError(m_fs->write(path, outBuff.data(), outBuff.size(), ox::FileType::NormalFile)); + const auto newFile = m_fs.stat(path).error != 0; + oxReturnError(m_fs.write(path, outBuff.data(), outBuff.size(), ox::FileType::NormalFile)); if (newFile) { fileAdded.emit(path); indexFile(path); @@ -105,14 +105,14 @@ ox::Error Project::writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexc } ox::Result Project::loadBuff(ox::CRStringView path) const noexcept { - return m_fs->read(path); + return m_fs.read(path); } ox::Error Project::lsProcDir(ox::Vector *paths, ox::CRStringView path) const noexcept { - oxRequire(files, m_fs->ls(path)); + oxRequire(files, m_fs.ls(path)); for (const auto &name : files) { auto fullPath = ox::sfmt("{}/{}", path, name); - oxRequire(stat, m_fs->stat(ox::StringView(fullPath))); + oxRequire(stat, m_fs.stat(ox::StringView(fullPath))); switch (stat.fileType) { case ox::FileType::NormalFile: paths->emplace_back(std::move(fullPath));