#include "profile.h" #include "profilelocker.h" #include "src/misc/settings.h" #include "src/core/core.h" #include #include #include #include #include #include QVector Profile::profiles; Profile::Profile(QString name, QString password) : name{name}, password{password} { coreThread = new QThread(); coreThread->setObjectName("qTox Core"); core = new Core(coreThread, *this); core->moveToThread(coreThread); QObject::connect(coreThread, &QThread::started, core, &Core::start); } Profile* Profile::loadProfile(QString name, QString password) { if (ProfileLocker::hasLock()) { } if (!ProfileLocker::lock(name)) { qWarning() << "Failed to lock profile "< Profile::getFilesByExt(QString extension) { QDir dir(Settings::getInstance().getSettingsDirPath()); QVector out; dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); dir.setNameFilters(QStringList("*."+extension)); QFileInfoList list = dir.entryInfoList(); out.reserve(list.size()); for (QFileInfo file : list) out += file.completeBaseName(); return out; } void Profile::scanProfiles() { profiles.clear(); QVector toxfiles = getFilesByExt("tox"), inifiles = getFilesByExt("ini"); for (QString toxfile : toxfiles) { if (!inifiles.contains(toxfile)) importProfile(toxfile); profiles.append(toxfile); } } void Profile::importProfile(QString name) { Settings& s = Settings::getInstance(); assert(!s.profileExists(name)); s.createPersonal(name); } QVector Profile::getProfiles() { return profiles; } Core* Profile::getCore() { return core; } void Profile::startCore() { coreThread->start(); } QByteArray Profile::loadToxSave() { QByteArray data; QString path = Settings::getSettingsDirPath() + QDir::separator() + name; QFile saveFile(path); qint64 fileSize; qDebug() << "Loading tox save "<(data.data()), salt); core->setPassword(password, Core::ptMain, salt); data = core->decryptData(data, Core::ptMain); if (data.isEmpty()) qCritical() << "Failed to decrypt the tox save file"; } else { if (!password.isEmpty()) qWarning() << "We have a password, but the tox save file is not encrypted"; } fail: saveFile.close(); return data; } bool Profile::isProfileEncrypted(QString name) { uint8_t data[encryptHeaderSize] = {0}; QString path = Settings::getSettingsDirPath() + QDir::separator() + name + ".tox"; QFile saveFile(path); if (!saveFile.open(QIODevice::ReadOnly)) { qWarning() << "Couldn't open tox save "<