3
3
4
4
#include < boost/container/small_vector.hpp>
5
5
6
+ #include " ../fsc.h"
7
+
6
8
// path parser and utility class for Wii U paths
7
9
// optimized to be allocation-free for common path lengths
8
10
class FSCPath
@@ -119,9 +121,7 @@ class FSCPath
119
121
template <typename F>
120
122
class FSAFileTree
121
123
{
122
- public:
123
-
124
- private:
124
+ private:
125
125
126
126
enum NODETYPE : uint8
127
127
{
@@ -133,6 +133,7 @@ class FSAFileTree
133
133
{
134
134
std::string name;
135
135
std::vector<node_t *> subnodes;
136
+ size_t fileSize;
136
137
F* custom;
137
138
NODETYPE type;
138
139
};
@@ -179,13 +180,54 @@ class FSAFileTree
179
180
return newNode;
180
181
}
181
182
183
+ class DirectoryIterator : public FSCVirtualFile
184
+ {
185
+ public:
186
+ DirectoryIterator (node_t * node)
187
+ : m_node(node), m_subnodeIndex(0 )
188
+ {
189
+ }
190
+
191
+ sint32 fscGetType () override
192
+ {
193
+ return FSC_TYPE_DIRECTORY;
194
+ }
195
+
196
+ bool fscDirNext (FSCDirEntry* dirEntry) override
197
+ {
198
+ if (m_subnodeIndex >= m_node->subnodes .size ())
199
+ return false ;
200
+
201
+ const node_t * subnode = m_node->subnodes [m_subnodeIndex];
202
+
203
+ strncpy (dirEntry->path , subnode->name .c_str (), sizeof (dirEntry->path ) - 1 );
204
+ dirEntry->path [sizeof (dirEntry->path ) - 1 ] = ' \0 ' ;
205
+ dirEntry->isDirectory = subnode->type == FSAFileTree::NODETYPE_DIRECTORY;
206
+ dirEntry->isFile = subnode->type == FSAFileTree::NODETYPE_FILE;
207
+ dirEntry->fileSize = subnode->type == FSAFileTree::NODETYPE_FILE ? subnode->fileSize : 0 ;
208
+
209
+ ++m_subnodeIndex;
210
+ return true ;
211
+ }
212
+
213
+ bool fscRewindDir () override
214
+ {
215
+ m_subnodeIndex = 0 ;
216
+ return true ;
217
+ }
218
+
219
+ private:
220
+ node_t * m_node;
221
+ size_t m_subnodeIndex;
222
+ };
223
+
182
224
public:
183
225
FSAFileTree ()
184
226
{
185
227
rootNode.type = NODETYPE_DIRECTORY;
186
228
}
187
229
188
- bool addFile (std::string_view path, F* custom)
230
+ bool addFile (std::string_view path, size_t fileSize, F* custom)
189
231
{
190
232
FSCPath p (path);
191
233
if (p.GetNodeCount () == 0 )
@@ -196,6 +238,7 @@ class FSAFileTree
196
238
return false ; // node already exists
197
239
// add file node
198
240
node_t * fileNode = newNode (directoryNode, NODETYPE_FILE, p.GetNodeName (p.GetNodeCount () - 1 ));
241
+ fileNode->fileSize = fileSize;
199
242
fileNode->custom = custom;
200
243
return true ;
201
244
}
@@ -214,6 +257,20 @@ class FSAFileTree
214
257
return true ;
215
258
}
216
259
260
+ bool getDirectory (std::string_view path, FSCVirtualFile*& dirIterator)
261
+ {
262
+ FSCPath p (path);
263
+ if (p.GetNodeCount () == 0 )
264
+ return false ;
265
+ node_t * node = getByNodePath (p, p.GetNodeCount (), false );
266
+ if (node == nullptr )
267
+ return false ;
268
+ if (node->type != NODETYPE_DIRECTORY)
269
+ return false ;
270
+ dirIterator = new DirectoryIterator (node);
271
+ return true ;
272
+ }
273
+
217
274
bool removeFile (std::string_view path)
218
275
{
219
276
FSCPath p (path);
0 commit comments