[nostalgia/studio] Make Project update file index when a file is added
This commit is contained in:
parent
29fd9b8c4f
commit
ed025bfa31
@ -40,8 +40,8 @@ bool Project::exists(const ox::String &path) const noexcept {
|
|||||||
return m_fs->stat(path.c_str()).error == 0;
|
return m_fs->stat(path.c_str()).error == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ox::Vector<ox::String> &Project::fileList(const char *ng) noexcept {
|
const ox::Vector<ox::String> &Project::fileList(const char *ext) noexcept {
|
||||||
return m_fileExtFileMap[ng];
|
return m_fileExtFileMap[ext];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::buildFileIndex() noexcept {
|
void Project::buildFileIndex() noexcept {
|
||||||
@ -50,23 +50,29 @@ void Project::buildFileIndex() noexcept {
|
|||||||
oxLogError(err);
|
oxLogError(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
m_fileExtFileMap.clear();
|
||||||
std::sort(files.begin(), files.end());
|
std::sort(files.begin(), files.end());
|
||||||
for (const auto &file : files) {
|
for (const auto &file : files) {
|
||||||
if (!file.beginsWith("/.nostalgia/")) {
|
if (!file.beginsWith("/.nostalgia/")) {
|
||||||
const auto [ext, err] = fileExt(file);
|
indexFile(file);
|
||||||
if (err) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
m_fileExtFileMap[ext].emplace_back(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;
|
const auto newFile = m_fs->stat(path.c_str()).error != 0;
|
||||||
oxReturnError(m_fs->write(path.c_str(), buff.data(), buff.size()));
|
oxReturnError(m_fs->write(path.c_str(), buff.data(), buff.size()));
|
||||||
if (newFile) {
|
if (newFile) {
|
||||||
fileAdded.emit(path);
|
fileAdded.emit(path);
|
||||||
|
indexFile(path);
|
||||||
} else {
|
} else {
|
||||||
fileUpdated.emit(path);
|
fileUpdated.emit(path);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ class NOSTALGIASTUDIO_EXPORT Project {
|
|||||||
/**
|
/**
|
||||||
* Writes a MetalClaw object to the project at the given path.
|
* 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>
|
template<typename T>
|
||||||
ox::Result<ox::UniquePtr<T>> loadObj(const ox::String &path) const noexcept;
|
ox::Result<ox::UniquePtr<T>> loadObj(const ox::String &path) const noexcept;
|
||||||
@ -76,7 +76,9 @@ class NOSTALGIASTUDIO_EXPORT Project {
|
|||||||
private:
|
private:
|
||||||
void buildFileIndex() noexcept;
|
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;
|
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
|
// write MetalClaw
|
||||||
oxRequireM(buff, ox::writeClaw(obj, fmt));
|
oxRequireM(buff, ox::writeClaw(obj, fmt));
|
||||||
// write to FS
|
// write to FS
|
||||||
|
Loading…
Reference in New Issue
Block a user