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)
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 ***********************************************************************/
15 #include <fc_config.h>
18 #include "fc_prehdrs.h"
25 #include "net_types.h"
30 #include "fc_interface.h"
37 static struct install_info_list
*main_ii_list
;
38 static bool main_list_changed
= FALSE
;
39 static struct install_info_list
*scenario_ii_list
;
40 static bool scenario_list_changed
= FALSE
;
42 static char main_ii_filename
[500];
43 static char scenario_ii_filename
[500];
45 /**************************************************************************
46 Load all required install info lists.
47 **************************************************************************/
48 void load_install_info_lists(struct fcmp_params
*fcmp
)
50 main_ii_list
= install_info_list_new();
51 scenario_ii_list
= install_info_list_new();
53 fc_snprintf(main_ii_filename
, sizeof(main_ii_filename
),
54 "%s/" DATASUBDIR
"/" FCMP_CONTROLD
"/modpacks.db", fcmp
->inst_prefix
);
55 fc_snprintf(scenario_ii_filename
, sizeof(scenario_ii_filename
),
56 "%s/scenarios/" FCMP_CONTROLD
"/modpacks.db", fcmp
->inst_prefix
);
58 load_install_info_list(main_ii_filename
, main_ii_list
);
59 load_install_info_list(scenario_ii_filename
, scenario_ii_list
);
62 /**************************************************************************
63 Save all changed install info lists.
64 **************************************************************************/
65 void save_install_info_lists(struct fcmp_params
*fcmp
)
67 if (main_list_changed
) {
70 fc_snprintf(controld
, sizeof(controld
),
71 "%s/" DATASUBDIR
"/" FCMP_CONTROLD
, fcmp
->inst_prefix
);
73 if (make_dir(controld
)) {
74 save_install_info_list(main_ii_filename
, main_ii_list
);
76 log_error(_("Failed to create control directory \"%s\""),
81 if (scenario_list_changed
) {
84 fc_snprintf(controld
, sizeof(controld
),
85 "%s/scenarios/" FCMP_CONTROLD
, fcmp
->inst_prefix
);
87 if (make_dir(controld
)) {
88 save_install_info_list(scenario_ii_filename
, scenario_ii_list
);
90 log_error(_("Failed to create control directory \"%s\""),
95 install_info_list_iterate(scenario_ii_list
, ii
) {
97 } install_info_list_iterate_end
;
99 install_info_list_iterate(main_ii_list
, ii
) {
101 } install_info_list_iterate_end
;
103 install_info_list_destroy(scenario_ii_list
);
104 install_info_list_destroy(main_ii_list
);
107 /**************************************************************************
108 Modpack successfully installed. Store information to appropriate list.
109 **************************************************************************/
110 void update_install_info_lists(const char *name
,
111 enum modpack_type type
,
114 struct install_info
*new_ii
;
115 struct install_info_list
*ii_list
;
117 if (type
== MPT_SCENARIO
) {
118 ii_list
= scenario_ii_list
;
119 scenario_list_changed
= TRUE
;
121 ii_list
= main_ii_list
;
122 main_list_changed
= TRUE
;
125 install_info_list_iterate(ii_list
, ii
) {
126 if (!fc_strcasecmp(name
, ii
->name
)) {
127 if (type
!= ii
->type
) {
128 /* TRANS: ... Ubermod ... Ruleset, not Scenario */
129 log_normal(_("Earlier installation of %s found, but it seems to be %s, not %s"),
130 name
, _(modpack_type_name(ii
->type
)), _(modpack_type_name(type
)));
132 log_debug("Earlier installation of %s found", name
);
136 strncpy(ii
->version
, version
, sizeof(ii
->version
));
140 } install_info_list_iterate_end
;
142 /* No existing entry with that name found, creating new one */
143 new_ii
= fc_malloc(sizeof(*new_ii
));
145 strncpy(new_ii
->name
, name
, sizeof(new_ii
->name
));
147 strncpy(new_ii
->version
, version
, sizeof(new_ii
->version
));
149 install_info_list_append(ii_list
, new_ii
);
152 /**************************************************************************
153 Get version number string of currently installed version, or NULL if not
155 **************************************************************************/
156 const char *get_installed_version(const char *name
, enum modpack_type type
)
158 struct install_info_list
*ii_list
;
160 if (type
== MPT_SCENARIO
) {
161 ii_list
= scenario_ii_list
;
163 ii_list
= main_ii_list
;
166 install_info_list_iterate(ii_list
, ii
) {
167 if (!fc_strcasecmp(name
, ii
->name
)) {
170 } install_info_list_iterate_end
;
175 /**************************************************************************
176 Initialize modpack installer
177 **************************************************************************/
181 init_character_encodings(FC_DEFAULT_DATA_ENCODING
, FALSE
);
182 registry_module_init();
186 fc_srand(time(NULL
)); /* Needed at least for Windows version of netfile_get_section_file() */
189 /**************************************************************************
190 Deinitialize modpack installer
191 **************************************************************************/
192 void fcmp_deinit(void)
194 registry_module_close();
195 fc_shutdown_network();
196 /* log_init() was not done by fcmp_init(); we assume the caller called
197 * fcmp_parse_cmdline() (which sets up logging) in between */