MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / LoadSharedStorage

Method LoadSharedStorage

src/openrct2/scripting/ScriptEngine.cpp:1874–1903  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1872}
1873
1874void ScriptEngine::LoadSharedStorage()
1875{
1876 InitSharedStorage();
1877
1878 auto path = _env.GetFilePath(PathId::pluginStore);
1879 try
1880 {
1881 if (File::Exists(path))
1882 {
1883 auto data = File::ReadAllBytes(path);
1884 // quickjs wants a null terminator not counted in the buf_len
1885 data.push_back(0);
1886 JSValue result = JS_ParseJSON(
1887 _replContext, reinterpret_cast<const char*>(data.data()), data.size() - 1, path.c_str());
1888 if (JS_IsObject(result))
1889 {
1890 JS_FreeValue(_replContext, _sharedStorage);
1891 _sharedStorage = result;
1892 }
1893 else
1894 {
1895 Console::Error::WriteLine("Unable to load plugin shared storage");
1896 }
1897 }
1898 }
1899 catch (const std::exception&)
1900 {
1901 Console::Error::WriteLine("Unable to read '%s'", path.c_str());
1902 }
1903}
1904
1905void ScriptEngine::SaveSharedStorage()
1906{

Callers

nothing calls this directly

Calls 7

ExistsFunction · 0.85
ReadAllBytesFunction · 0.85
WriteLineFunction · 0.85
GetFilePathMethod · 0.80
push_backMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected