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

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

View File

@ -6,14 +6,14 @@
namespace keel { namespace keel {
TypeStore::TypeStore(ox::FileSystem *fs, ox::String descPath) noexcept: TypeStore::TypeStore(ox::FileSystem &fs, ox::String descPath) noexcept:
m_fs(fs), m_fs(fs),
m_descPath(std::move(descPath)) { m_descPath(std::move(descPath)) {
} }
ox::Result<ox::UniquePtr<ox::DescriptorType>> TypeStore::loadDescriptor(ox::CRStringView typeId) noexcept { ox::Result<ox::UniquePtr<ox::DescriptorType>> TypeStore::loadDescriptor(ox::CRStringView typeId) noexcept {
auto path = ox::sfmt("{}/{}", m_descPath, typeId); auto path = ox::sfmt("{}/{}", m_descPath, typeId);
oxRequire(buff, m_fs->read(path)); oxRequire(buff, m_fs.read(path));
auto dt = ox::make_unique<ox::DescriptorType>(); auto dt = ox::make_unique<ox::DescriptorType>();
oxReturnError(ox::readClaw<ox::DescriptorType>(buff, dt.get())); oxReturnError(ox::readClaw<ox::DescriptorType>(buff, dt.get()));
return dt; return dt;

View File

@ -12,11 +12,11 @@ namespace keel {
class TypeStore: public ox::TypeStore { class TypeStore: public ox::TypeStore {
private: private:
ox::FileSystem *m_fs = nullptr; ox::FileSystem &m_fs;
ox::String m_descPath; ox::String m_descPath;
public: public:
explicit TypeStore(ox::FileSystem *fs, ox::String descPath) noexcept; explicit TypeStore(ox::FileSystem &fs, ox::String descPath) noexcept;
protected: protected:
ox::Result<ox::UniquePtr<ox::DescriptorType>> loadDescriptor(ox::CRStringView typeId) noexcept override; ox::Result<ox::UniquePtr<ox::DescriptorType>> loadDescriptor(ox::CRStringView typeId) noexcept override;

View File

@ -65,7 +65,7 @@ static ox::Error run(const ox::ClArgs &args) noexcept {
oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size())); oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
ox::FileSystem32 dst(dstBuff); ox::FileSystem32 dst(dstBuff);
oxRequire(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "nost-pack")); oxRequire(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "nost-pack"));
keel::TypeStore ts(ctx->rom.get(), "/.nostalgia/type_descriptors"); keel::TypeStore ts(*ctx->rom, "/.nostalgia/type_descriptors");
oxReturnError(generateTypes(&ts)); oxReturnError(generateTypes(&ts));
oxReturnError(keel::pack(*ctx, ts, dst)); oxReturnError(keel::pack(*ctx, ts, dst));
oxRequireM(pl, keel::GbaPreloader::make()); oxRequireM(pl, keel::GbaPreloader::make());

View File

@ -106,8 +106,7 @@ void NewMenu::drawLastPageButtons(turbine::Context *ctx) noexcept {
} }
void NewMenu::finish(turbine::Context *ctx) noexcept { void NewMenu::finish(turbine::Context *ctx) noexcept {
const auto itemName = ox::String(m_itemName); const auto err = m_types[static_cast<std::size_t>(m_selectedType)]->write(ctx, m_itemName);
const auto err = m_types[static_cast<std::size_t>(m_selectedType)]->write(ctx, itemName);
if (err) { if (err) {
oxLogError(err); oxLogError(err);
return; return;

View File

@ -305,7 +305,7 @@ ox::Error StudioUI::openProject(ox::CRStringView path) noexcept {
oxRequireM(fs, keel::loadRomFs(path)); oxRequireM(fs, keel::loadRomFs(path));
oxReturnError(keel::setRomFs(&m_ctx->keelCtx, std::move(fs))); oxReturnError(keel::setRomFs(&m_ctx->keelCtx, std::move(fs)));
turbine::setWindowTitle(*m_ctx, ox::sfmt("{} - {}", m_ctx->keelCtx.appName, path)); turbine::setWindowTitle(*m_ctx, ox::sfmt("{} - {}", m_ctx->keelCtx.appName, path));
m_project = ox::make_unique<studio::Project>(&m_ctx->keelCtx, ox::String(path), m_projectDir); m_project = ox::make_unique<studio::Project>(m_ctx->keelCtx, ox::String(path), m_projectDir);
auto sctx = applicationData<studio::StudioContext>(*m_ctx); auto sctx = applicationData<studio::StudioContext>(*m_ctx);
sctx->project = m_project.get(); sctx->project = m_project.get();
m_project->fileAdded.connect(m_projectExplorer.get(), &ProjectExplorer::refreshProjectTreeModel); m_project->fileAdded.connect(m_projectExplorer.get(), &ProjectExplorer::refreshProjectTreeModel);
@ -324,9 +324,7 @@ ox::Error StudioUI::openFile(ox::CRStringView path) noexcept {
} }
ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab) noexcept { ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab) noexcept {
// Warning: StringView to String if (m_openFiles.contains(path)) {
auto const pathStr = ox::String(path);
if (m_openFiles.contains(pathStr)) {
for (auto &e : m_editors) { for (auto &e : m_editors) {
if (makeActiveTab && e->itemName() == path) { if (makeActiveTab && e->itemName() == path) {
m_activeEditor = e.get(); m_activeEditor = e.get();
@ -365,7 +363,7 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab)
} }
// save to config // save to config
studio::editConfig<StudioConfig>(&m_ctx->keelCtx, [&](StudioConfig *config) { studio::editConfig<StudioConfig>(&m_ctx->keelCtx, [&](StudioConfig *config) {
if (!config->openFiles.contains(pathStr)) { if (!config->openFiles.contains(path)) {
config->openFiles.emplace_back(path); config->openFiles.emplace_back(path);
} }
}); });

View File

@ -42,11 +42,11 @@ class Project {
ox::String m_path; ox::String m_path;
ox::String m_projectDataDir; ox::String m_projectDataDir;
mutable keel::TypeStore m_typeStore; 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; ox::HashMap<ox::String, ox::Vector<ox::String>> m_fileExtFileMap;
public: 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; ox::Error create() noexcept;
@ -93,14 +93,14 @@ class Project {
// signals // signals
public: 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; ox::Signal<ox::Error(ox::CRStringView)> fileAdded;
// FileRecognized is triggered for all matching files upon a new // FileRecognized is triggered for all matching files upon a new
// subscription to a section of the project and upon the addition of a // subscription to a section of the project and upon the addition of a
// file. // file.
ox::Signal<ox::Error(ox::StringView)> fileRecognized; ox::Signal<ox::Error(ox::CRStringView)> fileRecognized;
ox::Signal<ox::Error(ox::StringView)> fileDeleted; ox::Signal<ox::Error(ox::CRStringView)> fileDeleted;
ox::Signal<ox::Error(ox::StringView)> fileUpdated; ox::Signal<ox::Error(ox::CRStringView)> fileUpdated;
}; };

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: Project::Project(keel::Context &ctx, ox::String path, ox::CRStringView projectDataDir) noexcept:
m_ctx(*ctx), m_ctx(ctx),
m_path(std::move(path)), m_path(std::move(path)),
m_projectDataDir(projectDataDir), m_projectDataDir(projectDataDir),
m_typeStore(ctx->rom.get(), ox::sfmt("/.{}/type_descriptors", projectDataDir)), m_typeStore(*m_ctx.rom, ox::sfmt("/.{}/type_descriptors", projectDataDir)),
m_fs(ctx->rom.get()) { m_fs(*m_ctx.rom) {
oxTracef("studio", "Project: {}", m_path); oxTracef("studio", "Project: {}", m_path);
generateTypes(&m_typeStore); generateTypes(&m_typeStore);
buildFileIndex(); buildFileIndex();
@ -39,21 +39,21 @@ ox::Error Project::create() noexcept {
} }
ox::FileSystem *Project::romFs() noexcept { ox::FileSystem *Project::romFs() noexcept {
return m_fs; return &m_fs;
} }
ox::Error Project::mkdir(ox::CRStringView path) const noexcept { ox::Error Project::mkdir(ox::CRStringView path) const noexcept {
oxReturnError(m_fs->mkdir(path, true)); oxReturnError(m_fs.mkdir(path, true));
fileUpdated.emit(path); fileUpdated.emit(path);
return {}; return {};
} }
ox::Result<ox::FileStat> Project::stat(ox::CRStringView path) const noexcept { 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 { 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 { const ox::Vector<ox::String> &Project::fileList(ox::CRStringView ext) noexcept {
@ -93,8 +93,8 @@ ox::Error Project::writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexc
oxReturnError(keel::writeUuidHeader(writer, *uuid)); oxReturnError(keel::writeUuidHeader(writer, *uuid));
} }
oxReturnError(writer.write(buff.data(), buff.size())); oxReturnError(writer.write(buff.data(), buff.size()));
const auto newFile = m_fs->stat(path).error != 0; const auto newFile = m_fs.stat(path).error != 0;
oxReturnError(m_fs->write(path, outBuff.data(), outBuff.size(), ox::FileType::NormalFile)); oxReturnError(m_fs.write(path, outBuff.data(), outBuff.size(), ox::FileType::NormalFile));
if (newFile) { if (newFile) {
fileAdded.emit(path); fileAdded.emit(path);
indexFile(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 { 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 { 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) { for (const auto &name : files) {
auto fullPath = ox::sfmt("{}/{}", path, name); 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) { switch (stat.fileType) {
case ox::FileType::NormalFile: case ox::FileType::NormalFile:
paths->emplace_back(std::move(fullPath)); paths->emplace_back(std::move(fullPath));