Skip to content

Commit

Permalink
Backported PlatformFoldersAddFromFile from 4.0.0 in case someone need…
Browse files Browse the repository at this point in the history
…s a 3.X.X version
  • Loading branch information
sago007 committed Jun 28, 2018
1 parent be6a67e commit 880fc26
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
project(platform_folders VERSION 3.2.0 LANGUAGES CXX)
project(platform_folders VERSION 3.2.1 LANGUAGES CXX)

# Since it's off, the library will be static by default
option(BUILD_SHARED_LIBS "Build shared instead of static." OFF)
Expand Down
2 changes: 1 addition & 1 deletion doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Platform folders"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "3.2.0"
PROJECT_NUMBER = "3.2.1"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
18 changes: 12 additions & 6 deletions sago/platform_folders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,20 @@ static void PlatformFoldersAddFromFile(const std::string& filename, std::map<std
std::ifstream infile(filename.c_str());
std::string line;
while (std::getline(infile, line)) {
if (line.length() == 0 || line.at(0) == '#') {
if (line.length() == 0 || line.at(0) == '#' || line.substr(0, 4) != "XDG_" || line.find("_DIR") == std::string::npos) {
continue;
}
try {
std::size_t splitPos = line.find('=');
std::string key = line.substr(0, splitPos);
std::size_t valueStart = line.find('"', splitPos);
std::size_t valueEnd = line.find('"', valueStart+1);
std::string value = line.substr(valueStart+1, valueEnd - valueStart - 1);
folders[key] = value;
} catch (std::exception& e) {
std::cerr << "WARNING: Failed to process \"" << line << "\" from \"" << filename << "\". Error: "<< e.what() << "\n";
continue;
}
std::size_t splitPos = line.find("=");
std::string key = line.substr(0, splitPos);
std::string value = line.substr(splitPos+2, line.length()-splitPos-3);
folders[key] = value;
//std::cout << key << " : " << value << "\n";
}
}

Expand Down

0 comments on commit 880fc26

Please sign in to comment.