diff --git a/src/core.cpp b/src/core.cpp index 9ea74d9..f5884a4 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -39,7 +39,7 @@ namespace linuxdeploy { deployedDesktopFiles.begin(), deployedDesktopFiles.end(), [&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) { - auto fileName = desktopFile.path().filename().string(); + auto fileName = desktopFile.path(); return fileName == firstDeployedDesktopFileName; } ); @@ -85,4 +85,34 @@ namespace linuxdeploy { return false; } } + + bool addDefaultKeys(DesktopFile& desktopFile, const std::string& executableFileName) { + ldLog() << "Adding default values to desktop file:" << desktopFile.path() << std::endl; + + auto rv = true; + + auto setDefault = [&rv, &desktopFile](const std::string& section, const std::string& key, const std::string& value) { + if (desktopFile.entryExists(section, key)) { + DesktopFileEntry entry; + + // this should never return false + auto entryExists = desktopFile.getEntry(section, key, entry); + assert(entryExists); + + ldLog() << LD_WARNING << "Key exists, not modified:" << key << "(current value:" << entry.value() << LD_NO_SPACE << ")" << std::endl; + rv = false; + } else { + auto entryOverwritten = desktopFile.setEntry(section, DesktopFileEntry(key, value)); + assert(!entryOverwritten); + } + }; + + setDefault("Desktop Entry", "Name", executableFileName); + setDefault("Desktop Entry", "Exec", executableFileName); + setDefault("Desktop Entry", "Icon", executableFileName); + setDefault("Desktop Entry", "Type", "Application"); + setDefault("Desktop Entry", "Categories", "Utility;"); + + return rv; + } } diff --git a/src/core.h b/src/core.h index 9559689..bbabe4d 100644 --- a/src/core.h +++ b/src/core.h @@ -7,7 +7,7 @@ namespace linuxdeploy { /** - * Deploy the application ".deskop", icon, and runnable files in the AppDir root path. According to the + * Deploy the application ".desktop", icon, and runnable files in the AppDir root path. According to the * AppDir spec at: https://docs.appimage.org/reference/appdir.html * * @param desktopFilePaths to be deployed in the AppDir root @@ -17,4 +17,12 @@ namespace linuxdeploy { */ bool deployAppDirRootFiles(std::vector desktopFilePaths, std::string customAppRunPath, linuxdeploy::core::appdir::AppDir& appDir); + + /** + * + * @param desktopFile + * @param executableFileName + * @return + */ + bool addDefaultKeys(desktopfile::DesktopFile& desktopFile, const std::string& executableFileName); } diff --git a/src/main.cpp b/src/main.cpp index 82c4cfb..5437065 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -245,7 +245,7 @@ int main(int argc, char** argv) { } desktopfile::DesktopFile desktopFile; - if (!desktopFile.addDefaultKeys(executableName)) { + if (!addDefaultKeys(desktopFile, executableName)) { ldLog() << LD_WARNING << "Tried to overwrite existing entries in desktop file:" << desktopFilePath << std::endl; }