void FileDescriptionDBManager::loadDescription(const boost::filesystem::path& filePath) { gatheringEnabled = true; std::ifstream file(filePath.string()); IR_ASSERT(file.is_open(), std::string("Cannot open file to read (FileDBDescriptionManager: ") + filePath.string() + ")"); std::string str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); std::string className = getClassNameFromPath(filePath); std::vector<std::string> lines(predictLineCount(str)); lines = boost::split(lines, str, isEoL); try { for(auto line: lines) { if(!std::all_of(line.begin(), line.end(), [](char c){return isblank(c, std::locale());})) addDescription(className, loadObjectDescription(line)); } gatheringEnabled = false; } catch(InvalidFile err) { gatheringEnabled = false; throw InvalidFile(filePath.string() + ": " + err.what()); } catch(boost::bad_lexical_cast err) { gatheringEnabled = false; throw InvalidFile(filePath.string() + ": Input data cannot be interpreted as numeric."); } }
MPTWrap::MPTWrap(QIODevice *device) { mod = openmpt_module_create(callbacks, device, openmpt_log_func_silent, nullptr, nullptr); if(mod == nullptr) throw InvalidFile(); openmpt_module_select_subsong(mod, -1); duration_ = openmpt_module_get_duration_seconds(mod) * 1000; title_ = copystr(openmpt_module_get_metadata(mod, "title")); format_ = copystr(openmpt_module_get_metadata(mod, "type_long")); pattern_count_ = openmpt_module_get_num_patterns(mod); instrument_count_ = openmpt_module_get_num_instruments(mod); sample_count_ = openmpt_module_get_num_samples(mod); channel_count_ = openmpt_module_get_num_channels(mod); for(int i = 0; i < openmpt_module_get_num_instruments(mod); i++) { instruments_.push_back(copystr(openmpt_module_get_instrument_name(mod, i))); } for(int i = 0; i < openmpt_module_get_num_samples(mod); i++) { samples_.push_back(copystr(openmpt_module_get_sample_name(mod, i))); } comment_ = copystr(openmpt_module_get_metadata(mod, "message_raw")); }
void Database::init(const std::string &path, const std::string &conn_name, const std::string &create_script) { if (db.get() != nullptr && db->isOpen()) throw AlreadyOpen(path); QString qconn_name = QString::fromStdString(conn_name); if (QSqlDatabase::contains(qconn_name)) { db.reset(new QSqlDatabase(QSqlDatabase::database(qconn_name))); } else { db.reset(new QSqlDatabase(QSqlDatabase::addDatabase(cfg::db::driver, qconn_name))); } QFileInfo info(QString::fromStdString(path)); if (!info.exists()) { info.setFile(QString::fromStdString(create_script)); if (!info.exists() || !info.isFile()) throw InvalidFile(create_script); db->setDatabaseName(QString::fromStdString(path)); if (!db->open()) throw DatabaseError(db->lastError()); QFile file(QString::fromStdString(create_script)); if (!file.open(QFile::ReadOnly)) throw InvalidFile(create_script); QString query = file.readAll(); auto query_list = query.split(';'); for (auto curr_query: query_list) { curr_query = curr_query.trimmed(); if (curr_query.isEmpty()) continue; execute(curr_query.toStdString()); } } else { db->setDatabaseName(QString::fromStdString(path)); } if (!db->open()) throw DatabaseError(db->lastError()); }