void checkNextVersion(void) { installedVersion = appSettings.value("InstalledVersion", "1.0.0").toString(); QStringList nameFilter; nameFilter << "cashflow_v*.exe"; QDir databaseDir(pth.pathes[PTH_installer]); QStringList fileList = databaseDir.entryList(nameFilter, QDir::Files, QDir::Unsorted); QRegExp versionPattern("cashflow_v(\\d\\.\\d\\.\\d)\\.exe"); QList<QString> versionList = installedVersion.split("."); for (int f=0; f<fileList.count(); f++) { versionPattern.indexIn(fileList[f]); if ((versionPattern.captureCount() > 0) && (!versionPattern.cap(1).isEmpty())) { QList<QString> foundList = versionPattern.cap(1).split("."); if ( (foundList[0].toInt() > versionList[0].toInt()) || ((foundList[0].toInt() == versionList[0].toInt()) && (foundList[1].toInt() > versionList[1].toInt())) || ((foundList[0].toInt() == versionList[0].toInt()) && (foundList[1].toInt() == versionList[1].toInt()) && (foundList[2].toInt() > versionList[2].toInt()))) Msg::show(MSG_INFO, MSG_NEWVERSION, fileList[f]); } } }
QSqlDatabase CommHistoryDatabase::open(const QString &databaseName) { QDir databaseDir(CommHistoryDatabasePath::databaseDir()); if (!databaseDir.exists()) databaseDir.mkpath(QLatin1String(".")); const QString databaseFile = databaseDir.absoluteFilePath(CommHistoryDatabasePath::databaseFile()); const bool exists = QFile::exists(databaseFile); QSqlDatabase database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), databaseName); database.setDatabaseName(databaseFile); if (!database.open()) { qWarning() << "Failed to open commhistory database"; qWarning() << database.lastError(); return database; } else { qWarning() << "Opened commhistory database:" << databaseFile; } for (int i = 0; i < db_setup_count; i++) { if (!execute(database, QLatin1String(db_setup[i]))) { database.close(); if (!exists) QFile::remove(databaseFile); return database; } } if (!exists) { if (!prepareDatabase(database)) { database.close(); QFile::remove(databaseFile); } } else { if (!execute(database, "BEGIN EXCLUSIVE TRANSACTION")) { database.close(); return database; } if (!upgradeDatabase(database) || !execute(database, "END TRANSACTION")) { execute(database, "ROLLBACK"); qCritical() << "Database upgrade failed! Everything may break catastrophically."; } } return database; }
inline void KNJsonDatabase::checkDatabaseDir() { //Check is the destination path is a real dir, and it's exist. QFileInfo databaseDir(m_fileInfo.absolutePath()); if(databaseDir.isDir() && databaseDir.exists()) { return; } //If it's a file, delete it. if(databaseDir.isFile()) { //Remove it. QFile::remove(databaseDir.absoluteFilePath()); } //Generate the dir. QDir().mkpath(databaseDir.absoluteFilePath()); }