12#include <QSqlDatabase>
14#include <QtConcurrentRun>
26 const std::shared_ptr<ConsistencyChecker> Checker_;
35 return Checker_->DumpReinit ();
63 std::shared_ptr<QSqlDatabase>
db
69 QSqlDatabase::removeDatabase (
connName);
73 db->setDatabaseName (DBPath_);
77 <<
"cannot open the DB, but that's not the kind of errors we're solving.";
102 iface.reportStarted ();
104 DumpReinitImpl (
iface);
106 return iface.future ();
133 if (QMessageBox::question (
nullptr,
135 tr (
"Not enough available space on partition with file %1: "
136 "%2 while the restored file is expected to be around %3. "
137 "Please either free some disk space on this partition "
138 "and retry or cancel the restore process.")
139 .
arg (
"<em>" + DBPath_ +
"</em>",
142 QMessageBox::Retry | QMessageBox::Cancel) == QMessageBox::Cancel)
144 ReportResult (
iface, DumpError {
tr (
"Not enough available disk space.") });
149 const auto&
newPath = DBPath_ +
".new";
156 if (QMessageBox::question (
nullptr,
158 tr (
"%1 already exists. Please either remove the file manually "
159 "and retry or cancel the restore process.")
161 QMessageBox::Retry | QMessageBox::Cancel) == QMessageBox::Cancel)
163 ReportResult (
iface, DumpError {
tr (
"Backup file already exists.") });
175 [
iface] (
const Dumper::Error& error)
178 DumpError {
tr (
"Unable to restore the database.") +
" " + error.What_ });
189 const auto&
backup = DBPath_ +
".bak";
190 while (!QFile::rename (DBPath_,
backup))
191 QMessageBox::critical (
nullptr,
193 tr (
"Unable to backup %1 to %2. Please remove %2 and hit OK.")
197 QFile::rename (
to, DBPath_);
QFuture< CheckResult_t > StartCheck()
std::variant< Succeeded, Failed > CheckResult_t
static std::shared_ptr< ConsistencyChecker > Create(QString dbPath, QString dialogContext)
std::variant< DumpFinished, DumpError > DumpResult_t
std::variant< Finished, Error > Result_t
FailedImpl(std::shared_ptr< ConsistencyChecker > checker)
QString GenConnectionName(const QString &base)
Generates an unique thread-safe connection name.
Container< T > Filter(const Container< T > &c, F f)
auto Visit(const Either< Left, Right > &either, Args &&... args)
SpaceInfo GetSpaceInfo(const QString &path)
Returns the disk space info of the partition containing path.
QString MakePrettySize(qint64 sourcesize)
Makes a formatted size from number.
quint64 Available_
How much space is available to the current user.