MCPcopy Create free account
hub / github.com/Selectively11/CloudRedirect / ReadConfigBool

Function ReadConfigBool

src/platform/linux/init.cpp:83–104  ·  view source on GitHub ↗

Quick JSON bool lookup for early-init config reads (before the full JSON parser is available). Returns defaultVal if the key is absent.

Source from the content-addressed store, hash-verified

81// Quick JSON bool lookup for early-init config reads (before the full JSON
82// parser is available). Returns defaultVal if the key is absent.
83static bool ReadConfigBool(const char* key, bool defaultVal)
84{
85 std::string configPath = XdgConfigHome() + "/CloudRedirect/config.json";
86 FILE* f = fopen(configPath.c_str(), "r");
87 if (!f) return defaultVal;
88
89 char buf[65536] = {};
90 size_t n = fread(buf, 1, sizeof(buf) - 1, f);
91 fclose(f);
92 buf[n] = '\0';
93
94 std::string needle = std::string("\"") + key + "\"";
95 const char* pos = strstr(buf, needle.c_str());
96 if (!pos) return defaultVal;
97
98 const char* p = pos + needle.size();
99 while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || *p == ':') ++p;
100
101 if (strncmp(p, "false", 5) == 0) return false;
102 if (strncmp(p, "true", 4) == 0) return true;
103 return defaultVal;
104}
105
106static bool NotificationsEnabled() { return ReadConfigBool("notifications_enabled", true); }
107static bool StatsSyncEnabled() { return ReadConfigBool("stats_sync_enabled", true); }

Callers 2

NotificationsEnabledFunction · 0.85
StatsSyncEnabledFunction · 0.85

Calls 2

XdgConfigHomeFunction · 0.85
sizeMethod · 0.80

Tested by

no test coverage detected