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