Filesystem rework to go through asset folder, build directory and populate folders with files
This commit is contained in:
parent
f5060ba0b0
commit
6f20b98ce1
|
@ -0,0 +1,31 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHFileSystemDefines.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date October 2022
|
||||
* \brief
|
||||
*
|
||||
* Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SHFolder;
|
||||
|
||||
typedef unsigned char FolderCounter;
|
||||
typedef unsigned char FileCounter;
|
||||
typedef uint64_t FolderLocation;
|
||||
typedef uint64_t FolderHandle;
|
||||
typedef std::string FolderName;
|
||||
typedef std::string FileName;
|
||||
typedef std::string FolderPath;
|
||||
typedef std::string FilePath;
|
||||
typedef std::string FileExt;
|
||||
typedef SHFolder* FolderPointer;
|
||||
|
||||
constexpr char FOLDER_BIT_ALLOCATE{ 4 };
|
||||
constexpr char FOLDER_MAX_DEPTH{ 16 };
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHFileSystem.h"
|
||||
#include "SHFileSystemLibrary.h"
|
||||
#include "fileapi.h"
|
||||
#include <filesystem>
|
||||
#include <queue>
|
||||
|
@ -8,15 +8,16 @@ namespace SHADE
|
|||
{
|
||||
char const FOLDER_MAX_COUNT {15};
|
||||
|
||||
std::unordered_map<FolderLocation, std::unique_ptr<SHFolder>> SHFileSystem::folders;
|
||||
FolderPointer SHFileSystem::root {nullptr};
|
||||
std::unordered_map<FolderLocation, std::unique_ptr<SHFolder>> SHFileSystemLibrary::folders;
|
||||
std::vector<SHFile> SHFileSystemLibrary::files;
|
||||
FolderPointer SHFileSystemLibrary::root {nullptr};
|
||||
|
||||
SHFolder::SHFolder(FolderHandle id, FolderName name)
|
||||
:id{ id }, name{ name }, subFolders(0), folded{ false }, path{""}
|
||||
{
|
||||
}
|
||||
|
||||
FolderLocation SHFileSystem::CreateNewFolderHere(FolderName name, FolderLocation here) noexcept
|
||||
FolderLocation SHFileSystemLibrary::CreateNewFolderHere(FolderName name, FolderLocation here) noexcept
|
||||
{
|
||||
if (here == 0)
|
||||
{
|
||||
|
@ -60,7 +61,7 @@ namespace SHADE
|
|||
return location;
|
||||
}
|
||||
|
||||
bool SHFileSystem::DeleteFolder(FolderPointer location) noexcept
|
||||
bool SHFileSystemLibrary::DeleteFolder(FolderPointer location) noexcept
|
||||
{
|
||||
if (!folders.contains(location->id))
|
||||
{
|
||||
|
@ -76,11 +77,12 @@ namespace SHADE
|
|||
return true;
|
||||
}
|
||||
|
||||
void SHFileSystem::StartupFillDirectories(FolderPath path) noexcept
|
||||
void SHFileSystemLibrary::BuildDirectory(FolderPath path) noexcept
|
||||
{
|
||||
std::queue<FolderPointer> folderQueue;
|
||||
|
||||
folderQueue.push(RegisterFolder(path, 0, 0, "Root"));
|
||||
folderQueue.push(RegisterFolder(path, 0, "Root"));
|
||||
root = folderQueue.front();
|
||||
|
||||
while (!folderQueue.empty())
|
||||
{
|
||||
|
@ -92,41 +94,36 @@ namespace SHADE
|
|||
{
|
||||
if (!dirEntry.is_directory())
|
||||
{
|
||||
folder->files.emplace_back(
|
||||
dirEntry.path().filename().string(),
|
||||
dirEntry.path().string(),
|
||||
dirEntry.path().extension().string()
|
||||
);
|
||||
SHFile newFile {
|
||||
dirEntry.path().stem().string(),
|
||||
dirEntry.path().extension().string(),
|
||||
dirEntry.path().string()
|
||||
};
|
||||
|
||||
continue;
|
||||
files.push_back(newFile);
|
||||
folder->files.push_back(&(files.back()));
|
||||
}
|
||||
else
|
||||
{
|
||||
FolderLocation location = folder->id;
|
||||
location <<= FOLDER_BIT_ALLOCATE;
|
||||
location |= ++count;
|
||||
|
||||
FolderLocation location = folder->id;
|
||||
location <<= FOLDER_BIT_ALLOCATE;
|
||||
location |= ++count;
|
||||
std::string name = dirEntry.path().stem().string();
|
||||
FolderPointer newFolder{ RegisterFolder(
|
||||
dirEntry.path().string(),
|
||||
location,
|
||||
name)
|
||||
};
|
||||
|
||||
std::string name = dirEntry.path().string();
|
||||
name = name.substr(name.find_last_of('/') + 1, name.length() - name.find_last_of('/'));
|
||||
|
||||
FolderPointer newFolder{ RegisterFolder(
|
||||
dirEntry.path().string(),
|
||||
folder->id,
|
||||
location,
|
||||
name)
|
||||
};
|
||||
|
||||
folderQueue.push(newFolder);
|
||||
folder->subFolders.push_back(newFolder);
|
||||
folderQueue.push(newFolder);
|
||||
folder->subFolders.push_back(newFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FolderPointer SHFileSystem::GetRoot() noexcept
|
||||
{
|
||||
return root;
|
||||
}
|
||||
|
||||
FolderPointer SHFileSystem::CreateFolder(FolderPath path, FolderLocation parent, FolderHandle location, FolderName name) noexcept
|
||||
FolderPointer SHFileSystemLibrary::CreateFolder(FolderPath path, FolderLocation parent, FolderHandle location, FolderName name) noexcept
|
||||
{
|
||||
|
||||
if (!CreateDirectoryA(path.c_str(), nullptr))
|
||||
|
@ -138,21 +135,20 @@ namespace SHADE
|
|||
folders[location]->path = path;
|
||||
folders[parent]->subFolders.push_back(folders[location].get());
|
||||
|
||||
return FolderMakeHelper(path, parent, location, name);
|
||||
return FolderMakeHelper(path, location, name);
|
||||
}
|
||||
|
||||
FolderPointer SHFileSystem::RegisterFolder(FolderPath path, FolderLocation parent, FolderHandle location,
|
||||
FolderPointer SHFileSystemLibrary::RegisterFolder(FolderPath path, FolderHandle location,
|
||||
FolderName name) noexcept
|
||||
{
|
||||
return FolderMakeHelper(path, parent, location, name);
|
||||
return FolderMakeHelper(path, location, name);
|
||||
}
|
||||
|
||||
FolderPointer SHFileSystem::FolderMakeHelper(FolderPath path, FolderLocation parent, FolderHandle location,
|
||||
FolderPointer SHFileSystemLibrary::FolderMakeHelper(FolderPath path, FolderHandle location,
|
||||
FolderName name) noexcept
|
||||
{
|
||||
folders[location] = std::make_unique<SHFolder>(location, name);
|
||||
folders[location]->path = path;
|
||||
folders[parent]->subFolders.push_back(folders[location].get());
|
||||
|
||||
return folders[location].get();
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
#pragma once
|
||||
|
||||
#include "SHFileSystemDefines.h"
|
||||
#include "Assets/SHAssetMacros.h"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
struct SHFile
|
||||
{
|
||||
FileName name;
|
||||
FileExt ext;
|
||||
FilePath path;
|
||||
|
||||
AssetID assetRef;
|
||||
};
|
||||
|
||||
class SHFolder
|
||||
{
|
||||
public:
|
||||
SHFolder(FolderHandle id, FolderName name);
|
||||
|
||||
FolderHandle id;
|
||||
FolderName name;
|
||||
std::vector<FolderPointer> subFolders;
|
||||
std::vector<SHFile const*> files;
|
||||
|
||||
bool folded;
|
||||
|
||||
private:
|
||||
FolderPath path;
|
||||
friend class SHFileSystemLibrary;
|
||||
};
|
||||
|
||||
class SHFileSystemLibrary
|
||||
{
|
||||
public:
|
||||
static FolderLocation CreateNewFolderHere(FolderName name, FolderLocation here = 0) noexcept;
|
||||
|
||||
static bool DeleteFolder(FolderPointer location) noexcept;
|
||||
|
||||
static void BuildDirectory(FolderPath path) noexcept;
|
||||
|
||||
static FolderPointer root;
|
||||
static std::unordered_map<FolderLocation, std::unique_ptr<SHFolder>> folders;
|
||||
static std::vector<SHFile> files;
|
||||
|
||||
private:
|
||||
|
||||
static FolderPointer CreateFolder(FolderPath path, FolderLocation parent, FolderHandle location, FolderName name) noexcept;
|
||||
static FolderPointer RegisterFolder(FolderPath path, FolderHandle location, FolderName name) noexcept;
|
||||
static FolderPointer FolderMakeHelper(FolderPath path, FolderHandle location, FolderName name) noexcept;
|
||||
};
|
||||
}
|
|
@ -11,7 +11,6 @@
|
|||
*****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Filesystem/SHFileSystem.h"
|
||||
#include "SHAssetMacros.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -22,6 +21,5 @@ namespace SHADE
|
|||
AssetID id;
|
||||
AssetType type;
|
||||
AssetPath path;
|
||||
FolderLocation location;
|
||||
};
|
||||
}
|
|
@ -12,7 +12,7 @@
|
|||
#include <chrono>
|
||||
#include "SHAssetManager.h"
|
||||
#include "SHAssetMetaHandler.h"
|
||||
#include "Filesystem/SHFileSystem.h"
|
||||
#include "Libraries/Filesystem/SHFileSystemLibrary.h"
|
||||
|
||||
#include "Libraries/SHMeshLoader.h"
|
||||
#include "Libraries/SHTextureLoader.h"
|
||||
|
@ -213,8 +213,7 @@ namespace SHADE
|
|||
.name {path.filename().string()},
|
||||
.id {0},
|
||||
.type {AssetType::MESH},
|
||||
.path {path},
|
||||
.location {0}
|
||||
.path {path}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -226,8 +225,7 @@ namespace SHADE
|
|||
.name {path.filename().string()},
|
||||
.id {0},
|
||||
.type {AssetType::DDS},
|
||||
.path {path},
|
||||
.location {0}
|
||||
.path {path}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -340,8 +338,7 @@ namespace SHADE
|
|||
mesh.header.meshName,
|
||||
id,
|
||||
AssetType::MESH,
|
||||
path,
|
||||
0
|
||||
path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -363,8 +360,7 @@ namespace SHADE
|
|||
image.name,
|
||||
id,
|
||||
AssetType::TEXTURE,
|
||||
path,
|
||||
0
|
||||
path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -376,6 +372,13 @@ namespace SHADE
|
|||
{
|
||||
RetrieveAssets();
|
||||
LoadAllData();
|
||||
SHFileSystemLibrary::BuildDirectory(ASSET_ROOT);
|
||||
auto const& root {SHFileSystemLibrary::root};
|
||||
|
||||
for (auto const& file : root->files)
|
||||
{
|
||||
SHLOG_INFO("{}", file->name);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SHFolder;
|
||||
|
||||
typedef unsigned char FolderCounter;
|
||||
typedef unsigned char FileCounter;
|
||||
typedef uint64_t FolderLocation;
|
||||
typedef uint64_t FolderHandle;
|
||||
typedef std::string FolderName;
|
||||
typedef std::string FileName;
|
||||
typedef std::string FolderPath;
|
||||
typedef std::string FilePath;
|
||||
typedef std::string FileExt;
|
||||
typedef SHFolder* FolderPointer;
|
||||
|
||||
constexpr char FOLDER_BIT_ALLOCATE{ 4 };
|
||||
constexpr char FOLDER_MAX_DEPTH{ 16 };
|
||||
|
||||
struct SHFile
|
||||
{
|
||||
FileName name;
|
||||
FilePath path;
|
||||
FileExt ext;
|
||||
};
|
||||
|
||||
class SHFolder
|
||||
{
|
||||
public:
|
||||
SHFolder(FolderHandle id, FolderName name);
|
||||
|
||||
FolderHandle id;
|
||||
FolderName name;
|
||||
std::vector<FolderPointer> subFolders;
|
||||
std::vector<SHFile> files;
|
||||
|
||||
bool folded;
|
||||
|
||||
private:
|
||||
FolderPath path;
|
||||
friend class SHFileSystem;
|
||||
};
|
||||
|
||||
class SHFileSystem
|
||||
{
|
||||
public:
|
||||
static FolderLocation CreateNewFolderHere(FolderName name, FolderLocation here = 0) noexcept;
|
||||
|
||||
static bool DeleteFolder(FolderPointer location) noexcept;
|
||||
|
||||
static void StartupFillDirectories(FolderPath path) noexcept;
|
||||
|
||||
static FolderPointer GetRoot() noexcept;
|
||||
|
||||
private:
|
||||
static FolderPointer root;
|
||||
|
||||
static std::unordered_map<FolderLocation, std::unique_ptr<SHFolder>> folders;
|
||||
|
||||
static FolderPointer CreateFolder(FolderPath path, FolderLocation parent, FolderHandle location, FolderName name) noexcept;
|
||||
static FolderPointer RegisterFolder(FolderPath path, FolderLocation parent, FolderHandle location, FolderName name) noexcept;
|
||||
static FolderPointer FolderMakeHelper(FolderPath path, FolderLocation parent, FolderHandle location, FolderName name) noexcept;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue