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