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
|
#include <RezFileList.h>
#include <rez/dir.h>
#include <rez.h>
#include <iostream>
static const irr::io::path s;
irr::u32 RezFileList::getFileCount(const rez::dir &dir) const
{
irr::u32 ret = 0;
for (const auto &d : dir.entries())
{
const auto &entry = d.second;
if (std::holds_alternative<rez::dir>(entry))
ret += getFileCount(std::get<rez::dir>(entry));
else if (std::holds_alternative<rez::resource>(entry))
ret++;
}
return ret;
}
irr::u32 RezFileList::getFileCount() const
{
return getFileCount(rez.root());
}
const irr::io::path &RezFileList::getFileName(irr::u32 index) const
{
return s;
}
const irr::io::path &RezFileList::getFullFileName(irr::u32 index) const
{
return s;
}
irr::u32 RezFileList::getFileSize(irr::u32 index) const
{
return 0;
}
irr::u32 RezFileList::getFileOffset(irr::u32 index) const
{
return 0;
}
irr::u32 RezFileList::getID(irr::u32 index) const
{
return 0;
}
bool RezFileList::isDirectory(irr::u32 index) const
{
if (index >= entries.size())
return false;
return std::holds_alternative<rez::dir>(*entries.at(index));
}
int RezFileList::findFile(const irr::io::path &filename, bool isFolder,
const rez::dir::direntry *entry) const
{
if (std::holds_alternative<rez::resource>(*entry))
{
const auto &resource = std::get<rez::resource>(*entry);
if (resource.name() == filename.c_str())
{
if (isFolder)
{
std::cerr << filename.c_str() << " expected to be a "
"directory, but is a file\n";
return -1;
}
else
return 1;
}
}
else if (std::holds_alternative<rez::dir>(*entry) && isFolder)
{
const auto &dir = std::get<rez::dir>(*entry);
if (dir.name() == filename.c_str())
{
if (!isFolder)
{
std::cerr << filename.c_str() << " expected to be a "
"file, but is a directory\n";
return -1;
}
else
return 1;
}
}
return 0;
}
irr::s32 RezFileList::findFile(const irr::io::path &filename, bool isFolder)
const
{
for (irr::u32 i = 0; i < entries.size(); i++)
{
auto entry = entries.at(i);
int n = findFile(filename, isFolder, entry);
if (n < 0)
return -1;
else if (n)
return i;
}
const rez::dir::direntry *entry = rez.access(filename.c_str());
if (!entry || findFile(filename, isFolder, entry) <= 0)
return -1;
entries.push_back(entry);
return entries.size() - 1;
}
const irr::io::path &RezFileList::getPath() const
{
return s;
}
irr::u32 RezFileList::addItem(const irr::io::path &fullPath, irr::u32 offset,
irr::u32 size, bool isDirectory, irr::u32 id)
{
return 0;
}
void RezFileList::sort()
{
}
RezFileList::RezFileList(const rez::ball &rez) :
rez(rez)
{
}
|