Handle relative paths when loading .worldedit files in World Editor.
This commit is contained in:
parent
eca3a92a08
commit
2fadeccaf1
3 changed files with 65 additions and 0 deletions
|
@ -507,6 +507,13 @@ public:
|
|||
*/
|
||||
static bool makePathRelative (const char *basePath, std::string &relativePath);
|
||||
|
||||
/** Make path absolute
|
||||
* \param relativePath - The relative path
|
||||
* \param directory - the directory to which the path is relative to
|
||||
* returns the absolute path, or empty if something went wrong.
|
||||
*/
|
||||
static std::string makePathAbsolute (const std::string &relativePath, const std::string &directory );
|
||||
|
||||
/** If File in this list is added more than one in an addSearchPath, it doesn't launch a warning.
|
||||
*/
|
||||
static void addIgnoredDoubleFile(const std::string &ignoredFile);
|
||||
|
|
|
@ -2544,6 +2544,57 @@ bool CPath::makePathRelative (const char *basePath, std::string &relativePath)
|
|||
return false;
|
||||
}
|
||||
|
||||
std::string CPath::makePathAbsolute( const std::string &relativePath, const std::string &directory )
|
||||
{
|
||||
if( relativePath.empty() )
|
||||
return "";
|
||||
if( directory.empty() )
|
||||
return "";
|
||||
|
||||
#ifdef NL_OS_WINDOWS
|
||||
// Windows network address. Eg.: \\someshare\path
|
||||
if( ( relativePath[ 0 ] == '\\' ) && ( relativePath[ 1 ] == '\\' ) )
|
||||
return relativePath;
|
||||
|
||||
// Normal Windows absolute path. Eg.: C:\something
|
||||
//
|
||||
if( isalpha( relativePath[ 0 ] ) && ( relativePath[ 1 ] == ':' ) && ( ( relativePath[ 2 ] == '\\' ) || ( relativePath[ 2 ] == '/' ) ) )
|
||||
return relativePath;
|
||||
#else
|
||||
// Unix filesystem absolute path
|
||||
if( relativePath[ 0 ] == '/' )
|
||||
return relativePath;
|
||||
|
||||
#endif
|
||||
|
||||
// Add a slash to the directory if necessary.
|
||||
// If the relative path starts with dots we need a slash.
|
||||
// If the relative path starts with a slash we don't.
|
||||
// If it starts with neither, we need a slash.
|
||||
bool needSlash = true;
|
||||
char c = relativePath[ 0 ];
|
||||
if( ( c == '\\' ) || ( c == '/' ) )
|
||||
needSlash = false;
|
||||
|
||||
bool hasSlash = false;
|
||||
std::string npath = directory;
|
||||
c = npath[ npath.size() - 1 ];
|
||||
if( ( c == '\\' ) || ( c == '/' ) )
|
||||
hasSlash = true;
|
||||
|
||||
if( needSlash && !hasSlash )
|
||||
npath += '/';
|
||||
else
|
||||
if( hasSlash && !needSlash )
|
||||
npath.resize( npath.size() - 1 );
|
||||
|
||||
// Now build the new absolute path
|
||||
npath += relativePath;
|
||||
npath = standardizePath( npath, false );
|
||||
|
||||
return npath;
|
||||
}
|
||||
|
||||
bool CFile::setRWAccess(const std::string &filename)
|
||||
{
|
||||
#ifdef NL_OS_WINDOWS
|
||||
|
|
|
@ -59,6 +59,8 @@ bool loadWorldEditFile(const std::string &fileName, WorldEditList &worldEditList
|
|||
|
||||
lastError = "";
|
||||
|
||||
std::string p = NLMISC::CFile::getPath( fileName );
|
||||
|
||||
// Load the document
|
||||
NLMISC::CIFile file;
|
||||
if (file.open(fileName))
|
||||
|
@ -122,6 +124,8 @@ bool loadWorldEditFile(const std::string &fileName, WorldEditList &worldEditList
|
|||
{
|
||||
std::string dataDir;
|
||||
NLMISC::CIXml::getPropertyString(dataDir, node, "VALUE");
|
||||
|
||||
dataDir = NLMISC::CPath::makePathAbsolute( dataDir, p );
|
||||
worldEditList.push_back(WorldEditItem(DataDirectoryType, dataDir));
|
||||
}
|
||||
|
||||
|
@ -149,6 +153,9 @@ bool loadWorldEditFile(const std::string &fileName, WorldEditList &worldEditList
|
|||
std::string filenameChild;
|
||||
if ( NLMISC::CIXml::getPropertyString(filenameChild, node, "FILENAME"))
|
||||
{
|
||||
|
||||
filenameChild = NLMISC::CPath::makePathAbsolute( filenameChild, p );
|
||||
|
||||
// Is it a landscape ?
|
||||
if (type == "landscape")
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue