+
+bool MainWindow::testDB(bool reset)
+{
+ try {
+ if (DatabaseManager::openDB()) {
+ qDebug() << " Database opened succesfully!";
+ }
+ else {
+ throw EmuFrontException("Database connection failed!");
+ }
+
+ int dbVer = DbCreator::dbExists();
+ if (dbVer == 0) reset = true;
+ if (!reset && dbVer != DbCreator::DB_VERSION) {
+ QString msg("Database is not compatible "
+ "with current version of EmuFront!"
+ "Do you want to continue to recreate the database?"
+ "ALL THE CURRENT DATA WILL BE LOST!!!");
+ if (QMessageBox::question(this, "Database not compatible!", msg,
+ QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
+ reset = true;
+ }
+ else throw EmuFrontException("The current database is not compatible!"
+ " Cannot continue.");
+ }
+
+ if (reset) {
+ createDB();
+ }
+ return true;
+ }
+ catch (EmuFrontException e) {
+ qDebug() << e.what();
+ errorMessage->showMessage(e.what());
+ return false;
+ }
+}
+
+void MainWindow::createDB() const
+{
+ try
+ {
+ DbCreator dbCreator;
+ dbCreator.createDB();
+ }
+ catch (QString str) {
+ QString msg(tr("Exception while trying to create"
+ " EmuFront database: %s").arg(str));
+ errorMessage->showMessage(msg);
+ }
+}
+