MCPcopy Create free account
hub / github.com/Aloshi/EmulationStation / loadConfig

Method loadConfig

src/SystemData.cpp:186–283  ·  view source on GitHub ↗

creates systems from information located in a config file

Source from the content-addressed store, hash-verified

184
185//creates systems from information located in a config file
186bool 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;

Callers

nothing calls this directly

Calls 8

findMethod · 0.80
getFileCountMethod · 0.80
getRootFolderMethod · 0.80
push_backMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected