Move linuxdeploy-specific helper out of desktop file class

This commit is contained in:
TheAssassin
2018-12-22 23:02:15 +01:00
parent 3df27ba175
commit 78f33a7190
3 changed files with 41 additions and 3 deletions

View File

@@ -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;
}
}

View File

@@ -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<std::string> desktopFilePaths, std::string customAppRunPath,
linuxdeploy::core::appdir::AppDir& appDir);
/**
*
* @param desktopFile
* @param executableFileName
* @return
*/
bool addDefaultKeys(desktopfile::DesktopFile& desktopFile, const std::string& executableFileName);
}

View File

@@ -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;
}