[nostalgia/studio] Add ability to index and list files of different types in Project
This commit is contained in:
@@ -6,14 +6,13 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <ox/claw/claw.hpp>
|
||||
#include <ox/claw/read.hpp>
|
||||
#include <ox/claw/write.hpp>
|
||||
#include <ox/event/signal.hpp>
|
||||
#include <ox/fs/fs.hpp>
|
||||
#include <ox/mc/mc.hpp>
|
||||
#include <ox/model/descwrite.hpp>
|
||||
#include <ox/event/signal.hpp>
|
||||
#include <ox/std/std.hpp>
|
||||
#include <ox/std/hashmap.hpp>
|
||||
|
||||
#include "nostalgiastudio_export.h"
|
||||
|
||||
@@ -29,6 +28,15 @@ enum class ProjectEvent {
|
||||
FileUpdated,
|
||||
};
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<ox::String> fileExt(auto path) noexcept {
|
||||
const auto extStart = std::find(path.crbegin(), path.crend(), '.').offset();
|
||||
if (!extStart) {
|
||||
return OxError(1, "Cannot open a file without valid extension.");
|
||||
}
|
||||
return path.substr(extStart + 1);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::String filePathToName(const ox::String &path, const ox::String &prefix, const ox::String &suffix) noexcept;
|
||||
|
||||
@@ -36,6 +44,7 @@ class NOSTALGIASTUDIO_EXPORT Project {
|
||||
private:
|
||||
ox::String m_path = "";
|
||||
mutable ox::FileSystem *m_fs = nullptr;
|
||||
ox::HashMap<ox::String, ox::Vector<ox::String>> m_fileExtFileMap;
|
||||
|
||||
public:
|
||||
explicit Project(ox::FileSystem *fs, const ox::String &path) noexcept;
|
||||
@@ -63,7 +72,12 @@ class NOSTALGIASTUDIO_EXPORT Project {
|
||||
template<typename Functor>
|
||||
ox::Error subscribe(ProjectEvent e, ox::SignalHandler *tgt, Functor &&slot) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
const ox::Vector<ox::String> &fileList(const char *ng) noexcept;
|
||||
|
||||
private:
|
||||
void buildFileIndex() noexcept;
|
||||
|
||||
ox::Error writeBuff(const ox::String &path, const ox::Buffer &buff) const noexcept;
|
||||
|
||||
ox::Result<ox::Buffer> loadBuff(const ox::String &path) const noexcept;
|
||||
@@ -96,8 +110,8 @@ ox::Error Project::writeObj(const ox::String &path, auto *obj) const noexcept {
|
||||
// replace garbage last character with new line
|
||||
typeOut.back().value = '\n';
|
||||
// write to FS
|
||||
ox::String descPath = "/.nostalgia/type_descriptors/";
|
||||
const auto typePath = descPath + type->typeName;
|
||||
static constexpr auto descPath = "/.nostalgia/type_descriptors/";
|
||||
const auto typePath = ox::sfmt("{}{}", descPath, type->typeName);
|
||||
oxReturnError(mkdir(descPath));
|
||||
oxReturnError(writeBuff(typePath, typeOut));
|
||||
fileUpdated.emit(path);
|
||||
@@ -121,8 +135,8 @@ ox::Error Project::subscribe(ProjectEvent e, ox::SignalHandler *tgt, Functor &&s
|
||||
break;
|
||||
case ProjectEvent::FileRecognized:
|
||||
{
|
||||
oxRequire(fileList, listFiles());
|
||||
for (auto f : fileList) {
|
||||
oxRequire(files, listFiles());
|
||||
for (auto f : files) {
|
||||
slot(f);
|
||||
}
|
||||
connect(this, &Project::fileRecognized, tgt, slot);
|
||||
|
||||
Reference in New Issue
Block a user