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>
19 #include "capability.h"
29 #define MPDB_CAPSTR "+mpdb"
31 /**************************************************************************
32 Construct install info list from file.
33 **************************************************************************/
34 void load_install_info_list(const char *filename
,
35 struct install_info_list
*list
)
37 struct section_file
*file
;
40 file
= secfile_load(filename
, FALSE
);
43 /* This happens in first run - or actually all runs until something is
44 * installed. Previous run has not saved database. */
45 log_debug("No install info file");
50 caps
= secfile_lookup_str(file
, "info.options");
53 log_error("MPDB %s missing capability information", filename
);
54 secfile_destroy(file
);
58 if (!has_capabilities(MPDB_CAPSTR
, caps
)) {
59 log_error("Incompatible mpdb file %s:", filename
);
60 log_error(" file options: %s", caps
);
61 log_error(" supported options: %s", MPDB_CAPSTR
);
63 secfile_destroy(file
);
69 bool all_read
= FALSE
;
72 for (i
= 0 ; !all_read
; i
++) {
76 fc_snprintf(buf
, sizeof(buf
), "modpacks.mp%d", i
);
78 str
= secfile_lookup_str_default(file
, NULL
, "%s.name", buf
);
81 struct install_info
*ii
;
83 ii
= fc_malloc(sizeof(*ii
));
85 strncpy(ii
->name
, str
, sizeof(ii
->name
));
86 str
= secfile_lookup_str(file
, "%s.type", buf
);
87 ii
->type
= modpack_type_by_name(str
, fc_strcasecmp
);
88 str
= secfile_lookup_str(file
, "%s.version", buf
);
89 strncpy(ii
->version
, str
, sizeof(ii
->version
));
91 install_info_list_append(list
, ii
);
97 secfile_destroy(file
);
101 /**************************************************************************
102 Save install info list to file.
103 **************************************************************************/
104 void save_install_info_list(const char *filename
,
105 struct install_info_list
*list
)
108 struct section_file
*file
= secfile_new(TRUE
);
110 secfile_insert_str(file
, MPDB_CAPSTR
, "info.options");
112 install_info_list_iterate(list
, ii
) {
115 fc_snprintf(buf
, sizeof(buf
), "modpacks.mp%d", i
);
117 secfile_insert_str(file
, ii
->name
, "%s.name", buf
);
118 secfile_insert_str(file
, modpack_type_name(ii
->type
),
120 secfile_insert_str(file
, ii
->version
, "%s.version", buf
);
123 } install_info_list_iterate_end
;
125 if (!secfile_save(file
, filename
, 0, FZ_PLAIN
)) {
126 log_error("Saving of install info to file %s failed.", filename
);
129 secfile_destroy(file
);