@@ -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+
115125QString 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
198225bool installUpdater (const QString& installPath) {
199226 QFileInfo src (QCoreApplication::applicationFilePath ());
227+
228+ if (!relativeInstallPath ().isNull ())
229+ {
230+ qDebug () << " Updater is in relative install location" ;
231+ return true ;
232+ }
233+
200234 QFileInfo dest (installPath + QDir::separator () + " updater" );
235+
201236 if (src == dest) {
202237 qDebug () << " Updater already in install location" ;
203238 return true ;
@@ -291,9 +326,18 @@ void initApplicationName()
291326 QCoreApplication::setApplicationName (" updater" );
292327}
293328
294- // Settings are stored in ~/.config/unvanquished/updater.conf
295329QSettings* 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+ qDebug () << " Updater is relative" ;
336+ return new QSettings (relative + QDir::separator () + " updater.conf" , QSettings::NativeFormat, parent);
337+ }
338+
339+ // Standard installation, settings are stored
340+ // in: ~/.config/unvanquished/updater.conf
297341 return new QSettings (parent);
298342}
299343
0 commit comments