creates systems from information located in a config file
| 184 | |
| 185 | //creates systems from information located in a config file |
| 186 | bool SystemData::loadConfig(const std::string& path, bool writeExample) |
| 187 | { |
| 188 | deleteSystems(); |
| 189 | |
| 190 | LOG(LogInfo) << "Loading system config file..."; |
| 191 | |
| 192 | if(!fs::exists(path)) |
| 193 | { |
| 194 | LOG(LogInfo) << "System config file \"" << path << "\" doesn't exist!"; |
| 195 | if(writeExample) |
| 196 | writeExampleConfig(path); |
| 197 | |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | std::ifstream file(path.c_str()); |
| 202 | if(file.is_open()) |
| 203 | { |
| 204 | size_t lineNr = 0; |
| 205 | std::string line; |
| 206 | std::string sysName, sysDescName, sysPath, sysExtension, sysCommand; |
| 207 | while(file.good()) |
| 208 | { |
| 209 | lineNr++; |
| 210 | std::getline(file, line); |
| 211 | |
| 212 | //remove whitespace from line through STL and lambda magic |
| 213 | line.erase(std::remove_if(line.begin(), line.end(), [&](char c){ return std::string("\t\r\n\v\f").find(c) != std::string::npos; }), line.end()); |
| 214 | |
| 215 | //skip blank lines and comments |
| 216 | if(line.empty() || line.at(0) == '#') |
| 217 | continue; |
| 218 | |
| 219 | //find the name (left of the equals sign) and the value (right of the equals sign) |
| 220 | bool lineValid = false; |
| 221 | std::string varName; |
| 222 | std::string varValue; |
| 223 | const std::string::size_type equalsPos = line.find('=', 1); |
| 224 | if(equalsPos != std::string::npos) |
| 225 | { |
| 226 | lineValid = true; |
| 227 | varName = line.substr(0, equalsPos); |
| 228 | varValue = line.substr(equalsPos + 1, line.length() - 1); |
| 229 | } |
| 230 | |
| 231 | if(lineValid) |
| 232 | { |
| 233 | //map the value to the appropriate variable |
| 234 | if(varName == "NAME") |
| 235 | sysName = varValue; |
| 236 | else if(varName == "DESCNAME") |
| 237 | sysDescName = varValue; |
| 238 | else if(varName == "PATH") |
| 239 | { |
| 240 | if(varValue[varValue.length() - 1] == '/') |
| 241 | sysPath = varValue.substr(0, varValue.length() - 1); |
| 242 | else |
| 243 | sysPath = varValue; |
nothing calls this directly
no test coverage detected