359
|
1 /*
|
|
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
|
|
3 * Copyright (C) 1999 - 2002 Simon Peter, <dn.tlp@gmx.net>, et al.
|
|
4 *
|
|
5 * This library is free software; you can redistribute it and/or
|
|
6 * modify it under the terms of the GNU Lesser General Public
|
|
7 * License as published by the Free Software Foundation; either
|
|
8 * version 2.1 of the License, or (at your option) any later version.
|
|
9 *
|
|
10 * This library is distributed in the hope that it will be useful,
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 * Lesser General Public License for more details.
|
|
14 *
|
|
15 * You should have received a copy of the GNU Lesser General Public
|
|
16 * License along with this library; if not, write to the Free Software
|
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 *
|
|
19 * fprovide.cpp - File provider class framework, by Simon Peter <dn.tlp@gmx.net>
|
|
20 */
|
|
21
|
|
22 #include <string.h>
|
|
23 #include <binio.h>
|
|
24 #include <binfile.h>
|
|
25
|
|
26 #include "fprovide.h"
|
|
27
|
|
28 /***** CFileProvider *****/
|
|
29
|
|
30 bool CFileProvider::extension(const std::string &filename,
|
|
31 const std::string &extension)
|
|
32 {
|
|
33 const char *fname = filename.c_str(), *ext = extension.c_str();
|
|
34
|
|
35 if(strlen(fname) < strlen(ext) ||
|
|
36 stricmp(fname + strlen(fname) - strlen(ext), ext))
|
|
37 return false;
|
|
38 else
|
|
39 return true;
|
|
40 }
|
|
41
|
|
42 unsigned long CFileProvider::filesize(binistream *f)
|
|
43 {
|
|
44 unsigned long oldpos = f->pos(), size;
|
|
45
|
|
46 f->seek(0, binio::End);
|
|
47 size = f->pos();
|
|
48 f->seek(oldpos, binio::Set);
|
|
49
|
|
50 return size;
|
|
51 }
|
|
52
|
|
53 /***** CProvider_Filesystem *****/
|
|
54
|
|
55 binistream *CProvider_Filesystem::open(std::string filename) const
|
|
56 {
|
|
57 binifstream *f = new binifstream(filename);
|
|
58
|
|
59 if(!f) return 0;
|
|
60 if(f->error()) { delete f; return 0; }
|
|
61
|
|
62 // Open all files as little endian with IEEE floats by default
|
|
63 f->setFlag(binio::BigEndian, false); f->setFlag(binio::FloatIEEE);
|
|
64
|
|
65 return f;
|
|
66 }
|
|
67
|
|
68 void CProvider_Filesystem::close(binistream *f) const
|
|
69 {
|
|
70 binifstream *ff = (binifstream *)f;
|
|
71
|
|
72 if(f) {
|
|
73 ff->close();
|
|
74 delete ff;
|
|
75 }
|
|
76 }
|