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 "ResourceDesc.h"
24 #include "ResourceSource.h"
25 #include "Interface.h"
26 #include "PluginMgr.h"
28 ResourceManager::ResourceManager()
33 ResourceManager::~ResourceManager()
35 std::vector
<ResourceSource
*>::iterator i
;
36 for (i
= searchPath
.begin(); i
!= searchPath
.end(); ++i
) {
42 bool ResourceManager::AddSource(char *path
, const char *description
, PluginID type
)
44 ResourceSource
*source
= ( ResourceSource
* ) core
->GetInterface( type
);
45 if (!source
->Open(path
, description
)) {
49 searchPath
.push_back(source
);
53 static void PrintPossibleFiles(const char* ResRef
, const TypeID
*type
)
55 const std::vector
<ResourceDesc
>& types
= PluginMgr::Get()->GetResourceDesc(type
);
56 for (size_t j
= 0; j
< types
.size(); j
++) {
57 printf("%s%s ", ResRef
, types
[j
].GetExt());
61 bool ResourceManager::Exists(const char *ResRef
, SClass_ID type
, bool silent
)
63 if (ResRef
[0] == '\0')
65 // TODO: check various caches
66 for (size_t i
= 0; i
< searchPath
.size(); i
++) {
67 if (searchPath
[i
]->HasResource( ResRef
, type
)) {
72 printMessage( "ResourceManager", "Searching for ", WHITE
);
73 printf( "%s%s...", ResRef
, core
->TypeExt( type
) );
74 printStatus( "NOT FOUND", YELLOW
);
79 bool ResourceManager::Exists(const char *ResRef
, const TypeID
*type
, bool silent
)
81 if (ResRef
[0] == '\0')
83 // TODO: check various caches
84 const std::vector
<ResourceDesc
> &types
= PluginMgr::Get()->GetResourceDesc(type
);
85 for (size_t j
= 0; j
< types
.size(); j
++) {
86 for (size_t i
= 0; i
< searchPath
.size(); i
++) {
87 if (searchPath
[i
]->HasResource(ResRef
, types
[j
])) {
93 printMessage( "ResourceManager", "Searching for ", WHITE
);
94 printf( "%s... ", ResRef
);
96 PrintPossibleFiles(ResRef
,type
);
97 printStatus( "NOT FOUND", YELLOW
);
102 DataStream
* ResourceManager::GetResource(const char* ResRef
, SClass_ID type
, bool silent
) const
104 if (ResRef
[0] == '\0')
107 printMessage( "ResourceManager", "Searching for ", WHITE
);
108 printf( "%s%s...", ResRef
, core
->TypeExt( type
) );
110 for (size_t i
= 0; i
< searchPath
.size(); i
++) {
111 DataStream
*ds
= searchPath
[i
]->GetResource(ResRef
, type
);
114 printStatus( searchPath
[i
]->GetDescription(), GREEN
);
120 printStatus( "ERROR", LIGHT_RED
);
125 Resource
* ResourceManager::GetResource(const char* ResRef
, const TypeID
*type
, bool silent
) const
127 if (ResRef
[0] == '\0')
130 printMessage( "ResourceManager", "Searching for ", WHITE
);
131 printf( "%.8s... ", ResRef
);
133 const std::vector
<ResourceDesc
> &types
= PluginMgr::Get()->GetResourceDesc(type
);
134 for (size_t j
= 0; j
< types
.size(); j
++) {
135 for (size_t i
= 0; i
< searchPath
.size(); i
++) {
136 DataStream
*str
= searchPath
[i
]->GetResource(ResRef
, types
[j
]);
138 Resource
*res
= types
[j
].Create(str
);
141 printf( "%s%s...", ResRef
, types
[j
].GetExt() );
142 printStatus( searchPath
[i
]->GetDescription(), GREEN
);
151 PrintPossibleFiles(ResRef
,type
);
152 printStatus( "ERROR", LIGHT_RED
);