Skip to content
Open
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
56 changes: 50 additions & 6 deletions linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,34 @@ void migrateHomePath()
}
}

QString relativeInstallPath()
{
QFileInfo applicationFileInfo(QCoreApplication::applicationFilePath());
if (applicationFileInfo.fileName().toLower().startsWith("relative"))
{
return applicationFileInfo.absolutePath();
}
return QString();
}

QString defaultInstallPath()
{
// if needed, migrate legacy homepath to prevent the updater
// to create the directory before the engine tries to migrate
// it itself
migrateHomePath();

// Does not use QStandardPaths::AppDataLocation because
// it returns "~/.local/share/unvanquished/updater"
// and we want "~/.local/share/unvanquished/base"
// game itself puts stuff in "~/.local/share/unvanquished"
// Relative installation, install next to the updater
// if there is an updater.conf file in the same directory.
QString relative = relativeInstallPath();
if (!relative.isNull()) {
return relative;
}

// Standard installation, do not use QStandardPaths::AppDataLocation
// because it returns: ~/.local/share/unvanquished/updater
// and we want: ~/.local/share/unvanquished/base
// The game itself stores its own files in: ~/.local/share/unvanquished
return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/unvanquished/base";
}

Expand Down Expand Up @@ -161,7 +178,17 @@ bool installShortcuts()
qDebug() << "missing resource" << desktopFileName;
return false;
}
QString desktopStr = QString(desktopFile.readAll().data()).arg(settings.installPath());

QString name = "updater";

if (!relativeInstallPath().isNull()) {
QFileInfo applicationFileInfo(QCoreApplication::applicationFilePath());
name = applicationFileInfo.fileName();
}

QString path = settings.installPath() + QDir::separator() + name;

QString desktopStr = QString(desktopFile.readAll().data()).arg(path);
{
QFile outputFile(desktopDir.filePath(desktopFileName));
if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
Expand Down Expand Up @@ -197,7 +224,15 @@ bool installShortcuts()

bool installUpdater(const QString& installPath) {
QFileInfo src(QCoreApplication::applicationFilePath());

if (!relativeInstallPath().isNull())
{
qDebug() << "Updater is in relative install location";
return true;
}

QFileInfo dest(installPath + QDir::separator() + "updater");

if (src == dest) {
qDebug() << "Updater already in install location";
return true;
Expand Down Expand Up @@ -291,9 +326,18 @@ void initApplicationName()
QCoreApplication::setApplicationName("updater");
}

// Settings are stored in ~/.config/unvanquished/updater.conf
QSettings* makePersistentSettings(QObject* parent)
{
// Relative installation, store the configuration file next to
// the updater if there is already one there.
QString relative = relativeInstallPath();
if (!relative.isNull()) {
qDebug() << "Updater is relative";
return new QSettings(relative + QDir::separator() + "updater.conf", QSettings::NativeFormat, parent);
}

// Standard installation, settings are stored
// in: ~/.config/unvanquished/updater.conf
return new QSettings(parent);
}

Expand Down
4 changes: 2 additions & 2 deletions resources/net.unvanquished.Unvanquished.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Comment=FPS/RTS Game - Aliens vs. Humans
Icon=unvanquished
Terminal=false
Type=Application
Exec="%1/updater" -- %u
TryExec=%1/updater
Exec="%1" -- %u
TryExec=%1
MimeType=x-scheme-handler/unv
Categories=Game;ActionGame;StrategyGame;
StartupWMClass=net.unvanquished.Unvanquished
Expand Down