[/Edit]MasterGod's post from below wrote:Just to conclude this thread.
The following patch is a code I'm testing for more then two weeks now.
It works perfectly and under linux there's the only problem when choosing to ignore case but this bug is well known for the whole file system.
I've done many testings and it works just fine.
I hope you like it:Tested under:Code: Select all
Index: source/Irrlicht/CZipReader.cpp =================================================================== --- source/Irrlicht/CZipReader.cpp (revision 1309) +++ source/Irrlicht/CZipReader.cpp (working copy) @@ -374,27 +374,90 @@ Base += "/"; } + core::stringc Buf = Parent->getWorkingDirectory(); + + Parent->changeWorkingDirectoryTo ( basename ); + buildDirectory ( ); + Parent->changeWorkingDirectoryTo ( Buf.c_str() ); + + FileList.sort(); } void CUnZipReader::buildDirectory ( ) { + IFileList * list = new CFileList(); + + SZipFileEntry entry; + + const u32 size = list->getFileCount(); + for (u32 i = 0; i!= size; ++i) + { + if ( !list->isDirectory( i ) ) + { + entry.zipFileName = list->getFullFileName ( i ); + entry.header.FilenameLength = entry.zipFileName.size (); + extractFilename(&entry); + FileList.push_back(entry); + } + else + { + const c8 * rel = list->getFileName ( i ); + + if (rel[0] != '.') + { + Parent->changeWorkingDirectoryTo ( rel ); + buildDirectory (); + Parent->changeWorkingDirectoryTo ( ".." ); + } + } + } + + list->drop (); } //! opens a file by file name IReadFile* CUnZipReader::openFile(const c8* filename) { - core::stringc fname; - fname = Base; - fname += filename; + SZipFileEntry entry; + core::stringc fileName = core::stringc(filename); + if ( IgnoreCase ) + { + Base.make_lower(); + fileName.make_lower(); + filename = fileName.c_str(); + } - CUnzipReadFile* file = new CUnzipReadFile( fname, filename); + if ( IgnorePaths ) + { + entry.simpleFileName = filename; + s32 index = FileList.binary_search(entry); + if(-1 == index) + return 0; + + entry = FileList[index]; + } + else + { + entry.zipFileName = Base; + entry.zipFileName += filename; + s32 i = fileName.findLastChar("\\/",2); + if (-1 == i) + { + entry.simpleFileName = filename; + } + else + { + entry.simpleFileName = fileName.subString( i+1, fileName.size() ); + } + } + + CUnzipReadFile* file = new CUnzipReadFile( entry.zipFileName, entry.simpleFileName.c_str() ); if (file->isOpen()) return file; file->drop(); return 0; - } //! returns fileindex @@ -480,3 +543,5 @@ } // end namespace io } // end namespace irr + +
1. Windows XP SP2, trunk revision 1309.
2. Linux Mint 4 (Based on Ubuntu), trunk revision 1309.
Tested with all combinations of 'ignorance' (lol) (true, true || false, false || true,false || false,true) and the behavior is as expected.
Also uploaded to the tracker:
http://sourceforge.net/tracker/index.ph ... tid=540678
I hope you like it![]()
Cya.
Post from below holding the latest fix - UP.
Original Post - DOWN.
The method is bugged in a way that when you give it a parent directory it doesn't scan right all the files and sub directories of that parent folder.hybrid wrote:The UnzipFolder is, just as md3, color chooser, and some other stuff, untested and mostly unfinished additions from one of the non-regular developers of Irrlicht. If you have worked with this code and know what it should do and how it should be implemented just tell us - we'll fix it then.
Problem - This code will log "can't find files":
Code: Select all
device->getFileSystem()->addFolderFileArchive("../../");
IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
/*
To let the mesh look a little bit nicer, we change its material a
little bit: We disable lighting because we do not have a dynamic light
in here, and the mesh would be totally black. Then we set the frame
loop, so that the animation is looped between the frames 0 and 310.
And at last, we apply a texture to the mesh. Without it the mesh
would be drawn using only a color.
*/
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation ( scene::EMAT_STAND );
node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );Code: Select all
Index: CZipReader.cpp
===================================================================
--- CZipReader.cpp (revision 1286)
+++ CZipReader.cpp (working copy)
@@ -374,27 +374,83 @@
Base += "/";
}
+ core::stringc Buf = Parent->getWorkingDirectory();
+
+ Parent->changeWorkingDirectoryTo ( basename );
+ buildDirectory ( );
+ Parent->changeWorkingDirectoryTo ( Buf.c_str() );
+
+ FileList.sort();
}
void CUnZipReader::buildDirectory ( )
{
+ IFileList * list = new CFileList();
+
+ SZipFileEntry entry;
+
+ const u32 size = list->getFileCount();
+ for (u32 i = 0; i!= size; ++i)
+ {
+ if ( !list->isDirectory( i ) )
+ {
+ entry.zipFileName = list->getFullFileName ( i );
+ entry.header.FilenameLength = entry.zipFileName.size ();
+ extractFilename(&entry);
+ FileList.push_back(entry);
+ }
+ else
+ {
+ const c8 * rel = list->getFileName ( i );
+
+ if (rel[0] != '.')
+ {
+ Parent->changeWorkingDirectoryTo ( rel );
+ buildDirectory ();
+ Parent->changeWorkingDirectoryTo ( ".." );
+ }
+ }
+ }
+
+ list->drop ();
}
//! opens a file by file name
IReadFile* CUnZipReader::openFile(const c8* filename)
{
- core::stringc fname;
- fname = Base;
- fname += filename;
+ SZipFileEntry entry;
+ if ( IgnorePaths )
+ {
+ entry.simpleFileName = filename;
+ s32 index = FileList.binary_search(entry);
+ if(-1 == index)
+ return 0;
- CUnzipReadFile* file = new CUnzipReadFile( fname, filename);
+ entry = FileList[index];
+ }
+ else
+ {
+ entry.zipFileName = Base;
+ entry.zipFileName += filename;
+ core::stringc fileName = filename;
+ s32 i = fileName.findLastChar("\\/",3);
+ if (-1 == i)
+ {
+ entry.simpleFileName = filename;
+ }
+ else
+ {
+ entry.simpleFileName = fileName.subString( i+1, fileName.size() );
+ }
+ }
+
+ CUnzipReadFile* file = new CUnzipReadFile( entry.zipFileName, filename);
if (file->isOpen())
return file;
file->drop();
return 0;
-
}
//! returns fileindex
P.S
I'm wondering, does posting patches here is the best way to get it noticed or should I upload to the tracker or some other method
