Commit b9d62659 authored by hybrid's avatar hybrid

Allow to add folder archives with names without trailing slash. Added test to...

Allow to add folder archives with names without trailing slash. Added test to make sure the possible variants are checked.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3392 dfc29bdd-3216-0410-991c-e03cc46cb475
parent d46ccdbb
...@@ -206,7 +206,11 @@ bool CFileSystem::addFileArchive(const io::path& filename, bool ignoreCase, ...@@ -206,7 +206,11 @@ bool CFileSystem::addFileArchive(const io::path& filename, bool ignoreCase,
// check if the archive was already loaded // check if the archive was already loaded
for (i = 0; i < FileArchives.size(); ++i) for (i = 0; i < FileArchives.size(); ++i)
{ {
if (getAbsolutePath(filename) == FileArchives[i]->getFileList()->getPath()) // TODO: This should go into a path normalization method
// We need to check for directory names with trailing slash and without
const core::stringc absPath = getAbsolutePath(filename);
const core::stringc arcPath = FileArchives[i]->getFileList()->getPath();
if ((absPath == arcPath) || ((absPath+"/") == arcPath))
{ {
if (password.size()) if (password.size())
FileArchives[i]->Password=password; FileArchives[i]->Password=password;
...@@ -588,7 +592,7 @@ io::path& CFileSystem::flattenFilename(io::path& directory, const io::path& root ...@@ -588,7 +592,7 @@ io::path& CFileSystem::flattenFilename(io::path& directory, const io::path& root
} }
//! Creates a list of files and directories in the current working directory //! Sets the current file systen type
EFileSystemType CFileSystem::setFileListSystem(EFileSystemType listType) EFileSystemType CFileSystem::setFileListSystem(EFileSystemType listType)
{ {
EFileSystemType current = FileSystemType; EFileSystemType current = FileSystemType;
......
...@@ -27,16 +27,19 @@ CArchiveLoaderMount::CArchiveLoaderMount( io::IFileSystem* fs) ...@@ -27,16 +27,19 @@ CArchiveLoaderMount::CArchiveLoaderMount( io::IFileSystem* fs)
//! returns true if the file maybe is able to be loaded by this class //! returns true if the file maybe is able to be loaded by this class
bool CArchiveLoaderMount::isALoadableFileFormat(const io::path& filename) const bool CArchiveLoaderMount::isALoadableFileFormat(const io::path& filename) const
{ {
bool ret = false;
io::path fname(filename); io::path fname(filename);
deletePathFromFilename(fname); deletePathFromFilename(fname);
if (!fname.size()) if (!fname.size())
return true;
IFileList* list = FileSystem->createFileList();
if (list)
{ {
ret = true; // check if name is found as directory
if (list->findFile(filename, true))
return true;
} }
return false;
return ret;
} }
//! Check to see if the loader can create archives of this type. //! Check to see if the loader can create archives of this type.
...@@ -58,11 +61,11 @@ IFileArchive* CArchiveLoaderMount::createArchive(const io::path& filename, bool ...@@ -58,11 +61,11 @@ IFileArchive* CArchiveLoaderMount::createArchive(const io::path& filename, bool
EFileSystemType current = FileSystem->setFileListSystem(FILESYSTEM_NATIVE); EFileSystemType current = FileSystem->setFileListSystem(FILESYSTEM_NATIVE);
io::path save = FileSystem->getWorkingDirectory(); const io::path save = FileSystem->getWorkingDirectory();
io::path fullPath = FileSystem->getAbsolutePath(filename); io::path fullPath = FileSystem->getAbsolutePath(filename);
FileSystem->flattenFilename(fullPath); FileSystem->flattenFilename(fullPath);
if ( FileSystem->changeWorkingDirectoryTo ( fullPath ) ) if (FileSystem->changeWorkingDirectoryTo(fullPath))
{ {
archive = new CMountPointReader(FileSystem, fullPath, ignoreCase, ignorePaths); archive = new CMountPointReader(FileSystem, fullPath, ignoreCase, ignorePaths);
} }
......
...@@ -30,6 +30,7 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName) ...@@ -30,6 +30,7 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName)
if ( !fs->addFileArchive(archiveName, /*bool ignoreCase=*/true, /*bool ignorePaths=*/false) ) if ( !fs->addFileArchive(archiveName, /*bool ignoreCase=*/true, /*bool ignorePaths=*/false) )
{ {
logTestString("Mounting a second time failed\n"); logTestString("Mounting a second time failed\n");
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false; return false;
} }
...@@ -37,7 +38,33 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName) ...@@ -37,7 +38,33 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName)
if ( fs->getFileArchiveCount() != 1 ) if ( fs->getFileArchiveCount() != 1 )
{ {
logTestString("Duplicate mount not recognized\n"); logTestString("Duplicate mount not recognized\n");
return false; while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false;
}
if (fs->getFileArchive(0)->getType()==io::EFAT_FOLDER)
{
// mount again with different path end symbol (either with slash or without)
core::stringc newArchiveName=archiveName;
if (archiveName.lastChar()=='/')
newArchiveName.erase(newArchiveName.size()-1);
else
newArchiveName.append('/');
if ( !fs->addFileArchive(newArchiveName, /*bool ignoreCase=*/true, /*bool ignorePaths=*/false) )
{
logTestString("Mounting a second time with different name failed\n");
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false;
}
// make sure there is exactly one archive mounted
if ( fs->getFileArchiveCount() != 1 )
{
logTestString("Duplicate mount with different filename not recognized\n");
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false;
}
} }
// log what we got // log what we got
...@@ -53,6 +80,8 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName) ...@@ -53,6 +80,8 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName)
if (!fs->existFile(filename)) if (!fs->existFile(filename))
{ {
logTestString("existFile with deep path failed\n"); logTestString("existFile with deep path failed\n");
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false; return false;
} }
...@@ -60,6 +89,8 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName) ...@@ -60,6 +89,8 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName)
if (!fs->existFile(filename)) if (!fs->existFile(filename))
{ {
logTestString("existFile failed\n"); logTestString("existFile failed\n");
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false; return false;
} }
...@@ -67,6 +98,8 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName) ...@@ -67,6 +98,8 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName)
if ( !readFile ) if ( !readFile )
{ {
logTestString("createAndOpenFile failed\n"); logTestString("createAndOpenFile failed\n");
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false; return false;
} }
...@@ -75,6 +108,8 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName) ...@@ -75,6 +108,8 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName)
if (strncmp(tmp, "Hello world!", 12)) if (strncmp(tmp, "Hello world!", 12))
{ {
logTestString("Read bad data from archive: %s\n", tmp); logTestString("Read bad data from archive: %s\n", tmp);
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false; return false;
} }
if (!fs->removeFileArchive(fs->getFileArchiveCount()-1)) if (!fs->removeFileArchive(fs->getFileArchiveCount()-1))
...@@ -197,6 +232,10 @@ bool archiveReader() ...@@ -197,6 +232,10 @@ bool archiveReader()
return false; return false;
bool ret = true; bool ret = true;
logTestString("Testing mount file.\n");
ret &= testArchive(fs, "media/file_with_path");
logTestString("Testing mount file.\n");
ret &= testArchive(fs, "media/file_with_path/");
logTestString("Testing zip files.\n"); logTestString("Testing zip files.\n");
ret &= testArchive(fs, "media/file_with_path.zip"); ret &= testArchive(fs, "media/file_with_path.zip");
logTestString("Testing pak files.\n"); logTestString("Testing pak files.\n");
......
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