31#define MPDB_CAPSTR "+mpdb"
33#define MPDB_FORMAT_VERSION "1"
38static int mpdb_query(sqlite3 *handle,
const char *query);
61 log_error(
"MPDB %s missing capability information", filename);
67 log_error(
"Incompatible mpdb file %s:", filename);
77 bool all_read =
FALSE;
80 for (i = 0 ; !all_read ; i++) {
114 ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
116 if (ret == SQLITE_OK) {
117 ret = sqlite3_step(stmt);
120 if (ret == SQLITE_DONE) {
121 ret = sqlite3_finalize(stmt);
124 if (ret != SQLITE_OK && ret != SQLITE_ROW) {
125 log_error(
"Query \"%s\" failed. (%d)", query, ret);
138 int llen = strlen(filename) + 1;
142 strncpy(local_name, filename, llen);
146 local_name[i] =
'\0';
148 log_error(
_(
"Can't create directory \"%s\" for modpack database."), local_name);
158 ret = sqlite3_open_v2(filename, handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
161 if (ret == SQLITE_OK) {
166 if (ret == SQLITE_OK) {
168 "create table modpacks (name VARCHAR(60) NOT NULL, type VARCHAR(32), version VARCHAR(32) NOT NULL);");
171 if (ret == SQLITE_OK) {
174 log_error(
_(
"Creating \"%s\" failed: %s"), filename, sqlite3_errstr(ret));
192 ret = sqlite3_open_v2(filename, handle, SQLITE_OPEN_READWRITE, NULL);
194 if (ret != SQLITE_OK) {
195 log_error(
_(
"Opening \"%s\" failed: %s"), filename, sqlite3_errstr(ret));
220 if (
type == MPT_SCENARIO) {
226 sqlite3_snprintf(
sizeof(qbuf), qbuf,
"select * from modpacks where name is '%q';",
230 if (ret == SQLITE_ROW) {
231 sqlite3_snprintf(
sizeof(qbuf), qbuf,
232 "update modpacks set type = '%q', version = '%q' where name is '%q';",
233 modpack_type_name(
type), version,
name);
237 sqlite3_snprintf(
sizeof(qbuf), qbuf,
238 "insert into modpacks values ('%q', '%q', '%q');",
239 name, modpack_type_name(
type), version);
243 if (ret != SQLITE_OK) {
247 return ret != SQLITE_OK;
254 enum modpack_type
type)
261 if (
type == MPT_SCENARIO) {
267 sqlite3_snprintf(
sizeof(qbuf), qbuf,
268 "select * from modpacks where name is '%q';",
270 ret = sqlite3_prepare_v2(*handle, qbuf, -1, &stmt, NULL);
272 if (ret == SQLITE_OK) {
273 ret = sqlite3_step(stmt);
276 if (ret == SQLITE_DONE) {
277 ret = sqlite3_finalize(stmt);
280 if (ret == SQLITE_ROW) {
281 return (
const char *)sqlite3_column_text(stmt, 2);
bool has_capabilities(const char *us, const char *them)
#define log_debug(message,...)
#define log_error(message,...)
#define MPDB_FORMAT_VERSION
const char * mpdb_installed_version(const char *name, enum modpack_type type)
static sqlite3 * main_handle
static sqlite3 * scenario_handle
void load_install_info_list(const char *filename)
void create_mpdb(const char *filename, bool scenario_db)
void open_mpdb(const char *filename, bool scenario_db)
bool mpdb_update_modpack(const char *name, enum modpack_type type, const char *version)
static int mpdb_query(sqlite3 *handle, const char *query)
struct section_file * secfile_load(const char *filename, bool allow_duplicates)
void secfile_destroy(struct section_file *secfile)
const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...)
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
bool make_dir(const char *pathname)
#define DIR_SEPARATOR_CHAR
int fc_snprintf(char *str, size_t n, const char *format,...)
int fc_strcasecmp(const char *str0, const char *str1)