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" DIR_SEPARATOR DATASUBDIR DIR_SEPARATOR FCMP_CONTROLD DIR_SEPARATOR
"modpacks.db",
56 fc_snprintf(scenario_ii_filename
, sizeof(scenario_ii_filename
),
57 "%s" DIR_SEPARATOR
"scenarios" DIR_SEPARATOR FCMP_CONTROLD DIR_SEPARATOR
"modpacks.db",
60 load_install_info_list(main_ii_filename
, main_ii_list
);
61 load_install_info_list(scenario_ii_filename
, scenario_ii_list
);
64 /**************************************************************************
65 Save all changed install info lists.
66 **************************************************************************/
67 void save_install_info_lists(struct fcmp_params
*fcmp
)
69 if (main_list_changed
) {
72 fc_snprintf(controld
, sizeof(controld
),
73 "%s" DIR_SEPARATOR DATASUBDIR DIR_SEPARATOR FCMP_CONTROLD
,
76 if (make_dir(controld
)) {
77 save_install_info_list(main_ii_filename
, main_ii_list
);
79 log_error(_("Failed to create control directory \"%s\""),
84 if (scenario_list_changed
) {
87 fc_snprintf(controld
, sizeof(controld
),
88 "%s" DIR_SEPARATOR
"scenarios" DIR_SEPARATOR FCMP_CONTROLD
,
91 if (make_dir(controld
)) {
92 save_install_info_list(scenario_ii_filename
, scenario_ii_list
);
94 log_error(_("Failed to create control directory \"%s\""),
99 install_info_list_iterate(scenario_ii_list
, ii
) {
101 } install_info_list_iterate_end
;
103 install_info_list_iterate(main_ii_list
, ii
) {
105 } install_info_list_iterate_end
;
107 install_info_list_destroy(scenario_ii_list
);
108 install_info_list_destroy(main_ii_list
);
111 /**************************************************************************
112 Modpack successfully installed. Store information to appropriate list.
113 **************************************************************************/
114 void update_install_info_lists(const char *name
,
115 enum modpack_type type
,
118 struct install_info
*new_ii
;
119 struct install_info_list
*ii_list
;
121 if (type
== MPT_SCENARIO
) {
122 ii_list
= scenario_ii_list
;
123 scenario_list_changed
= TRUE
;
125 ii_list
= main_ii_list
;
126 main_list_changed
= TRUE
;
129 install_info_list_iterate(ii_list
, ii
) {
130 if (!fc_strcasecmp(name
, ii
->name
)) {
131 if (type
!= ii
->type
) {
132 /* TRANS: ... Ubermod ... Ruleset, not Scenario */
133 log_normal(_("Earlier installation of %s found, but it seems to be %s, not %s"),
134 name
, _(modpack_type_name(ii
->type
)), _(modpack_type_name(type
)));
136 log_debug("Earlier installation of %s found", name
);
140 strncpy(ii
->version
, version
, sizeof(ii
->version
));
144 } install_info_list_iterate_end
;
146 /* No existing entry with that name found, creating new one */
147 new_ii
= fc_malloc(sizeof(*new_ii
));
149 strncpy(new_ii
->name
, name
, sizeof(new_ii
->name
));
151 strncpy(new_ii
->version
, version
, sizeof(new_ii
->version
));
153 install_info_list_append(ii_list
, new_ii
);
156 /**************************************************************************
157 Get version number string of currently installed version, or NULL if not
159 **************************************************************************/
160 const char *get_installed_version(const char *name
, enum modpack_type type
)
162 struct install_info_list
*ii_list
;
164 if (type
== MPT_SCENARIO
) {
165 ii_list
= scenario_ii_list
;
167 ii_list
= main_ii_list
;
170 install_info_list_iterate(ii_list
, ii
) {
171 if (!fc_strcasecmp(name
, ii
->name
)) {
174 } install_info_list_iterate_end
;
179 /**************************************************************************
180 Initialize modpack installer
181 **************************************************************************/
185 init_character_encodings(FC_DEFAULT_DATA_ENCODING
, FALSE
);
186 registry_module_init();
190 fc_srand(time(NULL
)); /* Needed at least for Windows version of netfile_get_section_file() */
193 /**************************************************************************
194 Deinitialize modpack installer
195 **************************************************************************/
196 void fcmp_deinit(void)
198 registry_module_close();
199 fc_shutdown_network();
200 /* log_init() was not done by fcmp_init(); we assume the caller called
201 * fcmp_parse_cmdline() (which sets up logging) in between */