Order of files added to file archive

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
PumpkinPieman
Posts: 13
Joined: Fri Apr 20, 2007 4:35 pm

Order of files added to file archive

Post by PumpkinPieman »

I've been fooling around with this for a while trying to get it all to work but nothing seems to work.


How does the ordering and overlapping of files within archives work?

Say I add a folder and I add a zip file, both of these have the same file inside, different data. Does it choose the last loaded, first loaded, or both?

Code: Select all

	fs->addZipFileArchive((boost::format("%1%.zip")%modName).str().c_str(), false, false);
	fs->addFolderFileArchive(modName, false, false);
The zip archive has a texture in it that's the original, the folder has an image with the same name that's different. Now it doesn't matter which one of these lines I execute first, it will only select the files in the zip file. So I never get the modified version.

Now sure why either...
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You should probably take a few minutes to look at the source code. I mean, you already have it on your machine and the answers you seek are in there for the taking.

Since I've alreay looked, I'll give you the answer. The createAndOpenFile() call looks through the .zip file systems [in the order they are added], then it looks through the .pak file systems [in the order they were added], then it looks through the folder file systems [in the order they were added], then it tries to create/open the file from the working directory.

So, in your example, you have <modname>.zip and a directory named <modname>. If you try to access image.jpg that is in the .zip and in the directory, it will give you back the one that is in the zip archive.

Travis
PumpkinPieman
Posts: 13
Joined: Fri Apr 20, 2007 4:35 pm

Post by PumpkinPieman »

Hmmm. Here's my dilema.

The order in which the files are to be loaded depend on the mod

default.zip
default/
<modname>.zip
<modname>/

So each consecutive add replace files that previously exist in the file archive. However say I add each of these in this order, if I try and find one of those textures when I'm in the /mod/ directory it will look for it in that directory, then it will go to the parent mapped directory and check that. I want it to have one list of files that get overwritten by others. (if you want them over written)
So all folders\zips can have texture.jpg, but only the last one loaded has the texture that is actually loaded.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I don't understand why this is a big issue. You want your plugin system to search for files in a specific way and Irrlicht doesn't do it that way. You have to write some code and probably rebuild the Irrlicht library. Simple as that.

Travis
PumpkinPieman
Posts: 13
Joined: Fri Apr 20, 2007 4:35 pm

Post by PumpkinPieman »

First, you don't have to sound defensive about the topic. I was just asking about the process and if it were possible. Recompiling the library isn't a hassle, just pinpointing where the changes need to be made takes a little longer.

Am I to assume that all other classes in Irrlicht use CFileSystem::createAndOpenFile() as the main function for opening files?

Taking a look at this function it checks all zip files, then pak, then folders. But how does the current directory play in this scenario? For example I have data\default.zip and data\default\. When the current directory is set to data\default\ it prefers files from that folder over the zip file. But how can that be possible if it checks the zip files and returns an IReadFile before it does a createReadFile?
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

You would have to modify the Irrlicht engine to read from the directory first before reading from a file archive. As you saw, it reads from the archives in the order they were added, starting with zip, then pak, then "unzip". If the file is still not found, it reads from the current directory.

If you really want to read from the current directory first, here is the altered function in CFileSystem.cpp:

Code: Select all

//! opens a file for read access
IReadFile* CFileSystem::createAndOpenFile(const c8* filename)
{
	IReadFile* file = 0;
	u32 i;

	file = createReadFile(filename);
	if ( file )
		return file;

	for ( i=0; i<ZipFileSystems.size(); ++i)
	{
		file = ZipFileSystems[i]->openFile(filename);
		if (file)
			return file;
	}

	for ( i = 0; i<PakFileSystems.size(); ++i)
	{
		file = PakFileSystems[i]->openFile(filename);
		if (file)
			return file;
	}

	for ( i = 0; i<UnZipFileSystems.size(); ++i)
	{
		file = UnZipFileSystems[i]->openFile(filename);
		if (file)
			return file;
	}

	return 0;
}
PumpkinPieman
Posts: 13
Joined: Fri Apr 20, 2007 4:35 pm

Post by PumpkinPieman »

Yeah, I tinkered around with the engine a little bit and got the desired effect I was looking for. Thanks! :D
Post Reply