//Copyright (C) 2007 SiegeLord
//See ReadMe.txt and License.txt for copying information

#pragma once

#include "engine.h"

//a folder type
struct SFolder
{
	string name;				//name of the folder
	string full_name;			//full path appended to the files

	SFolder* root;				//root

	vector<SFolder*> children;	//the children folders
	vector<string> files;

	~SFolder()
	{
		const int size = children.size();
		FOR1(size)
			delete children[ii];
	}
};

extern string g_sDataFolder;

void InitFileIO(const char* datafolder, const char* modzip);
void DeInitFileIO();

//loads the data zip file
void LoadDataZip();
void UnloadDataZip();

//loads the mod zip file
void LoadModZip(const char* filename);
void UnloadModZip();

//loads a file
PACKFILE* LoadFile(const char* filename);
void CloseFile(PACKFILE* file);

//reads a file to a buffer
int ReadFile(PACKFILE* file, void** buffer);

//fills out a folder with filenames/folders with a particular extension
void ParseFolder(SFolder* folder, const char* path, const char* extension);

//dumps all file names into an array
void DumpFilesIntoArray(SFolder* folder, vector<string>* array);

//does stuff for each file in a folder
void ForEachFile(SFolder* folder, void (*callback)(const char *filename, const char* name, void *param), void *param);
