// ---------------------------------------------------------------------------
// 
//   Lily Engine alpha
// 
//   Copyright (c) 2010 Clifford Jolly
//     http://cliffjolly.com
//     cliff@cliffjolly.com
// 
// ---------------------------------------------------------------------------
// 
//   This program is free software; you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation; either version 2 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 General Public License
//   along with this program; if not, write to the Free Software
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
//   USA
// -------------------------- END HEADER -------------------------------------

#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

#include "filesystem.h"
#include "archive.h"
using namespace FileSystem;

int main(int argc, char *argv[]) {

	vector<string> fileList;
	
	getAllFiles(".", fileList);

	for(int i = 0; i < (int)fileList.size(); i++) {
		cout << setw(20) << right << fileList[i] << " ";
		if(isDir(fileList[i])) {
			cout << "<DIR>" << endl;
		} else {
			cout << setw(20) << left << getFileSize(fileList[i]) << endl;
		}
	}


	int dataLen;
	char *data = loadFile("TODO", &dataLen);
	if(data) {
		for(int i = 0; i < dataLen; i++) {
			char c = data[i];
			cout << setfill('0') << setw(2) << right <<setbase(16) << (int)c << " " << c << endl;
		}
  	} else {
		cout << "Couldn't open \"TODO\"" << endl;
	}

	if(saveFile("TODO_copy", data, dataLen)) {
		cout << "Save fail." << endl;
	}

	deleteFile("TODO_copy");

	
	copyFile("README", "test1");
	copyFile("TODO", "test1");

	
	Archive *testArc = new Archive("testArc.fuk", true);
	testArc->addFile("sometestdata", data, dataLen);
	testArc->addFile("monkeyballs", data, dataLen);
	testArc->addFile("fuckpiss/damnshit", data, dataLen);
	testArc->addFile("warg", data, dataLen);
	testArc->addFile("foooooooooo/bar", data, dataLen);
	testArc->addFile("ASDF ASDF ASDF ASDF", data, dataLen);
	testArc->addFile("*.*", data, dataLen);
	delete testArc;

	testArc = new Archive("testArc.fuk");

	int dumpLen;
	char *dump = testArc->loadFile("warg", &dumpLen);
	delete testArc;

	saveFile("warg.txt", dump, dumpLen);


	delete data;

	return 0;
}


