#ifndef _MPFS2mLib_
#define _MPFS2mLib_
/*<<<***************************************************************************
The MIT License (MIT)

Copyright(C) 2013 - 2015 Marc Mirti Mancinelli, Christophe Lardau and Philippe Pamart (xdcube.org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

!!IMPORTANT!!
This software(mcTool) uses parts of sources owned by Microchip Technology, Inc, 
and so these parts are not covered by this licence. 
See header of concerned files (mpfs2dynVar.cpp, mpfs2lib.cpp) for their own licence. 
////////////////////////////////////////////////////////////////////////////////
#Title: mpfs2mLib
#Project: mcTool
////////////////////////////////////////////////////////////////////////////////
#Author: Marc MIRTI MANCINELLI
#History:
<31/12/2013: creation.
12/02/2014: this notice inserted.
***************************************************************************>>>*/

#ifndef _MPFS2lib_
#	include "mpfs2lib.h"
#endif

class __declspec(uuid("{3C1DE839-6543-4d88-8DB3-7B8D7DEC8DAE}")) 
	MPFS2mBuilder : public MPFS2Builder
{
public:
	virtual xbString GetLabel() const {return "MPFS2mBuilder";}
	xbImplCreateObject(MPFS2mBuilder,MPFS2mBuilder);

	virtual bool GetInterface(REFIID riid, void ** ppInterf)
	{
		xbImplInterface(MPFS2mBuilder);
		return MPFS2Builder::GetInterface(riid,ppInterf);
	}

    /// <summary>
    /// Adds a file to the MPFS image
    /// </summary>
    /// <param name="localName">Local file name to read</param>
    /// <param name="imageName">Name to use in image file</param>
    virtual void AddFile(const xbString &localName, const xbString &imageName);

protected:
	virtual MPFStokenVersion GetTokenVersion() {return MPFStokenVersion_2m;}
	virtual void WriteImage(MPFS2Writer &w);
	virtual xbRefPtr<MPFS2Writer> MPFS2WriterCreate(MPFSOutputFormat format);
	virtual void contentTypeCheck(MPFSFileRecord *pFile,bool bUtf8);

    class __declspec(uuid("{A86D3BDC-4E14-4707-9759-0D6948C58338}"))  
		MPFS2mBINWriter : public MPFS2BINWriter
    {
	public:
		xbImplCreateObjectWithArg(MPFS2mBINWriter,MPFS2Writer,xbString);

		virtual bool GetInterface(REFIID riid, void ** ppInterf)
		{
			xbImplInterface(MPFS2mBINWriter);
			return MPFS2BINWriter::GetInterface(riid,ppInterf);
		}
		MPFS2mBINWriter()
		{
		}

		void Create(xbString filename)
        {
			MPFS2Writer::Create();
            if (!filename.EndWithNC(".bin") && !filename.EndWithNC(".mpfs2m"))
                filename += ".mpfs2m";
			fout.Open(filename,xbOpenCreateAlways,xbAccessW);
            imageName = filename;
        }
    };
};

#endif
