Compare commits
No commits in common. "4e5c7499181904c6e0432a9d56e94c1449f06e79" and "7eb37c531837c30f42316162209be06d62fa892a" have entirely different histories.
4e5c749918
...
7eb37c5318
12
deps/ox/src/ox/fs/filesystem/filesystem.cpp
vendored
12
deps/ox/src/ox/fs/filesystem/filesystem.cpp
vendored
@ -63,6 +63,18 @@ Error FileSystem::read(const FileAddress &addr, std::size_t readStart, std::size
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Error FileSystem::remove(const FileAddress &addr, bool recursive) noexcept {
|
||||||
|
switch (addr.type()) {
|
||||||
|
case FileAddressType::Inode:
|
||||||
|
return remove(addr.getInode().value, recursive);
|
||||||
|
case FileAddressType::ConstPath:
|
||||||
|
case FileAddressType::Path:
|
||||||
|
return remove(StringView(addr.getPath().value), recursive);
|
||||||
|
default:
|
||||||
|
return ox::Error(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Error FileSystem::write(const FileAddress &addr, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
Error FileSystem::write(const FileAddress &addr, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||||
switch (addr.type()) {
|
switch (addr.type()) {
|
||||||
case FileAddressType::Inode:
|
case FileAddressType::Inode:
|
||||||
|
50
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
50
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@ -57,9 +57,9 @@ class FileSystem {
|
|||||||
|
|
||||||
virtual Result<Vector<String>> ls(StringViewCR dir) const noexcept = 0;
|
virtual Result<Vector<String>> ls(StringViewCR dir) const noexcept = 0;
|
||||||
|
|
||||||
Error remove(StringViewCR path, bool recursive = false) noexcept {
|
virtual Error remove(StringViewCR path, bool recursive) noexcept = 0;
|
||||||
return removePath(path, recursive);
|
|
||||||
}
|
Error remove(const FileAddress &addr, bool recursive = false) noexcept;
|
||||||
|
|
||||||
virtual Error resize(uint64_t size, void *buffer) noexcept = 0;
|
virtual Error resize(uint64_t size, void *buffer) noexcept = 0;
|
||||||
|
|
||||||
@ -142,8 +142,6 @@ class FileSystem {
|
|||||||
|
|
||||||
virtual Error readFileInodeRange(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept = 0;
|
virtual Error readFileInodeRange(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept = 0;
|
||||||
|
|
||||||
virtual Error removePath(StringViewCR path, bool recursive) noexcept = 0;
|
|
||||||
|
|
||||||
virtual Error writeFilePath(StringViewCR path, const void *buffer, uint64_t size, FileType fileType) noexcept = 0;
|
virtual Error writeFilePath(StringViewCR path, const void *buffer, uint64_t size, FileType fileType) noexcept = 0;
|
||||||
|
|
||||||
virtual Error writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept = 0;
|
virtual Error writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept = 0;
|
||||||
@ -211,8 +209,6 @@ class FileSystemTemplate: public MemFS {
|
|||||||
|
|
||||||
Error readFileInodeRange(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept override;
|
Error readFileInodeRange(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept override;
|
||||||
|
|
||||||
Error removePath(StringViewCR path, bool recursive) noexcept override;
|
|
||||||
|
|
||||||
Result<const char*> directAccessInode(uint64_t) const noexcept override;
|
Result<const char*> directAccessInode(uint64_t) const noexcept override;
|
||||||
|
|
||||||
Result<Vector<String>> ls(StringViewCR dir) const noexcept override;
|
Result<Vector<String>> ls(StringViewCR dir) const noexcept override;
|
||||||
@ -220,6 +216,8 @@ class FileSystemTemplate: public MemFS {
|
|||||||
template<typename F>
|
template<typename F>
|
||||||
Error ls(StringViewCR path, F cb) const;
|
Error ls(StringViewCR path, F cb) const;
|
||||||
|
|
||||||
|
Error remove(StringViewCR path, bool recursive) noexcept override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resizes FileSystem to minimum possible size.
|
* Resizes FileSystem to minimum possible size.
|
||||||
*/
|
*/
|
||||||
@ -358,25 +356,6 @@ Error FileSystemTemplate<FileStore, Directory>::readFileInodeRange(uint64_t inod
|
|||||||
return m_fs.read(inode, readStart, readSize, reinterpret_cast<uint8_t*>(buffer), size);
|
return m_fs.read(inode, readStart, readSize, reinterpret_cast<uint8_t*>(buffer), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
|
||||||
Error FileSystemTemplate<FileStore, Directory>::removePath(StringViewCR path, bool recursive) noexcept {
|
|
||||||
OX_REQUIRE(fd, fileSystemData());
|
|
||||||
Directory rootDir(m_fs, fd.rootDirInode);
|
|
||||||
OX_REQUIRE(inode, rootDir.find(path));
|
|
||||||
OX_REQUIRE(st, statInode(inode));
|
|
||||||
if (st.fileType == FileType::NormalFile || recursive) {
|
|
||||||
if (auto err = rootDir.remove(path)) {
|
|
||||||
// removal failed, try putting the index back
|
|
||||||
oxLogError(rootDir.write(path, inode));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
oxTrace("FileSystemTemplate.remove.fail", "Tried to remove directory without recursive setting.");
|
|
||||||
return ox::Error(1);
|
|
||||||
}
|
|
||||||
return ox::Error(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<const char*> FileSystemTemplate<FileStore, Directory>::directAccessInode(uint64_t inode) const noexcept {
|
Result<const char*> FileSystemTemplate<FileStore, Directory>::directAccessInode(uint64_t inode) const noexcept {
|
||||||
auto data = m_fs.read(inode);
|
auto data = m_fs.read(inode);
|
||||||
@ -405,6 +384,25 @@ Error FileSystemTemplate<FileStore, Directory>::ls(StringViewCR path, F cb) cons
|
|||||||
return dir.ls(cb);
|
return dir.ls(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename FileStore, typename Directory>
|
||||||
|
Error FileSystemTemplate<FileStore, Directory>::remove(StringViewCR path, bool recursive) noexcept {
|
||||||
|
OX_REQUIRE(fd, fileSystemData());
|
||||||
|
Directory rootDir(m_fs, fd.rootDirInode);
|
||||||
|
OX_REQUIRE(inode, rootDir.find(path));
|
||||||
|
OX_REQUIRE(st, statInode(inode));
|
||||||
|
if (st.fileType == FileType::NormalFile || recursive) {
|
||||||
|
if (auto err = rootDir.remove(path)) {
|
||||||
|
// removal failed, try putting the index back
|
||||||
|
oxLogError(rootDir.write(path, inode));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
oxTrace("FileSystemTemplate.remove.fail", "Tried to remove directory without recursive setting.");
|
||||||
|
return ox::Error(1);
|
||||||
|
}
|
||||||
|
return ox::Error(0);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::resize() noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::resize() noexcept {
|
||||||
return m_fs.resize();
|
return m_fs.resize();
|
||||||
|
16
deps/ox/src/ox/fs/filesystem/passthroughfs.cpp
vendored
16
deps/ox/src/ox/fs/filesystem/passthroughfs.cpp
vendored
@ -75,6 +75,14 @@ Result<Vector<String>> PassThroughFS::ls(StringViewCR dir) const noexcept {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Error PassThroughFS::remove(StringViewCR path, bool recursive) noexcept {
|
||||||
|
if (recursive) {
|
||||||
|
return ox::Error(std::filesystem::remove_all(m_path / stripSlash(path)) != 0);
|
||||||
|
} else {
|
||||||
|
return ox::Error(std::filesystem::remove(m_path / stripSlash(path)) != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Error PassThroughFS::resize(uint64_t, void*) noexcept {
|
Error PassThroughFS::resize(uint64_t, void*) noexcept {
|
||||||
// unsupported
|
// unsupported
|
||||||
return ox::Error(1, "resize is not supported by PassThroughFS");
|
return ox::Error(1, "resize is not supported by PassThroughFS");
|
||||||
@ -159,14 +167,6 @@ Error PassThroughFS::readFileInodeRange(uint64_t, std::size_t, std::size_t, void
|
|||||||
return ox::Error(1, "read(uint64_t, std::size_t, std::size_t, void*, std::size_t*) is not supported by PassThroughFS");
|
return ox::Error(1, "read(uint64_t, std::size_t, std::size_t, void*, std::size_t*) is not supported by PassThroughFS");
|
||||||
}
|
}
|
||||||
|
|
||||||
Error PassThroughFS::removePath(StringViewCR path, bool const recursive) noexcept {
|
|
||||||
if (recursive) {
|
|
||||||
return ox::Error{std::filesystem::remove_all(m_path / stripSlash(path)) == 0};
|
|
||||||
} else {
|
|
||||||
return ox::Error{!std::filesystem::remove(m_path / stripSlash(path))};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Error PassThroughFS::writeFilePath(StringViewCR path, const void *buffer, uint64_t size, FileType) noexcept {
|
Error PassThroughFS::writeFilePath(StringViewCR path, const void *buffer, uint64_t size, FileType) noexcept {
|
||||||
const auto p = (m_path / stripSlash(path));
|
const auto p = (m_path / stripSlash(path));
|
||||||
try {
|
try {
|
||||||
|
@ -45,6 +45,8 @@ class PassThroughFS: public FileSystem {
|
|||||||
template<typename F>
|
template<typename F>
|
||||||
Error ls(StringViewCR dir, F cb) const noexcept;
|
Error ls(StringViewCR dir, F cb) const noexcept;
|
||||||
|
|
||||||
|
Error remove(StringViewCR path, bool recursive) noexcept override;
|
||||||
|
|
||||||
Error resize(uint64_t size, void *buffer) noexcept override;
|
Error resize(uint64_t size, void *buffer) noexcept override;
|
||||||
|
|
||||||
Result<FileStat> statInode(uint64_t inode) const noexcept override;
|
Result<FileStat> statInode(uint64_t inode) const noexcept override;
|
||||||
@ -73,8 +75,6 @@ class PassThroughFS: public FileSystem {
|
|||||||
|
|
||||||
Error readFileInodeRange(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept override;
|
Error readFileInodeRange(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept override;
|
||||||
|
|
||||||
Error removePath(StringViewCR path, bool recursive) noexcept override;
|
|
||||||
|
|
||||||
Error writeFilePath(StringViewCR path, const void *buffer, uint64_t size, FileType fileType) noexcept override;
|
Error writeFilePath(StringViewCR path, const void *buffer, uint64_t size, FileType fileType) noexcept override;
|
||||||
|
|
||||||
Error writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept override;
|
Error writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept override;
|
||||||
|
@ -12,12 +12,12 @@ namespace studio {
|
|||||||
|
|
||||||
static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
|
static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
|
||||||
ProjectExplorer &explorer,
|
ProjectExplorer &explorer,
|
||||||
ox::StringParam name,
|
ox::StringView name,
|
||||||
ox::StringView path,
|
ox::StringView path,
|
||||||
ProjectTreeModel *parent) noexcept {
|
ProjectTreeModel *parent) noexcept {
|
||||||
auto const fs = explorer.romFs();
|
auto const fs = explorer.romFs();
|
||||||
OX_REQUIRE(stat, fs->stat(path));
|
OX_REQUIRE(stat, fs->stat(path));
|
||||||
auto out = ox::make_unique<ProjectTreeModel>(explorer, std::move(name), parent);
|
auto out = ox::make_unique<ProjectTreeModel>(explorer, ox::String(name), parent);
|
||||||
if (stat.fileType == ox::FileType::Directory) {
|
if (stat.fileType == ox::FileType::Directory) {
|
||||||
OX_REQUIRE_M(children, fs->ls(path));
|
OX_REQUIRE_M(children, fs->ls(path));
|
||||||
std::sort(children.begin(), children.end());
|
std::sort(children.begin(), children.end());
|
||||||
@ -37,14 +37,12 @@ static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
|
|||||||
ProjectExplorer::ProjectExplorer(turbine::Context &ctx) noexcept: m_ctx(ctx) {
|
ProjectExplorer::ProjectExplorer(turbine::Context &ctx) noexcept: m_ctx(ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorer::draw(StudioContext &ctx) noexcept {
|
void ProjectExplorer::draw(studio::StudioContext &ctx) noexcept {
|
||||||
auto const viewport = ImGui::GetContentRegionAvail();
|
auto const viewport = ImGui::GetContentRegionAvail();
|
||||||
ImGui::BeginChild("ProjectExplorer", ImVec2(300, viewport.y), true);
|
ImGui::BeginChild("ProjectExplorer", ImVec2(300, viewport.y), true);
|
||||||
ImGui::SetNextItemOpen(true);
|
ImGui::SetNextItemOpen(true);
|
||||||
if (m_treeModel) {
|
if (m_treeModel) {
|
||||||
if (m_treeModel->draw(ctx.tctx)) {
|
m_treeModel->draw(ctx.tctx);
|
||||||
oxLogError(refreshProjectTreeModel());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
}
|
}
|
||||||
|
@ -12,28 +12,27 @@
|
|||||||
|
|
||||||
namespace studio {
|
namespace studio {
|
||||||
|
|
||||||
class ProjectExplorer: public Widget {
|
class ProjectExplorer: public studio::Widget {
|
||||||
private:
|
private:
|
||||||
ox::UPtr<ProjectTreeModel> m_treeModel;
|
ox::UPtr<ProjectTreeModel> m_treeModel;
|
||||||
turbine::Context &m_ctx;
|
turbine::Context &m_ctx;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// slots
|
|
||||||
ox::Signal<ox::Error(ox::StringView const&)> fileChosen;
|
|
||||||
|
|
||||||
explicit ProjectExplorer(turbine::Context &ctx) noexcept;
|
explicit ProjectExplorer(turbine::Context &ctx) noexcept;
|
||||||
|
|
||||||
void draw(StudioContext &ctx) noexcept override;
|
void draw(studio::StudioContext &ctx) noexcept override;
|
||||||
|
|
||||||
void setModel(ox::UPtr<ProjectTreeModel> &&model) noexcept;
|
void setModel(ox::UPtr<ProjectTreeModel> &&model) noexcept;
|
||||||
|
|
||||||
ox::Error refreshProjectTreeModel(ox::StringViewCR = {}) noexcept;
|
ox::Error refreshProjectTreeModel(ox::StringViewCR = {}) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::FileSystem *romFs() noexcept {
|
inline ox::FileSystem *romFs() noexcept {
|
||||||
return rom(m_ctx);
|
return rom(m_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// slots
|
||||||
|
public:
|
||||||
|
ox::Signal<ox::Error(ox::StringView const&)> fileChosen;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,7 @@
|
|||||||
|
|
||||||
namespace studio {
|
namespace studio {
|
||||||
|
|
||||||
ProjectTreeModel::ProjectTreeModel(
|
ProjectTreeModel::ProjectTreeModel(ProjectExplorer &explorer, ox::String name,
|
||||||
ProjectExplorer &explorer,
|
|
||||||
ox::StringParam name,
|
|
||||||
ProjectTreeModel *parent) noexcept:
|
ProjectTreeModel *parent) noexcept:
|
||||||
m_explorer(explorer),
|
m_explorer(explorer),
|
||||||
m_parent(parent),
|
m_parent(parent),
|
||||||
@ -25,13 +23,12 @@ ProjectTreeModel::ProjectTreeModel(ProjectTreeModel &&other) noexcept:
|
|||||||
m_children(std::move(other.m_children)) {
|
m_children(std::move(other.m_children)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProjectTreeModel::draw(turbine::Context &ctx) const noexcept {
|
void ProjectTreeModel::draw(turbine::Context &ctx) const noexcept {
|
||||||
bool updated = false;
|
|
||||||
constexpr auto dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
constexpr auto dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
||||||
if (!m_children.empty()) {
|
if (!m_children.empty()) {
|
||||||
if (ImGui::TreeNodeEx(m_name.c_str(), dirFlags)) {
|
if (ImGui::TreeNodeEx(m_name.c_str(), dirFlags)) {
|
||||||
for (auto const&child : m_children) {
|
for (auto const&child : m_children) {
|
||||||
updated = child->draw(ctx) || updated;
|
child->draw(ctx);
|
||||||
}
|
}
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
@ -42,16 +39,9 @@ bool ProjectTreeModel::draw(turbine::Context &ctx) const noexcept {
|
|||||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
|
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
|
||||||
m_explorer.fileChosen.emit(path);
|
m_explorer.fileChosen.emit(path);
|
||||||
}
|
}
|
||||||
if (ImGui::BeginPopupContextItem("FileMenu", ImGuiPopupFlags_MouseButtonRight)) {
|
|
||||||
if (ImGui::MenuItem("Delete")) {
|
|
||||||
updated = m_explorer.romFs()->remove(path).errCode == 0 || updated;
|
|
||||||
}
|
|
||||||
ImGui::EndPopup();
|
|
||||||
}
|
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return updated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectTreeModel::setChildren(ox::Vector<ox::UPtr<ProjectTreeModel>> children) noexcept {
|
void ProjectTreeModel::setChildren(ox::Vector<ox::UPtr<ProjectTreeModel>> children) noexcept {
|
||||||
|
@ -17,23 +17,19 @@ class ProjectTreeModel {
|
|||||||
ProjectTreeModel *m_parent = nullptr;
|
ProjectTreeModel *m_parent = nullptr;
|
||||||
ox::String m_name;
|
ox::String m_name;
|
||||||
ox::Vector<ox::UPtr<ProjectTreeModel>> m_children;
|
ox::Vector<ox::UPtr<ProjectTreeModel>> m_children;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ProjectTreeModel(
|
explicit ProjectTreeModel(class ProjectExplorer &explorer, ox::String name,
|
||||||
ProjectExplorer &explorer, ox::StringParam name,
|
|
||||||
ProjectTreeModel *parent = nullptr) noexcept;
|
ProjectTreeModel *parent = nullptr) noexcept;
|
||||||
|
|
||||||
ProjectTreeModel(ProjectTreeModel &&other) noexcept;
|
ProjectTreeModel(ProjectTreeModel &&other) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
void draw(turbine::Context &ctx) const noexcept;
|
||||||
bool draw(turbine::Context &ctx) const noexcept;
|
|
||||||
|
|
||||||
void setChildren(ox::Vector<ox::UPtr<ProjectTreeModel>> children) noexcept;
|
void setChildren(ox::Vector<ox::UPtr<ProjectTreeModel>> children) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::BasicString<255> fullPath() const noexcept;
|
ox::BasicString<255> fullPath() const noexcept;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user