27 #define MPDB_CAPSTR "+mpdb"
29 #define MPDB_FORMAT_VERSION "1"
34 static int mpdb_query(sqlite3 *handle,
const char *query);
46 if (file ==
nullptr) {
56 if (caps ==
nullptr) {
57 qCritical(
"MPDB %s missing capability information", filename);
63 qCritical(
"Incompatible mpdb file %s:", filename);
64 qCritical(
" file options: %s", caps);
72 if (file !=
nullptr) {
73 bool all_read =
false;
76 for (i = 0; !all_read; i++) {
111 ret = sqlite3_prepare_v2(handle, query, -1, &stmt,
nullptr);
113 if (ret == SQLITE_OK) {
114 ret = sqlite3_step(stmt);
117 if (ret != SQLITE_DONE && ret != SQLITE_ROW) {
118 qCritical(
"Query \"%s\" failed. (%d)", query, ret);
121 if (
int errcode = sqlite3_finalize(stmt); errcode != SQLITE_OK) {
122 qCritical(
"Finalizing query \"%s\" returned error. (%d)", query,
138 if (QFileInfo info(filename); !QDir().mkpath(info.dir().path())) {
139 qCritical(
_(
"Can't create directory \"%s\" for modpack database."),
140 qUtf8Printable(info.dir().path()));
150 ret = sqlite3_open_v2(filename, handle,
151 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
nullptr);
153 if (ret == SQLITE_OK) {
160 if (ret == SQLITE_DONE) {
162 "create table modpacks (name VARCHAR(60) NOT null, "
163 "type VARCHAR(32), version VARCHAR(32) NOT null);");
166 if (ret == SQLITE_DONE) {
169 qCritical(
_(
"Creating \"%s\" failed: %s"), filename,
170 sqlite3_errstr(ret));
188 ret = sqlite3_open_v2(filename, handle, SQLITE_OPEN_READWRITE,
nullptr);
190 if (ret != SQLITE_OK) {
191 qCritical(
_(
"Opening \"%s\" failed: %s"), filename, sqlite3_errstr(ret));
216 if (type == MPT_SCENARIO) {
222 sqlite3_snprintf(
sizeof(qbuf), qbuf,
223 "select * from modpacks where name is '%q';",
name);
226 if (ret == SQLITE_ROW) {
227 sqlite3_snprintf(
sizeof(qbuf), qbuf,
228 "update modpacks set type = '%q', version = '%q' where "
230 modpack_type_name(type), version,
name);
234 sqlite3_snprintf(
sizeof(qbuf), qbuf,
235 "insert into modpacks values ('%q', '%q', '%q');",
name,
236 modpack_type_name(type), version);
240 if (ret != SQLITE_DONE) {
241 qCritical(
_(
"Failed to insert modpack '%s' information"),
name);
244 return ret != SQLITE_DONE;
256 const char *version =
nullptr;
259 if (type == MPT_SCENARIO) {
265 sqlite3_snprintf(
sizeof(qbuf), qbuf,
266 "select * from modpacks where name is '%q';",
name);
267 ret = sqlite3_prepare_v2(*handle, qbuf, -1, &stmt,
nullptr);
269 if (ret == SQLITE_OK) {
270 ret = sqlite3_step(stmt);
273 if (ret == SQLITE_ROW) {
274 version = qstrdup((
const char *) sqlite3_column_text(stmt, 2));
277 if (ret != SQLITE_DONE && ret != SQLITE_ROW) {
278 qCritical(
"Query to get installed version for \"%s\" failed. (%d)",
name,
282 if (
int errcode = sqlite3_finalize(stmt); errcode != SQLITE_OK) {
284 "Finalizing query to get installed version for \"%s\" failed. (%d)",
bool has_capabilities(const char *us, const char *them)
This routine returns true if all the mandatory capabilities in us appear in them.
#define fc_assert_action(condition, action)
#define log_debug(message,...)
#define MPDB_FORMAT_VERSION
void close_mpdbs()
Close open databases.
static sqlite3 * main_handle
static sqlite3 * scenario_handle
void load_install_info_list(const char *filename)
Construct install info list from file.
const char * mpdb_installed_version(const char *name, enum modpack_type type)
Return version of modpack.
void create_mpdb(const char *filename, bool scenario_db)
Create modpack database.
void open_mpdb(const char *filename, bool scenario_db)
Open existing database.
bool mpdb_update_modpack(const char *name, enum modpack_type type, const char *version)
Update modpack information in database.
static int mpdb_query(sqlite3 *handle, const char *query)
SQL query to database.
struct section_file * secfile_load(const QString &filename, bool allow_duplicates)
Create a section file from a file.
void secfile_destroy(struct section_file *secfile)
Free a section file.
const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...)
Lookup a string value in the secfile.
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
Lookup a string value in the secfile.
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.