versiondump.cpp
1 //------------------------------------------------------------------------------
2 // versiondump.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2013 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "versiondump.h"
24 
25 #include "plugins/engineplugin.h"
26 #include "plugins/pluginloader.h"
27 #include "json.h"
28 #include "version.h"
29 #include <QIODevice>
30 #include <QString>
31 #include <wadseeker/wadseekerversioninfo.h>
32 
33 class Module
34 {
35  public:
36  Module(const QString& displayName, unsigned long long revision,
37  const QString& displayVersion = QString())
38  {
39  _displayName = displayName;
40  _revision = revision;
41  _displayVersion = displayVersion;
42  }
43 
44  QVariantMap toVariantMap()
45  {
46  QVariantMap result;
47  result["display-name"] = _displayName;
48  result["revision"] = _revision;
49  if (!_displayVersion.isNull())
50  {
51  result["display-version"] = _displayVersion;
52  }
53  return result;
54  }
55 
56  private:
57  QString _displayName;
58  unsigned long long _revision;
59  QString _displayVersion;
60 };
61 
62 void VersionDump::dumpJsonToIO(QIODevice& io)
63 {
64  QVariantMap root;
65  root["doomseeker"] = Module(Version::name(), Version::revisionNumber(),
66  Version::versionRevision()).toVariantMap();
67  root["wadseeker"] = Module("Wadseeker", Version::revisionNumber(),
68  WadseekerVersionInfo::version()).toVariantMap();
69  for (unsigned int i = 0; i < gPlugins->numPlugins(); ++i)
70  {
71  const PluginLoader::Plugin* plugin = gPlugins->plugin(i);
72  QString name = plugin->info()->data()->name;
73  QString keyword = "p-" + name.toLower().replace(" ", "");
74  root[keyword] = Module(name, plugin->info()->data()->version).toVariantMap();
75  }
76 
77  io.write(QtJson::Json::serialize(root));
78 }
static QString versionRevision()
Combines version and revision strings.
Definition: version.cpp:69
static QByteArray serialize(const QVariant &data)
Definition: json.cpp:102
EnginePlugin * info() const
Main plugin interface.