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

Method SaveSharedStorage

src/openrct2/scripting/ScriptEngine.cpp:1905–1926  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1903}
1904
1905void ScriptEngine::SaveSharedStorage()
1906{
1907 auto path = _env.GetFilePath(PathId::pluginStore);
1908 try
1909 {
1910 JSValue jsonVal = JS_JSONStringify(_replContext, _sharedStorage, JS_UNDEFINED, JS_UNDEFINED);
1911 if (JS_IsString(jsonVal))
1912 {
1913 // inefficient to copy the whole string out first, but we have to do this to avoid breaking the exception flow
1914 std::string json = JSToStdString(_replContext, jsonVal);
1915 JS_FreeValue(_replContext, jsonVal);
1916 File::WriteAllBytes(path, json.c_str(), json.size());
1917 return;
1918 }
1919 JS_FreeValue(_replContext, jsonVal);
1920 Console::Error::WriteLine("Unable to stringify shared storage JSON");
1921 }
1922 catch (const std::exception&)
1923 {
1924 Console::Error::WriteLine("Unable to write to '%s'", path.c_str());
1925 }
1926}
1927
1928void ScriptEngine::ClearParkStorage()
1929{

Callers 1

setMethod · 0.80

Calls 5

JSToStdStringFunction · 0.85
WriteAllBytesFunction · 0.85
WriteLineFunction · 0.85
GetFilePathMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected