Add a method to get a relative filename, based on an given base directory.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3529 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
7e0decbdd2
commit
16cf9f58b9
|
@ -232,6 +232,9 @@ public:
|
|||
//! flatten a path and file name for example: "/you/me/../." becomes "/you"
|
||||
virtual path& flattenFilename(path& directory, const path& root="/") const =0;
|
||||
|
||||
//! Get the relative filename, relative to the given directory
|
||||
virtual path getRelativeFilename(const path& filename, const path& directory) const =0;
|
||||
|
||||
//! Creates a list of files and directories in the current working directory and returns it.
|
||||
/** \return a Pointer to the created IFileList is returned. After the list has been used
|
||||
it has to be deleted using its IFileList::drop() method.
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "CAttributes.h"
|
||||
#include "CMemoryFile.h"
|
||||
#include "CLimitReadFile.h"
|
||||
#include "irrList.h"
|
||||
|
||||
#if defined (_IRR_WINDOWS_API_)
|
||||
#if !defined ( _WIN32_WCE )
|
||||
|
@ -592,6 +593,42 @@ io::path& CFileSystem::flattenFilename(io::path& directory, const io::path& root
|
|||
}
|
||||
|
||||
|
||||
//! Get the relative filename, relative to the given directory
|
||||
path CFileSystem::getRelativeFilename(const path& filename, const path& directory) const
|
||||
{
|
||||
io::path path, file, ext;
|
||||
core::splitFilename(getAbsolutePath(filename), &path, &file, &ext);
|
||||
io::path path2(getAbsolutePath(directory));
|
||||
core::list<io::path> list1, list2;
|
||||
path.split(list1, "/\\", 2);
|
||||
path2.split(list2, "/\\", 2);
|
||||
u32 i=0;
|
||||
core::list<io::path>::ConstIterator it1,it2;
|
||||
it1=list1.begin();
|
||||
it2=list2.begin();
|
||||
for (; i<list1.size() && (*it1==*it2); ++i)
|
||||
{
|
||||
++it1;
|
||||
++it2;
|
||||
}
|
||||
path="";
|
||||
for (; i<list2.size(); ++i)
|
||||
path += "../";
|
||||
while (it1 != list1.end())
|
||||
{
|
||||
path += *it1++;
|
||||
path += "/";
|
||||
}
|
||||
path += file;
|
||||
if (ext.size())
|
||||
{
|
||||
path += ".";
|
||||
path += ext;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
//! Sets the current file systen type
|
||||
EFileSystemType CFileSystem::setFileListSystem(EFileSystemType listType)
|
||||
{
|
||||
|
|
|
@ -92,6 +92,9 @@ public:
|
|||
//! flatten a path and file name for example: "/you/me/../." becomes "/you"
|
||||
virtual io::path& flattenFilename( io::path& directory, const io::path& root = "/" ) const;
|
||||
|
||||
//! Get the relative filename, relative to the given directory
|
||||
virtual path getRelativeFilename(const path& filename, const path& directory) const;
|
||||
|
||||
virtual EFileSystemType setFileListSystem(EFileSystemType listType);
|
||||
|
||||
//! Creates a list of files and directories in the current working directory
|
||||
|
|
|
@ -101,6 +101,27 @@ static bool testFlattenFilename(io::IFileSystem* fs)
|
|||
return result;
|
||||
}
|
||||
|
||||
static bool testgetRelativeFilename(io::IFileSystem* fs)
|
||||
{
|
||||
bool result=true;
|
||||
io::path apath = fs->getAbsolutePath("media");
|
||||
io::path cwd = fs->getWorkingDirectory();
|
||||
if (fs->getRelativeFilename(apath, cwd) != "media")
|
||||
{
|
||||
logTestString("getRelativePath failed on %s\n", apath.c_str());
|
||||
result = false;
|
||||
}
|
||||
|
||||
apath = fs->getAbsolutePath("../media/");
|
||||
if (fs->getRelativeFilename(apath, cwd) != "../media/")
|
||||
{
|
||||
logTestString("getRelativePath failed on %s\n", apath.c_str());
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool filesystem(void)
|
||||
{
|
||||
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1));
|
||||
|
@ -151,7 +172,7 @@ bool filesystem(void)
|
|||
|
||||
result &= testFlattenFilename(fs);
|
||||
result &= testgetAbsoluteFilename(fs);
|
||||
|
||||
result &= testgetRelativeFilename(fs);
|
||||
|
||||
device->closeDevice();
|
||||
device->run();
|
||||
|
|
Loading…
Reference in New Issue