| 81 | } |
| 82 | |
| 83 | void ScriptGlobal::WriteToFile(const String& filename) |
| 84 | { |
| 85 | Log(LogInformation, "ScriptGlobal") |
| 86 | << "Dumping variables to file '" << filename << "'"; |
| 87 | |
| 88 | AtomicFile fp (filename, 0600); |
| 89 | StdioStream::Ptr sfp = new StdioStream(&fp, false); |
| 90 | |
| 91 | ObjectLock olock(m_Globals); |
| 92 | for (const Namespace::Pair& kv : m_Globals) { |
| 93 | Value value = kv.second.Val; |
| 94 | |
| 95 | if (value.IsObject()) |
| 96 | value = Convert::ToString(value); |
| 97 | |
| 98 | Dictionary::Ptr persistentVariable = new Dictionary({ |
| 99 | { "name", kv.first }, |
| 100 | { "value", value } |
| 101 | }); |
| 102 | |
| 103 | String json = JsonEncode(persistentVariable); |
| 104 | |
| 105 | NetString::WriteStringToStream(sfp, json); |
| 106 | } |
| 107 | |
| 108 | sfp->Close(); |
| 109 | fp.Commit(); |
| 110 | } |