Function to call to refresh asset directory

This commit is contained in:
Xiao Qi 2022-11-10 17:09:55 +08:00
parent 0e5609995f
commit 03f9c593b6
4 changed files with 35 additions and 7 deletions

View File

@ -373,6 +373,13 @@ namespace SHADE
return folderRoot;
}
void SHAssetManager::RefreshDirectory() noexcept
{
SHFileSystem::DestroyDirectory(folderRoot);
assetCollection.clear();
BuildAssetCollection();
}
bool SHAssetManager::IsRecognised(char const* ext) noexcept
{
for (auto const& e : EXTENSIONS)

View File

@ -90,6 +90,7 @@ namespace SHADE
static void CompileAsset(AssetPath const& path, bool genMeta) noexcept;
static FolderPointer GetRootFolder() noexcept;
static void RefreshDirectory() noexcept;
private:

View File

@ -12,6 +12,7 @@
#include "SHFileSystem.h"
#include <filesystem>
#include <queue>
#include <stack>
#include "Assets/SHAssetMetaHandler.h"
@ -39,15 +40,15 @@ namespace SHADE
void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept
{
std::queue<FolderPointer> folderQueue;
std::stack<FolderPointer> folderStack;
root = new SHFolder("root");
root->path = path;
folderQueue.push(root);
folderStack.push(root);
while (!folderQueue.empty())
while (!folderStack.empty())
{
auto const folder = folderQueue.front();
folderQueue.pop();
auto const folder = folderStack.top();
folderStack.pop();
std::vector<SHAsset> assets;
@ -77,7 +78,7 @@ namespace SHADE
}
auto newFolder{ folder->CreateSubFolderHere(path.stem().string()) };
folderQueue.push(newFolder);
folderStack.push(newFolder);
}
for (auto const& asset : assets)
@ -98,4 +99,23 @@ namespace SHADE
}
}
}
void SHFileSystem::DestroyDirectory(FolderPointer root) noexcept
{
std::stack<FolderPointer> folderStack;
folderStack.push(root);
while(!folderStack.empty())
{
auto const folder = folderStack.top();
folderStack.pop();
for (auto const& ptr : folder->subFolders)
{
folderStack.push(ptr);
}
delete folder;
}
}
}

View File

@ -20,7 +20,7 @@ namespace SHADE
{
public:
static void BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map<AssetID, SHAsset>& assetCollection) noexcept;
static void DestroyDirectory(FolderPointer root) noexcept;
private:
static bool DeleteFolder(FolderPointer location) noexcept;
static bool IsCompilable(std::string ext) noexcept;