Commit 09cd4c38 authored by cutealien's avatar cutealien

bugfix: CMountPointReader::openFile no longer returns file for empty...

bugfix: CMountPointReader::openFile no longer returns file for empty filenames. Corresponding test added.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2421 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 23cfb47e
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#ifndef _IRR_USE_NON_SYSTEM_ZLIB_ #ifndef _IRR_USE_NON_SYSTEM_ZLIB_
#include <zlib.h> // use system lib #include <zlib.h> // use system lib
#else // _IRR_USE_NON_SYSTEM_ZLIB_ #else // _IRR_USE_NON_SYSTEM_ZLIB_
#include "zlib/zlib.h" #include "zlib/zlib.h"
#endif // _IRR_USE_NON_SYSTEM_ZLIB_ #endif // _IRR_USE_NON_SYSTEM_ZLIB_
#endif // _IRR_COMPILE_WITH_ZLIB_ #endif // _IRR_COMPILE_WITH_ZLIB_
...@@ -58,7 +58,7 @@ IFileArchive* CArchiveLoaderZIP::createArchive(const core::string<c16>& filename ...@@ -58,7 +58,7 @@ IFileArchive* CArchiveLoaderZIP::createArchive(const core::string<c16>& filename
archive = createArchive ( file, ignoreCase, ignorePaths ); archive = createArchive ( file, ignoreCase, ignorePaths );
file->drop (); file->drop ();
} }
return archive; return archive;
} }
...@@ -108,7 +108,7 @@ CZipReader::CZipReader(IReadFile* file, bool ignoreCase, bool ignorePaths) ...@@ -108,7 +108,7 @@ CZipReader::CZipReader(IReadFile* file, bool ignoreCase, bool ignorePaths)
Base.replace ( '\\', '/' ); Base.replace ( '\\', '/' );
// scan local headers // scan local headers
while (scanLocalHeader()); while (scanLocalHeader()) ;
//while (scanLocalHeader2()); //while (scanLocalHeader2());
// prepare file index for binary search // prepare file index for binary search
...@@ -136,7 +136,7 @@ void CZipReader::extractFilename(SZipFileEntry* entry) ...@@ -136,7 +136,7 @@ void CZipReader::extractFilename(SZipFileEntry* entry)
entry->zipFileName.make_lower(); entry->zipFileName.make_lower();
const c16* p = entry->zipFileName.c_str() + lorfn; const c16* p = entry->zipFileName.c_str() + lorfn;
// suche ein slash oder den anfang. // suche ein slash oder den anfang.
while (*p!='/' && p!=entry->zipFileName.c_str()) while (*p!='/' && p!=entry->zipFileName.c_str())
...@@ -161,7 +161,7 @@ void CZipReader::extractFilename(SZipFileEntry* entry) ...@@ -161,7 +161,7 @@ void CZipReader::extractFilename(SZipFileEntry* entry)
if (thereIsAPath) if (thereIsAPath)
{ {
lorfn = (s32)(p - entry->zipFileName.c_str()); lorfn = (s32)(p - entry->zipFileName.c_str());
entry->path = entry->zipFileName.subString ( 0, lorfn ); entry->path = entry->zipFileName.subString ( 0, lorfn );
//entry->path.append(entry->zipFileName, lorfn); //entry->path.append(entry->zipFileName, lorfn);
...@@ -366,8 +366,8 @@ IReadFile* CZipReader::openFile(s32 index) ...@@ -366,8 +366,8 @@ IReadFile* CZipReader::openFile(s32 index)
case 8: case 8:
{ {
#ifdef _IRR_COMPILE_WITH_ZLIB_ #ifdef _IRR_COMPILE_WITH_ZLIB_
const u32 uncompressedSize = e.header.DataDescriptor.UncompressedSize; const u32 uncompressedSize = e.header.DataDescriptor.UncompressedSize;
const u32 compressedSize = e.header.DataDescriptor.CompressedSize; const u32 compressedSize = e.header.DataDescriptor.CompressedSize;
void* pBuf = new c8[ uncompressedSize ]; void* pBuf = new c8[ uncompressedSize ];
...@@ -389,7 +389,7 @@ IReadFile* CZipReader::openFile(s32 index) ...@@ -389,7 +389,7 @@ IReadFile* CZipReader::openFile(s32 index)
//memset(pcData, 0, compressedSize ); //memset(pcData, 0, compressedSize );
File->seek( e.fileDataPosition ); File->seek( e.fileDataPosition );
File->read(pcData, compressedSize ); File->read(pcData, compressedSize );
// Setup the inflate stream. // Setup the inflate stream.
z_stream stream; z_stream stream;
s32 err; s32 err;
...@@ -415,7 +415,7 @@ IReadFile* CZipReader::openFile(s32 index) ...@@ -415,7 +415,7 @@ IReadFile* CZipReader::openFile(s32 index)
delete[] pcData; delete[] pcData;
if (err != Z_OK) if (err != Z_OK)
{ {
swprintf ( buf, 64, L"Error decompressing %s", e.simpleFileName.c_str() ); swprintf ( buf, 64, L"Error decompressing %s", e.simpleFileName.c_str() );
...@@ -425,7 +425,7 @@ IReadFile* CZipReader::openFile(s32 index) ...@@ -425,7 +425,7 @@ IReadFile* CZipReader::openFile(s32 index)
} }
else else
return io::createMemoryReadFile(pBuf, uncompressedSize, e.zipFileName, true); return io::createMemoryReadFile(pBuf, uncompressedSize, e.zipFileName, true);
#else #else
return 0; // zlib not compiled, we cannot decompress the data. return 0; // zlib not compiled, we cannot decompress the data.
#endif #endif
...@@ -454,7 +454,7 @@ const IFileArchiveEntry* CZipReader::getFileInfo(u32 index) ...@@ -454,7 +454,7 @@ const IFileArchiveEntry* CZipReader::getFileInfo(u32 index)
//! return the id of the file Archive //! return the id of the file Archive
const core::string<c16>& CZipReader::getArchiveName () const core::string<c16>& CZipReader::getArchiveName ()
{ {
return Base; return Base;
} }
...@@ -603,6 +603,9 @@ void CMountPointReader::buildDirectory ( ) ...@@ -603,6 +603,9 @@ void CMountPointReader::buildDirectory ( )
//! opens a file by file name //! opens a file by file name
IReadFile* CMountPointReader::openFile(const core::string<c16>& filename) IReadFile* CMountPointReader::openFile(const core::string<c16>& filename)
{ {
if ( !filename.size() )
return 0;
core::string<c16> fname ( Base ); core::string<c16> fname ( Base );
fname += filename; fname += filename;
...@@ -629,7 +632,7 @@ s32 CMountPointReader::findFile(const core::string<c16>& filename) ...@@ -629,7 +632,7 @@ s32 CMountPointReader::findFile(const core::string<c16>& filename)
#else #else
//! compatible Folder Archticture //! compatible Folder Archticture
// //
CMountPointReader::CMountPointReader( IFileSystem * parent, const core::string<c16>& basename, bool ignoreCase, bool ignorePaths) CMountPointReader::CMountPointReader( IFileSystem * parent, const core::string<c16>& basename, bool ignoreCase, bool ignorePaths)
: CZipReader( 0, ignoreCase, ignorePaths ), Parent ( parent ) : CZipReader( 0, ignoreCase, ignorePaths ), Parent ( parent )
{ {
......
#include "irrlicht.h"
#include "testUtils.h"
using namespace irr;
using namespace core;
using namespace io;
bool filesystem(void)
{
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1));
assert(device);
if(!device)
return false;
io::IFileSystem * fs = device->getFileSystem ();
if ( !fs )
return false;
bool result = true;
core::string<c16> workingDir = device->getFileSystem()->getWorkingDirectory();
core::string<c16> empty;
if ( fs->existFile(empty) )
{
logTestString("Empty filename should not exist.\n");
result = false;
}
stringc newWd = workingDir + "/media";
bool changed = device->getFileSystem()->changeWorkingDirectoryTo(newWd);
assert(changed);
if ( fs->existFile(empty) )
{
logTestString("Empty filename should not exist even in another workingdirectory.\n");
result = false;
}
// The working directory must be restored for the other tests to work.
changed = device->getFileSystem()->changeWorkingDirectoryTo(workingDir.c_str());
assert(changed);
// adding a folder archive which just should not really change anything
device->getFileSystem()->addFolderFileArchive( "./" );
if ( fs->existFile(empty) )
{
logTestString("Empty filename should not exist in folder file archive.\n");
result = false;
}
// remove it again to not affect other tests
device->getFileSystem()->unregisterFileArchive( device->getFileSystem()->getFileArchiveCount() );
return result;
}
...@@ -57,6 +57,7 @@ int main(int argumentCount, char * arguments[]) ...@@ -57,6 +57,7 @@ int main(int argumentCount, char * arguments[])
// process. // process.
TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory. TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory.
TEST(filesystem);
TEST(zipReader); TEST(zipReader);
TEST(exports); TEST(exports);
TEST(sceneCollisionManager); TEST(sceneCollisionManager);
......
Test suite pass at GMT Thu Jun 11 22:44:22 2009 Test suite pass at GMT Mon Jun 15 15:44:00 2009
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment