1 /** @file file.cpp
2  *
3  * Abstract base for all classes which represent loaded files.
4  * @ingroup fs
5  *
6  * @authors Copyright &copy; 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
7  * @authors Copyright &copy; 2005-2013 Daniel Swanson <danij@dengine.net>
8  *
9  * @par License
10  * GPL: http://www.gnu.org/licenses/gpl.html
11  *
12  * <small>This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by the
14  * Free Software Foundation; either version 2 of the License, or (at your
15  * option) any later version. This program is distributed in the hope that it
16  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
17  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18  * Public License for more details. You should have received a copy of the GNU
19  * General Public License along with this program; if not, write to the Free
20  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA</small>
22  */
23 
24 #include "doomsday/filesys/file.h"
25 #include "doomsday/filesys/fs_main.h"
26 
27 #include <de/NativePath>
28 
29 namespace de {
30 
File1(FileHandle * hndl,String _path,FileInfo const & _info,File1 * _container)31 File1::File1(FileHandle *hndl, String _path, FileInfo const &_info, File1 *_container)
32     : handle_(hndl)
33     , info_(_info)
34     , container_(_container)
35     , flags(DefaultFlags)
36     , path_(_path)
37     , name_(_path.fileName())
38 {
39     // Used to favor newer files when duplicates are pruned.
40     /// @todo Does not belong at this level. Load order should be determined
41     ///       at file system level. -ds
42     static uint fileCounter = 0;
43     order = fileCounter++;
44 }
45 
~File1()46 File1::~File1()
47 {
48     App_FileSystem().releaseFile(*this);
49     if (handle_) delete handle_;
50 }
51 
info() const52 FileInfo const &File1::info() const
53 {
54     return info_;
55 }
56 
isContained() const57 bool File1::isContained() const
58 {
59     return !!container_;
60 }
61 
container() const62 File1 &File1::container() const
63 {
64     if (!container_) throw NotContainedError("File1::container", "File \"" + NativePath(composePath()).pretty() + " is not contained");
65     return *container_;
66 }
67 
handle()68 FileHandle &File1::handle()
69 {
70     return *handle_;
71 }
72 
composeUri(QChar delimiter) const73 Uri File1::composeUri(QChar delimiter) const
74 {
75     return Uri(path_, RC_NULL, delimiter);
76 }
77 
loadOrderIndex() const78 uint File1::loadOrderIndex() const
79 {
80     return order;
81 }
82 
hasStartup() const83 bool File1::hasStartup() const
84 {
85     return flags.testFlag(Startup);
86 }
87 
setStartup(bool yes)88 File1 &File1::setStartup(bool yes)
89 {
90     if (yes) flags |= Startup;
91     else    flags &= ~Startup;
92     return *this;
93 }
94 
hasCustom() const95 bool File1::hasCustom() const
96 {
97     return flags.testFlag(Custom);
98 }
99 
setCustom(bool yes)100 File1 &File1::setCustom(bool yes)
101 {
102     if (yes) flags |= Custom;
103     else    flags &= ~Custom;
104     return *this;
105 }
106 
name() const107 String const &File1::name() const
108 {
109     return name_;
110 }
111 
read(uint8_t *,bool)112 size_t File1::read(uint8_t* /*buffer*/, bool /*tryCache*/)
113 {
114     /// @todo writeme
115     throw Error("File1::read", "Not yet implemented");
116 }
117 
read(uint8_t *,size_t,size_t,bool)118 size_t File1::read(uint8_t* /*buffer*/, size_t /*startOffset*/, size_t /*length*/,
119                    bool /*tryCache*/)
120 {
121     /// @todo writeme
122     throw Error("File1::read", "Not yet implemented");
123 }
124 
cache()125 uint8_t const *File1::cache()
126 {
127     /// @todo writeme
128     throw Error("File1::cache", "Not yet implemented");
129 }
130 
unlock()131 File1& File1::unlock()
132 {
133     /// @todo writeme
134     throw Error("File1::unlock", "Not yet implemented");
135 }
136 
clearCache(bool *)137 File1 &File1::clearCache(bool* /*retCleared*/)
138 {
139     /// @todo writeme
140     throw Error("File1::clearCache", "Not yet implemented");
141 }
142 
143 } // namespace de
144