CMountPointReader expects ID to be a unique index into "CMountPointReader::RealFileNames". The first entry added to RealFilesNames (index 0) is added with an ID of 1. The second entry (index 1) is also added with an ID of 1.
Then, when you open a file via CMountPointReader::createAndOpenFile(first entry filename), it opens the file with an ID of 1 which actually opens the second file.
Test Case:
Code: Select all
void test4()
{
IrrlichtDevice* nd;
IFileSystem* fs;
IReadFile* rf;
IFileArchive* fa;
const IFileList* fl;
bool rc;
// CMountPointReader test
nd = createDevice(EDT_NULL);
fs = nd->getFileSystem();
rc = fs->addFileArchive("c:/scenes/", false, false, EFAT_FOLDER);
fa = fs->getFileArchive(0);
fl = fa->getFileList();
u32 count = fl->getFileCount();
for(u32 i=0; i<count; i++)
{
printf(" fileName: %s\n", fl->getFileName(i).c_str());
printf(" isDir: %d\n", fl->isDirectory(i));
printf(" FullFileName: %s\n", fl->getFullFileName(i).c_str());
printf(" Path: %s\n", fl->getPath().c_str());
printf(" ID: %d\n", fl->getID(i));
printf("\n");
}
rf = fs->createAndOpenFile("mdl/Cube.irrmesh");
if(rf)
{
printf("open mdl/Cube.irrmesh success.\n");
printf("rf->getFileName(): %s\n", rf->getFileName().c_str());
}
else
{
printf("open mdl/Cube.irrmesh failed.\n");
}
if(rf)
rf->drop();
nd->drop();
}
Code: Select all
c:/scenes/
irrb.log
mdl/
mdl/Cube.irrmesh
Scene.irr
tex/
Code: Select all
Irrlicht Engine version 1.7.1-beta
Microsoft Windows 7 Ultimate Edition (Build 7
fileName: mdl
isDir: 1
FullFileName: mdl
Path: c:/scenes/
ID: 0
fileName: tex
isDir: 1
FullFileName: tex
Path: c:/scenes/
ID: 0
fileName: irrb.log
isDir: 0
FullFileName: irrb.log
Path: c:/scenes/
ID: 1
fileName: cube.irrmesh
isDir: 0
FullFileName: mdl/cube.irrmesh
Path: c:/scenes/
ID: 0
fileName: scene.irr
isDir: 0
FullFileName: scene.irr
Path: c:/scenes/
ID: 2
open mdl/Cube.irrmesh success.
rf->getFileName(): c:/scenes/mdl/cube.irrmesh
Code: Select all
Irrlicht Engine version 1.7.1-beta
Microsoft Windows 7 Ultimate Edition (Build 7600)
fileName: mdl
isDir: 1
FullFileName: mdl
Path: c:/scenes/
ID: 0
fileName: tex
isDir: 1
FullFileName: tex
Path: c:/scenes/
ID: 2
fileName: irrb.log
isDir: 0
FullFileName: irrb.log
Path: c:/scenes/
ID: 1
fileName: cube.irrmesh
isDir: 0
FullFileName: mdl/cube.irrmesh
Path: c:/scenes/
ID: 1
fileName: scene.irr
isDir: 0
FullFileName: scene.irr
Path: c:/scenes/
ID: 2
open mdl/Cube.irrmesh success.
rf->getFileName(): c:/scenes/irrb.log <------ problem
Code: Select all
Index: source/Irrlicht/CMountPointReader.cpp
===================================================================
--- source/Irrlicht/CMountPointReader.cpp (revision 3382)
+++ source/Irrlicht/CMountPointReader.cpp (working copy)
@@ -118,7 +118,7 @@
if (!list->isDirectory(i))
{
- addItem(full, list->getFileOffset(i), list->getFileSize(i), false, RealFileNames.size());
+ addItem(full, list->getFileOffset(i), list->getFileSize(i), false, RealFileNames.size()+1);
RealFileNames.push_back(list->getFullFileName(i));
}
else
@@ -148,7 +148,7 @@
if (index >= Files.size())
return 0;
- return createReadFile(RealFileNames[Files[index].ID]);
+ return createReadFile(RealFileNames[Files[index].ID-1]);
}
//! opens a file by file name