From ed025bfa3162f02a63c997724238a7ba41b652c6 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 30 Jul 2022 15:06:46 -0500 Subject: [PATCH] [nostalgia/studio] Make Project update file index when a file is added --- src/nostalgia/studio/lib/project.cpp | 22 ++++++++++++++-------- src/nostalgia/studio/lib/project.hpp | 8 +++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/nostalgia/studio/lib/project.cpp b/src/nostalgia/studio/lib/project.cpp index 916fe99d..f1a8f1e4 100644 --- a/src/nostalgia/studio/lib/project.cpp +++ b/src/nostalgia/studio/lib/project.cpp @@ -40,8 +40,8 @@ bool Project::exists(const ox::String &path) const noexcept { return m_fs->stat(path.c_str()).error == 0; } -const ox::Vector &Project::fileList(const char *ng) noexcept { - return m_fileExtFileMap[ng]; +const ox::Vector &Project::fileList(const char *ext) noexcept { + return m_fileExtFileMap[ext]; } void Project::buildFileIndex() noexcept { @@ -50,23 +50,29 @@ void Project::buildFileIndex() noexcept { oxLogError(err); return; } + m_fileExtFileMap.clear(); std::sort(files.begin(), files.end()); for (const auto &file : files) { if (!file.beginsWith("/.nostalgia/")) { - const auto [ext, err] = fileExt(file); - if (err) { - continue; - } - m_fileExtFileMap[ext].emplace_back(file); + indexFile(file); } } } -ox::Error Project::writeBuff(const ox::String &path, const ox::Buffer &buff) const noexcept { +void Project::indexFile(const ox::String &path) noexcept { + const auto [ext, err] = fileExt(path); + if (err) { + return; + } + 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())); if (newFile) { fileAdded.emit(path); + indexFile(path); } else { fileUpdated.emit(path); } diff --git a/src/nostalgia/studio/lib/project.hpp b/src/nostalgia/studio/lib/project.hpp index cce928f6..1113a790 100644 --- a/src/nostalgia/studio/lib/project.hpp +++ b/src/nostalgia/studio/lib/project.hpp @@ -57,7 +57,7 @@ class NOSTALGIASTUDIO_EXPORT Project { /** * Writes a MetalClaw object to the project at the given path. */ - ox::Error writeObj(const ox::String &path, auto *obj, ox::ClawFormat fmt = ox::ClawFormat::Metal) const noexcept; + ox::Error writeObj(const ox::String &path, auto *obj, ox::ClawFormat fmt = ox::ClawFormat::Metal) noexcept; template ox::Result> loadObj(const ox::String &path) const noexcept; @@ -76,7 +76,9 @@ class NOSTALGIASTUDIO_EXPORT Project { private: void buildFileIndex() noexcept; - ox::Error writeBuff(const ox::String &path, const ox::Buffer &buff) const noexcept; + void indexFile(const ox::String &path) noexcept; + + ox::Error writeBuff(const ox::String &path, const ox::Buffer &buff) noexcept; ox::Result loadBuff(const ox::String &path) const noexcept; @@ -97,7 +99,7 @@ class NOSTALGIASTUDIO_EXPORT Project { }; -ox::Error Project::writeObj(const ox::String &path, auto *obj, ox::ClawFormat fmt) const noexcept { +ox::Error Project::writeObj(const ox::String &path, auto *obj, ox::ClawFormat fmt) noexcept { // write MetalClaw oxRequireM(buff, ox::writeClaw(obj, fmt)); // write to FS