diff options
author | Konstantin Podsvirov <konstantin@podsvirov.pro> | 2016-09-19 15:48:27 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-09-19 17:17:59 (GMT) |
commit | b807cd9b54e4a9324ddd64281254b6fe80be5b24 (patch) | |
tree | 683a118372760a9a85a808151b093e8aa0cf9e21 /Source/CPack/IFW/cmCPackIFWInstaller.cxx | |
parent | 5c87b92b1b7888ee032e3c2a75f35f1f94f4dfa5 (diff) | |
download | CMake-b807cd9b54e4a9324ddd64281254b6fe80be5b24.zip CMake-b807cd9b54e4a9324ddd64281254b6fe80be5b24.tar.gz CMake-b807cd9b54e4a9324ddd64281254b6fe80be5b24.tar.bz2 |
CPackIFW: Add 'cpack_ifw_add_package_resources' command
Diffstat (limited to 'Source/CPack/IFW/cmCPackIFWInstaller.cxx')
-rw-r--r-- | Source/CPack/IFW/cmCPackIFWInstaller.cxx | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.cxx b/Source/CPack/IFW/cmCPackIFWInstaller.cxx index 5a3efc9..aa609e2 100644 --- a/Source/CPack/IFW/cmCPackIFWInstaller.cxx +++ b/Source/CPack/IFW/cmCPackIFWInstaller.cxx @@ -13,11 +13,13 @@ #include "cmCPackIFWInstaller.h" #include "CPack/cmCPackGenerator.h" +#include "CPack/cmCPackLog.h" #include "cmCPackIFWGenerator.h" #include "cmCPackIFWPackage.h" #include "cmCPackIFWRepository.h" #include "cmGeneratedFileStream.h" #include "cmSystemTools.h" +#include "cmXMLParser.h" #include "cmXMLWriter.h" #include <cmConfigure.h> @@ -198,8 +200,70 @@ void cmCPackIFWInstaller::ConfigureFromOptions() this->GetOption("CPACK_IFW_PACKAGE_CONTROL_SCRIPT")) { ControlScript = optIFW_CONTROL_SCRIPT; } + + // Resources + if (const char* optIFW_PACKAGE_RESOURCES = + this->GetOption("CPACK_IFW_PACKAGE_RESOURCES")) { + Resources.clear(); + cmSystemTools::ExpandListArgument(optIFW_PACKAGE_RESOURCES, Resources); + } } +/** \class cmCPackIFWResourcesParser + * \brief Helper class that parse resources form .qrc (Qt) + */ +class cmCPackIFWResourcesParser : public cmXMLParser +{ +public: + cmCPackIFWResourcesParser(cmCPackIFWInstaller* i) + : installer(i) + , file(false) + { + path = i->Directory + "/resources"; + } + + bool ParseResource(size_t r) + { + hasFiles = false; + hasErrors = false; + + basePath = cmSystemTools::GetFilenamePath(installer->Resources[r].data()); + + ParseFile(installer->Resources[r].data()); + + return hasFiles && !hasErrors; + } + + cmCPackIFWInstaller* installer; + bool file, hasFiles, hasErrors; + std::string path, basePath; + +protected: + void StartElement(const std::string& name, const char** /*atts*/) CM_OVERRIDE + { + file = name == "file" ? true : false; + if (file) { + hasFiles = true; + } + } + + void CharacterDataHandler(const char* data, int length) CM_OVERRIDE + { + if (file) { + std::string content(data, data + length); + content = cmSystemTools::TrimWhitespace(content); + std::string source = basePath + "/" + content; + std::string destination = path + "/" + content; + if (!cmSystemTools::CopyFileIfDifferent(source.data(), + destination.data())) { + hasErrors = true; + } + } + } + + void EndElement(const std::string& /*name*/) CM_OVERRIDE {} +}; + void cmCPackIFWInstaller::GenerateInstallerFile() { // Lazy directory initialization @@ -315,6 +379,26 @@ void cmCPackIFWInstaller::GenerateInstallerFile() xout.Element("ControlScript", name); } + // Resources (copy to resources dir) + if (!Resources.empty()) { + std::vector<std::string> resources; + cmCPackIFWResourcesParser parser(this); + for (size_t i = 0; i < Resources.size(); i++) { + if (parser.ParseResource(i)) { + std::string name = cmSystemTools::GetFilenameName(Resources[i]); + std::string path = Directory + "/resources/" + name; + cmsys::SystemTools::CopyFileIfDifferent(Resources[i].data(), + path.data()); + resources.push_back(name); + } else { + cmCPackLogger(cmCPackLog::LOG_WARNING, "Can't copy resources from \"" + << Resources[i] << "\". Resource will be skipped." + << std::endl); + } + } + Resources = resources; + } + xout.EndElement(); xout.EndDocument(); } |