mirror of https://github.com/kiwix/libkiwix.git
+ Fix path computation functions for Windows
This commit is contained in:
parent
457406b743
commit
1209e27e8c
|
@ -63,6 +63,14 @@ string computeRelativePath(const string path, const string absolutePath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
string relativePath;
|
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++) {
|
for (unsigned int i = commonCount ; i < pathParts.size() ; i++) {
|
||||||
relativePath += "../";
|
relativePath += "../";
|
||||||
}
|
}
|
||||||
|
@ -83,9 +91,9 @@ string computeAbsolutePath(const string path, const string relativePath) {
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
path = _getcwd(path,size);
|
path = _getcwd(path, size);
|
||||||
#else
|
#else
|
||||||
path = getcwd(path,size);
|
path = getcwd(path, size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
absolutePath = string(path) + SEPARATOR;
|
absolutePath = string(path) + SEPARATOR;
|
||||||
|
@ -121,7 +129,9 @@ string removeLastPathElement(const string path, const bool removePreSeparator, c
|
||||||
string newPath = path;
|
string newPath = path;
|
||||||
size_t offset = newPath.find_last_of(SEPARATOR);
|
size_t offset = newPath.find_last_of(SEPARATOR);
|
||||||
if (removePreSeparator &&
|
if (removePreSeparator &&
|
||||||
|
#ifndef _WIN32
|
||||||
offset != newPath.find_first_of(SEPARATOR) &&
|
offset != newPath.find_first_of(SEPARATOR) &&
|
||||||
|
#endif
|
||||||
offset == newPath.length()-1) {
|
offset == newPath.length()-1) {
|
||||||
newPath = newPath.substr(0, offset);
|
newPath = newPath.substr(0, offset);
|
||||||
offset = newPath.find_last_of(SEPARATOR);
|
offset = newPath.find_last_of(SEPARATOR);
|
||||||
|
|
Loading…
Reference in New Issue