Profile::Profile(QString name, const QString& password, bool isNewProfile) : name{name}, password{password} , database(std::make_shared<RawDatabase>(getDbPath(name), password)) , newProfile{isNewProfile}, isRemoved{false} { if (!password.isEmpty()) { passkey = *core->createPasskey(password); } Settings& s = Settings::getInstance(); s.setCurrentProfile(name); s.saveGlobal(); // At this point it's too early to load the personal settings (Nexus will do // it), so we always load the history, and if it fails we can't change the // setting now, but we keep a nullptr if (database->isOpen()) { history.reset(new History(database)); } else { qWarning() << "Failed to open history for profile" << name; GUI::showError(QObject::tr("Error"), QObject::tr("qTox couldn't open your chat logs, they will be disabled.")); } coreThread = new QThread(); coreThread->setObjectName("qTox Core"); core = new Core(coreThread, *this); core->moveToThread(coreThread); QObject::connect(coreThread, &QThread::started, core, &Core::start); }
/** * @brief ConfigHandler::dbPathExists * @return Vrai si le fichier de config db existe, faux sinon */ bool ConfigHandler::dbPathExists() const { return (QFile(configFolder + QString(QDir::separator()) + DB).exists() && !getDbPath().isEmpty()); }
void GeoManager::init() { geo6.reset(new GeoIP(getDbPath(true))); geo4.reset(new GeoIP(getDbPath(false))); rebuild(); }
/** * @brief Removes the profile permanently. * Updates the profiles vector. * @return Vector of filenames that could not be removed. * @warning It is invalid to call loadToxSave or saveToxSave on a deleted profile. */ QVector<QString> Profile::remove() { if (isRemoved) { qWarning() << "Profile " << name << " is already removed!"; return {}; } isRemoved = true; qDebug() << "Removing profile" << name; for (int i=0; i<profiles.size(); ++i) { if (profiles[i] == name) { profiles.removeAt(i); i--; } } QString path = Settings::getInstance().getSettingsDirPath() + name; ProfileLocker::unlock(); QFile profileMain {path + ".tox"}; QFile profileConfig {path + ".ini"}; QFile historyLegacyUnencrypted {HistoryKeeper::getHistoryPath(name, 0)}; QFile historyLegacyEncrypted {HistoryKeeper::getHistoryPath(name, 1)}; QVector<QString> ret; if (!profileMain.remove() && profileMain.exists()) { ret.push_back(profileMain.fileName()); qWarning() << "Could not remove file " << profileMain.fileName(); } if (!profileConfig.remove() && profileConfig.exists()) { ret.push_back(profileConfig.fileName()); qWarning() << "Could not remove file " << profileConfig.fileName(); } if (!historyLegacyUnencrypted.remove() && historyLegacyUnencrypted.exists()) { ret.push_back(historyLegacyUnencrypted.fileName()); qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName(); } if (!historyLegacyEncrypted.remove() && historyLegacyEncrypted.exists()) { ret.push_back(historyLegacyEncrypted.fileName()); qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName(); } QString dbPath = getDbPath(name); if (database->isOpen() && !database->remove() && QFile::exists(dbPath)) { ret.push_back(dbPath); qWarning() << "Could not remove file " << dbPath; } history.release(); database.reset(); return ret; }