MCPcopy Create free account
hub / github.com/DFHack/dfhack / read_config

Function read_config

plugins/autogems.cpp:301–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299IMPLEMENT_VMETHOD_INTERPOSE(autogem_hook, render);
300
301bool read_config(color_ostream &out) {
302 std::string path = "save/" + World::ReadWorldFolder() + "/autogems.json";
303 if (!Filesystem::isfile(path)) {
304 // no need to require the config file to exist
305 return true;
306 }
307
308 std::ifstream f(path);
309 Json::Value config;
310 try {
311 if (!f.good() || !(f >> config)) {
312 out.printerr("autogems: failed to read autogems.json\n");
313 return false;
314 }
315 }
316 catch (Json::Exception &e) {
317 out.printerr("autogems: failed to read autogems.json: {}\n", e.what());
318 return false;
319 }
320
321 if (config["blacklist"].isArray()) {
322 blacklist.clear();
323 for (int i = 0; i < int(config["blacklist"].size()); i++) {
324 Json::Value item = config["blacklist"][i];
325 if (item.isInt()) {
326 blacklist.insert(mat_index(item.asInt()));
327 }
328 else {
329 out.printerr("autogems: illegal item at position {} in blacklist\n", i);
330 }
331 }
332 }
333 return true;
334}
335
336command_result cmd_reload_config(color_ostream &out, std::vector<std::string>&) {
337 return read_config(out) ? CR_OK : CR_FAILURE;

Callers 3

cmd_reload_configFunction · 0.85

Calls 4

whatMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected