[keel,nostalgia/tools/pack,studio] Cleanup

This commit is contained in:
2023-11-30 21:45:03 -06:00
parent 68a0dd9660
commit 0fc7e7005c
7 changed files with 30 additions and 33 deletions

View File

@@ -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<ox::String, ox::Vector<ox::String>> 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<ox::Error(ProjectEvent, const ox::String&)> fileEvent;
ox::Signal<ox::Error(ProjectEvent, ox::CRStringView)> fileEvent;
ox::Signal<ox::Error(ox::CRStringView)> 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<ox::Error(ox::StringView)> fileRecognized;
ox::Signal<ox::Error(ox::StringView)> fileDeleted;
ox::Signal<ox::Error(ox::StringView)> fileUpdated;
ox::Signal<ox::Error(ox::CRStringView)> fileRecognized;
ox::Signal<ox::Error(ox::CRStringView)> fileDeleted;
ox::Signal<ox::Error(ox::CRStringView)> fileUpdated;
};
@@ -133,7 +133,7 @@ ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat f
template<typename T>
ox::Result<T> Project::loadObj(ox::CRStringView path) const noexcept {
oxRequire(buff, loadBuff(path));
if constexpr (ox::is_same_v<T, ox::ModelObject>) {
if constexpr(ox::is_same_v<T, ox::ModelObject>) {
return keel::readAsset(&m_typeStore, buff);
} else {
return keel::readAsset<T>(buff);

View File

@@ -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<ox::FileStat> 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<ox::String> &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<ox::Buffer> Project::loadBuff(ox::CRStringView path) const noexcept {
return m_fs->read(path);
return m_fs.read(path);
}
ox::Error Project::lsProcDir(ox::Vector<ox::String> *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));