diff --git a/code/ryzom/tools/client/ryzom_installer/res/resources.qrc b/code/ryzom/tools/client/ryzom_installer/res/resources.qrc index 0e7224f4e..66d8f502e 100644 --- a/code/ryzom/tools/client/ryzom_installer/res/resources.qrc +++ b/code/ryzom/tools/client/ryzom_installer/res/resources.qrc @@ -5,4 +5,7 @@ ryzom.ico + + template.desktop + diff --git a/code/ryzom/tools/client/ryzom_installer/res/template.desktop b/code/ryzom/tools/client/ryzom_installer/res/template.desktop new file mode 100644 index 000000000..83c42f5a6 --- /dev/null +++ b/code/ryzom/tools/client/ryzom_installer/res/template.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Version=1.0 +Name=$NAME +Type=Application +GenericName=MMORPG +Exec=$COMMAND +Icon=$ICON +Terminal=false +Hidden=false +Categories=Game;RolePlaying; diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp index ba65bd2ad..1e3c324a7 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp @@ -97,21 +97,7 @@ wchar_t* qToWide(const QString &str) #ifdef Q_OS_WIN32 -// CreateLink - Uses the Shell's IShellLink and IPersistFile interfaces -// to create and store a shortcut to the specified object. -// -// Returns the result of calling the member functions of the interfaces. -// -// Parameters: -// lpszPathObj - Address of a buffer that contains the path of the object, -// including the file name. -// lpszPathLink - Address of a buffer that contains the path where the -// Shell link is to be stored, including the file name. -// lpszDesc - Address of a buffer that contains a description of the -// Shell link, stored in the Comment field of the link -// properties. - -bool createLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc) +bool createLink(const QString &link, const QString &name, const QString &executable, const QString &arguments, const QString &icon, const QString &workingDir) { IShellLinkW* psl; @@ -123,8 +109,9 @@ bool createLink(const QString &pathObj, const QString &pathLink, const QString & IPersistFile* ppf; // Set the path to the shortcut target and add the description. - psl->SetPath(qToWide(QDir::toNativeSeparators(pathObj))); - psl->SetDescription(qToWide(desc)); + psl->SetPath(qToWide(QDir::toNativeSeparators(executable))); + psl->SetIconLocation(qToWide(QDir::toNativeSeparators(icon)), 0); + psl->SetDescription(qToWide(name)); psl->SetArguments(qToWide(arguments)); psl->SetWorkingDirectory(qToWide(QDir::toNativeSeparators(workingDir))); @@ -138,7 +125,7 @@ bool createLink(const QString &pathObj, const QString &pathLink, const QString & // for success. // Save the link by calling IPersistFile::Save. - hres = ppf->Save(qToWide(QDir::toNativeSeparators(pathLink)), TRUE); + hres = ppf->Save(qToWide(QDir::toNativeSeparators(link)), TRUE); ppf->Release(); } psl->Release(); @@ -146,23 +133,6 @@ bool createLink(const QString &pathObj, const QString &pathLink, const QString & return SUCCEEDED(hres); } -// ResolveIt - Uses the Shell's IShellLink and IPersistFile interfaces -// to retrieve the path and description from an existing shortcut. -// -// Returns the result of calling the member functions of the interfaces. -// -// Parameters: -// hwnd - A handle to the parent window. The Shell uses this window to -// display a dialog box if it needs to prompt the user for more -// information while resolving the link. -// lpszLinkFile - Address of a buffer that contains the path of the link, -// including the file name. -// lpszPath - Address of a buffer that receives the path of the link -// target, including the file name. -// lpszDesc - Address of a buffer that receives the description of the -// Shell link, stored in the Comment field of the link -// properties. - bool resolveLink(const QWidget &window, const QString &linkFile, QString &path) { IShellLinkW* psl; @@ -232,11 +202,35 @@ bool resolveLink(const QWidget &window, const QString &linkFile, QString &path) #else -bool createLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc) +bool createLink(const QString &link, const QString &name, const QString &executable, const QString &arguments, const QString &icon, const QString &workingDir) { - // TODO: create .desktop file under Linux + // open template + QFile file(":/templates/template.desktop"); - return false; + if (!file.open(QFile::ReadOnly)) return false; + + QString data = QString::fromUtf8(file.readAll()); + + file.close(); + + // build command + QString command = executable; + if (!arguments.isEmpty()) command += " " + arguments; + + // replace strings + data.replace("$NAME", name); + data.replace("$COMMAND", command); + data.replace("$ICON", icon); + + // write file + file.setFileName(link); + + if (!file.open(QFile::WriteOnly)) return false; + + file.write(data.toUtf8()); + file.close(); + + return true; } bool resolveLink(const QWidget &window, const QString &pathLink, QString &pathObj) diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.h b/code/ryzom/tools/client/ryzom_installer/src/utils.h index c729ba2cb..8072f69d6 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.h +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.h @@ -48,7 +48,7 @@ QString qFromWide(const wchar_t *str); wchar_t* qToWide(const QString &str); -bool createLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc); +bool createLink(const QString &link, const QString &name, const QString &executable, const QString &arguments, const QString &icon, const QString &workingDir); bool resolveLink(const QWidget &window, const QString &pathLink, QString &pathObj); bool copyInstallerExecutable(const QString &destination);