[keel,nostalgia/tools/pack,studio] Cleanup
This commit is contained in:
		@@ -6,14 +6,14 @@
 | 
			
		||||
 | 
			
		||||
namespace keel {
 | 
			
		||||
 | 
			
		||||
TypeStore::TypeStore(ox::FileSystem *fs, ox::String descPath) noexcept:
 | 
			
		||||
TypeStore::TypeStore(ox::FileSystem &fs, ox::String descPath) noexcept:
 | 
			
		||||
	m_fs(fs),
 | 
			
		||||
	m_descPath(std::move(descPath)) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ox::Result<ox::UniquePtr<ox::DescriptorType>> TypeStore::loadDescriptor(ox::CRStringView typeId) noexcept {
 | 
			
		||||
	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>();
 | 
			
		||||
	oxReturnError(ox::readClaw<ox::DescriptorType>(buff, dt.get()));
 | 
			
		||||
	return dt;
 | 
			
		||||
 
 | 
			
		||||
@@ -12,11 +12,11 @@ namespace keel {
 | 
			
		||||
 | 
			
		||||
class TypeStore: public ox::TypeStore {
 | 
			
		||||
	private:
 | 
			
		||||
		ox::FileSystem *m_fs = nullptr;
 | 
			
		||||
		ox::FileSystem &m_fs;
 | 
			
		||||
		ox::String m_descPath;
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
		explicit TypeStore(ox::FileSystem *fs, ox::String descPath) noexcept;
 | 
			
		||||
		explicit TypeStore(ox::FileSystem &fs, ox::String descPath) noexcept;
 | 
			
		||||
 | 
			
		||||
	protected:
 | 
			
		||||
		ox::Result<ox::UniquePtr<ox::DescriptorType>> loadDescriptor(ox::CRStringView typeId) noexcept override;
 | 
			
		||||
 
 | 
			
		||||
@@ -65,7 +65,7 @@ static ox::Error run(const ox::ClArgs &args) noexcept {
 | 
			
		||||
	oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
 | 
			
		||||
	ox::FileSystem32 dst(dstBuff);
 | 
			
		||||
	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(keel::pack(*ctx, ts, dst));
 | 
			
		||||
	oxRequireM(pl, keel::GbaPreloader::make());
 | 
			
		||||
 
 | 
			
		||||
@@ -106,8 +106,7 @@ void NewMenu::drawLastPageButtons(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, itemName);
 | 
			
		||||
	const auto err = m_types[static_cast<std::size_t>(m_selectedType)]->write(ctx, m_itemName);
 | 
			
		||||
	if (err) {
 | 
			
		||||
		oxLogError(err);
 | 
			
		||||
		return;
 | 
			
		||||
 
 | 
			
		||||
@@ -305,7 +305,7 @@ ox::Error StudioUI::openProject(ox::CRStringView path) noexcept {
 | 
			
		||||
	oxRequireM(fs, keel::loadRomFs(path));
 | 
			
		||||
	oxReturnError(keel::setRomFs(&m_ctx->keelCtx, std::move(fs)));
 | 
			
		||||
	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);
 | 
			
		||||
	sctx->project = m_project.get();
 | 
			
		||||
	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 {
 | 
			
		||||
	// Warning: StringView to String
 | 
			
		||||
	auto const pathStr = ox::String(path);
 | 
			
		||||
	if (m_openFiles.contains(pathStr)) {
 | 
			
		||||
	if (m_openFiles.contains(path)) {
 | 
			
		||||
		for (auto &e : m_editors) {
 | 
			
		||||
			if (makeActiveTab && e->itemName() == path) {
 | 
			
		||||
				m_activeEditor = e.get();
 | 
			
		||||
@@ -365,7 +363,7 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab)
 | 
			
		||||
	}
 | 
			
		||||
	// save to config
 | 
			
		||||
	studio::editConfig<StudioConfig>(&m_ctx->keelCtx, [&](StudioConfig *config) {
 | 
			
		||||
		if (!config->openFiles.contains(pathStr)) {
 | 
			
		||||
		if (!config->openFiles.contains(path)) {
 | 
			
		||||
			config->openFiles.emplace_back(path);
 | 
			
		||||
		}
 | 
			
		||||
	});
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user