/
patchname.cpp
79 lines (68 loc) · 2.34 KB
/
patchname.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
/**
* @file patchname.cpp PatchName
*
* @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/IReadable>
#include <de/Reader>
#include <de/String>
#include "filesys/fs_main.h"
#include "resource/patchname.h"
namespace de {
PatchName::PatchName(String percentEncodedName, lumpnum_t _lumpNum)
: name(percentEncodedName), lumpNum_(_lumpNum)
{}
lumpnum_t PatchName::lumpNum()
{
// Have we already searched for this lump?
if(lumpNum_ == -2)
{
// Mark as not found.
lumpNum_ = -1;
// Perform the search.
try
{
lumpNum_ = App_FileSystem()->lumpNumForName(name);
}
catch(FS1::NotFoundError const &er)
{
// Log but otherwise ignore this error.
LOG_WARNING(er.asText() + ", ignoring.");
}
}
return lumpNum_;
}
void PatchName::operator << (Reader &from)
{
// The raw ASCII name is not necessarily terminated.
char asciiName[9];
for(int i = 0; i < 8; ++i) { from >> asciiName[i]; }
asciiName[8] = 0;
// WAD format allows characters not normally permitted in native paths.
// To achieve uniformity we apply a percent encoding to the "raw" names.
name = QString(QByteArray(asciiName).toPercentEncoding());
// The cached found lump number is no longer valid.
lumpNum_ = -2;
}
String PatchName::percentEncodedName() const {
return name;
}
String const &PatchName::percentEncodedNameRef() const {
return name;
}
} // namespace de