@@ -138,9 +138,22 @@ bool installShortcuts()
138
138
{
139
139
// Set up menu and protocol handler
140
140
Settings settings;
141
- QString desktopDir = QStandardPaths::writableLocation (QStandardPaths::ApplicationsLocation);
142
- QFile::remove (desktopDir + " /unvanquished.desktop" ); // updater v0.0.5 and before
143
- QFile::remove (desktopDir + " /net.unvanquished.UnvanquishedProtocolHandler.desktop" ); // up to v0.2.0
141
+ QString desktopDirString = QStandardPaths::writableLocation (QStandardPaths::ApplicationsLocation);
142
+ if (desktopDirString.isEmpty ()) {
143
+ qDebug () << " ApplicationsLocation for desktop files not provided" ;
144
+ return false ;
145
+ }
146
+ QDir desktopDir (desktopDirString);
147
+ if (desktopDir.exists ()) {
148
+ desktopDir.remove (" unvanquished.desktop" ); // updater v0.0.5 and before
149
+ desktopDir.remove (" net.unvanquished.UnvanquishedProtocolHandler.desktop" ); // up to v0.2.0
150
+ } else {
151
+ if (!desktopDir.mkpath (" ." )) {
152
+ qDebug () << " Could not create directory for desktop files" << desktopDirString;
153
+ return false ;
154
+ }
155
+ qDebug () << " Created directory for desktop files" << desktopDirString;
156
+ }
144
157
145
158
QString desktopFileName = " net.unvanquished.Unvanquished.desktop" ;
146
159
QFile desktopFile (" :resources/" + desktopFileName);
@@ -150,22 +163,24 @@ bool installShortcuts()
150
163
}
151
164
QString desktopStr = QString (desktopFile.readAll ().data ()).arg (settings.installPath ());
152
165
{
153
- QFile outputFile (desktopDir + " / " + desktopFileName);
166
+ QFile outputFile (desktopDir. filePath ( desktopFileName) );
154
167
if (!outputFile.open (QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
155
- qDebug () << " error opening" << desktopFileName ;
168
+ qDebug () << " error opening" << outputFile. fileName () ;
156
169
return false ;
157
170
}
158
171
if (outputFile.write (desktopStr.toUtf8 ().constData (), desktopStr.size ()) != desktopStr.size ()) {
159
- qDebug () << " error writing" << desktopFileName ;
172
+ qDebug () << " error writing" << outputFile. fileName () ;
160
173
return false ;
161
174
}
175
+ qDebug () << " Created desktop file" << outputFile.fileName ();
162
176
}
177
+
163
178
int ret = QProcess::execute (" xdg-mime" ,
164
179
{QString (" default" ),
165
- desktopDir + " / " + desktopFileName,
180
+ desktopDir. filePath ( desktopFileName) ,
166
181
QString (" x-scheme-handler/unv" )});
167
182
qDebug () << " xdg-mime returned" << ret;
168
- ret = QProcess::execute (" update-desktop-database" , {desktopDir });
183
+ ret = QProcess::execute (" update-desktop-database" , {desktopDirString });
169
184
qDebug () << " update-desktop-database returned" << ret;
170
185
171
186
// install icon
0 commit comments