Skip to content

Commit

Permalink
fix: Saves migration on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pktiuk committed Oct 27, 2021
1 parent b0b983a commit 9594836
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
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

0 comments on commit 9594836

Please sign in to comment.