From 7c7e351d3402692fc2a0d9e213e5cc819d52d52f Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 13 Jan 2020 16:51:48 +0100 Subject: [PATCH 1/3] Add missing function's declarations to convert path for windows. --- include/tools/pathTools.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/tools/pathTools.h b/include/tools/pathTools.h index 19c843321..37ab6fd2b 100644 --- a/include/tools/pathTools.h +++ b/include/tools/pathTools.h @@ -22,6 +22,10 @@ #include +#ifdef _WIN32 +std::string WideToUtf8(const std::wstring& wstr); +std::wstring Utf8ToWide(const std::string& str); +#endif bool isRelativePath(const std::string& path); std::string computeAbsolutePath(const std::string& path, const std::string& relativePath); std::string computeRelativePath(const std::string& path, const std::string& absolutePath); From 5540149e2b1cdf045d54652457d8d3738d28e49f Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 13 Jan 2020 16:54:09 +0100 Subject: [PATCH 2/3] Correctly open the library path on windows. We need to convert the path to wstring on Windows to handle directory with accented characters. Fix kiwix-desktop#269 --- src/manager.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/manager.cpp b/src/manager.cpp index 7ff386d7c..ba01e9b18 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -19,6 +19,8 @@ #include "manager.h" +#include "tools/pathTools.h" + #include namespace kiwix @@ -145,7 +147,12 @@ bool Manager::readFile(const std::string& nativePath, { bool retVal = true; pugi::xml_document doc; + +#ifdef _WIN32 + pugi::xml_parse_result result = doc.load_file(Utf8ToWide(nativePath).c_str()); +#else pugi::xml_parse_result result = doc.load_file(nativePath.c_str()); +#endif if (result) { this->parseXmlDom(doc, readOnly, UTF8Path); From 91db055d869d18e5b0bf9790238bf29e9d5578b5 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 13 Jan 2020 16:59:58 +0100 Subject: [PATCH 3/3] Remove function to read file using a native path. All path must be utf8. This is already the case in all our project. (If this not the case, this is a bug) So we don't need to have a version with a native and utf8 path. --- include/manager.h | 16 +--------------- src/manager.cpp | 15 ++++----------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/include/manager.h b/include/manager.h index 843af32d9..13087ca70 100644 --- a/include/manager.h +++ b/include/manager.h @@ -69,27 +69,13 @@ class Manager /** * Read a `library.xml` and add book in the file to the library. * - * @param path The path to the `library.xml`. + * @param path The (utf8) path to the `library.xml`. * @param readOnly Set if the libray path could be overwritten latter with * updated content. * @return True if file has been properly parsed. */ bool readFile(const std::string& path, const bool readOnly = true); - /** - * Read a `library.xml` and add book in the file to the library. - * - * @param nativePath The path of the `library.xml` - * @param UTF8Path The utf8 version (?) of the path. Also the path where the - * library will be writen i readOnly is False. - * @param readOnly Set if the libray path could be overwritten latter with - * updated content. - * @return True if file has been properly parsed. - */ - bool readFile(const std::string& nativePath, - const std::string& UTF8Path, - const bool readOnly = true); - /** * Load a library content store in the string. * diff --git a/src/manager.cpp b/src/manager.cpp index ba01e9b18..cf2534856 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -137,25 +137,18 @@ bool Manager::readOpds(const std::string& content, const std::string& urlHost) } bool Manager::readFile(const std::string& path, const bool readOnly) -{ - return this->readFile(path, path, readOnly); -} - -bool Manager::readFile(const std::string& nativePath, - const std::string& UTF8Path, - const bool readOnly) { bool retVal = true; pugi::xml_document doc; #ifdef _WIN32 - pugi::xml_parse_result result = doc.load_file(Utf8ToWide(nativePath).c_str()); + pugi::xml_parse_result result = doc.load_file(Utf8ToWide(path).c_str()); #else - pugi::xml_parse_result result = doc.load_file(nativePath.c_str()); + pugi::xml_parse_result result = doc.load_file(path.c_str()); #endif if (result) { - this->parseXmlDom(doc, readOnly, UTF8Path); + this->parseXmlDom(doc, readOnly, path); } else { retVal = false; } @@ -164,7 +157,7 @@ bool Manager::readFile(const std::string& nativePath, * able to know where to save the library if new content are * available */ if (!readOnly) { - this->writableLibraryPath = UTF8Path; + this->writableLibraryPath = path; } return retVal;