[nostalgia/studio] Make Project update file index when a file is added

This commit is contained in:
Gary Talent 2022-07-30 15:06:46 -05:00
parent 29fd9b8c4f
commit ed025bfa31
2 changed files with 19 additions and 11 deletions

View File

@ -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<ox::String> &Project::fileList(const char *ng) noexcept {
return m_fileExtFileMap[ng];
const ox::Vector<ox::String> &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);
}

View File

@ -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<typename T>
ox::Result<ox::UniquePtr<T>> 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<ox::Buffer> 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