[nostalgia] Fix to allow building UUID map later
This commit is contained in:
parent
d17f536832
commit
53229b05da
@ -18,6 +18,11 @@ ox::Result<ox::UUID> readUuidHeader(const ox::Buffer &buff) noexcept;
|
|||||||
|
|
||||||
ox::Result<ox::UUID> readUuidHeader(const char *buff, std::size_t buffLen) noexcept;
|
ox::Result<ox::UUID> readUuidHeader(const char *buff, std::size_t buffLen) noexcept;
|
||||||
|
|
||||||
|
ox::Error writeUuidHeader(ox::Writer_c auto *writer, const ox::UUID &uuid) noexcept {
|
||||||
|
const auto hdr = ox::sfmt<ox::BString<40>>("N1{};", uuid.toString());
|
||||||
|
return write(writer, hdr);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Result<T> readAsset(const ox::Buffer &buff) noexcept {
|
ox::Result<T> readAsset(const ox::Buffer &buff) noexcept {
|
||||||
std::size_t offset = 0;
|
std::size_t offset = 0;
|
||||||
|
@ -15,9 +15,8 @@ namespace nostalgia::foundation {
|
|||||||
template<typename Ctx = foundation::Context>
|
template<typename Ctx = foundation::Context>
|
||||||
ox::Result<ox::UPtr<Ctx>> init(ox::UPtr<ox::FileSystem> &&fs, ox::CRStringView appName) noexcept {
|
ox::Result<ox::UPtr<Ctx>> init(ox::UPtr<ox::FileSystem> &&fs, ox::CRStringView appName) noexcept {
|
||||||
auto ctx = ox::make_unique<Ctx>();
|
auto ctx = ox::make_unique<Ctx>();
|
||||||
ctx->rom = std::move(fs);
|
|
||||||
ctx->appName = appName;
|
ctx->appName = appName;
|
||||||
oxReturnError(buildUuidMap(ctx.get()));
|
oxIgnoreError(setRomFs(ctx.get(), std::move(fs)));
|
||||||
auto mods = modules();
|
auto mods = modules();
|
||||||
if (mods) {
|
if (mods) {
|
||||||
for (auto &mod : *mods) {
|
for (auto &mod : *mods) {
|
||||||
|
@ -40,6 +40,11 @@ ox::Result<void*> findPreloadSection() noexcept {
|
|||||||
return OxError(1, "findPreloadSection is unsupported on this platform");
|
return OxError(1, "findPreloadSection is unsupported on this platform");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void clearUuidMap(Context *ctx) noexcept {
|
||||||
|
ctx->uuidToPath.clear();
|
||||||
|
ctx->pathToUuid.clear();
|
||||||
|
}
|
||||||
|
|
||||||
static ox::Error buildUuidMap(Context *ctx, ox::CRStringView path) noexcept {
|
static ox::Error buildUuidMap(Context *ctx, ox::CRStringView path) noexcept {
|
||||||
oxRequire(files, ctx->rom->ls(path));
|
oxRequire(files, ctx->rom->ls(path));
|
||||||
for (const auto &f : files) {
|
for (const auto &f : files) {
|
||||||
@ -76,6 +81,9 @@ ox::Error buildUuidMap(Context *ctx) noexcept {
|
|||||||
|
|
||||||
namespace nostalgia::foundation {
|
namespace nostalgia::foundation {
|
||||||
|
|
||||||
|
static void clearUuidMap(Context*) noexcept {
|
||||||
|
}
|
||||||
|
|
||||||
ox::Error buildUuidMap(Context*) noexcept {
|
ox::Error buildUuidMap(Context*) noexcept {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -122,6 +130,12 @@ ox::Result<std::size_t> getPreloadAddr(foundation::Context *ctx, const ox::FileA
|
|||||||
|
|
||||||
namespace nostalgia::foundation {
|
namespace nostalgia::foundation {
|
||||||
|
|
||||||
|
ox::Error setRomFs(Context *ctx, ox::UPtr<ox::FileSystem> fs) noexcept {
|
||||||
|
ctx->rom = std::move(fs);
|
||||||
|
clearUuidMap(ctx);
|
||||||
|
return buildUuidMap(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView path) noexcept {
|
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView path) noexcept {
|
||||||
const auto lastDot = ox_lastIndexOf(path, '.');
|
const auto lastDot = ox_lastIndexOf(path, '.');
|
||||||
const auto fsExt = lastDot != -1 ? path.substr(static_cast<std::size_t>(lastDot)) : "";
|
const auto fsExt = lastDot != -1 ? path.substr(static_cast<std::size_t>(lastDot)) : "";
|
||||||
|
@ -133,6 +133,8 @@ ox::Error writeObj(
|
|||||||
return ctx->rom->write(file, objBuff.data(), objBuff.size());
|
return ctx->rom->write(file, objBuff.data(), objBuff.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ox::Error setRomFs(Context *ctx, ox::UPtr<ox::FileSystem> fs) noexcept;
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView assetId) noexcept;
|
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView assetId) noexcept;
|
||||||
|
|
||||||
ox::Result<char*> loadRom(ox::CRStringView assetId = "") noexcept;
|
ox::Result<char*> loadRom(ox::CRStringView assetId = "") noexcept;
|
||||||
|
@ -21,7 +21,11 @@ static void generateTypes(ox::TypeStore *ts) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Project::Project(ox::FileSystem *fs, ox::String path) noexcept: m_path(std::move(path)), m_typeStore(fs), m_fs(fs) {
|
Project::Project(foundation::Context *ctx, ox::String path) noexcept:
|
||||||
|
m_path(std::move(path)),
|
||||||
|
m_typeStore(ctx->rom.get()),
|
||||||
|
m_fs(ctx->rom.get()),
|
||||||
|
m_ctx(ctx) {
|
||||||
oxTracef("nostalgia::studio", "Project: {}", m_path);
|
oxTracef("nostalgia::studio", "Project: {}", m_path);
|
||||||
generateTypes(&m_typeStore);
|
generateTypes(&m_typeStore);
|
||||||
buildFileIndex();
|
buildFileIndex();
|
||||||
@ -79,15 +83,22 @@ void Project::indexFile(ox::CRStringView path) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error Project::writeBuff(const ox::StringView &path, const ox::Buffer &buff) noexcept {
|
ox::Error Project::writeBuff(const ox::StringView &path, const ox::Buffer &buff) noexcept {
|
||||||
|
constexpr auto HdrSz = 40;
|
||||||
|
ox::Buffer outBuff;
|
||||||
|
outBuff.reserve(buff.size() + HdrSz);
|
||||||
|
ox::BufferWriter writer(&outBuff);
|
||||||
|
oxRequire(uuid, m_ctx->pathToUuid.at(path));
|
||||||
|
oxReturnError(foundation::writeUuidHeader(&writer, *uuid));
|
||||||
|
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, buff.data(), buff.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);
|
||||||
} else {
|
} else {
|
||||||
fileUpdated.emit(path);
|
fileUpdated.emit(path);
|
||||||
}
|
}
|
||||||
return OxError(0);
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::Buffer> Project::loadBuff(const ox::String &path) const noexcept {
|
ox::Result<ox::Buffer> Project::loadBuff(const ox::String &path) const noexcept {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@ -43,10 +43,11 @@ class NOSTALGIASTUDIO_EXPORT Project {
|
|||||||
ox::String m_path;
|
ox::String m_path;
|
||||||
mutable core::TypeStore m_typeStore;
|
mutable core::TypeStore m_typeStore;
|
||||||
mutable ox::FileSystem *m_fs = nullptr;
|
mutable ox::FileSystem *m_fs = nullptr;
|
||||||
|
foundation::Context *m_ctx = nullptr;
|
||||||
ox::HashMap<ox::String, ox::Vector<ox::String>> m_fileExtFileMap;
|
ox::HashMap<ox::String, ox::Vector<ox::String>> m_fileExtFileMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Project(ox::FileSystem *fs, ox::String path) noexcept;
|
explicit Project(foundation::Context *ctx, ox::String path) noexcept;
|
||||||
|
|
||||||
ox::Error create() noexcept;
|
ox::Error create() noexcept;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <ox/logconn/logconn.hpp>
|
#include <ox/logconn/logconn.hpp>
|
||||||
#include <ox/std/trace.hpp>
|
#include <ox/std/trace.hpp>
|
||||||
|
#include <ox/std/uuid.hpp>
|
||||||
|
|
||||||
#include <nostalgia/appmodules/appmodules.hpp>
|
#include <nostalgia/appmodules/appmodules.hpp>
|
||||||
#include <nostalgia/core/core.hpp>
|
#include <nostalgia/core/core.hpp>
|
||||||
@ -54,17 +55,12 @@ static ox::Error run(ox::UniquePtr<ox::FileSystem> fs) noexcept {
|
|||||||
return core::run(ctx.get());
|
return core::run(ctx.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
static ox::Error run(int argc, const char **argv) noexcept {
|
static ox::Error run(int, const char**) noexcept {
|
||||||
ox::trace::init();
|
ox::trace::init();
|
||||||
|
ox::UUID::seedGenerator({});
|
||||||
loadModules();
|
loadModules();
|
||||||
if (argc >= 2) {
|
|
||||||
const auto path = argv[1];
|
|
||||||
oxRequireM(fs, foundation::loadRomFs(path));
|
|
||||||
return run(std::move(fs));
|
|
||||||
} else {
|
|
||||||
return run(ox::UniquePtr<ox::FileSystem>(nullptr));
|
return run(ox::UniquePtr<ox::FileSystem>(nullptr));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
@ -286,9 +286,9 @@ void StudioUI::save() noexcept {
|
|||||||
|
|
||||||
ox::Error StudioUI::openProject(ox::CRStringView path) noexcept {
|
ox::Error StudioUI::openProject(ox::CRStringView path) noexcept {
|
||||||
oxRequireM(fs, foundation::loadRomFs(path));
|
oxRequireM(fs, foundation::loadRomFs(path));
|
||||||
m_ctx->rom = std::move(fs);
|
oxReturnError(foundation::setRomFs(m_ctx, std::move(fs)));
|
||||||
core::setWindowTitle(m_ctx, ox::sfmt("Nostalgia Studio - {}", path));
|
core::setWindowTitle(m_ctx, ox::sfmt("Nostalgia Studio - {}", path));
|
||||||
m_project = ox::make_unique<studio::Project>(m_ctx->rom.get(), path);
|
m_project = ox::make_unique<studio::Project>(m_ctx, path);
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user