/**------------------------------------------------------------------------
 * @file
 *
 * Copyright 2001 by the University of Toronto (UT).
 *
 *                       All Rights Reserved
 * 
 * Permission to copy and modify this software and its documentation 
 * only for internal use in your organization is hereby granted, 
 * provided that this notice is retained thereon and on all copies.  
 * UT makes no representations as to the suitability and operability 
 * of this software for any purpose.  It is provided "as is" without 
 * express or implied warranty.
 *
 * UT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
 * SHALL UT BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
 * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 * No other rights, including for example, the right to redistribute 
 * this software and its documentation or the right to prepare 
 * derivative works, are granted unless specifically provided in a 
 * separate license agreement.
 *
 * Author: Diego Macrini
 * 
 * $Log: DirWalker.h,v $
 * Revision 1.2  2002/05/16 22:49:29  dmac
 * Several bugs fixed and a new DAG-derived class added
 *
 * Revision 1.1.1.1  2002/03/10 07:38:07  dmac
 * Imported sources
 *
 *
 *-----------------------------------------------------------------------*/

#ifndef __DIR_WALKER_H__
#define __DIR_WALKER_H__

#include <string>
#include <map>

#ifdef WIN32
# include <windows.h>
# define MAX_PATH_SIZE MAX_PATH
#else
# include <sys/types.h>
# include <dirent.h>
# define INVALID_HANDLE_VALUE	0
# define MAX_PATH_SIZE	500
  typedef DIR* HANDLE;
#endif //WIN32

class DirWalker
{
	HANDLE hFile;
	char szDirPath[MAX_PATH_SIZE];
	size_t nDirPathLen;

#ifdef WIN32
	WIN32_FIND_DATA findData;
#endif

public:
	std::string path, name, ext;
	std::map<std::string, int> params;
public:
	DirWalker();
	~DirWalker() { CloseDir(); }

	const char* GetDirPath() { return szDirPath; }
	int GetDirPathLen() { return nDirPathLen; }

	bool OpenDir(const char* szDirName);
	void CloseDir();
	bool GetNextFileOrDir(char* szFileName, size_t buffSize);
	bool GetNextFile(char* szFileName, size_t buffSize, char* szFileExt = NULL);
	bool GetNextDir(char* szFileName, size_t buffSize);
	
	bool ParseFileName(const char* szFileName);
	bool ParseFileNameParams();

	static bool IsDirectory(const char* szFileName);
	static const char* FindFileExtention(const char* szFileName);
	static bool CompFileExt(const char* szFileName, const char* szFileExt);
	static void ChangeFileExt(const char* szFileName, const char* szExt, char* szNewName);
	static int CreateFileName(const char* szDirName, const char* szPrefix, 
		const char* szFileExt, char szFileName[]);
	static int CompareLastModifDate(const char* szFileName1, const char* szFileName2);
	static bool CheckFilePath(const char* szFullFileName);
};

#endif //__DIR_WALKER_H__
