MCPcopy Create free account
hub / github.com/cafali/SnapKey / LoadConfig

Function LoadConfig

SnapKey.cpp:373–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

371}
372
373bool LoadConfig(const std::string& filename) {
374 std::ifstream configFile(filename);
375 if (!configFile.is_open()) {
376 CreateDefaultConfig(filename);
377 return false;
378 }
379
380 string line;
381 int id = 0;
382 while (getline(configFile, line)) {
383 istringstream iss(line);
384 string key;
385 int value;
386 regex secPat(R"(\s*\[Group\]\s*)");
387 if (regex_match(line, secPat)) {
388 id++;
389 } else if (getline(iss, key, '=') && (iss >> value)) {
390 if (key.find("key") != string::npos) {
391 if (!KeyInfo[value].registered) {
392 KeyInfo[value].registered = true;
393 KeyInfo[value].group = id;
394 } else {
395 MessageBox(NULL,
396 TEXT("The config file contains duplicate keys. Please review the setup."),
397 TEXT("SnapKey Error"), MB_ICONEXCLAMATION | MB_OK);
398 return false;
399 }
400 }
401 }
402 }
403 return true;
404}

Callers 1

mainFunction · 0.85

Calls 1

CreateDefaultConfigFunction · 0.85

Tested by

no test coverage detected