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
|
@ -59,6 +59,7 @@ include_directories(
|
|||
)
|
||||
|
||||
set(HEADERS ${HEADERS}
|
||||
${CMAKE_CURRENT_LIST_DIR}/migrations.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/../ipc/ipc.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/amnezia_application.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/containers/containers_defs.h
|
||||
|
@ -85,6 +86,7 @@ if(NOT IOS)
|
|||
endif()
|
||||
|
||||
set(SOURCES ${SOURCES}
|
||||
${CMAKE_CURRENT_LIST_DIR}/migrations.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/amnezia_application.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/containers/containers_defs.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/core/errorstrings.cpp
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "amnezia_application.h"
|
||||
#include "defines.h"
|
||||
#include "migrations.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "Windows.h"
|
||||
|
@ -16,6 +17,9 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Migrations migrationsManager;
|
||||
migrationsManager.doMigrations();
|
||||
|
||||
QLoggingCategory::setFilterRules(QStringLiteral("qtc.ssh=false"));
|
||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
|
||||
|
||||
|
|
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
|
||||
}
|
24
client/migrations.h
Normal file
24
client/migrations.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef MIGRATIONS_H
|
||||
#define MIGRATIONS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Migrations : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Migrations(QObject *parent = nullptr);
|
||||
|
||||
void doMigrations();
|
||||
|
||||
private:
|
||||
void migrateV3();
|
||||
|
||||
private:
|
||||
int currentMajor = 0;
|
||||
int currentMinor = 0;
|
||||
int currentMicro = 0;
|
||||
int currentPatch = 0;
|
||||
};
|
||||
|
||||
#endif // MIGRATIONS_H
|
Loading…
Add table
Add a link
Reference in a new issue