git repos / PlatformFolders

commit 58f17ad3

Poul Sander · 2018-06-16 10:30
58f17ad3564e12576c01004146369b2754b85ad5 patch · browse files
parent 66a26d0b2bf42da3d7aa5924c0e0e7ebe636eef4
parent 0823b4a5060f000f9aca5837b061f7729a6622fe

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;
}
}