From e735ce04c415834fc08b3d255ae97e451bb1bdac Mon Sep 17 00:00:00 2001 From: danij Date: Thu, 20 Mar 2014 02:17:26 +0000 Subject: [PATCH] Savegame Converter: Basic mechanism for savegame conversion using Savegame Tool --- .../src/savegameconverter.cpp | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/doomsday/plugins/savegameconverter/src/savegameconverter.cpp b/doomsday/plugins/savegameconverter/src/savegameconverter.cpp index 858bb11f5c..93b5b8f614 100644 --- a/doomsday/plugins/savegameconverter/src/savegameconverter.cpp +++ b/doomsday/plugins/savegameconverter/src/savegameconverter.cpp @@ -17,18 +17,52 @@ * 02110-1301 USA */ +#include +#include #include +#include #include #include "savegameconverter.h" using namespace de; -int SavegameConvertHook(int /*hook_type*/, int /*parm*/, void * /*data*/) +int SavegameConvertHook(int /*hook_type*/, int /*parm*/, void *data) { + DENG2_ASSERT(data != 0); + ddhook_savegame_convert_t const &parm = *static_cast(data); + LOG_AS("SavegameConverter"); - LOG_NOTE("No conversion attempted. Returning false"); - return false; // Conversion failed. + + CommandLine cmd; + +#ifdef MACOSX + // First locate the savegametool executable. + NativePath bin = NativePath(qApp->applicationDirPath()) / "../Resources/savegametool"; + /// @todo fixme: Need to try alternate locations? +#elif WIN32 + NativePath bin = NativePath(qApp->applicationDirPath()) / "savegametool.exe"; +#else // UNIX + NativePath bin = NativePath(qApp->applicationDirPath()) / "savegametool"; + /// @todo fixme: Need to try alternate locations? +#endif + if(!bin.exists()) + { + LOG_RES_ERROR("Failed to locate Savegame Tool"); + return false; + } + cmd.append(bin); + + cmd.append("-idkey"); + cmd.append(Str_Text(&parm.fallbackGameIdentityKey)); + + cmd.append(Str_Text(&parm.inputFilePath)); + + LOG_RES_NOTE("Starting conversion of \"%s\" using Savegame Tool") + << NativePath(Str_Text(&parm.inputFilePath)).pretty(); + cmd.execute(); + + return true; // A conversion attempt was made (using Savegame Tool). } /**