Resource database can now keep track of empty directories

This commit is contained in:
Aruki 2017-07-04 13:34:14 -06:00
parent 9a52fe52d4
commit 4652e125e5
3 changed files with 59 additions and 5 deletions

View File

@ -476,6 +476,21 @@ inline void SerializeContainer(IArchive& rArc, std::list<ValType>& rList, const
rArc << SERIAL_ABSTRACT(*rkElemName, rVec[iElem], pFactory); rArc << SERIAL_ABSTRACT(*rkElemName, rVec[iElem], pFactory);
} }
// Overload for TStringList and TWideStringList so they can use the TString/TWideString serialize functions
inline void SerializeContainer(IArchive& rArc, TStringList& rList, const TString& rkElemName)
{
typedef std::list<TString> ListType;
ListType& rGenericList = *reinterpret_cast<ListType*>(&rList);
SerializeContainer(rArc, rGenericList, rkElemName);
}
inline void SerializeContainer(IArchive& rArc, TWideStringList& rList, const TString& rkElemName)
{
typedef std::list<TWideString> ListType;
ListType& rGenericList = *reinterpret_cast<ListType*>(&rList);
SerializeContainer(rArc, rGenericList, rkElemName);
}
// std::set // std::set
template<typename ValType> template<typename ValType>
inline void SerializeContainer(IArchive& rArc, std::set<ValType>& rSet, const TString& rkElemName) inline void SerializeContainer(IArchive& rArc, std::set<ValType>& rSet, const TString& rkElemName)

View File

@ -46,6 +46,20 @@ CResourceStore::~CResourceStore()
delete It->second; delete It->second;
} }
void RecursiveGetListOfEmptyDirectories(CVirtualDirectory *pDir, TStringList& rOutList)
{
// Helper function for SerializeResourceDatabase
if (pDir->IsEmpty())
{
rOutList.push_back(pDir->FullPath());
}
else
{
for (u32 SubIdx = 0; SubIdx < pDir->NumSubdirectories(); SubIdx++)
RecursiveGetListOfEmptyDirectories(pDir->SubdirectoryByIndex(SubIdx), rOutList);
}
}
bool CResourceStore::SerializeResourceDatabase(IArchive& rArc) bool CResourceStore::SerializeResourceDatabase(IArchive& rArc)
{ {
struct SDatabaseResource struct SDatabaseResource
@ -71,12 +85,22 @@ bool CResourceStore::SerializeResourceDatabase(IArchive& rArc)
Resources.push_back( SDatabaseResource { It->ID(), It->TypeInfo(), It->Directory()->FullPath(), It->Name() } ); Resources.push_back( SDatabaseResource { It->ID(), It->TypeInfo(), It->Directory()->FullPath(), It->Name() } );
} }
// Populate directory list
TStringList EmptyDirectories;
if (!rArc.IsReader())
RecursiveGetListOfEmptyDirectories(mpDatabaseRoot, EmptyDirectories);
// Serialize // Serialize
rArc << SERIAL_CONTAINER_AUTO(Resources, "Resource"); rArc << SERIAL_CONTAINER_AUTO(Resources, "Resource")
<< SERIAL_CONTAINER_AUTO(EmptyDirectories, "Directory");
// Register resources // Register resources
if (rArc.IsReader()) if (rArc.IsReader())
{ {
for (auto Iter = EmptyDirectories.begin(); Iter != EmptyDirectories.end(); Iter++)
CreateVirtualDirectory(*Iter);
for (auto Iter = Resources.begin(); Iter != Resources.end(); Iter++) for (auto Iter = Resources.begin(); Iter != Resources.end(); Iter++)
{ {
SDatabaseResource& rRes = *Iter; SDatabaseResource& rRes = *Iter;
@ -295,6 +319,12 @@ CVirtualDirectory* CResourceStore::GetVirtualDirectory(const TString& rkPath, bo
return nullptr; return nullptr;
} }
void CResourceStore::CreateVirtualDirectory(const TString& rkPath)
{
if (!rkPath.IsEmpty())
mpDatabaseRoot->FindChildDirectory(rkPath, true);
}
void CResourceStore::ConditionalDeleteDirectory(CVirtualDirectory *pDir, bool Recurse) void CResourceStore::ConditionalDeleteDirectory(CVirtualDirectory *pDir, bool Recurse)
{ {
if (pDir->IsEmpty() && !pDir->IsRoot()) if (pDir->IsEmpty() && !pDir->IsRoot())
@ -351,11 +381,10 @@ void CResourceStore::ClearDatabase()
mCacheFileDirty = true; mCacheFileDirty = true;
} }
void CResourceStore::RebuildFromDirectory() void CResourceStore::BuildFromDirectory()
{ {
ASSERT(mpProj != nullptr); ASSERT(mpProj != nullptr);
mpProj->AudioManager()->ClearAssets(); ASSERT(mResourceEntries.empty());
ClearDatabase();
// Get list of resources // Get list of resources
TString ResDir = ResourcesDir(); TString ResDir = ResourcesDir();
@ -398,8 +427,16 @@ void CResourceStore::RebuildFromDirectory()
} }
else if (FileUtil::IsDirectory(Path)) else if (FileUtil::IsDirectory(Path))
GetVirtualDirectory(RelPath, true); CreateVirtualDirectory(RelPath);
} }
}
void CResourceStore::RebuildFromDirectory()
{
ASSERT(mpProj != nullptr);
mpProj->AudioManager()->ClearAssets();
ClearDatabase();
BuildFromDirectory();
// Make sure audio manager is loaded correctly so AGSC dependencies can be looked up // Make sure audio manager is loaded correctly so AGSC dependencies can be looked up
mpProj->AudioManager()->LoadAssets(); mpProj->AudioManager()->LoadAssets();

View File

@ -52,6 +52,7 @@ public:
void SetProject(CGameProject *pProj); void SetProject(CGameProject *pProj);
void CloseProject(); void CloseProject();
CVirtualDirectory* GetVirtualDirectory(const TString& rkPath, bool AllowCreate); CVirtualDirectory* GetVirtualDirectory(const TString& rkPath, bool AllowCreate);
void CreateVirtualDirectory(const TString& rkPath);
void ConditionalDeleteDirectory(CVirtualDirectory *pDir, bool Recurse); void ConditionalDeleteDirectory(CVirtualDirectory *pDir, bool Recurse);
bool IsResourceRegistered(const CAssetID& rkID) const; bool IsResourceRegistered(const CAssetID& rkID) const;
@ -60,6 +61,7 @@ public:
CResourceEntry* FindEntry(const TString& rkPath) const; CResourceEntry* FindEntry(const TString& rkPath) const;
bool AreAllEntriesValid() const; bool AreAllEntriesValid() const;
void ClearDatabase(); void ClearDatabase();
void BuildFromDirectory();
void RebuildFromDirectory(); void RebuildFromDirectory();
template<typename ResType> ResType* LoadResource(const CAssetID& rkID) { return static_cast<ResType*>(LoadResource(rkID, ResType::StaticType())); } template<typename ResType> ResType* LoadResource(const CAssetID& rkID) { return static_cast<ResType*>(LoadResource(rkID, ResType::StaticType())); }