Commit eed14a0e authored by hybrid's avatar hybrid

Add new methods for adding and removing file archives based on ifilearchive...

Add new methods for adding and removing file archives based on ifilearchive pointers. The existing methods are also enhanced by an optional return value of the newly added archive. Addition suggested and coded by Nalin.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3958 dfc29bdd-3216-0410-991c-e03cc46cb475
parent c7ea8077
......@@ -111,11 +111,13 @@ public:
you use a different extension then you can use this parameter to force
a specific type of archive.
\param password An optional password, which is used in case of encrypted archives.
\param retArchive A pointer that will be set to the archive that is added.
\return True if the archive was added successfully, false if not. */
virtual bool addFileArchive(const path& filename, bool ignoreCase=true,
bool ignorePaths=true,
E_FILE_ARCHIVE_TYPE archiveType=EFAT_UNKNOWN,
const core::stringc& password="") =0;
const core::stringc& password="",
IFileArchive** retArchive=0) =0;
//! Adds an archive to the file system.
/** After calling this, the Irrlicht Engine will also search and open
......@@ -141,18 +143,26 @@ public:
you use a different extension then you can use this parameter to force
a specific type of archive.
\param password An optional password, which is used in case of encrypted archives.
\param retArchive A pointer that will be set to the archive that is added.
\return True if the archive was added successfully, false if not. */
virtual bool addFileArchive(IReadFile* file, bool ignoreCase=true,
bool ignorePaths=true,
E_FILE_ARCHIVE_TYPE archiveType=EFAT_UNKNOWN,
const core::stringc& password="") =0;
const core::stringc& password="",
IFileArchive** retArchive=0) =0;
//! Adds an archive to the file system.
/** \param archive: The archive to add to the file system.
\return True if the archive was added successfully, false if not. */
virtual bool addFileArchive(IFileArchive* archive) =0;
//! Get the number of archives currently attached to the file system
virtual u32 getFileArchiveCount() const =0;
//! Removes an archive from the file system.
/** This will close the archive and free any file handles, but will not close resources which have already
been loaded and are now cached, for example textures and meshes.
/** This will close the archive and free any file handles, but will not
close resources which have already been loaded and are now cached, for
example textures and meshes.
\param index: The index of the archive to remove
\return True on success, false on failure */
virtual bool removeFileArchive(u32 index) =0;
......@@ -164,13 +174,21 @@ public:
interpreted differently on each call, depending on the current working
directory. In case you want to remove an archive that was added using
a relative path name, you have to change to the same working directory
again. This means, that the filename given on creation is not an identifier
for the archive, but just a usual filename that is used for locating the
archive to work with.
again. This means, that the filename given on creation is not an
identifier for the archive, but just a usual filename that is used for
locating the archive to work with.
\param filename The archive pointed to by the name will be removed
\return True on success, false on failure */
virtual bool removeFileArchive(const path& filename) =0;
//! Removes an archive from the file system.
/** This will close the archive and free any file handles, but will not
close resources which have already been loaded and are now cached, for
example textures and meshes.
\param archive The archive to remove.
\return True on success, false on failure */
virtual bool removeFileArchive(const IFileArchive* archive) =0;
//! Changes the search order of attached archives.
/**
\param sourceIndex: The index of the archive to change
......
......@@ -212,13 +212,14 @@ bool CFileSystem::moveFileArchive(u32 sourceIndex, s32 relative)
//! Adds an archive to the file system.
bool CFileSystem::addFileArchive(const io::path& filename, bool ignoreCase,
bool ignorePaths, E_FILE_ARCHIVE_TYPE archiveType,
const core::stringc& password)
const core::stringc& password,
IFileArchive** retArchive)
{
IFileArchive* archive = 0;
bool ret = false;
// see if archive is already added
if (changeArchivePassword(filename, password))
if (changeArchivePassword(filename, password, retArchive))
return true;
s32 i;
......@@ -303,6 +304,8 @@ bool CFileSystem::addFileArchive(const io::path& filename, bool ignoreCase,
FileArchives.push_back(archive);
if (password.size())
archive->Password=password;
if (retArchive)
*retArchive = archive;
ret = true;
}
else
......@@ -315,7 +318,9 @@ bool CFileSystem::addFileArchive(const io::path& filename, bool ignoreCase,
}
// don't expose!
bool CFileSystem::changeArchivePassword(const path& filename, const core::stringc& password)
bool CFileSystem::changeArchivePassword(const path& filename,
const core::stringc& password,
IFileArchive** archive)
{
for (s32 idx = 0; idx < (s32)FileArchives.size(); ++idx)
{
......@@ -327,6 +332,8 @@ bool CFileSystem::changeArchivePassword(const path& filename, const core::string
{
if (password.size())
FileArchives[idx]->Password=password;
if (archive)
*archive = FileArchives[idx];
return true;
}
}
......@@ -334,15 +341,16 @@ bool CFileSystem::changeArchivePassword(const path& filename, const core::string
return false;
}
bool CFileSystem::addFileArchive(IReadFile* file, bool ignoreCase, bool ignorePaths,
E_FILE_ARCHIVE_TYPE archiveType, const core::stringc& password)
bool CFileSystem::addFileArchive(IReadFile* file, bool ignoreCase,
bool ignorePaths, E_FILE_ARCHIVE_TYPE archiveType,
const core::stringc& password, IFileArchive** retArchive)
{
if (!file || archiveType == EFAT_FOLDER)
return false;
if (file)
{
if (changeArchivePassword(file->getFileName(), password))
if (changeArchivePassword(file->getFileName(), password, retArchive))
return true;
IFileArchive* archive = 0;
......@@ -402,6 +410,8 @@ bool CFileSystem::addFileArchive(IReadFile* file, bool ignoreCase, bool ignorePa
FileArchives.push_back(archive);
if (password.size())
archive->Password=password;
if (retArchive)
*retArchive = archive;
return true;
}
else
......@@ -414,6 +424,22 @@ bool CFileSystem::addFileArchive(IReadFile* file, bool ignoreCase, bool ignorePa
}
//! Adds an archive to the file system.
bool CFileSystem::addFileArchive(IFileArchive* archive)
{
for (u32 i=0; i < FileArchives.size(); ++i)
{
if (archive == FileArchives[i])
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false;
}
}
FileArchives.push_back(archive);
return true;
}
//! removes an archive from the file system.
bool CFileSystem::removeFileArchive(u32 index)
{
......@@ -442,6 +468,22 @@ bool CFileSystem::removeFileArchive(const io::path& filename)
}
//! Removes an archive from the file system.
bool CFileSystem::removeFileArchive(const IFileArchive* archive)
{
for (u32 i=0; i < FileArchives.size(); ++i)
{
if (archive == FileArchives[i])
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return removeFileArchive(i);
}
}
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false;
}
//! gets an archive
u32 CFileSystem::getFileArchiveCount() const
{
......@@ -535,7 +577,7 @@ bool CFileSystem::changeWorkingDirectoryTo(const io::path& newDirectory)
WorkingDirectory[FILESYSTEM_VIRTUAL] = newDirectory;
// is this empty string constant really intended?
flattenFilename(WorkingDirectory[FILESYSTEM_VIRTUAL], _IRR_TEXT(""));
success = 1;
success = true;
}
else
{
......@@ -545,12 +587,12 @@ bool CFileSystem::changeWorkingDirectoryTo(const io::path& newDirectory)
success = true;
#elif defined(_MSC_VER)
#if defined(_IRR_WCHAR_FILESYSTEM)
success=(_wchdir(newDirectory.c_str()) == 0);
success = (_wchdir(newDirectory.c_str()) == 0);
#else
success=(_chdir(newDirectory.c_str()) == 0);
success = (_chdir(newDirectory.c_str()) == 0);
#endif
#else
success=(chdir(newDirectory.c_str()) == 0);
success = (chdir(newDirectory.c_str()) == 0);
#endif
}
......
......@@ -49,16 +49,21 @@ public:
virtual bool addFileArchive(const io::path& filename,
bool ignoreCase = true, bool ignorePaths = true,
E_FILE_ARCHIVE_TYPE archiveType = EFAT_UNKNOWN,
const core::stringc& password="");
const core::stringc& password="",
IFileArchive** retArchive = 0);
//! Adds an archive to the file system.
virtual bool addFileArchive(IReadFile* file, bool ignoreCase=true,
bool ignorePaths=true,
E_FILE_ARCHIVE_TYPE archiveType=EFAT_UNKNOWN,
const core::stringc& password="");
const core::stringc& password="",
IFileArchive** retArchive = 0);
//! Adds an archive to the file system.
virtual bool addFileArchive(IFileArchive* archive);
//! move the hirarchy of the filesystem. moves sourceIndex relative up or down
virtual bool moveFileArchive( u32 sourceIndex, s32 relative );
virtual bool moveFileArchive(u32 sourceIndex, s32 relative);
//! Adds an external archive loader to the engine.
virtual void addArchiveLoader(IArchiveLoader* loader);
......@@ -81,6 +86,9 @@ public:
//! removes an archive from the file system.
virtual bool removeFileArchive(const io::path& filename);
//! Removes an archive from the file system.
virtual bool removeFileArchive(const IFileArchive* archive);
//! Returns the string of the current working directory
virtual const io::path& getWorkingDirectory();
......@@ -143,7 +151,9 @@ public:
private:
// don't expose, needs refactoring
bool changeArchivePassword(const path& filename, const core::stringc& password);
bool changeArchivePassword(const path& filename,
const core::stringc& password,
IFileArchive** archive = 0);
//! Currently used FileSystemType
EFileSystemType FileSystemType;
......
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