From 72e4220929db4014df366a26759284b87fd8fc1a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 5 May 2021 23:33:24 +0200 Subject: [PATCH] - added an option to dump the list of discovered games to a JSON file. --- source/core/gamecontrol.cpp | 55 +++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 75b4b577e..dcf45e9a9 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -538,12 +538,12 @@ int GameMain() { r = RunGame(); } - catch (const CExitEvent & exit) + catch (const CExitEvent& exit) { // Just let the rest of the function execute. r = exit.Reason(); } - catch (const std::exception & err) + catch (const std::exception& err) { // shut down critical systems before showing a message box. I_ShowFatalError(err.what()); @@ -818,6 +818,56 @@ void CreateStatusBar() StatusBar = static_cast(stbarclass->CreateNew()); } + +void GetGames() +{ + auto getgames = Args->CheckValue("-getgames"); + if (getgames) + { + try + { + auto groups = GrpScan(); + FSerializer arc; + if (arc.OpenWriter()) + { + if (arc.BeginArray("games")) + { + for (auto& entry : groups) + { + if (arc.BeginObject(nullptr)) + { + arc("filename", entry.FileName) + ("description", entry.FileInfo.name) + ("defname", entry.FileInfo.defname) + ("scriptname", entry.FileInfo.scriptname) + ("gamefilter", entry.FileInfo.gamefilter) + ("gameid", entry.FileInfo.gameid) + ("fgcolor", entry.FileInfo.FgColor) + ("bkcolor", entry.FileInfo.BgColor) + ("addon", entry.FileInfo.isAddon) + .EndObject(); + } + } + arc.EndArray(); + } + unsigned int len; + auto p = arc.GetOutput(&len); + FILE* f = fopen(getgames, "wb"); + if (f) + { + fwrite(p, 1, len, f); + fclose(f); + } + } + } + catch (...) + { + // Ignore all errors + } + throw CExitEvent(0); + } +} + //========================================================================== // // @@ -844,6 +894,7 @@ int RunGame() I_DetectOS(); userConfig.ProcessOptions(); G_LoadConfig(); + GetGames(); auto usedgroups = SetupGame(); bool colorset = false;