#if !defined( _IOAFOLDER_H )
#define _IOAFOLDER_H

// Class to collect together functions for handling folder information

class IoAFolder
{
public:
	static int IsExistingFolder( const char *FolderPath );
	static int      ClearFolder( const char *FolderPath );
	static int     CreateFolder( const char *FolderPath );

	IoAFolder( ) { Initialise( NULL ); }
	IoAFolder( const char *FolderPath ) { Initialise( FolderPath ); }
	IoAFolder( const char *FolderPath, const char *FolderName ) { Initialise( FolderPath, FolderName ); }

	~IoAFolder( )
	{
		delete [ ] m_FolderPath;
		delete [ ] m_pFolders;
		delete [ ] m_pFileNames;
	}

	const char *FolderPath( ) { return m_FolderPath; }

	int IsDefined( ) { return m_FolderPath != NULL; }

	int Exists( ) { return IsExistingFolder( m_FolderPath ); }
	int Clear ( ) { return      ClearFolder( m_FolderPath ); }
	int Create( ) { return     CreateFolder( m_FolderPath ); }

	int Parse( );

	int FolderCount( ) { return m_FolderCount; }
	int FileCount  ( ) { return m_FileCount;   }

	const IoAFolder *Folder( int FolderIndex )
	{
		if ( FolderIndex < 0 || FolderIndex >= m_FolderCount ) return NULL;

		return m_pFolders + FolderIndex;
	}

	const char *FileName( int FileIndex )
	{
		if ( FileIndex < 0 || FileIndex >= m_FileCount ) return NULL;

		return m_pFileNames[ FileIndex ];
	}

private:
	void Initialise( const char *FolderPath, const char *FolderName )
	{
		m_FolderCount = 0;
		m_FileCount   = 0;

		m_FolderPath = NULL;
		m_pFolders   = NULL;
		m_pFileNames = NULL;

		if ( FolderPath != NULL && FolderName != NULL )
		{
			int PathLength = ::strlen( FolderPath );
			int NameLength = ::strlen( FolderName );

			m_FolderPath = new char[ PathLength + 1 + NameLength + 1 ];

			if ( m_FolderPath != NULL )
			{
				::CopyMemory( m_FolderPath, FolderPath, PathLength );

				m_FolderPath[ PathLength ] = '\\';

				::CopyMemory( m_FolderPath + PathLength + 1, FolderName, NameLength );

				m_FolderPath[ PathLength + 1 + NameLength ] = '\0';
			}
		}
	}

	void Initialise( const char *FolderPath )
	{
		m_FolderCount = 0;
		m_FileCount   = 0;

		m_FolderPath = NULL;
		m_pFolders   = NULL;
		m_pFileNames = NULL;

		if ( FolderPath != NULL )
		{
			int PathLength = ::strlen( FolderPath );

			m_FolderPath = new char[ PathLength + 1 ];

			if ( m_FolderPath != NULL )
			{
				::CopyMemory( m_FolderPath, FolderPath, PathLength );

				m_FolderPath[ PathLength ] = '\0';
			}
		}
	}

	int m_FolderCount;
	int m_FileCount;

	char      *m_FolderPath;
	IoAFolder *m_pFolders;
	char     **m_pFileNames;
};

#endif
