From 1209e27e8ca356d58c9826e09aca42685149c1b9 Mon Sep 17 00:00:00 2001 From: Kelson42 Date: Wed, 14 May 2014 18:33:11 +0200 Subject: [PATCH] + Fix path computation functions for Windows --- src/common/pathTools.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/common/pathTools.cpp b/src/common/pathTools.cpp index 55f6b6a05..2e3f0715e 100644 --- a/src/common/pathTools.cpp +++ b/src/common/pathTools.cpp @@ -63,6 +63,14 @@ string computeRelativePath(const string path, const string absolutePath) { } string relativePath; +#ifdef _WIN32 + /* On Windows you have a token more because the root is represented + by a letter */ + if (commonCount == 0) { + relativePath = "../" + } +#endif + for (unsigned int i = commonCount ; i < pathParts.size() ; i++) { relativePath += "../"; } @@ -83,9 +91,9 @@ string computeAbsolutePath(const string path, const string relativePath) { size_t size = 0; #ifdef _WIN32 - path = _getcwd(path,size); + path = _getcwd(path, size); #else - path = getcwd(path,size); + path = getcwd(path, size); #endif absolutePath = string(path) + SEPARATOR; @@ -121,7 +129,9 @@ string removeLastPathElement(const string path, const bool removePreSeparator, c string newPath = path; size_t offset = newPath.find_last_of(SEPARATOR); if (removePreSeparator && +#ifndef _WIN32 offset != newPath.find_first_of(SEPARATOR) && +#endif offset == newPath.length()-1) { newPath = newPath.substr(0, offset); offset = newPath.find_last_of(SEPARATOR);