////////////////////////////////////////////////////////////////////////////////
// ISO9660.h
// Class for reading ISO 9660 image files
// Copyright Bjoern Ganster 2010
////////////////////////////////////////////////////////////////////////////////

#ifndef ISO9660__h
#define ISO9660__h

#include "Archive.h"
#include "FileCache.h"

// Class for reading ISO 9660 image files is defined of a subclass of MW2 readable archives
class ISO9660 FINAL: public MWArchive {
public:
    ISO9660();

    ~ISO9660() OVERRIDE;

    // Open file
    virtual bool open (const PathChar* PRJFN, bool readOnly = true);

    // Close file
    virtual void close();

    // Read bufSize bytes from file numbered index at offset into buf
    virtual bool getFileChunk(size_t index, size_t offset, void* buf, size_t bufSize);

    // Enter subdirectory
    virtual bool enterSubDir (size_t index);

    // Leave subdirectory
    virtual bool leaveDir();

    // Check if currently in sub directory
    virtual bool inSubDir() const;

    // Check if entry index is a directory
    virtual bool isDirectory (size_t index) const;
private:
	FileCache fc;
	static const int SectorSize = 2352;

	std::vector <bool> m_isDirectory;
	std::list <int> m_parentDirStartSector;
	std::list <int> m_parentDirSize;

	// Read directory entries
	bool readDirectory(int sector, int dirSize);

	// Read extent (directory or file data)
	bool readExtent(int startSector, void* buf, int toRead, 
		int startOffset);

	void forgetDirectoryContents();
};

#endif
