Rename icons like <appname>_*.ext to <appname>.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).
This commit is contained in:
TheAssassin 2018-06-01 21:49:03 +02:00
parent d1e2f9a5d9
commit 2bee994f53
3 changed files with 26 additions and 2 deletions

View File

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

View File

@ -41,8 +41,11 @@ namespace linuxdeploy {
// the little amount of additional memory is worth it, considering the improved performance
std::set<bf::path> 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 <appname>_*.ext to <appname>.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;
}
}
}
}

View File

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