Filesystem builds directory tree of asset folder to show all files and subfolders
This commit is contained in:
commit
ffc55c5e0c
|
@ -11,7 +11,6 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Filesystem/SHFileSystem.h"
|
|
||||||
#include "Assets/SHAssetMacros.h"
|
#include "Assets/SHAssetMacros.h"
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,11 @@ constexpr size_t TYPE_COUNT{ static_cast<size_t>(AssetType::MAX_COUNT) };
|
||||||
|
|
||||||
//Directory
|
//Directory
|
||||||
#ifdef _PUBLISH
|
#ifdef _PUBLISH
|
||||||
constexpr std::string_view ASSET_ROOT {"Assets"};
|
constexpr std::string_view ASSET_ROOT{ "Assets" };
|
||||||
|
constexpr std::string_view BUILT_IN_ASSET_ROOT {"Built_In"};
|
||||||
#else
|
#else
|
||||||
constexpr std::string_view ASSET_ROOT {"../../Assets"};
|
constexpr std::string_view ASSET_ROOT {"../../Assets"};
|
||||||
|
constexpr std::string_view BUILT_IN_ASSET_ROOT{ "../../Built_In" };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// INTERNAL ASSET PATHS
|
// INTERNAL ASSET PATHS
|
||||||
|
|
|
@ -23,8 +23,12 @@
|
||||||
#include "Libraries/Compilers/SHTextureCompiler.h"
|
#include "Libraries/Compilers/SHTextureCompiler.h"
|
||||||
#include "Libraries/Compilers/SHShaderSourceCompiler.h"
|
#include "Libraries/Compilers/SHShaderSourceCompiler.h"
|
||||||
|
|
||||||
|
#include "Filesystem/SHFileSystem.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
FolderPointer SHAssetManager::folderRoot{ nullptr };
|
||||||
|
|
||||||
FMOD::System* SHAssetManager::audioSystem;
|
FMOD::System* SHAssetManager::audioSystem;
|
||||||
std::unordered_map<AssetID, SHSound >* SHAssetManager::audioSoundList;
|
std::unordered_map<AssetID, SHSound >* SHAssetManager::audioSoundList;
|
||||||
|
|
||||||
|
@ -318,7 +322,7 @@ namespace SHADE
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetID SHAssetManager::CompileAsset(AssetPath path) noexcept
|
AssetID SHAssetManager::CompileAsset(AssetPath const& path) noexcept
|
||||||
{
|
{
|
||||||
SHAsset newAsset
|
SHAsset newAsset
|
||||||
{
|
{
|
||||||
|
@ -450,8 +454,8 @@ namespace SHADE
|
||||||
void SHAssetManager::Load() noexcept
|
void SHAssetManager::Load() noexcept
|
||||||
{
|
{
|
||||||
//CompileAll();
|
//CompileAll();
|
||||||
|
BuildAssetCollection();
|
||||||
InitLoaders();
|
InitLoaders();
|
||||||
BuildAssetCollection();
|
|
||||||
//LoadAllData();
|
//LoadAllData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,18 +487,8 @@ namespace SHADE
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAssetManager::BuildAssetCollection() noexcept
|
void SHAssetManager::BuildAssetCollection() noexcept
|
||||||
{
|
{
|
||||||
for (auto const& dir : std::filesystem::recursive_directory_iterator{ASSET_ROOT})
|
SHFileSystem::BuildDirectory(ASSET_ROOT.data(), folderRoot, assetCollection);
|
||||||
{
|
}
|
||||||
if (dir.is_regular_file())
|
|
||||||
{
|
|
||||||
if (dir.path().extension().string() == META_EXTENSION.data())
|
|
||||||
{
|
|
||||||
auto asset = SHAssetMetaHandler::RetrieveMetaData(dir.path());
|
|
||||||
assetCollection.insert({ asset.id, asset });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "tinyddsloader.h"
|
#include "tinyddsloader.h"
|
||||||
|
|
||||||
#include "SHAsset.h"
|
#include "SHAsset.h"
|
||||||
#include "Asset Types/SHAssetData.h"
|
#include "Asset Types/SHAssetData.h"
|
||||||
#include "Assets/Libraries/Loaders/SHAssetLoader.h"
|
#include "Assets/Libraries/Loaders/SHAssetLoader.h"
|
||||||
#include "Filesystem/SHFileSystem.h"
|
|
||||||
|
#include "Filesystem/SHFolder.h"
|
||||||
|
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
|
|
||||||
|
@ -85,7 +87,7 @@ namespace SHADE
|
||||||
static std::vector<SHAssetData const*> GetAllDataOfType(AssetType type) noexcept;
|
static std::vector<SHAssetData const*> GetAllDataOfType(AssetType type) noexcept;
|
||||||
static std::vector<SHAsset> GetAllRecordOfType(AssetType type) noexcept;
|
static std::vector<SHAsset> GetAllRecordOfType(AssetType type) noexcept;
|
||||||
|
|
||||||
static AssetID CompileAsset(AssetPath path) noexcept;
|
static AssetID CompileAsset(AssetPath const& path) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -105,6 +107,8 @@ namespace SHADE
|
||||||
//TODO use this function to create asset data internall at all calls to generate id
|
//TODO use this function to create asset data internall at all calls to generate id
|
||||||
//static AssetID CreateAsset(AssetName name, AssetType type) noexcept;
|
//static AssetID CreateAsset(AssetName name, AssetType type) noexcept;
|
||||||
|
|
||||||
|
static FolderPointer folderRoot;
|
||||||
|
|
||||||
static FMOD::System* audioSystem;
|
static FMOD::System* audioSystem;
|
||||||
static std::unordered_map<AssetID,SHSound>* audioSoundList;
|
static std::unordered_map<AssetID,SHSound>* audioSoundList;
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,22 @@
|
||||||
|
/*************************************************************************//**
|
||||||
|
* \file SHFileSystem.cpp
|
||||||
|
* \author Loh Xiao Qi
|
||||||
|
* \date 30 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.
|
||||||
|
*****************************************************************************/
|
||||||
#include "SHpch.h"
|
#include "SHpch.h"
|
||||||
#include "SHFileSystem.h"
|
#include "SHFileSystem.h"
|
||||||
#include "fileapi.h"
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
|
#include "Assets/SHAssetMetaHandler.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
SHFolder::SHFolder(FolderName name)
|
|
||||||
:name{ name }, subFolders(0), folded{ false }, path{""}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
FolderPointer SHFileSystem::CreateNewFolderHere(FolderPointer parent, FolderName name) noexcept
|
|
||||||
{
|
|
||||||
for (auto const& folder : parent->subFolders)
|
|
||||||
{
|
|
||||||
if (name == folder->name)
|
|
||||||
{
|
|
||||||
SHLOG_ERROR("Unable to create subfolder {} at {} as it already exists", name, folder->name);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto result = new SHFolder(name);
|
|
||||||
parent->subFolders.push_back(result);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SHFileSystem::DeleteFolder(FolderPointer location) noexcept
|
bool SHFileSystem::DeleteFolder(FolderPointer location) noexcept
|
||||||
{
|
{
|
||||||
|
@ -34,40 +24,59 @@ namespace SHADE
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FolderPointer SHFileSystem::BuildDirectory(FolderPath path) noexcept
|
void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept
|
||||||
{
|
{
|
||||||
std::queue<FolderPointer> folderQueue;
|
std::queue<FolderPointer> folderQueue;
|
||||||
auto result = new SHFolder("root");
|
root = new SHFolder("root");
|
||||||
folderQueue.push(result);
|
root->path = path;
|
||||||
|
folderQueue.push(root);
|
||||||
|
|
||||||
while (!folderQueue.empty())
|
while (!folderQueue.empty())
|
||||||
{
|
{
|
||||||
auto folder = folderQueue.front();
|
auto const folder = folderQueue.front();
|
||||||
folderQueue.pop();
|
folderQueue.pop();
|
||||||
FolderCounter count = 0;
|
|
||||||
|
std::vector<SHAsset> assets;
|
||||||
|
|
||||||
for (auto const& dirEntry : std::filesystem::directory_iterator(folder->path))
|
for (auto const& dirEntry : std::filesystem::directory_iterator(folder->path))
|
||||||
{
|
{
|
||||||
|
auto const& path = dirEntry.path();
|
||||||
if (!dirEntry.is_directory())
|
if (!dirEntry.is_directory())
|
||||||
{
|
{
|
||||||
folder->files.emplace_back(
|
if (path.extension().string() == META_EXTENSION)
|
||||||
dirEntry.path().filename().string(),
|
{
|
||||||
dirEntry.path().string(),
|
//auto asset = SHAssetMetaHandler::RetrieveMetaData(path);
|
||||||
dirEntry.path().extension().string()
|
//assetCollection.insert({ asset.id, asset });
|
||||||
);
|
assets.push_back(SHAssetMetaHandler::RetrieveMetaData(path));
|
||||||
|
}
|
||||||
continue;
|
else
|
||||||
|
{
|
||||||
|
folder->files.emplace_back(
|
||||||
|
path.stem().string(),
|
||||||
|
path.string(),
|
||||||
|
path.extension().string(),
|
||||||
|
nullptr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name = dirEntry.path().stem().string();
|
auto newFolder{ folder->CreateSubFolderHere(path.stem().string()) };
|
||||||
|
folderQueue.push(newFolder);
|
||||||
FolderPointer newFolder{ new SHFolder(name) };
|
|
||||||
|
|
||||||
folderQueue.push(newFolder);
|
|
||||||
folder->subFolders.push_back(newFolder);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
for (auto const& asset : assets)
|
||||||
|
{
|
||||||
|
assetCollection.emplace(asset.id, asset);
|
||||||
|
for(auto& file : folder->files)
|
||||||
|
{
|
||||||
|
if (file.name == asset.name)
|
||||||
|
{
|
||||||
|
file.assetMeta = &assetCollection[asset.id];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SHFolder.h"
|
#include "SHFolder.h"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -18,12 +19,10 @@ namespace SHADE
|
||||||
class SHFileSystem
|
class SHFileSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static FolderPointer BuildDirectory(FolderPath path) noexcept;
|
static void BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static FolderPointer CreateNewFolderHere(FolderPointer parent, FolderName name) noexcept;
|
|
||||||
static bool DeleteFolder(FolderPointer location) noexcept;
|
static bool DeleteFolder(FolderPointer location) noexcept;
|
||||||
|
|
||||||
friend class SHFolder;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*************************************************************************//**
|
||||||
|
* \file SHFolder.cpp
|
||||||
|
* \author Loh Xiao Qi
|
||||||
|
* \date 30 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHFolder.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
SHFolder::SHFolder(FolderName name)
|
||||||
|
:name{ name }, subFolders(0), folded{ false }, path{ "" }
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FolderPointer SHFolder::CreateSubFolderHere(FolderName name)
|
||||||
|
{
|
||||||
|
for (auto const& folder : subFolders)
|
||||||
|
{
|
||||||
|
if (name == folder->name)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Unable to create subfolder {} at {} as it already exists", name, folder->name);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto result = new SHFolder(name);
|
||||||
|
result->path = path + "/" + name;
|
||||||
|
subFolders.push_back(result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Assets/SHAssetMacros.h"
|
#include "Assets/SHAsset.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -27,15 +27,12 @@ namespace SHADE
|
||||||
typedef std::string FileExt;
|
typedef std::string FileExt;
|
||||||
typedef SHFolder* FolderPointer;
|
typedef SHFolder* FolderPointer;
|
||||||
|
|
||||||
// Forward Declare
|
|
||||||
class SHFileSystem;
|
|
||||||
|
|
||||||
struct SHFile
|
struct SHFile
|
||||||
{
|
{
|
||||||
FileName name;
|
FileName name;
|
||||||
FilePath path;
|
FilePath path;
|
||||||
FileExt ext;
|
FileExt ext;
|
||||||
|
SHAsset const* assetMeta;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SHFolder
|
class SHFolder
|
||||||
|
@ -50,9 +47,6 @@ namespace SHADE
|
||||||
bool folded;
|
bool folded;
|
||||||
|
|
||||||
FolderPointer CreateSubFolderHere(FolderName name);
|
FolderPointer CreateSubFolderHere(FolderName name);
|
||||||
|
|
||||||
private:
|
|
||||||
FolderPath path;
|
FolderPath path;
|
||||||
friend class SHFileSystem;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue