MCPcopy Create free account
hub / github.com/OpenSteam001/OpenSteamTool / Load

Function Load

src/Utils/Config/Config.cpp:77–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75} // namespace
76
77 LoadResult Load(const std::string& configPath) {
78 Snapshot snapshot = MakeDefaultSnapshot(configPath);
79 if (!std::filesystem::exists(configPath)) {
80 LOG_INFO("Config file not found, using defaults");
81 ApplyManifestProvider(snapshot.manifestProvider);
82 LoadResult result = ApplySnapshotLocked(snapshot);
83 LOG_INFO("Config loaded: manifest.url={} log.level={} lua.paths={} remote.url_template={}",
84 ManifestClient::ActiveProviderName(),
85 ToString(GetLogLevel()),
86 (uint32_t)GetLuaPaths().size(),
87 GetRemoteUrlTemplate().empty() ? "<default>" : GetRemoteUrlTemplate());
88 return result;
89 }
90
91 try {
92 auto tbl = toml::parse_file(configPath);
93
94 // [manifest]
95 if (auto manifest = tbl["manifest"].as_table()) {
96 if (auto val = (*manifest)["url"].value<std::string>()) {
97 snapshot.manifestProvider = *val;
98 }
99 if (auto val = (*manifest)["timeout_resolve_ms"].value<int64_t>())
100 snapshot.manifestTimeouts.resolve = static_cast<uint32_t>(*val);
101 if (auto val = (*manifest)["timeout_connect_ms"].value<int64_t>())
102 snapshot.manifestTimeouts.connect = static_cast<uint32_t>(*val);
103 if (auto val = (*manifest)["timeout_send_ms"].value<int64_t>())
104 snapshot.manifestTimeouts.send = static_cast<uint32_t>(*val);
105 if (auto val = (*manifest)["timeout_recv_ms"].value<int64_t>())
106 snapshot.manifestTimeouts.recv = static_cast<uint32_t>(*val);
107 }
108
109 // [log]
110 if (auto log = tbl["log"].as_table()) {
111 if (auto val = (*log)["level"].value<std::string>()) {
112 if (*val == "trace") snapshot.logLevel = LogLevel::Trace;
113 else if (*val == "debug") snapshot.logLevel = LogLevel::Debug;
114 else if (*val == "info") snapshot.logLevel = LogLevel::Info;
115 else if (*val == "warn") snapshot.logLevel = LogLevel::Warn;
116 else if (*val == "error") snapshot.logLevel = LogLevel::Error;
117 }
118 }
119
120 // [lua]
121 if (auto lua = tbl["lua"].as_table()) {
122 if (auto arr = (*lua)["paths"].as_array()) {
123 for (auto& elem : *arr) {
124 if (auto str = elem.value<std::string>()) {
125 snapshot.luaPaths.push_back(*str);
126 }
127 }
128 }
129 }
130
131 // [remote]
132 if (auto remote = tbl["remote"].as_table()) {
133 if (auto val = (*remote)["url_template"].value<std::string>()) {
134 snapshot.remoteUrlTemplate = *val;

Callers 3

ReloadConfigFunction · 0.70
InitThreadFunction · 0.50

Calls 11

MakeDefaultSnapshotFunction · 0.85
ApplyManifestProviderFunction · 0.85
ApplySnapshotLockedFunction · 0.85
ActiveProviderNameFunction · 0.85
GetLogLevelFunction · 0.85
GetLuaPathsFunction · 0.85
GetRemoteUrlTemplateFunction · 0.85
ApplySnapshotFunction · 0.85
sizeMethod · 0.80
emptyMethod · 0.80
ToStringFunction · 0.70

Tested by

no test coverage detected