/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


#ifndef	__NFILESYSTEM__
#define	__NFILESYSTEM__


		#include "container/nlist.h"
		#include "filesystem/io_base.h"
		#include "nstring/nstring.h"
		#include "memory/nauto_ptr.h"


namespace GS {
	namespace IO {
		class Handle;
		struct Base;

//
struct	MountPoint
{
		String		mount_point;
		SharedPtr <Base> io_sys;

		MountPoint(const char *mount, Base *io) : mount_point(mount), io_sys(io) {}
};

/*!
	@short	I/O system.
	@author	Emmanuel Julien (ejulien@nworks.fr)
*/
class	Filesystem
{
		AutoList <MountPoint *> mount_list;
		SharedList <Base *> root_mount;
public:

		String		MapToAbsolute(const char *) const;
		String		StripRootPath(const char *) const;

		bool		Mount(Base *, const char *mount_point = 0);
		void		Unmount(const char *);
		void		Unmount(Base *);
		void		UnmountAll();

		Base		*GetIOSystem(const char *mount_point) const;
		const char	*GetMountPoint(const Base *) const;

		Handle		*Open(const char *, Mode = ModeRead) const;
		void		Close(Handle *) const;

		bool		MkDir(const char *) const;

		bool		Exists(const char *) const;
		bool		Delete(const char *) const;

		size_t		FileSize(const char *) const;
		bool		FileLoad(const char *, Array <char> &, bool verbose = true) const;
		bool		FileSave(const char *, const Array <char> &) const;
		bool		FileCopy(const char *src, const char *dst) const;
		bool		FileMove(const char *src, const char *dst) const;
		~Filesystem() { UnmountAll(); } 

};

	} // IO
} // GS


#endif	// __NFILESYSTEM__
