Save replay metadata for non-visual games too, refs #4577, #5548, fixes #5565.

Remove gui/common/ hack by going through the GUIInterface and fragile
EndGame() hardcoding by saving if and only if a ReplayLogger exists
following 7470e88624, refs #4020.
Refs D2211, D2213.

Differential Revision: https://code.wildfiregames.com/D2197
Based on patch by: irishninja
Tested on: clang 8.0.1, Jenkins

This was SVN commit r22991.
This commit is contained in:
elexis
2019-09-25 10:06:12 +00:00
parent 9425572bb1
commit 35408e7e7e
13 changed files with 71 additions and 69 deletions
-24
View File
@@ -473,30 +473,6 @@ void VisualReplay::AddReplayToCache(const ScriptInterface& scriptInterface, cons
StoreCacheFile(scriptInterface, cachedReplaysObject);
}
void VisualReplay::SaveReplayMetadata(ScriptInterface* scriptInterface)
{
JSContext* cx = scriptInterface->GetContext();
JSAutoRequest rq(cx);
JS::RootedValue metadata(cx);
JS::RootedValue global(cx, scriptInterface->GetGlobalObject());
if (!scriptInterface->CallFunction(global, "getReplayMetadata", &metadata))
{
LOGERROR("Could not save replay metadata!");
return;
}
// Get the directory of the currently active replay
const OsPath fileName = g_Game->GetReplayLogger().GetDirectory() / L"metadata.json";
CreateDirectories(fileName.Parent(), 0700);
std::ofstream stream (OsString(fileName).c_str(), std::ofstream::out | std::ofstream::trunc);
stream << scriptInterface->StringifyJSON(&metadata, false);
stream.close();
debug_printf("Saved replay metadata to %s\n", fileName.string8().c_str());
}
bool VisualReplay::HasReplayMetadata(const OsPath& directoryName)
{
const OsPath filePath(GetDirectoryPath() / directoryName / L"metadata.json");