1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Correctly rename and lock imported profiles

Imported profiles are legact 'data' and 'tox_save' files
This commit is contained in:
tux3 2015-04-24 20:45:26 +02:00
parent dc5f812946
commit 694933d24b
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
3 changed files with 31 additions and 2 deletions

View File

@ -83,6 +83,8 @@ int main(int argc, char *argv[])
a.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
#endif
qsrand(time(0));
// Process arguments
QCommandLineParser parser;
parser.setApplicationDescription("qTox, version: " + QString(GIT_VERSION) + "\nBuilt: " + __TIME__ + " " + __DATE__);

View File

@ -20,6 +20,7 @@
#include "src/misc/db/plaindb.h"
#include "src/core/core.h"
#include "src/widget/gui.h"
#include "src/profilelocker.h"
#ifdef QTOX_PLATFORM_EXT
#include "src/platform/autorun.h"
#endif
@ -71,6 +72,19 @@ void Settings::switchProfile(const QString& profile)
load();
}
QString Settings::genRandomProfileName()
{
QDir dir(getSettingsDirPath());
QString basename = "imported_";
QString randname;
do {
randname = QString().setNum(qrand()*qrand()*qrand(), 16);
randname.truncate(6);
randname = basename + randname;
} while (QFile(dir.filePath(randname)).exists());
return randname;
}
QString Settings::detectProfile()
{
QDir dir(getSettingsDirPath());
@ -85,9 +99,19 @@ QString Settings::detectProfile()
path = dir.filePath(Core::CONFIG_FILE_NAME);
QFile file(path);
if (file.exists())
return path;
{
profile = genRandomProfileName();
setCurrentProfile(profile);
file.rename(profile + Core::TOX_EXT);
return profile;
}
else if (QFile(path = dir.filePath("tox_save")).exists()) // also import tox_save if no data
return path;
{
profile = genRandomProfileName();
setCurrentProfile(profile);
QFile(path).rename(profile + Core::TOX_EXT);
return profile;
}
else
#endif
{

View File

@ -256,6 +256,9 @@ public:
void save(QString path, bool writePersonal = true);
void load();
private:
static QString genRandomProfileName();
private:
static Settings* settings;