commit 58f17ad3
Merge pull request #12 from sago007/XDG_SOMETHING_DIR-check
XDG_ dirs check
Changed files
| M | sago/platform_folders.cpp before |
diff --git a/sago/platform_folders.cpp b/sago/platform_folders.cpp
index 9bf1593..4f89040 100644
--- a/sago/platform_folders.cpp
+++ b/sago/platform_folders.cpp
@@ -253,13 +253,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;
}
}