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