MCPcopy Create free account
hub / github.com/TheAssassin/AppImageLauncher / installDesktopFileAndIcons

Function installDesktopFileAndIcons

src/shared/shared.cpp:603–874  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

601#endif
602
603bool installDesktopFileAndIcons(const QString& pathToAppImage, bool resolveCollisions) {
604 if (appimage_register_in_system(pathToAppImage.toStdString().c_str(), false) != 0) {
605 displayError(QObject::tr("Failed to register AppImage in system via libappimage"));
606 return false;
607 }
608
609 const auto* desktopFilePath = appimage_registered_desktop_file_path(pathToAppImage.toStdString().c_str(), nullptr, false);
610
611 // sanity check -- if the file doesn't exist, the function returns NULL
612 if (desktopFilePath == nullptr) {
613 displayError(QObject::tr("Failed to find integrated desktop file"));
614 return false;
615 }
616
617 // check that file exists
618 if (!QFile(desktopFilePath).exists()) {
619 displayError(QObject::tr("Couldn't find integrated AppImage's desktop file"));
620 return false;
621 }
622
623 /* write AppImageLauncher specific entries to desktop file
624 *
625 * unfortunately, QSettings doesn't work as a desktop file reader/writer, and libqtxdg isn't really meant to be
626 * used by projects via add_subdirectory/ExternalProject
627 * a system dependency is not an option for this project, and we link to glib already anyway, so let's just use
628 * glib, which is known to work
629 */
630
631 std::shared_ptr<GKeyFile> desktopFile(g_key_file_new(), gKeyFileDeleter);
632
633 std::shared_ptr<GError*> error(nullptr, gErrorDeleter);
634
635 const auto flags = GKeyFileFlags(G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS);
636
637 auto handleError = [error, desktopFile]() {
638 std::ostringstream ss;
639 ss << QObject::tr("Failed to load desktop file:").toStdString() << std::endl << (*error)->message;
640 displayError(QString::fromStdString(ss.str()));
641 };
642
643 if (!g_key_file_load_from_file(desktopFile.get(), desktopFilePath, flags, error.get())) {
644 handleError();
645 return false;
646 }
647
648 const auto* nameEntry = g_key_file_get_string(desktopFile.get(), G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, error.get());
649
650 if (nameEntry == nullptr) {
651 displayWarning(QObject::tr("AppImage has invalid desktop file"));
652 }
653
654 if (resolveCollisions) {
655 // TODO: support multilingual collisions
656 auto collisions = findCollisions(nameEntry);
657
658 // make sure to remove own entry
659 collisions.erase(collisions.find(desktopFilePath));
660

Callers 5

execMethod · 0.85
integrateAppImageFunction · 0.85
mainFunction · 0.85
runMethod · 0.85

Calls 5

displayErrorFunction · 0.85
displayWarningFunction · 0.85
findCollisionsFunction · 0.85
privateLibDirPathFunction · 0.85
makeExecutableFunction · 0.85

Tested by

no test coverage detected