From 2bee994f5394df02002a8e81a787750aea3420ff Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Fri, 1 Jun 2018 21:49:03 +0200 Subject: [PATCH] Rename icons like _*.ext to .ext This allows users to specify multiple icons like -i app_res1.png -i app_res2.png -i [...] linuxdeploy can sort them into the right directory structure, and their name will be equal to the app name (which is most likely equal to the Icon entry in the desktop file). --- include/linuxdeploy/core/appdir.h | 6 ++++++ src/core/appdir.cpp | 21 +++++++++++++++++++-- src/core/main.cpp | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/linuxdeploy/core/appdir.h b/include/linuxdeploy/core/appdir.h index 20c6e58..14c92e4 100644 --- a/include/linuxdeploy/core/appdir.h +++ b/include/linuxdeploy/core/appdir.h @@ -65,6 +65,12 @@ namespace linuxdeploy { // create symlinks for AppRun, desktop file and icon in the AppDir root directory bool createLinksInAppDirRoot(const desktopfile::DesktopFile& desktopFile, boost::filesystem::path customAppRunPath = ""); + + // set application name of primary "entry point" application + // icons and other resources will then automatically be renamed using this value in order to + // make the deployment easier by not requiring special filenames + // resources' filenames should be prefixed with this value (example: linuxdeploy_48x48.png) + void setAppName(const std::string& appName); }; } } diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index 97df2a6..e9fe5b8 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -41,8 +41,11 @@ namespace linuxdeploy { // the little amount of additional memory is worth it, considering the improved performance std::set visitedFiles; + // used to automatically rename resources to improve the UX, e.g. icons + std::string appName; + public: - PrivateData() : copyOperations(), setElfRPathOperations(), visitedFiles(), appDirPath() {}; + PrivateData() : copyOperations(), setElfRPathOperations(), visitedFiles(), appDirPath(), appName() {}; public: // actually copy file @@ -325,7 +328,17 @@ namespace linuxdeploy { } } - deployFile(path, appDirPath / "usr/share/icons/hicolor" / resolution / "apps/"); + // rename files like _*.ext to .ext + auto filename = path.filename().string(); + if (!appName.empty() && util::stringStartsWith(path.string(), appName)) { + auto newFilename = appName + path.extension().string(); + if (newFilename != filename) { + ldLog() << LD_WARNING << "Renaming icon" << path << "to" << newFilename << std::endl; + filename = newFilename; + } + } + + deployFile(path, appDirPath / "usr/share/icons/hicolor" / resolution / "apps" / filename); return true; } @@ -567,6 +580,10 @@ namespace linuxdeploy { return true; } + + void AppDir::setAppName(const std::string& appName) { + d->appName = appName; + } } } } diff --git a/src/core/main.cpp b/src/core/main.cpp index 397a1c3..194eccd 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -72,6 +72,7 @@ int main(int argc, char** argv) { if (appName) { ldLog() << std::endl << "-- Deploying application \"" << LD_NO_SPACE << appName.Get() << LD_NO_SPACE << "\" --" << std::endl; + appDir.setAppName(appName.Get()); } // initialize AppDir with common directories on request