33
44#include  < boost/container/small_vector.hpp> 
55
6+ #include  " ../fsc.h" 
7+ 
68//  path parser and utility class for Wii U paths
79//  optimized to be allocation-free for common path lengths
810class  FSCPath 
@@ -119,9 +121,7 @@ class FSCPath
119121template <typename  F>
120122class  FSAFileTree 
121123{
122- public: 
123- 
124- private: 
124+   private: 
125125
126126	enum  NODETYPE : uint8
127127	{
@@ -133,6 +133,7 @@ class FSAFileTree
133133	{
134134		std::string name;
135135		std::vector<node_t *> subnodes;
136+ 		size_t  fileSize;
136137		F* custom;
137138		NODETYPE type;
138139	};
@@ -179,13 +180,54 @@ class FSAFileTree
179180		return  newNode;
180181	}
181182
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+ 
182224public: 
183225	FSAFileTree ()
184226	{
185227		rootNode.type  = NODETYPE_DIRECTORY;
186228	}
187229
188- 	bool  addFile (std::string_view path, F* custom)
230+ 	bool  addFile (std::string_view path, size_t  fileSize,  F* custom)
189231	{
190232		FSCPath p (path);
191233		if  (p.GetNodeCount () == 0 )
@@ -196,6 +238,7 @@ class FSAFileTree
196238			return  false ; //  node already exists
197239		//  add file node
198240		node_t * fileNode = newNode (directoryNode, NODETYPE_FILE, p.GetNodeName (p.GetNodeCount () - 1 ));
241+ 		fileNode->fileSize  = fileSize;
199242		fileNode->custom  = custom;
200243		return  true ;
201244	}
@@ -214,6 +257,20 @@ class FSAFileTree
214257		return  true ;
215258	}
216259
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+ 
217274	bool  removeFile (std::string_view path)
218275	{
219276		FSCPath p (path);
0 commit comments