1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003-2005 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "ResourceManager.h"
23 #include "Interface.h"
24 #include "PluginMgr.h"
26 #include "ResourceDesc.h"
27 #include "ResourceSource.h"
29 ResourceManager::ResourceManager()
34 ResourceManager::~ResourceManager()
38 bool ResourceManager::AddSource(const char *path
, const char *description
, PluginID type
)
40 PluginHolder
<ResourceSource
> source(type
);
41 if (!source
->Open(path
, description
)) {
44 searchPath
.push_back(source
);
48 static void PrintPossibleFiles(const char* ResRef
, const TypeID
*type
)
50 const std::vector
<ResourceDesc
>& types
= PluginMgr::Get()->GetResourceDesc(type
);
51 for (size_t j
= 0; j
< types
.size(); j
++) {
52 printf("%s%s ", ResRef
, types
[j
].GetExt());
56 bool ResourceManager::Exists(const char *ResRef
, SClass_ID type
, bool silent
) const
58 if (ResRef
[0] == '\0')
60 // TODO: check various caches
61 for (size_t i
= 0; i
< searchPath
.size(); i
++) {
62 if (searchPath
[i
]->HasResource( ResRef
, type
)) {
67 printMessage( "ResourceManager", "Searching for ", WHITE
);
68 printf( "%s%s...", ResRef
, core
->TypeExt( type
) );
69 printStatus( "NOT FOUND", YELLOW
);
74 bool ResourceManager::Exists(const char *ResRef
, const TypeID
*type
, bool silent
) const
76 if (ResRef
[0] == '\0')
78 // TODO: check various caches
79 const std::vector
<ResourceDesc
> &types
= PluginMgr::Get()->GetResourceDesc(type
);
80 for (size_t j
= 0; j
< types
.size(); j
++) {
81 for (size_t i
= 0; i
< searchPath
.size(); i
++) {
82 if (searchPath
[i
]->HasResource(ResRef
, types
[j
])) {
88 printMessage( "ResourceManager", "Searching for ", WHITE
);
89 printf( "%s... ", ResRef
);
91 PrintPossibleFiles(ResRef
,type
);
92 printStatus( "NOT FOUND", YELLOW
);
97 DataStream
* ResourceManager::GetResource(const char* ResRef
, SClass_ID type
, bool silent
) const
99 if (ResRef
[0] == '\0')
102 printMessage( "ResourceManager", "Searching for ", WHITE
);
103 printf( "%s%s...", ResRef
, core
->TypeExt( type
) );
105 for (size_t i
= 0; i
< searchPath
.size(); i
++) {
106 DataStream
*ds
= searchPath
[i
]->GetResource(ResRef
, type
);
109 printStatus( searchPath
[i
]->GetDescription(), GREEN
);
115 printStatus( "ERROR", LIGHT_RED
);
120 Resource
* ResourceManager::GetResource(const char* ResRef
, const TypeID
*type
, bool silent
) const
122 if (ResRef
[0] == '\0')
125 printMessage( "ResourceManager", "Searching for ", WHITE
);
126 printf( "%s... ", ResRef
);
128 const std::vector
<ResourceDesc
> &types
= PluginMgr::Get()->GetResourceDesc(type
);
129 for (size_t j
= 0; j
< types
.size(); j
++) {
130 for (size_t i
= 0; i
< searchPath
.size(); i
++) {
131 DataStream
*str
= searchPath
[i
]->GetResource(ResRef
, types
[j
]);
133 Resource
*res
= types
[j
].Create(str
);
136 printf( "%s%s...", ResRef
, types
[j
].GetExt() );
137 printStatus( searchPath
[i
]->GetDescription(), GREEN
);
146 PrintPossibleFiles(ResRef
,type
);
147 printStatus( "ERROR", LIGHT_RED
);