Rework README.ruleset_civ2civ3 defense bonus description.
[freeciv.git] / tools / mpcli.c
blobb96b8e2552fb0ad2c05b9097d55fee701cf51962
1 /**********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 #include <stdlib.h>
20 /* utility */
21 #include "fciconv.h"
22 #include "fcintl.h"
23 #include "log.h"
24 #include "mem.h"
25 #include "shared.h"
27 /* common */
28 #include "version.h"
30 /* modinst */
31 #include "download.h"
32 #include "mpcmdline.h"
33 #include "mpdb.h"
35 #include "modinst.h"
37 struct fcmp_params fcmp = {
38 .list_url = MODPACK_LIST_URL,
39 .inst_prefix = NULL,
40 .autoinstall = NULL
43 /**************************************************************************
44 Progress indications from downloader
45 **************************************************************************/
46 static void msg_callback(const char *msg)
48 log_normal("%s", msg);
51 /**************************************************************************
52 Build main modpack list view
53 **************************************************************************/
54 static void setup_modpack_list(const char *name, const char *URL,
55 const char *version, const char *license,
56 enum modpack_type type, const char *subtype,
57 const char *notes)
59 const char *type_str;
60 const char *lic_str;
61 const char *inst_str;
63 if (modpack_type_is_valid(type)) {
64 type_str = _(modpack_type_name(type));
65 } else {
66 /* TRANS: Unknown modpack type */
67 type_str = _("?");
70 if (license != NULL) {
71 lic_str = license;
72 } else {
73 /* TRANS: License of modpack is not known */
74 lic_str = Q_("?license:Unknown");
77 inst_str = get_installed_version(name, type);
78 if (inst_str == NULL) {
79 inst_str = _("Not installed");
82 log_normal("%s", "");
83 log_normal(_("Name=\"%s\""), name);
84 log_normal(_("Version=\"%s\""), version);
85 log_normal(_("Installed=\"%s\""), inst_str);
86 log_normal(_("Type=\"%s\" / \"%s\""), type_str, subtype);
87 log_normal(_("License=\"%s\""), lic_str);
88 log_normal(_("URL=\"%s\""), URL);
89 if (notes != NULL) {
90 log_normal(_("Comment=\"%s\""), notes);
94 /**************************************************************************
95 Entry point of the freeciv-modpack program
96 **************************************************************************/
97 int main(int argc, char *argv[])
99 int loglevel = LOG_NORMAL;
100 int ui_options;
102 fcmp_init(loglevel);
104 /* This modifies argv! */
105 ui_options = fcmp_parse_cmdline(argc, argv);
107 if (ui_options != -1) {
108 int i;
110 for (i = 1; i <= ui_options; i++) {
111 if (is_option("--help", argv[i])) {
112 fc_fprintf(stderr,
113 _("This modpack installer does not support any specific options\n\n"));
115 /* TRANS: No full stop after the URL, could cause confusion. */
116 fc_fprintf(stderr, _("Report bugs at %s\n"), BUG_URL);
118 ui_options = -1;
119 } else {
120 log_error(_("Unknown option '--' '%s'"), argv[i]);
121 ui_options = -1;
126 if (ui_options != -1) {
127 const char *rev_ver = fc_svn_revision();
129 load_install_info_lists(&fcmp);
131 log_normal(_("Freeciv modpack installer (command line version)"));
133 if (rev_ver == NULL) {
134 log_normal("%s%s", word_version(), VERSION_STRING);
136 rev_ver = fc_git_revision();
137 if (rev_ver != NULL) {
138 log_normal(_("commit: %s"), rev_ver);
140 } else {
141 log_normal("%s%s (%s)", word_version(), VERSION_STRING, rev_ver);
144 if (fcmp.autoinstall == NULL) {
145 download_modpack_list(&fcmp, setup_modpack_list, msg_callback);
146 } else {
147 const char *errmsg;
149 errmsg = download_modpack(fcmp.autoinstall, &fcmp, msg_callback, NULL);
151 if (errmsg == NULL) {
152 log_normal(_("Modpack installed successfully"));
153 } else {
154 log_error(_("Modpack install failed: %s"), errmsg);
158 save_install_info_lists(&fcmp);
161 fcmp_deinit();
163 return EXIT_SUCCESS;