Implementation of "migration manager" to fix placement of config files issue appeared after moving from Qt 5 to Qt 6
This commit is contained in:
parent
c0bb06bf49
commit
3a5317f16a
4 changed files with 116 additions and 0 deletions
86
client/migrations.cpp
Normal file
86
client/migrations.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "migrations.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
Migrations::Migrations(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
QString version(APP_MAJOR_VERSION);
|
||||
|
||||
QStringList versionDigits = version.split(".");
|
||||
|
||||
if (versionDigits.size() >= 3) {
|
||||
currentMajor = versionDigits[0].toInt();
|
||||
currentMinor = versionDigits[1].toInt();
|
||||
currentMicro = versionDigits[2].toInt();
|
||||
}
|
||||
|
||||
if (versionDigits.size() == 4) {
|
||||
currentPatch = versionDigits[3].toInt();
|
||||
}
|
||||
}
|
||||
|
||||
void Migrations::doMigrations()
|
||||
{
|
||||
if (currentMajor == 3) {
|
||||
migrateV3();
|
||||
}
|
||||
}
|
||||
|
||||
void Migrations::migrateV3()
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
qDebug() << "Migration to V3 on Android...";
|
||||
|
||||
QString packageName = "org.amnezia.vpn";
|
||||
|
||||
QDir dir(".");
|
||||
QString currentDir = dir.absolutePath();
|
||||
|
||||
int packageNameIndex = currentDir.indexOf(packageName);
|
||||
|
||||
if (packageNameIndex == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString rootLocation = currentDir.left(packageNameIndex + packageName.size());
|
||||
|
||||
if (rootLocation.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString location = rootLocation + "/files/.config/AmneziaVPN.ORG/AmneziaVPN.conf";
|
||||
|
||||
QFile oldConfig(location);
|
||||
|
||||
if (oldConfig.exists()) {
|
||||
QString newConfigPath = rootLocation + "/files/settings";
|
||||
|
||||
QDir newConfigDir(newConfigPath);
|
||||
|
||||
newConfigPath += "/AmneziaVPN.ORG";
|
||||
|
||||
bool mkPathRes = newConfigDir.mkpath(newConfigPath);
|
||||
|
||||
if (!mkPathRes) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile newConfigFile(newConfigPath + "/AmneziaVPN.conf");
|
||||
|
||||
if (!newConfigFile.exists()) {
|
||||
bool cpResult = QFile::copy(oldConfig.fileName(), newConfigFile.fileName());
|
||||
if (cpResult) {
|
||||
oldConfig.remove();
|
||||
QDir oldConfigDir(rootLocation + "/files/.config");
|
||||
oldConfigDir.rmdir("AmneziaVPN.ORG");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue