-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdatabaseresetmanager.cpp
More file actions
54 lines (47 loc) · 1.84 KB
/
Copy pathdatabaseresetmanager.cpp
File metadata and controls
54 lines (47 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "databaseresetmanager.h"
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDir>
#include <QCoreApplication>
#include <QProcess>
#include <QWidget>
DatabaseResetManager::DatabaseResetManager(QObject *parent)
: QObject(parent)
{
}
void DatabaseResetManager::resetDatabase(QWidget *parentWidget, const QString &databaseDir)
{
QMessageBox msgBox;
msgBox.setTextFormat(Qt::PlainText);
msgBox.setText("Initialize adblink?\nWARNING: This action will delete all device records and settings, then close and restart adblink. Are you sure you want to proceed?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setIcon(QMessageBox::Critical);
QMessageBox::StandardButton reply = static_cast<QMessageBox::StandardButton>(msgBox.exec());
if (reply == QMessageBox::Yes) {
QStringList connections = QSqlDatabase::connectionNames();
for (const QString &conn : connections) {
QSqlDatabase db = QSqlDatabase::database(conn, false);
if (db.isOpen()) {
QSqlQuery query(db);
query.clear();
if (db.transaction())
db.commit();
db.close();
}
QSqlDatabase::removeDatabase(conn);
}
QDir dir(databaseDir);
if (dir.exists() && !dir.removeRecursively()) {
/* #ifdef Q_OS_WIN
QString command = QString("cmd.exe /C rmdir /S /Q \"%1\"").arg(databaseDir.replace("/", "\\"));
QProcess::startDetached(command, QStringList());
#endif */
}
QCoreApplication::quit();
QString program = QCoreApplication::applicationFilePath();
QStringList arguments = QCoreApplication::arguments();
QProcess::startDetached(program, arguments);
}
}