diff --git a/Configuration.cpp b/Configuration.cpp index dbbf741ec..03f5b2ac2 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -160,8 +160,6 @@ #include #include #include -#include -#include #include #include "pimpl_impl.hpp" @@ -949,14 +947,6 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network ui_->setupUi (this); { - // Find a suitable data file location - if (!writeable_data_dir_.mkpath (".")) - { - MessageBox::critical_message (this, tr ("Failed to create data directory"), - tr ("path: \"%1\"").arg (writeable_data_dir_.absolutePath ())); - throw std::runtime_error {"Failed to create data directory"}; - } - // Make sure the default save directory exists QString save_dir {"save"}; default_save_directory_ = writeable_data_dir_; @@ -1002,18 +992,6 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network // this must be done after the default paths above are set read_settings (); - // set up SQLite database - if (!QSqlDatabase::drivers ().contains ("QSQLITE")) - { - throw std::runtime_error {"Failed to find SQLite Qt driver"}; - } - auto db = QSqlDatabase::addDatabase ("QSQLITE"); - db.setDatabaseName (writeable_data_dir_.absoluteFilePath ("db.sqlite")); - if (!db.open ()) - { - throw std::runtime_error {("Database Error: " + db.lastError ().text ()).toStdString ()}; - } - // conditionally load LotW users data ui_->LotW_CSV_fetch_push_button->setEnabled (false); connect (&lotw_users_, &LotWUsers::load_finished, [this] () { diff --git a/main.cpp b/main.cpp index bc337bb7d..784b709cd 100644 --- a/main.cpp +++ b/main.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include "revision_utils.hpp" #include "MetaDataRegistry.hpp" @@ -233,6 +235,27 @@ int main(int argc, char *argv[]) } } + // create writeable data directory if not already there + auto writeable_data_dir = QDir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}; + if (!writeable_data_dir.mkpath (".")) + { + MessageBox::critical_message (nullptr, a.translate ("main", "Failed to create data directory"), + a.translate ("main", "path: \"%1\"").arg (writeable_data_dir.absolutePath ())); + throw std::runtime_error {"Failed to create data directory"}; + } + + // set up SQLite database + if (!QSqlDatabase::drivers ().contains ("QSQLITE")) + { + throw std::runtime_error {"Failed to find SQLite Qt driver"}; + } + auto db = QSqlDatabase::addDatabase ("QSQLITE"); + db.setDatabaseName (writeable_data_dir.absoluteFilePath ("db.sqlite")); + if (!db.open ()) + { + throw std::runtime_error {("Database Error: " + db.lastError ().text ()).toStdString ()}; + } + int result; do {