Managers: redesign the VFS and adapt BackupManager.

This commit is contained in:
Guillaume Jacquemin 2024-07-13 11:00:28 +02:00
parent c0bf16144f
commit c1ad757f80
Signed by: williamjcm
SSH key fingerprint: SHA256:AYLOg+iTV0ElElnlu4vqM4edFazVdRiuQB0Y5LoKc4A
5 changed files with 38 additions and 66 deletions

View file

@ -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

View file

@ -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<const Backup>
@ -58,10 +61,10 @@ BackupManager::backups() const {
return _backups;
}
const Vfs::VirtualFileSystem<Backup>&
const Vfs::Directory<Backup>&
BackupManager::vfs() const
{
return _vfs;
return _root;
}
bool

View file

@ -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<const Backup>;
auto vfs() const -> const Vfs::VirtualFileSystem<Backup>&;
auto vfs() const -> const Vfs::Directory<Backup>&;
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<Backup> _backups;
Vfs::VirtualFileSystem<Backup> _vfs;
Vfs::Directory<Backup> _root;
};
}}

View file

@ -27,22 +27,22 @@ namespace mbst { namespace Managers { namespace Vfs {
CORRADE_HAS_TYPE(HasFilename, decltype(T::filename));
template<typename FileType>
class VfsDirectory {
class Directory {
public:
static_assert(HasFilename<FileType>::value && (std::is_same<decltype(FileType::filename), Containers::String>::value || std::is_same<decltype(FileType::filename), Containers::StringView>::value),
"FileType has no string-like member named filename.");
using DirType = VfsDirectory<FileType>;
using DirType = Directory<FileType>;
explicit VfsDirectory(Containers::StringView name): _name{name} {
explicit Directory(Containers::StringView name): _name{name} {
// ctor
}
VfsDirectory(const VfsDirectory<FileType>& other) = delete;
VfsDirectory& operator=(const VfsDirectory<FileType>& other) = delete;
Directory(const Directory<FileType>& other) = delete;
Directory& operator=(const Directory<FileType>& other) = delete;
VfsDirectory(VfsDirectory<FileType>&& other) = default;
VfsDirectory& operator=(VfsDirectory<FileType>&& other) = default;
Directory(Directory<FileType>&& other) = default;
Directory& operator=(Directory<FileType>&& other) = default;
auto name() const -> Containers::StringView {
return _name;
@ -52,12 +52,26 @@ class VfsDirectory {
return _subdirs;
}
auto files() const -> Containers::ArrayView<const FileType*> {
auto files() const -> Containers::ArrayView<FileType* const> {
return _files;
}
protected:
void buildNestedPath(VfsDirectory<FileType>& root, Containers::ArrayView<const Containers::MutableStringView> components,
void clear() {
_subdirs = Containers::Array<DirType>{};
_files = Containers::Array<FileType*>{};
}
void build(Containers::ArrayView<FileType> files) {
for(auto& file : files) {
auto components = file.filename.split('/');
CORRADE_INTERNAL_ASSERT(components.size() != 0);
buildNestedPath(*this, components, file);
}
}
private:
void buildNestedPath(Directory<FileType>& root, Containers::ArrayView<const Containers::MutableStringView> components,
FileType& file)
{
if(components.size() > 1) {

View file

@ -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 <https://www.gnu.org/licenses/>.
#include "VfsDirectory.h"
namespace mbst { namespace Managers { namespace Vfs {
template<typename FileType>
class VirtualFileSystem: public VfsDirectory<FileType> {
public:
explicit VirtualFileSystem():
VfsDirectory<FileType>("")
{
// ctor
}
explicit VirtualFileSystem(Containers::ArrayView<FileType> files):
VfsDirectory<FileType>("")
{
build(files);
}
void build(Containers::ArrayView<FileType> files) {
for(auto& file : files) {
auto components = file.filename.split('/');
CORRADE_INTERNAL_ASSERT(components.size() != 0);
VfsDirectory<FileType>::buildNestedPath(*this, components, file);
}
}
};
}}}