diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7998333..6340051 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -199,8 +199,7 @@ add_executable(MassBuilderSaveTool Managers/MassManager.cpp Managers/ProfileManager.h Managers/ProfileManager.cpp - Managers/Vfs/VirtualFileSystem.h - Managers/Vfs/VfsDirectory.h + Managers/Vfs/Directory.h Maps/ArmourSlots.hpp Maps/BulletLauncherAttachmentStyles.hpp Maps/BulletLauncherSockets.hpp diff --git a/src/Managers/BackupManager.cpp b/src/Managers/BackupManager.cpp index b41586e..6d7a5b2 100644 --- a/src/Managers/BackupManager.cpp +++ b/src/Managers/BackupManager.cpp @@ -35,7 +35,9 @@ namespace mbst { namespace Managers { -BackupManager::BackupManager() { +BackupManager::BackupManager(): + _root{""} +{ refresh(); } @@ -50,7 +52,8 @@ BackupManager::refresh() { scanSubdir(""_s); - _vfs.build(_backups); + _root.clear(); + _root.build(_backups); } Containers::ArrayView @@ -58,10 +61,10 @@ BackupManager::backups() const { return _backups; } -const Vfs::VirtualFileSystem& +const Vfs::Directory& BackupManager::vfs() const { - return _vfs; + return _root; } bool diff --git a/src/Managers/BackupManager.h b/src/Managers/BackupManager.h index 938f88e..cc7678f 100644 --- a/src/Managers/BackupManager.h +++ b/src/Managers/BackupManager.h @@ -25,7 +25,7 @@ #include "Backup.h" #include "../GameObjects/Profile.h" -#include "Vfs/VirtualFileSystem.h" +#include "Vfs/Directory.h" using namespace Corrade; @@ -41,10 +41,13 @@ class BackupManager { auto backups() const -> Containers::ArrayView; - auto vfs() const -> const Vfs::VirtualFileSystem&; + auto vfs() const -> const Vfs::Directory&; bool create(const GameObjects::Profile& profile); + bool remove(std::size_t index); + bool remove(Containers::StringView filename); + bool restore(std::size_t index); private: @@ -54,7 +57,7 @@ class BackupManager { Containers::Array _backups; - Vfs::VirtualFileSystem _vfs; + Vfs::Directory _root; }; }} diff --git a/src/Managers/Vfs/VfsDirectory.h b/src/Managers/Vfs/Directory.h similarity index 70% rename from src/Managers/Vfs/VfsDirectory.h rename to src/Managers/Vfs/Directory.h index e0c203f..5fd600f 100644 --- a/src/Managers/Vfs/VfsDirectory.h +++ b/src/Managers/Vfs/Directory.h @@ -27,22 +27,22 @@ namespace mbst { namespace Managers { namespace Vfs { CORRADE_HAS_TYPE(HasFilename, decltype(T::filename)); template -class VfsDirectory { +class Directory { public: static_assert(HasFilename::value && (std::is_same::value || std::is_same::value), "FileType has no string-like member named filename."); - using DirType = VfsDirectory; + using DirType = Directory; - explicit VfsDirectory(Containers::StringView name): _name{name} { + explicit Directory(Containers::StringView name): _name{name} { // ctor } - VfsDirectory(const VfsDirectory& other) = delete; - VfsDirectory& operator=(const VfsDirectory& other) = delete; + Directory(const Directory& other) = delete; + Directory& operator=(const Directory& other) = delete; - VfsDirectory(VfsDirectory&& other) = default; - VfsDirectory& operator=(VfsDirectory&& other) = default; + Directory(Directory&& other) = default; + Directory& operator=(Directory&& other) = default; auto name() const -> Containers::StringView { return _name; @@ -52,12 +52,26 @@ class VfsDirectory { return _subdirs; } - auto files() const -> Containers::ArrayView { + auto files() const -> Containers::ArrayView { return _files; } - protected: - void buildNestedPath(VfsDirectory& root, Containers::ArrayView components, + void clear() { + _subdirs = Containers::Array{}; + _files = Containers::Array{}; + } + + void build(Containers::ArrayView files) { + for(auto& file : files) { + auto components = file.filename.split('/'); + CORRADE_INTERNAL_ASSERT(components.size() != 0); + + buildNestedPath(*this, components, file); + } + } + + private: + void buildNestedPath(Directory& root, Containers::ArrayView components, FileType& file) { if(components.size() > 1) { diff --git a/src/Managers/Vfs/VirtualFileSystem.h b/src/Managers/Vfs/VirtualFileSystem.h deleted file mode 100644 index a9e227e..0000000 --- a/src/Managers/Vfs/VirtualFileSystem.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -// MassBuilderSaveTool -// Copyright (C) 2021-2024 Guillaume Jacquemin -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#include "VfsDirectory.h" - -namespace mbst { namespace Managers { namespace Vfs { - -template -class VirtualFileSystem: public VfsDirectory { - public: - explicit VirtualFileSystem(): - VfsDirectory("") - { - // ctor - } - explicit VirtualFileSystem(Containers::ArrayView files): - VfsDirectory("") - { - build(files); - } - - void build(Containers::ArrayView files) { - for(auto& file : files) { - auto components = file.filename.split('/'); - CORRADE_INTERNAL_ASSERT(components.size() != 0); - - VfsDirectory::buildNestedPath(*this, components, file); - } - } -}; - -}}}