Freeciv21
Develop your civilization from humble roots to a global empire
mpcli.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2022 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 #include <fc_config.h>
15 
16 #include <cstdlib>
17 
18 // Qt
19 #include <QCoreApplication>
20 #include <QString>
21 
22 // utility
23 #include "fcintl.h"
24 
25 // common
26 #include "version.h"
27 
28 // modinst
29 #include "download.h"
30 #include "mpcmdline.h"
31 #include "mpdb.h"
32 
33 #include "modinst.h"
34 
35 struct fcmp_params fcmp = {
36  QUrl::fromUserInput(QStringLiteral(MODPACK_LIST_URL)), QLatin1String(),
37  QLatin1String()};
38 
42 static void msg_callback(const QString &msg)
43 {
44  qInfo("%s", msg.toLocal8Bit().data());
45 }
46 
50 static void setup_modpack_list(const QString &name, const QUrl &url,
51  const QString &version,
52  const QString &license,
53  enum modpack_type type,
54  const QString &subtype, const QString &notes)
55 {
56  // TRANS: Unknown modpack type
57  QString type_str =
58  modpack_type_is_valid(type) ? (modpack_type_name(type)) : _("?");
59 
60  // TRANS: License of modpack is not known
61  QString lic_str = license.isEmpty() ? Q_("?license:Unknown") : license;
62 
63  const char *tmp = mpdb_installed_version(qUtf8Printable(name), type);
64  QString inst_str = tmp ? tmp : _("Not installed");
65 
66  qInfo();
67  qInfo() << _("Name=") << name;
68  qInfo() << _("Version=") << version;
69  qInfo() << _("Installed=") << inst_str;
70  qInfo() << _("Type=") << type_str << "/" << subtype;
71  qInfo() << _("License=") << lic_str;
72  qInfo() << _("URL=") << url.toDisplayString();
73  if (!notes.isEmpty()) {
74  qInfo() << _("Comment=") << notes;
75  }
76 
77  delete[] tmp;
78 }
79 
83 int main(int argc, char *argv[])
84 {
85  QCoreApplication app(argc, argv);
86  QCoreApplication::setApplicationVersion(freeciv21_version());
87 
88  // Delegate option parsing to the common function.
89  fcmp_parse_cmdline(app);
90 
91  fcmp_init();
92 
94 
95  qInfo(_("Freeciv21 modpack installer (command line version)"));
96  qInfo(_("Version %s"), freeciv21_version());
97 
98  if (fcmp.autoinstall.isEmpty()) {
99  if (auto msg =
101  qCritical() << msg;
102  }
103  } else {
104  auto errmsg =
106 
107  if (errmsg == nullptr) {
108  qInfo(_("Modpack installed successfully"));
109  } else {
110  qCritical(_("Modpack install failed: %s"), errmsg);
111  }
112  }
113 
114  close_mpdbs();
115 
116  fcmp_deinit();
117 
118  return EXIT_SUCCESS;
119 }
const char * download_modpack(const QUrl &url, const struct fcmp_params *fcmp, const dl_msg_callback &mcb, const dl_pb_callback &pbcb, int recursion)
Download modpack from a given URL.
Definition: download.cpp:150
const char * download_modpack_list(const struct fcmp_params *fcmp, const modpack_list_setup_cb &cb, const dl_msg_callback &mcb)
Download modpack list.
Definition: download.cpp:417
#define Q_(String)
Definition: fcintl.h:53
#define _(String)
Definition: fcintl.h:50
const char * name
Definition: inputfile.cpp:118
void fcmp_deinit()
Deinitialize modpack installer.
Definition: modinst.cpp:89
void load_install_info_lists(struct fcmp_params *fcmp)
Load all required install info lists.
Definition: modinst.cpp:39
void fcmp_init()
Initialize modpack installer.
Definition: modinst.cpp:77
#define MODPACK_LIST_URL
Definition: modinst.h:25
int main(int argc, char *argv[])
Entry point of the freeciv-modpack program.
Definition: mpcli.cpp:83
static void setup_modpack_list(const QString &name, const QUrl &url, const QString &version, const QString &license, enum modpack_type type, const QString &subtype, const QString &notes)
Build main modpack list view.
Definition: mpcli.cpp:50
static void msg_callback(const QString &msg)
Progress indications from downloader.
Definition: mpcli.cpp:42
struct fcmp_params fcmp
Definition: mpcli.cpp:35
void fcmp_parse_cmdline(const QCoreApplication &app)
Parse commandline parameters.
Definition: mpcmdline.cpp:39
void close_mpdbs()
Close open databases.
Definition: mpdb.cpp:198
const char * mpdb_installed_version(const char *name, enum modpack_type type)
Return version of modpack.
Definition: mpdb.cpp:251
QString autoinstall
Definition: modinst.h:22
const char * freeciv21_version()
Returns the raw version string.
Definition: version.cpp:29