comparison engine/core/vfs/dat/dat2.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_MAP_LOADERS_FALLOUT_DAT2_H
23 #define FIFE_MAP_LOADERS_FALLOUT_DAT2_H
24
25 // Standard C++ library includes
26 #include <map>
27 #include <string>
28
29 // Platform specific includes
30 #include "util/base/fife_stdint.h"
31
32 // 3rd party library includes
33 #include <boost/scoped_ptr.hpp>
34
35 // FIFE includes
36 // These includes are split up in two parts, separated by one empty line
37 // First block: files included from the FIFE root src directory
38 // Second block: files included from the same folder
39 #include "util/time/timer.h"
40 #include "vfs/vfs.h"
41 #include "vfs/vfssource.h"
42
43 #include "rawdatadat2.h"
44
45 namespace FIFE {
46 class RawData;
47
48 /** VFSource for the Fallout2 DAT file format
49 *
50 * Implements a kind of lazy initializing, by reading the file list
51 * in chunks. Behaviour is the same as if it wouldn't do this,
52 * but startup is very fast. But a open/fileExists call with a
53 * filename that doesn't exist, does trigger completely loading
54 * the file entries.
55 *
56 * @see MFFalloutDAT1
57 * @todo @b maybe merge common DAT1/DAT2 code in a common base class
58 */
59 class DAT2 : public VFSSource {
60
61 public:
62 /** Constructor
63 * Create a VFSSource for a Fallout2 DAT file.
64 * @param file A Fallout2 DAT file - e.g. master.DAT
65 */
66 DAT2(VFS* vfs, const std::string& path);
67
68 bool fileExists(const std::string& name) const;
69 RawData* open(const std::string& file) const;
70
71 /** Get Information needed to unpack and extract data
72 *
73 * @see MFFalloutDAT1::getInfo
74 */
75 const RawDataDAT2::s_info& getInfo(const std::string& name) const;
76
77 std::set<std::string> listFiles(const std::string& pathstr) const;
78 std::set<std::string> listDirectories(const std::string& pathstr) const;
79
80 private:
81 std::string m_datpath;
82 mutable boost::scoped_ptr<RawData> m_data;
83 typedef std::map<std::string, RawDataDAT2::s_info> type_filelist;
84 mutable type_filelist m_filelist;
85
86 /// number of file entries to read
87 mutable uint32_t m_filecount;
88 /// current index in file
89 mutable unsigned int m_currentIndex;
90 /// lazy loading timer
91 mutable Timer m_timer;
92
93 /// read a bunch of file entries
94 void readFileEntry() const;
95
96 /// find a file entry
97 type_filelist::const_iterator findFileEntry(const std::string& name) const;
98
99 std::set<std::string> list(const std::string& pathstr, bool dirs) const;
100
101 // Not copyable
102 DAT2(const DAT2&);
103 DAT2& operator=(const DAT2&);
104 };
105
106 } // FIFE
107
108 #endif