Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saves migration win #266

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
static QString findWinSystemConfigPath()
{
QString temp;
temp = (!qgetenv("LocalAppData").isEmpty()) ? QString::fromUtf8(qgetenv("LocalAppData")) + "/antimicrox"
: QDir::homePath() + "/.antimicrox";
temp = (!qgetenv("LocalAppData").isEmpty()) ? QString::fromUtf8(qgetenv("LocalAppData")) + "\\antimicrox"
: QDir::homePath() + "\\.antimicrox";
return temp;
}

Expand Down Expand Up @@ -95,30 +95,38 @@ const QString configFileName = "antimicrox_settings.ini";
inline QString configFilePath()
{
#if defined(Q_OS_WIN) && defined(WIN_PORTABLE_PACKAGE)
return QString(configPath()).append("/").append(configFileName);
return QString(configPath()).append("\\").append(configFileName);
#elif defined(Q_OS_WIN)
return QString(configPath()).append("/").append(configFileName);
return QString(configPath()).append("\\").append(configFileName);
#else
return QString(configPath()).append("/").append(configFileName);
#endif
}

inline QString configLegacyFilePath()
{
#if defined(Q_OS_WIN)
return ""; // earlier vesrions of antimicrox was not supported by Windows
#else
QString configPath = (!qgetenv("XDG_CONFIG_HOME").isEmpty())
? QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicroX"
: QDir::homePath() + "/.config/antimicroX";

return QString(configPath).append("/").append("antimicroX_settings.ini");
#endif
}

inline QString configAntimicroLegacyFilePath()
{
#if defined(Q_OS_WIN)
QString temp = configFilePath().replace("antimicrox", "antimicro").replace("/", "\\");
return temp;
#else
QString configPath = (!qgetenv("XDG_CONFIG_HOME").isEmpty())
? QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicro"
: QDir::homePath() + "/.config/antimicro";

return QString(configPath).append("/").append("antimicro_settings.ini");
#endif
}

const int LATESTCONFIGFILEVERSION = 19;
Expand Down
27 changes: 15 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,23 @@ void importLegacySettingsIfExist()
if (requireMigration)
{
const QFileInfo fileToCopy = legacyConfigExists ? legacyConfig : legacyAntimicroConfig;
#if defined(Q_OS_WIN)
const QString location = PadderCommon::configPath();
#else
const QString location = "~/.config/antimicrox";
#endif
QDir(PadderCommon::configPath()).mkpath(PadderCommon::configPath());
const bool copySuccess = QFile::copy(fileToCopy.canonicalFilePath(), PadderCommon::configFilePath());
qDebug() << "Legacy settings found";
const QString successMessage = QString("Your original settings (previously stored in %1) "
"have been copied to "
"~/.config/antimicrox to ensure consistent naming across "
"entire project.\nIf you want you can "
"delete the original directory or leave it as it is.")
.arg(fileToCopy.canonicalFilePath());
const QString errorMessage = QString("Some problem with settings migration occurred.\nOriginal "
"configs are stored in %1 "
"but their new location is ~/.config/antimicrox.\n"
"You can migrate manually by renaming old directory and "
"renaming file to antimicrox_settings.ini.")
.arg(fileToCopy.canonicalFilePath());
const QString successMessage =
QObject::tr("Your original settings (previously stored in %1) have been copied to\n%2\n If you want you can "
"delete the original directory or leave it as it is.")
.arg(fileToCopy.canonicalFilePath(), location);
const QString errorMessage =
QObject::tr("Some problem with settings migration occurred.\nOriginal configs are stored in \n%1\n but their "
"new location is: \n%2\nYou can migrate manually by renaming old directory and renaming file to "
"antimicrox_settings.ini.")
.arg(fileToCopy.canonicalFilePath(), location);

QMessageBox msgBox;
if (copySuccess)
Expand Down