AnnResourceManager.cpp
Go to the documentation of this file.
1 // This is an open source non-commercial project. Dear PVS-Studio, please check it.
2 // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3 
4 #include "AnnResourceManager.hpp"
5 #include "AnnLogger.hpp"
6 #include <OgreConfigFile.h>
7 
8 using namespace Annwvyn;
9 
11  AnnSubSystem("ResourceManager"),
12  ResourceGroupManager{ Ogre::ResourceGroupManager::getSingletonPtr() }
13 {
14  ResourceGroupManager->createResourceGroup(getDefaultResourceGroupName());
15  addDefaultResourceLocation();
16 }
17 
18 void AnnResourceManager::addZipLocation(const std::string& path, const std::string& resourceGroupName) const
19 {
20  if(resourceGroupName == getReservedResourceGroupName()) return refuseResource(path, resourceGroupName);
21  AnnDebug("Will load resources from Zip archive :");
22  AnnDebug() << path;
23  ResourceGroupManager->addResourceLocation(path, "Zip", resourceGroupName);
24 }
25 
26 void AnnResourceManager::addFileLocation(const std::string& path, const std::string& resourceGroupName) const
27 {
28  if(resourceGroupName == getReservedResourceGroupName()) return refuseResource(path, resourceGroupName);
29  AnnDebug("Will load resources from File-system directory :");
30  AnnDebug() << path;
31  ResourceGroupManager->addResourceLocation(path, "FileSystem", resourceGroupName);
32 }
33 
35 {
36  AnnDebug("Adding Annwvyn CORE resource locations");
37  ResourceGroupManager->addResourceLocation("media/CORE.zip", "Zip", getReservedResourceGroupName());
38  ResourceGroupManager->addResourceLocation("media", "FileSystem", getReservedResourceGroupName(), true);
39  ResourceGroupManager->initialiseResourceGroup(getReservedResourceGroupName(), true);
40 }
41 
43 {
44  /*from ogre wiki : load the given resource file*/
45  Ogre::ConfigFile configFile;
46  configFile.load(path);
47  auto seci = configFile.getSectionIterator();
48  Ogre::String secName, typeName, archName;
49  while(seci.hasMoreElements())
50  {
51  secName = seci.peekNextKey();
52 
53  if(secName == getReservedResourceGroupName())
54  {
55  refuseResource("*Did not read form file*", secName);
56  continue;
57  }
58 
59  auto settings = seci.getNext();
60  for(const auto& setting : *settings)
61  {
62  typeName = setting.first;
63  archName = setting.second;
64  ResourceGroupManager->addResourceLocation(archName, typeName, secName);
65  }
66  }
67 }
68 
70 {
71  //addDefaultResourceLocaton();
72  ResourceGroupManager->initialiseAllResourceGroups(true);
73  AnnDebug("Resources initialized");
74 }
75 
76 void AnnResourceManager::loadGroup(const std::string& groupName) const
77 {
78  if(!ResourceGroupManager->isResourceGroupLoaded(groupName))
79  ResourceGroupManager->loadResourceGroup(groupName);
80 }
81 
83 {
84  return "b";
85 }
86 
88 {
89  return "a";
90 }
91 
92 void AnnResourceManager::refuseResource(const std::string& resourceName, const std::string& group)
93 {
94  AnnDebug() << "Annwvyn cannot allow you to set location inside the " << group << " resource group";
95  AnnDebug() << "Resource location " << resourceName << "has been rejected";
96 }
Namespace containing the totality of Annwvyn components.
Definition: AnnGetter.cpp:8
void initResources() const
InitAllResources.
static const char * getDefaultResourceGroupName()
Return the default resource group name.
void loadGroup(const std::string &groupName) const
Load in memory the content of the specified group.
Create a ostream to the Ogre logger.
void addDefaultResourceLocation() const
Add to the default resource group "FileSystem=media" and "Zip=media/CORE.zip".
Ogre::ResourceGroupManager * ResourceGroupManager
Pointer to the resource group manager. We cache the address to prevent calling a static method all th...
void addFileLocation(const std::string &path, const std::string &resourceGroupName=getDefaultResourceGroupName()) const
Open an output stream to the engine log.
Definition: AnnLogger.hpp:24
void addZipLocation(const std::string &path, const std::string &resourceGroupName=getDefaultResourceGroupName()) const
Parent class of all Annwvyn SubSystem.
void loadReseourceFile(const std::string &path) const
Load resource.cfg like file.
static const char * getReservedResourceGroupName()
Return the reserved resource group name.
static void refuseResource(const std::string &name, const std::string &group)
Log the fact that resource location creation as been rejected.