MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / ReadModJsonString

Function ReadModJsonString

engine/Poseidon/Core/ModCollection.cpp:25–46  ·  view source on GitHub ↗

Read a top-level string field from /mod.json, or "" if absent/unreadable.

Source from the content-addressed store, hash-verified

23}
24
25// Read a top-level string field from <modDir>/mod.json, or "" if absent/unreadable.
26std::string ReadModJsonString(const std::filesystem::path& modDir, const char* key)
27{
28 const std::filesystem::path metadata = modDir / "mod.json";
29 std::error_code ec;
30 if (!std::filesystem::exists(metadata, ec))
31 return {};
32 std::ifstream in(metadata, std::ios::binary);
33 if (!in)
34 return {};
35 std::ostringstream buffer;
36 buffer << in.rdbuf();
37 cJSON* root = cJSON_Parse(buffer.str().c_str());
38 std::string out;
39 if (root != nullptr)
40 {
41 const cJSON* item = cJSON_GetObjectItemCaseSensitive(root, key);
42 if (cJSON_IsString(item) && item->valuestring != nullptr)
43 out = item->valuestring;
44 cJSON_Delete(root);
45 }
46 return out;
47}
48
49// Total size of every regular file under dir (recursive). Best-effort: I/O errors

Callers 2

ScanModsRootFunction · 0.85
ActiveModsFromMountPathFunction · 0.85

Calls 1

strMethod · 0.80

Tested by

no test coverage detected