versiondump.cpp
1 //------------------------------------------------------------------------------
2 // versiondump.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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 VersionDump::Module
34 {
35  public:
36  Module(const QString& displayName, const QString &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 
50  if (!_displayVersion.isNull())
51  {
52  result["display-version"] = _displayVersion;
53  }
54  return result;
55  }
56 
57  private:
58  QString _displayName;
59  QString _revision;
60  QString _displayVersion;
61 };
62 
63 void VersionDump::dumpJsonToIO(QIODevice& io)
64 {
65  QVariantMap root;
66  Module doomseeker(Version::name(), QString::number(Version::revisionNumber()),
68  // "doomseeker" is legacy package and hardcoded to download version 1.1.
69  root["doomseeker"] = Module("Doomseeker", "1496802976", "1.1-170607-0236").toVariantMap();
70  root["doomseeker-core"] = doomseeker.toVariantMap();
71  root["wadseeker"] = Module("Wadseeker", WadseekerVersionInfo::version(),
72  WadseekerVersionInfo::version()).toVariantMap();
73  root["qt"] = Module("Qt", Version::qtPackageVersion()).toVariantMap();
74  for (unsigned int i = 0; i < gPlugins->numPlugins(); ++i)
75  {
76  const PluginLoader::Plugin* plugin = gPlugins->plugin(i);
77  QString name = plugin->info()->data()->name;
78  QString keyword = "p-" + name.toLower().replace(" ", "");
79  root[keyword] = Module(name, QString::number(plugin->info()->data()->version)).toVariantMap();
80  }
81 
82  io.write(QtJson::Json::serialize(root));
83  io.write("\n");
84 }
static QString versionRevision()
Combines version and revision strings.
Definition: version.cpp:74
static QByteArray serialize(const QVariant &data)
Definition: json.cpp:102
EnginePlugin * info() const
Main plugin interface.