Sort include order.
[gemrb.git] / gemrb / plugins / DirectoryImporter / DirectoryImporter.cpp
blob025b10c8abd0e7f32436db909cc9cab9d4cea567
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 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.
19 #include "DirectoryImporter.h"
21 #include "globals.h"
22 #include "win32def.h"
24 #include "FileStream.h"
25 #include "Interface.h"
26 #include "ResourceDesc.h"
28 #ifndef WIN32
29 #include <unistd.h>
30 #endif
32 DirectoryImporter::DirectoryImporter(void)
36 DirectoryImporter::~DirectoryImporter(void)
40 bool DirectoryImporter::Open(const char *dir, const char *desc)
42 description = desc;
43 strcpy(path, dir);
44 return true;
47 static bool FindIn(const char *Path, const char *ResRef, const char *Type)
49 char p[_MAX_PATH], f[_MAX_PATH] = {0};
50 strcpy(f, ResRef);
51 strcat(f, Type);
52 strlwr(f);
54 return PathJoin(p, Path, f, NULL);
57 static FileStream *SearchIn(const char * Path,const char * ResRef, const char *Type)
59 char p[_MAX_PATH], f[_MAX_PATH] = {0};
60 strcpy(f, ResRef);
61 strcat(f, Type);
62 strlwr(f);
64 if (!PathJoin(p, Path, f, NULL))
65 return NULL;
67 FileStream * fs = new FileStream();
68 if(!fs) return NULL;
69 if(!fs->Open(p, true)) {
70 delete fs;
71 return NULL;
73 return fs;
76 bool DirectoryImporter::HasResource(const char* resname, SClass_ID type)
78 return FindIn( path, resname, core->TypeExt(type) );
81 bool DirectoryImporter::HasResource(const char* resname, const ResourceDesc &type)
83 return FindIn( path, resname, type.GetExt() );
86 DataStream* DirectoryImporter::GetResource(const char* resname, SClass_ID type)
88 return SearchIn( path, resname, core->TypeExt(type) );
91 DataStream* DirectoryImporter::GetResource(const char* resname, const ResourceDesc &type)
93 return SearchIn( path, resname, type.GetExt() );
96 #include "plugindef.h"
98 GEMRB_PLUGIN(0xAB4534, "Directory Importer")
99 PLUGIN_CLASS(PLUGIN_RESOURCE_DIRECTORY, DirectoryImporter)
100 END_PLUGIN()