//	Zinc Application Framework - Z_DSKFIL.HPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#if !defined(Z_DSKFIL_HPP)
#define Z_DSKFIL_HPP
#include <z_file.hpp>
#include <z_stdio.hpp>

// --------------------------------------------------------------------------
// ----- ZafDiskFileSystem --------------------------------------------------
// --------------------------------------------------------------------------

class ZAF_EXPORT ZafDiskFileSystem : public ZafFileSystem
{
public:
	static void ChangeExtension(ZafIChar *name, const ZafIChar *newExtension);
	static void MakeFullPath(ZafIChar *fullPath,
		const ZafIChar *pathName, const ZafIChar *fileName,
		const ZafIChar *extension = ZAF_NULLP(ZafIChar));
	static void StripFullPath(const ZafIChar *fullPath,
		ZafIChar *pathName = ZAF_NULLP(ZafIChar),
		ZafIChar *fileName = ZAF_NULLP(ZafIChar),
		ZafIChar *objectName = ZAF_NULLP(ZafIChar),
		ZafIChar *objectPathName = ZAF_NULLP(ZafIChar));
	static void TempName(ZafIChar *tempname);
	static bool ValidName(const ZafIChar *name, bool create = false);

	static int GetDriveNames(ZafIChar **driveName[]);
	static void DeleteDriveNames(ZafIChar *driveName[]);
	static int SetDrive(const ZafIChar *driveName);

	ZafDiskFileSystem(void);
	virtual ~ZafDiskFileSystem(void);

	// --- Directory Members ---
	virtual int ChDir(const ZafIChar *newPath,
		ZafStringID stringID = ZAF_NULLP(ZafIChar), ZafNumberID numberID = 0);
	virtual int FindFirst(ZafFileInfoStruct &fileInfo, const ZafIChar *searchName,
		ZafStringID stringID = ZAF_NULLP(ZafIChar), ZafNumberID numberID = 0);
	virtual int FindNext(ZafFileInfoStruct &fileInfo, const ZafIChar *searchName,
		ZafStringID stringID = ZAF_NULLP(ZafIChar), ZafNumberID numberID = 0);
	virtual int FindClose(ZafFileInfoStruct &fileInfo);
	virtual int GetCWD(ZafIChar *pathName, int pathLength);
	virtual int MkDir(const ZafIChar *pathName,
		ZafStringID stringID = ZAF_NULLP(ZafIChar), ZafNumberID numberID = 0);
	virtual int RmDir(const ZafIChar *pathName, bool deleteContents = false);

	// --- File Members ---
	virtual void Close(ZafFile *file);
	virtual ZafFile *Open(const ZafIChar *fileName, const ZafFileMode mode,
		ZafStringID stringID = ZAF_NULLP(ZafIChar), ZafNumberID numberID = 0);
	virtual int Remove(const ZafIChar *name);
	virtual int Rename(const ZafIChar *oldName, const ZafIChar *newName,
		ZafStringID stringID = ZAF_NULLP(ZafIChar), ZafNumberID numberID = 0);
};

// --------------------------------------------------------------------------
// ----- ZafDiskFile --------------------------------------------------------
// --------------------------------------------------------------------------

class ZAF_EXPORT ZafDiskFile : public ZafFile
{
public:
	ZafDiskFile(const ZafIChar *pathName, ZafFileMode mode);
	virtual ~ZafDiskFile(void);

	// --- General members ---
	bool Destroyable(void) const;

	// --- Search functions ---
	virtual ZafOffset Length(void) const;
	virtual int Seek(ZafOffset offset, ZafSeek location);
	virtual ZafOffset Tell(void) const;

	// --- I/O functions ---
	virtual int ReadData(void *buffer, int size);
	virtual int WriteData(const void *buffer, int size);

#if defined(ZAF_MACINTOSH)
	static OSType fileCreator;
	static OSType fileType;
#endif

protected:
	ZafIChar *pathName;
#	if defined(ZAF_MACINTOSH)
	Ptr readCacheBuffer;
	long readCacheLength;
	long readCachePosition;

	short file;
#	elif defined(ZAF_PSOS)
	unsigned long file;
#	else
	FILE *file;
#	endif
};

#endif // ZAF_DSKFIL_HPP
