Source

lrc / src / example / ListResources.cxx

//      ListResources.cxx
//
//      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.


#include <iostream>
#include "../include/ResourceManager.hxx"


using namespace lrc;

void usage(void)
{
	std::cout << "Usage:\n./ListResources <rdfFile> [<compression Type>]\n";
};

int main(int argc, char **argv)
{
	ResourceManager *cliRes;
	lrc::CompressionType comprType = lrc::NoneCompression;
	char **cliList;
	int cliNum;


	if (argc < 2) {
		usage();
		return -1;
	};

	if (argc > 2) {
		comprType = static_cast<lrc::CompressionType> (atoi(argv[2]));
	};

	try {
		cliRes = new ResourceManager(argv[1], comprType, lrc::NoneEncryption, nullptr);
	} catch (lrcFileNotFoundException const &fnfE) {
		std::cout << fnfE.what() << std::endl;
		return -1;
	};

	cliList = cliRes->get_resource_ids(cliNum);

	for (int i=0; i<cliNum; i++) {
		std::cout << i << ". " << cliList[i] << "\n";
	};

	for (int i=cliNum-1; i>=0; i--) {
		delete[] cliList[i];
	};
	delete[] cliList;

	delete cliRes;
}