Debian Codegraph @

engine/core/vfs/dat/dat2.h

raw
1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the FIFE team *
3 * http://www.fifengine.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library 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 GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, 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 <memory>
28 #include <string>
29
30 // Platform specific includes
31 #include "util/base/fife_stdint.h"
32
33 // 3rd party library includes
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 vfs A pointer to the VFS.
65 * @param path A Fallout2 DAT file - e.g. master.DAT
66 */
67 DAT2(VFS* vfs, const std::string& path);
68
69 bool fileExists(const std::string& name) const;
70 RawData* open(const std::string& file) const;
71
72 /** Get Information needed to unpack and extract data
73 *
74 * @see MFFalloutDAT1::getInfo
75 */
76 const RawDataDAT2::s_info& getInfo(const std::string& name) const;
77
78 std::set<std::string> listFiles(const std::string& pathstr) const;
79 std::set<std::string> listDirectories(const std::string& pathstr) const;
80
81 private:
82 std::string m_datpath;
83 mutable std::unique_ptr<RawData> m_data;
84 typedef std::map<std::string, RawDataDAT2::s_info> type_filelist;
85 mutable type_filelist m_filelist;
86
87 /// number of file entries to read
88 mutable uint32_t m_filecount;
89 /// current index in file
90 mutable uint32_t m_currentIndex;
91 /// lazy loading timer
92 mutable Timer m_timer;
93
94 /// read a bunch of file entries
95 void readFileEntry() const;
96
97 /// find a file entry
98 type_filelist::const_iterator findFileEntry(const std::string& name) const;
99
100 std::set<std::string> list(const std::string& pathstr, bool dirs) const;
101
102 // Not copyable
103 DAT2(const DAT2&);
104 DAT2& operator=(const DAT2&);
105 };
106
107 } // FIFE
108
109 #endif