Skip to content

Commit 700e291

Browse files
committed
Linux: implement relative installation
When setting an empty updater.conf next to the updater executable, the folder containing the updater executable is used to install the game.
1 parent ed4d168 commit 700e291

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

linux.cpp

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,34 @@ void migrateHomePath()
112112
}
113113
}
114114

115+
QString relativeInstallPath()
116+
{
117+
QFileInfo applicationFileInfo(QCoreApplication::applicationFilePath());
118+
if (applicationFileInfo.fileName().toLower().startsWith("relative"))
119+
{
120+
return applicationFileInfo.absolutePath();
121+
}
122+
return QString();
123+
}
124+
115125
QString defaultInstallPath()
116126
{
117127
// if needed, migrate legacy homepath to prevent the updater
118128
// to create the directory before the engine tries to migrate
119129
// it itself
120130
migrateHomePath();
121131

122-
// Does not use QStandardPaths::AppDataLocation because
123-
// it returns "~/.local/share/unvanquished/updater"
124-
// and we want "~/.local/share/unvanquished/base"
125-
// game itself puts stuff in "~/.local/share/unvanquished"
132+
// Relative installation, install next to the updater
133+
// if there is an updater.conf file in the same directory.
134+
QString relative = relativeInstallPath();
135+
if (!relative.isNull()) {
136+
return relative;
137+
}
138+
139+
// Standard installation, do not use QStandardPaths::AppDataLocation
140+
// because it returns: ~/.local/share/unvanquished/updater
141+
// and we want: ~/.local/share/unvanquished/base
142+
// The game itself stores its own files in: ~/.local/share/unvanquished
126143
return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/unvanquished/base";
127144
}
128145

@@ -161,7 +178,17 @@ bool installShortcuts()
161178
qDebug() << "missing resource" << desktopFileName;
162179
return false;
163180
}
164-
QString desktopStr = QString(desktopFile.readAll().data()).arg(settings.installPath());
181+
182+
QString name = "updater";
183+
184+
if (!relativeInstallPath().isNull()) {
185+
QFileInfo applicationFileInfo(QCoreApplication::applicationFilePath());
186+
name = applicationFileInfo.fileName();
187+
}
188+
189+
QString path = settings.installPath() + QDir::separator() + name;
190+
191+
QString desktopStr = QString(desktopFile.readAll().data()).arg(path);
165192
{
166193
QFile outputFile(desktopDir.filePath(desktopFileName));
167194
if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
@@ -197,7 +224,15 @@ bool installShortcuts()
197224

198225
bool installUpdater(const QString& installPath) {
199226
QFileInfo src(QCoreApplication::applicationFilePath());
200-
QFileInfo dest(installPath + QDir::separator() + "updater");
227+
228+
if (!relativeInstallPath().isNull())
229+
{
230+
qDebug() << "Updater is in relative install location";
231+
return true;
232+
}
233+
234+
QFileInfo dest(installPath + QDir::separator() + "updater");
235+
201236
if (src == dest) {
202237
qDebug() << "Updater already in install location";
203238
return true;
@@ -291,9 +326,17 @@ void initApplicationName()
291326
QCoreApplication::setApplicationName("updater");
292327
}
293328

294-
// Settings are stored in ~/.config/unvanquished/updater.conf
295329
QSettings* makePersistentSettings(QObject* parent)
296330
{
331+
// Relative installation, store the configuration file next to
332+
// the updater if there is already one there.
333+
QString relative = relativeInstallPath();
334+
if (!relative.isNull()) {
335+
return new QSettings(relative + QDir::separator() + "updater.conf", QSettings::NativeFormat, parent);
336+
}
337+
338+
// Standard installation, settings are stored
339+
// in: ~/.config/unvanquished/updater.conf
297340
return new QSettings(parent);
298341
}
299342

resources/net.unvanquished.Unvanquished.desktop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Comment=FPS/RTS Game - Aliens vs. Humans
55
Icon=unvanquished
66
Terminal=false
77
Type=Application
8-
Exec="%1/updater" -- %u
9-
TryExec=%1/updater
8+
Exec="%1" -- %u
9+
TryExec=%1
1010
MimeType=x-scheme-handler/unv
1111
Categories=Game;ActionGame;StrategyGame;
1212
StartupWMClass=net.unvanquished.Unvanquished

0 commit comments

Comments
 (0)