Easy Filesystem Initialization

A forum to store posts deemed exceptionally wise and useful
Post Reply
eXodus
Posts: 320
Joined: Tue Jan 04, 2005 10:07 am
Location: Canada
Contact:

Easy Filesystem Initialization

Post by eXodus »

This is a simple function that will add all of the .ZIP files found in the "data" directory to the Irrlicht's file system. I usually place it in a FileSystem.h header file.

Code: Select all

#pragma once

#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace io;

void initializeFileSystem(IrrlichtDevice * device)
{
	IFileSystem * fs = device->getFileSystem();
	fs->changeWorkingDirectoryTo("data");

	IFileList * fl = fs->createFileList();
	for(int i = 0; i < fl->getFileCount(); i++)
	{
		if(!fl->isDirectory(i))
		{
			// Only load ".zip" files
			stringc fn(fl->getFileName(i));
			if(fn.size() > 3)
			{
				stringc ext(fn.subString(fn.size() - 3, 3));
				if(ext.equals_ignore_case("zip"))
					fs->addZipFileArchive(fl->getFileName(i));
			}
		}
	}
	fl->drop();

	fs->changeWorkingDirectoryTo("..");
}
This is a time saver! Fell free to criticize.
Guest

Post by Guest »

I made something like this a while ago for my app, always very helpful to use ;)

what I would reccomend is having it pull the info from an xml file or something, what the directory is u want to check for zips, and the file extension u want to use. then instead of using 3 always for file extension, counting the amount of characters in the file extenstion specified :P

now, what would be awesome is if files loaded from one directory would overwrite the other ingame.....
Post Reply