/
savegameconverter.cpp
92 lines (77 loc) · 2.8 KB
/
savegameconverter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/** @file savegameconverter.h Legacy savegame converter plugin.
*
* @authors Copyright © 2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#include <QCoreApplication>
#include <de/CommandLine>
#include <de/Log>
#include <de/NativePath>
#include <de/String>
#include "savegameconverter.h"
using namespace de;
int SavegameConvertHook(int /*hook_type*/, int /*parm*/, void *data)
{
DENG2_ASSERT(data != 0);
ddhook_savegame_convert_t const &parm = *static_cast<ddhook_savegame_convert_t *>(data);
LOG_AS("SavegameConverter");
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).
}
/**
* This function is called automatically when the plugin is loaded.
* We let the engine know what we'd like to do.
*/
void DP_Initialize()
{
Plug_AddHook(HOOK_SAVEGAME_CONVERT, SavegameConvertHook);
}
/**
* Declares the type of the plugin so the engine knows how to treat it. Called
* automatically when the plugin is loaded.
*/
extern "C" char const *deng_LibraryType()
{
return "deng-plugin/generic";
}
DENG_DECLARE_API(Base);
DENG_DECLARE_API(Plug);
DENG_API_EXCHANGE(
DENG_GET_API(DE_API_BASE, Base);
DENG_GET_API(DE_API_PLUGIN, Plug);
)