Source

lrc / src / compiler / Collector.hxx

//      Collector.hxx
//
//      Copyright 2011, 2012 Andreas Tscharner <andy@vis.ethz.ch>
//
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU Lesser General Public License as
//      published by the Free Software Foundation; either version 3 of the
//      License, or (at your option) any later version.
//
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//
//      You should have received a copy of the GNU Lesser General Public
//      License along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.


/*! \file Collector.hxx
 *
 * This file contains the class definition of the collector class that is
 * responsible to collect all resource data
 *
 * \author Andreas Tscharner
 * \date 2012-05-06
 */


#ifndef __COLLECTOR_HXX__
#define __COLLECTOR_HXX__


// Include files
#include <vector>
#include "../lrcExceptions.hxx"
#include "../ResourceData.hxx"


/*! \class Collector
 *  \brief Class to collect all resource data
 *
 * This class collects all files that are defined as resource data and
 * generates one big file from them
 */
class Collector
{
	private:
		char *m_rcName;                //!< Filename of .rc file
		char *m_rdfName;               //!< Filename for .rdf file

		/*! \brief Check for unique resource IDs
		 *
		 * This method checks if there are alle resource IDs unique and
		 * returns a warning if they are not
		 *
		 * \param[in] p_entries List of resource data (of type resEntry)
		 * \param[out] p_doubleIDPos Position of double ID
		 * \param[out] p_doubleID Resource ID that is not unique
		 *
		 * \retval NO_ERROR All IDs are unique
		 * \retval WARNING_DOUBLE_RESOURCE_ID A resource ID appears more
		 *                                    than once
		 * \retval ERROR_INVALID_PARAMETER One or more parameters are
		 *                                 invalid
		 *
		 * \remarks The caller is responsible to free the string containing
		 *          the name of the resource ID that appears more than once
		 */
		int are_resIDs_unique(std::vector<ResourceData *>, inFilePosition &, char **);

		/*! \brief Show error message from resource data
		 *
		 * This method shows an appropriate error message if the return
		 * value from the ResourceData class indicates an error
		 *
		 * \param[in] p_errorCode Error code
		 * \param[in] p_resData ResourceData instance that caused the error
		 */
		void show_resource_data_error(int, ResourceData *);

	public:
		/*! \brief Constructor
		 *
		 * Ths constructor is responsible to set up the class for collecting
		 * the resource data. It expects a filename for the .rdf file and a
		 * flag indicating whether or not overwriting is allowed
		 *
		 * \param[in] p_rcName Filename of rc file
		 * \param[in] p_rdfName Filename for .rdf file
		 * \param[in] p_overwriteAllow Flag indicating that overwriting is
		 *                             allowed (or not)
		 *
		 * \exception lrcFileExistsException Exception that is thrown if the
		 * given .rdf file exists and the overwrite flag indicates that
		 * overwriting is forbidden
		 */
		Collector(char *, char *, bool) throw(lrcFileExistsException);
		/*! \brief Destructor
		 *
		 * Clean up the memory that was needed by the class
		 */
		~Collector(void);

		/*! \brief Collect, compress and encrypt data
		 *
		 * This method collects all resource data files, reads them into
		 * memory, compresses and encrypts it if desired and finally
		 * generates the one big resource file.
		 *
		 * \param[in] p_resEntries Collection of data resource entries
		 * \param[in] p_compress Compression type for complete file
		 * \param[in] p_encrypt Encryption type for complete file
		 * \param[in] p_key Password if encryption is requested
		 *
		 * \retval NO_ERROR Resource Data File successfully compiled
		 * \retval ERROR_FILE_OPEN An error occurred opening the rdf file
		 * \retval ERROR_FILE_NOT_FOUND The desired resource data file could
		 *                              not be found
		 * \retval ERROR_INVALID_PARAMETER The provided parameter was nullptr
		 * \retval ERROR_FILE_NOT_FOUND The resource file could not be found
		 * \retval ERROR_COMPRESSION_NOT_AVAILABLE The selected compression
		 *                                         is not available
		 * \retval ERROR_COMPRESSION_COMPRESS An error occurred while
		 *                                    compressing the complete file
		 * \retval ERROR_ENCRYPTION_NOT_AVAILABLE The selected encryption is
		 *                                        not availale
		 * \retval ERROR_ENCRYPTION_ENCRYPT An error occurred while
		 *                                  encrypting the complete file
		 * \retval ERROR_FILE_READ An error occurred while reading the file
		 * \retval ERROR_FILE_WRITE An error occurred while writing the file
		 */
		int collect(std::vector<ResourceData *> *, lrc::CompressionType, lrc::EncryptionType, const unsigned char *);
};


#endif /* __COLLECTOR_HXX__ */