diff options
author | Kitware Robot <kwrobot@kitware.com> | 2016-05-16 14:34:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-05-16 20:05:19 (GMT) |
commit | d9fd2f5402eeaa345691313658e02b51038f570b (patch) | |
tree | dca71b9a7e267f4c6300da3eb770415381726785 /Source/CPack/WiX | |
parent | 82df6deaafb36cbbfd450202bb20b320f637751a (diff) | |
download | CMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2 |
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.
* If you reached this commit for a line in `git blame`, re-run the blame
operation starting at the parent of this commit to see older history
for the content.
* See the parent commit for instructions to rebase a change across this
style transition commit.
Diffstat (limited to 'Source/CPack/WiX')
-rw-r--r-- | Source/CPack/WiX/cmCPackWIXGenerator.cxx | 831 | ||||
-rw-r--r-- | Source/CPack/WiX/cmCPackWIXGenerator.h | 83 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXAccessControlList.cxx | 76 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXAccessControlList.h | 12 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx | 29 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h | 6 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx | 43 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXFeaturesSourceWriter.h | 8 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXFilesSourceWriter.cxx | 71 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXFilesSourceWriter.h | 37 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXPatch.cxx | 88 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXPatch.h | 5 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXPatchParser.cxx | 133 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXPatchParser.h | 4 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx | 126 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXShortcut.cxx | 78 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXShortcut.h | 21 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXSourceWriter.cxx | 176 | ||||
-rw-r--r-- | Source/CPack/WiX/cmWIXSourceWriter.h | 17 |
19 files changed, 769 insertions, 1075 deletions
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index a98c684..8777296 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -32,18 +32,16 @@ #include <rpc.h> // for GUID generation -cmCPackWIXGenerator::cmCPackWIXGenerator(): - Patch(0) +cmCPackWIXGenerator::cmCPackWIXGenerator() + : Patch(0) { - } cmCPackWIXGenerator::~cmCPackWIXGenerator() { - if(this->Patch) - { + if (this->Patch) { delete this->Patch; - } + } } int cmCPackWIXGenerator::InitializeInternal() @@ -58,41 +56,39 @@ bool cmCPackWIXGenerator::RunWiXCommand(std::string const& command) { std::string logFileName = this->CPackTopLevel + "/wix.log"; - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "Running WiX command: " << command << std::endl); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Running WiX command: " << command + << std::endl); std::string output; int returnValue = 0; - bool status = cmSystemTools::RunSingleCommand( - command.c_str(), &output, &output, - &returnValue, 0, cmSystemTools::OUTPUT_NONE); + bool status = cmSystemTools::RunSingleCommand(command.c_str(), &output, + &output, &returnValue, 0, + cmSystemTools::OUTPUT_NONE); cmsys::ofstream logFile(logFileName.c_str(), std::ios::app); logFile << command << std::endl; logFile << output; logFile.close(); - if(!status || returnValue) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem running WiX candle. " - "Please check '" << logFileName << "' for errors." << std::endl); + if (!status || returnValue) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running WiX candle. " + "Please check '" + << logFileName << "' for errors." << std::endl); return false; - } + } return true; } -bool cmCPackWIXGenerator::RunCandleCommand( - std::string const& sourceFile, std::string const& objectFile) +bool cmCPackWIXGenerator::RunCandleCommand(std::string const& sourceFile, + std::string const& objectFile) { std::string executable; - if(!RequireOption("CPACK_WIX_CANDLE_EXECUTABLE", executable)) - { + if (!RequireOption("CPACK_WIX_CANDLE_EXECUTABLE", executable)) { return false; - } + } std::stringstream command; command << QuotePath(executable); @@ -100,11 +96,10 @@ bool cmCPackWIXGenerator::RunCandleCommand( command << " -arch " << GetArchitecture(); command << " -out " << QuotePath(objectFile); - for(extension_set_t::const_iterator i = CandleExtensions.begin(); - i != CandleExtensions.end(); ++i) - { + for (extension_set_t::const_iterator i = CandleExtensions.begin(); + i != CandleExtensions.end(); ++i) { command << " -ext " << QuotePath(*i); - } + } AddCustomFlags("CPACK_WIX_CANDLE_EXTRA_FLAGS", command); @@ -116,27 +111,24 @@ bool cmCPackWIXGenerator::RunCandleCommand( bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles) { std::string executable; - if(!RequireOption("CPACK_WIX_LIGHT_EXECUTABLE", executable)) - { + if (!RequireOption("CPACK_WIX_LIGHT_EXECUTABLE", executable)) { return false; - } + } std::stringstream command; command << QuotePath(executable); command << " -nologo"; command << " -out " << QuotePath(packageFileNames.at(0)); - for(extension_set_t::const_iterator i = this->LightExtensions.begin(); - i != this->LightExtensions.end(); ++i) - { + for (extension_set_t::const_iterator i = this->LightExtensions.begin(); + i != this->LightExtensions.end(); ++i) { command << " -ext " << QuotePath(*i); - } + } const char* const cultures = GetOption("CPACK_WIX_CULTURES"); - if(cultures) - { + if (cultures) { command << " -cultures:" << cultures; - } + } AddCustomFlags("CPACK_WIX_LIGHT_EXTRA_FLAGS", command); @@ -147,90 +139,80 @@ bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles) int cmCPackWIXGenerator::PackageFiles() { - if(!PackageFilesImpl() || cmSystemTools::GetErrorOccuredFlag()) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Fatal WiX Generator Error" << std::endl); + if (!PackageFilesImpl() || cmSystemTools::GetErrorOccuredFlag()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Fatal WiX Generator Error" + << std::endl); return false; - } + } return true; } bool cmCPackWIXGenerator::InitializeWiXConfiguration() { - if(!ReadListFile("CPackWIX.cmake")) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error while executing CPackWIX.cmake" << std::endl); + if (!ReadListFile("CPackWIX.cmake")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while executing CPackWIX.cmake" + << std::endl); return false; - } + } - if(GetOption("CPACK_WIX_PRODUCT_GUID") == 0) - { + if (GetOption("CPACK_WIX_PRODUCT_GUID") == 0) { std::string guid = GenerateGUID(); SetOption("CPACK_WIX_PRODUCT_GUID", guid.c_str()); cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "CPACK_WIX_PRODUCT_GUID implicitly set to " << guid << " . " - << std::endl); - } + "CPACK_WIX_PRODUCT_GUID implicitly set to " << guid << " . " + << std::endl); + } - if(GetOption("CPACK_WIX_UPGRADE_GUID") == 0) - { + if (GetOption("CPACK_WIX_UPGRADE_GUID") == 0) { std::string guid = GenerateGUID(); SetOption("CPACK_WIX_UPGRADE_GUID", guid.c_str()); - cmCPackLogger(cmCPackLog::LOG_WARNING, - "CPACK_WIX_UPGRADE_GUID implicitly set to " << guid << " . " - "Please refer to the documentation on how and why " - "you might want to set this explicitly." << std::endl); - } + cmCPackLogger( + cmCPackLog::LOG_WARNING, "CPACK_WIX_UPGRADE_GUID implicitly set to " + << guid << " . " + "Please refer to the documentation on how and why " + "you might want to set this explicitly." + << std::endl); + } - if(!RequireOption("CPACK_TOPLEVEL_DIRECTORY", this->CPackTopLevel)) - { + if (!RequireOption("CPACK_TOPLEVEL_DIRECTORY", this->CPackTopLevel)) { return false; - } + } - if(GetOption("CPACK_WIX_LICENSE_RTF") == 0) - { + if (GetOption("CPACK_WIX_LICENSE_RTF") == 0) { std::string licenseFilename = this->CPackTopLevel + "/License.rtf"; SetOption("CPACK_WIX_LICENSE_RTF", licenseFilename.c_str()); - if(!CreateLicenseFile()) - { + if (!CreateLicenseFile()) { return false; - } } + } - if(GetOption("CPACK_PACKAGE_VENDOR") == 0) - { + if (GetOption("CPACK_PACKAGE_VENDOR") == 0) { std::string defaultVendor = "Humanity"; SetOption("CPACK_PACKAGE_VENDOR", defaultVendor.c_str()); cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "CPACK_PACKAGE_VENDOR implicitly set to " << defaultVendor << " . " - << std::endl); - } + "CPACK_PACKAGE_VENDOR implicitly set to " + << defaultVendor << " . " << std::endl); + } - if(GetOption("CPACK_WIX_UI_REF") == 0) - { + if (GetOption("CPACK_WIX_UI_REF") == 0) { std::string defaultRef = "WixUI_InstallDir"; - if(!this->Components.empty()) - { + if (!this->Components.empty()) { defaultRef = "WixUI_FeatureTree"; - } + } SetOption("CPACK_WIX_UI_REF", defaultRef.c_str()); - } + } const char* packageContact = GetOption("CPACK_PACKAGE_CONTACT"); - if(packageContact != 0 && - GetOption("CPACK_WIX_PROPERTY_ARPCONTACT") == 0) - { + if (packageContact != 0 && GetOption("CPACK_WIX_PROPERTY_ARPCONTACT") == 0) { SetOption("CPACK_WIX_PROPERTY_ARPCONTACT", packageContact); - } + } CollectExtensions("CPACK_WIX_EXTENSIONS", this->CandleExtensions); CollectExtensions("CPACK_WIX_CANDLE_EXTENSIONS", this->CandleExtensions); @@ -240,46 +222,40 @@ bool cmCPackWIXGenerator::InitializeWiXConfiguration() CollectExtensions("CPACK_WIX_LIGHT_EXTENSIONS", this->LightExtensions); const char* patchFilePath = GetOption("CPACK_WIX_PATCH_FILE"); - if(patchFilePath) - { + if (patchFilePath) { std::vector<std::string> patchFilePaths; cmSystemTools::ExpandListArgument(patchFilePath, patchFilePaths); - for(size_t i = 0; i < patchFilePaths.size(); ++i) - { - if(!this->Patch->LoadFragments(patchFilePaths[i])) - { + for (size_t i = 0; i < patchFilePaths.size(); ++i) { + if (!this->Patch->LoadFragments(patchFilePaths[i])) { return false; - } } } + } return true; } bool cmCPackWIXGenerator::PackageFilesImpl() { - if(!InitializeWiXConfiguration()) - { + if (!InitializeWiXConfiguration()) { return false; - } + } CreateWiXVariablesIncludeFile(); CreateWiXPropertiesIncludeFile(); CreateWiXProductFragmentIncludeFile(); - if(!CreateWiXSourceFiles()) - { + if (!CreateWiXSourceFiles()) { return false; - } + } AppendUserSuppliedExtraSources(); std::set<std::string> usedBaseNames; std::stringstream objectFiles; - for(size_t i = 0; i < this->WixSources.size(); ++i) - { + for (size_t i = 0; i < this->WixSources.size(); ++i) { std::string const& sourceFilename = this->WixSources[i]; std::string baseName = @@ -288,25 +264,23 @@ bool cmCPackWIXGenerator::PackageFilesImpl() unsigned int counter = 0; std::string uniqueBaseName = baseName; - while(usedBaseNames.find(uniqueBaseName) != usedBaseNames.end()) - { + while (usedBaseNames.find(uniqueBaseName) != usedBaseNames.end()) { std::stringstream tmp; tmp << baseName << ++counter; uniqueBaseName = tmp.str(); - } + } usedBaseNames.insert(uniqueBaseName); std::string objectFilename = this->CPackTopLevel + "/" + uniqueBaseName + ".wixobj"; - if(!RunCandleCommand(sourceFilename, objectFilename)) - { + if (!RunCandleCommand(sourceFilename, objectFilename)) { return false; - } + } objectFiles << " " << QuotePath(objectFilename); - } + } AppendUserSuppliedExtraObjects(objectFiles); @@ -315,35 +289,34 @@ bool cmCPackWIXGenerator::PackageFilesImpl() void cmCPackWIXGenerator::AppendUserSuppliedExtraSources() { - const char *cpackWixExtraSources = GetOption("CPACK_WIX_EXTRA_SOURCES"); - if(!cpackWixExtraSources) return; + const char* cpackWixExtraSources = GetOption("CPACK_WIX_EXTRA_SOURCES"); + if (!cpackWixExtraSources) + return; cmSystemTools::ExpandListArgument(cpackWixExtraSources, this->WixSources); } void cmCPackWIXGenerator::AppendUserSuppliedExtraObjects(std::ostream& stream) { - const char *cpackWixExtraObjects = GetOption("CPACK_WIX_EXTRA_OBJECTS"); - if(!cpackWixExtraObjects) return; + const char* cpackWixExtraObjects = GetOption("CPACK_WIX_EXTRA_OBJECTS"); + if (!cpackWixExtraObjects) + return; std::vector<std::string> expandedExtraObjects; - cmSystemTools::ExpandListArgument( - cpackWixExtraObjects, expandedExtraObjects); + cmSystemTools::ExpandListArgument(cpackWixExtraObjects, + expandedExtraObjects); - for(size_t i = 0; i < expandedExtraObjects.size(); ++i) - { + for (size_t i = 0; i < expandedExtraObjects.size(); ++i) { stream << " " << QuotePath(expandedExtraObjects[i]); - } + } } void cmCPackWIXGenerator::CreateWiXVariablesIncludeFile() { - std::string includeFilename = - this->CPackTopLevel + "/cpack_variables.wxi"; + std::string includeFilename = this->CPackTopLevel + "/cpack_variables.wxi"; - cmWIXSourceWriter includeFile( - this->Logger, includeFilename, true); + cmWIXSourceWriter includeFile(this->Logger, includeFilename, true); CopyDefinition(includeFile, "CPACK_WIX_PRODUCT_GUID"); CopyDefinition(includeFile, "CPACK_WIX_UPGRADE_GUID"); @@ -355,29 +328,25 @@ void cmCPackWIXGenerator::CreateWiXVariablesIncludeFile() CopyDefinition(includeFile, "CPACK_WIX_UI_BANNER"); CopyDefinition(includeFile, "CPACK_WIX_UI_DIALOG"); SetOptionIfNotSet("CPACK_WIX_PROGRAM_MENU_FOLDER", - GetOption("CPACK_PACKAGE_NAME")); + GetOption("CPACK_PACKAGE_NAME")); CopyDefinition(includeFile, "CPACK_WIX_PROGRAM_MENU_FOLDER"); CopyDefinition(includeFile, "CPACK_WIX_UI_REF"); } void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile() { - std::string includeFilename = - this->CPackTopLevel + "/properties.wxi"; + std::string includeFilename = this->CPackTopLevel + "/properties.wxi"; - cmWIXSourceWriter includeFile( - this->Logger, includeFilename, true); + cmWIXSourceWriter includeFile(this->Logger, includeFilename, true); std::string prefix = "CPACK_WIX_PROPERTY_"; std::vector<std::string> options = GetOptions(); - for(size_t i = 0; i < options.size(); ++i) - { + for (size_t i = 0; i < options.size(); ++i) { std::string const& name = options[i]; - if(name.length() > prefix.length() && - name.substr(0, prefix.length()) == prefix) - { + if (name.length() > prefix.length() && + name.substr(0, prefix.length()) == prefix) { std::string id = name.substr(prefix.length()); std::string value = GetOption(name.c_str()); @@ -385,11 +354,10 @@ void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile() includeFile.AddAttribute("Id", id); includeFile.AddAttribute("Value", value); includeFile.EndElement("Property"); - } } + } - if(GetOption("CPACK_WIX_PROPERTY_ARPINSTALLLOCATION") == 0) - { + if (GetOption("CPACK_WIX_PROPERTY_ARPINSTALLLOCATION") == 0) { includeFile.BeginElement("Property"); includeFile.AddAttribute("Id", "INSTALL_ROOT"); includeFile.AddAttribute("Secure", "yes"); @@ -397,8 +365,9 @@ void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile() includeFile.BeginElement("RegistrySearch"); includeFile.AddAttribute("Id", "FindInstallLocation"); includeFile.AddAttribute("Root", "HKLM"); - includeFile.AddAttribute("Key", "Software\\Microsoft\\Windows\\" - "CurrentVersion\\Uninstall\\[WIX_UPGRADE_DETECTED]"); + includeFile.AddAttribute( + "Key", "Software\\Microsoft\\Windows\\" + "CurrentVersion\\Uninstall\\[WIX_UPGRADE_DETECTED]"); includeFile.AddAttribute("Name", "InstallLocation"); includeFile.AddAttribute("Type", "raw"); includeFile.EndElement("RegistrySearch"); @@ -409,38 +378,36 @@ void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile() includeFile.AddAttribute("Value", "[INSTALL_ROOT]"); includeFile.AddAttribute("After", "CostFinalize"); includeFile.EndElement("SetProperty"); - } + } } void cmCPackWIXGenerator::CreateWiXProductFragmentIncludeFile() { - std::string includeFilename = - this->CPackTopLevel + "/product_fragment.wxi"; + std::string includeFilename = this->CPackTopLevel + "/product_fragment.wxi"; - cmWIXSourceWriter includeFile( - this->Logger, includeFilename, true); + cmWIXSourceWriter includeFile(this->Logger, includeFilename, true); - this->Patch->ApplyFragment("#PRODUCT", includeFile); + this->Patch->ApplyFragment("#PRODUCT", includeFile); } -void cmCPackWIXGenerator::CopyDefinition( - cmWIXSourceWriter &source, std::string const& name) +void cmCPackWIXGenerator::CopyDefinition(cmWIXSourceWriter& source, + std::string const& name) { const char* value = GetOption(name.c_str()); - if(value) - { + if (value) { AddDefinition(source, name, value); - } + } } void cmCPackWIXGenerator::AddDefinition(cmWIXSourceWriter& source, - std::string const& name, std::string const& value) + std::string const& name, + std::string const& value) { std::stringstream tmp; tmp << name << "=\"" << value << '"'; - source.AddProcessingInstruction("define", - cmWIXSourceWriter::CMakeEncodingToUtf8(tmp.str())); + source.AddProcessingInstruction( + "define", cmWIXSourceWriter::CMakeEncodingToUtf8(tmp.str())); } bool cmCPackWIXGenerator::CreateWiXSourceFiles() @@ -455,10 +422,9 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() directoryDefinitions.BeginElement("Fragment"); std::string installRoot; - if(!RequireOption("CPACK_PACKAGE_INSTALL_DIRECTORY", installRoot)) - { + if (!RequireOption("CPACK_PACKAGE_INSTALL_DIRECTORY", installRoot)) { return false; - } + } directoryDefinitions.BeginElement("Directory"); directoryDefinitions.AddAttribute("Id", "TARGETDIR"); @@ -468,23 +434,22 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() directoryDefinitions.BeginInstallationPrefixDirectory( GetProgramFilesFolderId(), installRoot); - std::string fileDefinitionsFilename = - this->CPackTopLevel + "/files.wxs"; + std::string fileDefinitionsFilename = this->CPackTopLevel + "/files.wxs"; this->WixSources.push_back(fileDefinitionsFilename); - cmWIXFilesSourceWriter fileDefinitions( - this->Logger, fileDefinitionsFilename); + cmWIXFilesSourceWriter fileDefinitions(this->Logger, + fileDefinitionsFilename); fileDefinitions.BeginElement("Fragment"); std::string featureDefinitionsFilename = - this->CPackTopLevel +"/features.wxs"; + this->CPackTopLevel + "/features.wxs"; this->WixSources.push_back(featureDefinitionsFilename); - cmWIXFeaturesSourceWriter featureDefinitions( - this->Logger, featureDefinitionsFilename); + cmWIXFeaturesSourceWriter featureDefinitions(this->Logger, + featureDefinitionsFilename); featureDefinitions.BeginElement("Fragment"); @@ -495,45 +460,39 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() featureDefinitions.AddAttribute("ConfigurableDirectory", "INSTALL_ROOT"); std::string cpackPackageName; - if(!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName)) - { + if (!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName)) { return false; - } + } featureDefinitions.AddAttribute("Title", cpackPackageName); featureDefinitions.AddAttribute("Level", "1"); this->Patch->ApplyFragment("#PRODUCTFEATURE", featureDefinitions); const char* package = GetOption("CPACK_WIX_CMAKE_PACKAGE_REGISTRY"); - if(package) - { + if (package) { featureDefinitions.CreateCMakePackageRegistryEntry( - package, GetOption("CPACK_WIX_UPGRADE_GUID")); - } + package, GetOption("CPACK_WIX_UPGRADE_GUID")); + } - if(!CreateFeatureHierarchy(featureDefinitions)) - { + if (!CreateFeatureHierarchy(featureDefinitions)) { return false; - } + } featureDefinitions.EndElement("Feature"); std::set<cmWIXShortcuts::Type> emittedShortcutTypes; cmWIXShortcuts globalShortcuts; - if(Components.empty()) - { - AddComponentsToFeature(toplevel, "ProductFeature", - directoryDefinitions, fileDefinitions, featureDefinitions, - globalShortcuts); + if (Components.empty()) { + AddComponentsToFeature(toplevel, "ProductFeature", directoryDefinitions, + fileDefinitions, featureDefinitions, + globalShortcuts); globalShortcuts.AddShortcutTypes(emittedShortcutTypes); - } - else - { - for(std::map<std::string, cmCPackComponent>::const_iterator - i = this->Components.begin(); i != this->Components.end(); ++i) - { + } else { + for (std::map<std::string, cmCPackComponent>::const_iterator i = + this->Components.begin(); + i != this->Components.end(); ++i) { cmCPackComponent const& component = i->second; std::string componentPath = toplevel; @@ -544,102 +503,91 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() cmWIXShortcuts featureShortcuts; AddComponentsToFeature(componentPath, componentFeatureId, - directoryDefinitions, fileDefinitions, - featureDefinitions, featureShortcuts); + directoryDefinitions, fileDefinitions, + featureDefinitions, featureShortcuts); featureShortcuts.AddShortcutTypes(emittedShortcutTypes); - if(!CreateShortcuts(component.Name, componentFeatureId, - featureShortcuts, false, fileDefinitions, featureDefinitions)) - { + if (!CreateShortcuts(component.Name, componentFeatureId, + featureShortcuts, false, fileDefinitions, + featureDefinitions)) { return false; - } } } + } - bool emitUninstallShortcut = emittedShortcutTypes.find( - cmWIXShortcuts::START_MENU) != emittedShortcutTypes.end(); + bool emitUninstallShortcut = + emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) != + emittedShortcutTypes.end(); - if(!CreateShortcuts(std::string(), "ProductFeature", - globalShortcuts, emitUninstallShortcut, - fileDefinitions, featureDefinitions)) - { + if (!CreateShortcuts(std::string(), "ProductFeature", globalShortcuts, + emitUninstallShortcut, fileDefinitions, + featureDefinitions)) { return false; - } + } featureDefinitions.EndElement("Fragment"); fileDefinitions.EndElement("Fragment"); - directoryDefinitions.EndInstallationPrefixDirectory( - installRootSize); + directoryDefinitions.EndInstallationPrefixDirectory(installRootSize); - if(emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) != - emittedShortcutTypes.end()) - { + if (emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) != + emittedShortcutTypes.end()) { directoryDefinitions.EmitStartMenuFolder( GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER")); - } + } - if(emittedShortcutTypes.find(cmWIXShortcuts::DESKTOP) != - emittedShortcutTypes.end()) - { + if (emittedShortcutTypes.find(cmWIXShortcuts::DESKTOP) != + emittedShortcutTypes.end()) { directoryDefinitions.EmitDesktopFolder(); - } + } - if(emittedShortcutTypes.find(cmWIXShortcuts::STARTUP) != - emittedShortcutTypes.end()) - { + if (emittedShortcutTypes.find(cmWIXShortcuts::STARTUP) != + emittedShortcutTypes.end()) { directoryDefinitions.EmitStartupFolder(); - } + } directoryDefinitions.EndElement("Directory"); directoryDefinitions.EndElement("Fragment"); - if(!GenerateMainSourceFileFromTemplate()) - { + if (!GenerateMainSourceFileFromTemplate()) { return false; - } + } return this->Patch->CheckForUnappliedFragments(); } std::string cmCPackWIXGenerator::GetProgramFilesFolderId() const { - if(GetArchitecture() == "x86") - { + if (GetArchitecture() == "x86") { return "ProgramFilesFolder"; - } - else - { + } else { return "ProgramFiles64Folder"; - } + } } bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate() { std::string wixTemplate = FindTemplate("WIX.template.in"); - if(GetOption("CPACK_WIX_TEMPLATE") != 0) - { + if (GetOption("CPACK_WIX_TEMPLATE") != 0) { wixTemplate = GetOption("CPACK_WIX_TEMPLATE"); - } + } - if(wixTemplate.empty()) - { + if (wixTemplate.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Could not find CPack WiX template file WIX.template.in" << std::endl); + "Could not find CPack WiX template file WIX.template.in" + << std::endl); return false; - } + } std::string mainSourceFilePath = this->CPackTopLevel + "/main.wxs"; - if(!ConfigureFile(wixTemplate.c_str(), mainSourceFilePath .c_str())) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Failed creating '" << mainSourceFilePath << - "'' from template." << std::endl); + if (!ConfigureFile(wixTemplate.c_str(), mainSourceFilePath.c_str())) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Failed creating '" + << mainSourceFilePath << "'' from template." << std::endl); return false; - } + } this->WixSources.push_back(mainSourceFilePath); @@ -649,70 +597,64 @@ bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate() bool cmCPackWIXGenerator::CreateFeatureHierarchy( cmWIXFeaturesSourceWriter& featureDefinitions) { - for(std::map<std::string, cmCPackComponentGroup>::const_iterator - i = ComponentGroups.begin(); i != ComponentGroups.end(); ++i) - { + for (std::map<std::string, cmCPackComponentGroup>::const_iterator i = + ComponentGroups.begin(); + i != ComponentGroups.end(); ++i) { cmCPackComponentGroup const& group = i->second; - if(group.ParentGroup == 0) - { + if (group.ParentGroup == 0) { featureDefinitions.EmitFeatureForComponentGroup(group); - } } + } - for(std::map<std::string, cmCPackComponent>::const_iterator - i = this->Components.begin(); i != this->Components.end(); ++i) - { + for (std::map<std::string, cmCPackComponent>::const_iterator i = + this->Components.begin(); + i != this->Components.end(); ++i) { cmCPackComponent const& component = i->second; - if(!component.Group) - { + if (!component.Group) { featureDefinitions.EmitFeatureForComponent(component); - } } + } return true; } bool cmCPackWIXGenerator::AddComponentsToFeature( - std::string const& rootPath, - std::string const& featureId, + std::string const& rootPath, std::string const& featureId, cmWIXDirectoriesSourceWriter& directoryDefinitions, cmWIXFilesSourceWriter& fileDefinitions, - cmWIXFeaturesSourceWriter& featureDefinitions, - cmWIXShortcuts& shortcuts) + cmWIXFeaturesSourceWriter& featureDefinitions, cmWIXShortcuts& shortcuts) { featureDefinitions.BeginElement("FeatureRef"); featureDefinitions.AddAttribute("Id", featureId); std::vector<std::string> cpackPackageExecutablesList; - const char *cpackPackageExecutables = GetOption("CPACK_PACKAGE_EXECUTABLES"); - if(cpackPackageExecutables) - { - cmSystemTools::ExpandListArgument(cpackPackageExecutables, - cpackPackageExecutablesList); - if(cpackPackageExecutablesList.size() % 2 != 0 ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and " - "<text label>." << std::endl); - return false; - } + const char* cpackPackageExecutables = GetOption("CPACK_PACKAGE_EXECUTABLES"); + if (cpackPackageExecutables) { + cmSystemTools::ExpandListArgument(cpackPackageExecutables, + cpackPackageExecutablesList); + if (cpackPackageExecutablesList.size() % 2 != 0) { + cmCPackLogger( + cmCPackLog::LOG_ERROR, + "CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and " + "<text label>." + << std::endl); + return false; } + } std::vector<std::string> cpackPackageDesktopLinksList; - const char *cpackPackageDesktopLinks = + const char* cpackPackageDesktopLinks = GetOption("CPACK_CREATE_DESKTOP_LINKS"); - if(cpackPackageDesktopLinks) - { - cmSystemTools::ExpandListArgument(cpackPackageDesktopLinks, - cpackPackageDesktopLinksList); - } + if (cpackPackageDesktopLinks) { + cmSystemTools::ExpandListArgument(cpackPackageDesktopLinks, + cpackPackageDesktopLinksList); + } - AddDirectoryAndFileDefinitons( - rootPath, "INSTALL_ROOT", - directoryDefinitions, fileDefinitions, featureDefinitions, - cpackPackageExecutablesList, cpackPackageDesktopLinksList, - shortcuts); + AddDirectoryAndFileDefinitons(rootPath, "INSTALL_ROOT", directoryDefinitions, + fileDefinitions, featureDefinitions, + cpackPackageExecutablesList, + cpackPackageDesktopLinksList, shortcuts); featureDefinitions.EndElement("FeatureRef"); @@ -720,62 +662,48 @@ bool cmCPackWIXGenerator::AddComponentsToFeature( } bool cmCPackWIXGenerator::CreateShortcuts( - std::string const& cpackComponentName, - std::string const& featureId, - cmWIXShortcuts const& shortcuts, - bool emitUninstallShortcut, + std::string const& cpackComponentName, std::string const& featureId, + cmWIXShortcuts const& shortcuts, bool emitUninstallShortcut, cmWIXFilesSourceWriter& fileDefinitions, cmWIXFeaturesSourceWriter& featureDefinitions) { - if(!shortcuts.empty(cmWIXShortcuts::START_MENU)) - { - if(!this->CreateShortcutsOfSpecificType(cmWIXShortcuts::START_MENU, - cpackComponentName, featureId, "", - shortcuts, emitUninstallShortcut, - fileDefinitions, featureDefinitions)) - { + if (!shortcuts.empty(cmWIXShortcuts::START_MENU)) { + if (!this->CreateShortcutsOfSpecificType( + cmWIXShortcuts::START_MENU, cpackComponentName, featureId, "", + shortcuts, emitUninstallShortcut, fileDefinitions, + featureDefinitions)) { return false; - } } + } - if(!shortcuts.empty(cmWIXShortcuts::DESKTOP)) - { - if(!this->CreateShortcutsOfSpecificType(cmWIXShortcuts::DESKTOP, - cpackComponentName, featureId, "DESKTOP", - shortcuts, false, - fileDefinitions, featureDefinitions)) - { + if (!shortcuts.empty(cmWIXShortcuts::DESKTOP)) { + if (!this->CreateShortcutsOfSpecificType( + cmWIXShortcuts::DESKTOP, cpackComponentName, featureId, "DESKTOP", + shortcuts, false, fileDefinitions, featureDefinitions)) { return false; - } } + } - if(!shortcuts.empty(cmWIXShortcuts::STARTUP)) - { - if(!this->CreateShortcutsOfSpecificType(cmWIXShortcuts::STARTUP, - cpackComponentName, featureId, "STARTUP", - shortcuts, false, - fileDefinitions, featureDefinitions)) - { + if (!shortcuts.empty(cmWIXShortcuts::STARTUP)) { + if (!this->CreateShortcutsOfSpecificType( + cmWIXShortcuts::STARTUP, cpackComponentName, featureId, "STARTUP", + shortcuts, false, fileDefinitions, featureDefinitions)) { return false; - } } + } return true; } bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( - cmWIXShortcuts::Type type, - std::string const& cpackComponentName, - std::string const& featureId, - std::string const& idPrefix, - cmWIXShortcuts const& shortcuts, - bool emitUninstallShortcut, + cmWIXShortcuts::Type type, std::string const& cpackComponentName, + std::string const& featureId, std::string const& idPrefix, + cmWIXShortcuts const& shortcuts, bool emitUninstallShortcut, cmWIXFilesSourceWriter& fileDefinitions, cmWIXFeaturesSourceWriter& featureDefinitions) { std::string directoryId; - switch(type) - { + switch (type) { case cmWIXShortcuts::START_MENU: directoryId = "PROGRAM_MENU_FOLDER"; break; @@ -787,35 +715,31 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( break; default: return false; - } + } featureDefinitions.BeginElement("FeatureRef"); featureDefinitions.AddAttribute("Id", featureId); std::string cpackVendor; - if(!RequireOption("CPACK_PACKAGE_VENDOR", cpackVendor)) - { + if (!RequireOption("CPACK_PACKAGE_VENDOR", cpackVendor)) { return false; - } + } std::string cpackPackageName; - if(!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName)) - { + if (!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName)) { return false; - } + } std::string idSuffix; - if(!cpackComponentName.empty()) - { - idSuffix += "_"; - idSuffix += cpackComponentName; - } + if (!cpackComponentName.empty()) { + idSuffix += "_"; + idSuffix += cpackComponentName; + } std::string componentId = "CM_SHORTCUT"; - if(idPrefix.size()) - { + if (idPrefix.size()) { componentId += "_" + idPrefix; - } + } componentId += idSuffix; @@ -828,22 +752,20 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( this->Patch->ApplyFragment(componentId, fileDefinitions); - std::string registryKey = std::string("Software\\") + - cpackVendor + "\\" + cpackPackageName; + std::string registryKey = + std::string("Software\\") + cpackVendor + "\\" + cpackPackageName; - shortcuts.EmitShortcuts(type, registryKey, - cpackComponentName, fileDefinitions); + shortcuts.EmitShortcuts(type, registryKey, cpackComponentName, + fileDefinitions); - if(type == cmWIXShortcuts::START_MENU) - { - fileDefinitions.EmitRemoveFolder( - "CM_REMOVE_PROGRAM_MENU_FOLDER" + idSuffix); - } + if (type == cmWIXShortcuts::START_MENU) { + fileDefinitions.EmitRemoveFolder("CM_REMOVE_PROGRAM_MENU_FOLDER" + + idSuffix); + } - if(emitUninstallShortcut) - { + if (emitUninstallShortcut) { fileDefinitions.EmitUninstallShortcut(cpackPackageName); - } + } fileDefinitions.EndElement("Component"); fileDefinitions.EndElement("DirectoryRef"); @@ -857,53 +779,43 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( bool cmCPackWIXGenerator::CreateLicenseFile() { std::string licenseSourceFilename; - if(!RequireOption("CPACK_RESOURCE_FILE_LICENSE", licenseSourceFilename)) - { + if (!RequireOption("CPACK_RESOURCE_FILE_LICENSE", licenseSourceFilename)) { return false; - } + } std::string licenseDestinationFilename; - if(!RequireOption("CPACK_WIX_LICENSE_RTF", licenseDestinationFilename)) - { + if (!RequireOption("CPACK_WIX_LICENSE_RTF", licenseDestinationFilename)) { return false; - } + } std::string extension = GetRightmostExtension(licenseSourceFilename); - if(extension == ".rtf") - { - cmSystemTools::CopyAFile( - licenseSourceFilename.c_str(), - licenseDestinationFilename.c_str()); - } - else if(extension == ".txt") - { + if (extension == ".rtf") { + cmSystemTools::CopyAFile(licenseSourceFilename.c_str(), + licenseDestinationFilename.c_str()); + } else if (extension == ".txt") { cmWIXRichTextFormatWriter rtfWriter(licenseDestinationFilename); cmsys::ifstream licenseSource(licenseSourceFilename.c_str()); std::string line; - while(std::getline(licenseSource, line)) - { + while (std::getline(licenseSource, line)) { rtfWriter.AddText(line); rtfWriter.AddText("\n"); - } } - else - { + } else { cmCPackLogger(cmCPackLog::LOG_ERROR, - "unsupported WiX License file extension '" << - extension << "'" << std::endl); + "unsupported WiX License file extension '" + << extension << "'" << std::endl); return false; - } + } return true; } void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons( - std::string const& topdir, - std::string const& directoryId, + std::string const& topdir, std::string const& directoryId, cmWIXDirectoriesSourceWriter& directoryDefinitions, cmWIXFilesSourceWriter& fileDefinitions, cmWIXFeaturesSourceWriter& featureDefinitions, @@ -917,61 +829,51 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons( std::string relativeDirectoryPath = cmSystemTools::RelativePath(toplevel.c_str(), topdir.c_str()); - if(relativeDirectoryPath.empty()) - { + if (relativeDirectoryPath.empty()) { relativeDirectoryPath = "."; - } + } cmInstalledFile const* directoryInstalledFile = this->GetInstalledFile( - this->RelativePathWithoutComponentPrefix(relativeDirectoryPath) - ); + this->RelativePathWithoutComponentPrefix(relativeDirectoryPath)); bool emptyDirectory = dir.GetNumberOfFiles() == 2; bool createDirectory = false; - if(emptyDirectory) - { + if (emptyDirectory) { createDirectory = true; - } + } - if(directoryInstalledFile) - { - if(directoryInstalledFile->HasProperty("CPACK_WIX_ACL")) - { + if (directoryInstalledFile) { + if (directoryInstalledFile->HasProperty("CPACK_WIX_ACL")) { createDirectory = true; - } } + } - if(createDirectory) - { + if (createDirectory) { std::string componentId = fileDefinitions.EmitComponentCreateFolder( directoryId, GenerateGUID(), directoryInstalledFile); featureDefinitions.EmitComponentRef(componentId); - } + } - if(emptyDirectory) - { + if (emptyDirectory) { return; - } + } - for(size_t i = 0; i < dir.GetNumberOfFiles(); ++i) - { + for (size_t i = 0; i < dir.GetNumberOfFiles(); ++i) { std::string fileName = dir.GetFile(static_cast<unsigned long>(i)); - if(fileName == "." || fileName == "..") - { + if (fileName == "." || fileName == "..") { continue; - } + } std::string fullPath = topdir + "/" + fileName; - std::string relativePath = cmSystemTools::RelativePath( - toplevel.c_str(), fullPath.c_str()); + std::string relativePath = + cmSystemTools::RelativePath(toplevel.c_str(), fullPath.c_str()); std::string id = PathToId(relativePath); - if(cmSystemTools::FileIsDirectory(fullPath.c_str())) - { + if (cmSystemTools::FileIsDirectory(fullPath.c_str())) { std::string subDirectoryId = std::string("CM_D") + id; directoryDefinitions.BeginElement("Directory"); @@ -979,77 +881,60 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons( directoryDefinitions.AddAttribute("Name", fileName); AddDirectoryAndFileDefinitons( - fullPath, subDirectoryId, - directoryDefinitions, - fileDefinitions, - featureDefinitions, - packageExecutables, - desktopExecutables, - shortcuts); + fullPath, subDirectoryId, directoryDefinitions, fileDefinitions, + featureDefinitions, packageExecutables, desktopExecutables, shortcuts); this->Patch->ApplyFragment(subDirectoryId, directoryDefinitions); directoryDefinitions.EndElement("Directory"); - } - else - { + } else { cmInstalledFile const* installedFile = this->GetInstalledFile( - this->RelativePathWithoutComponentPrefix(relativePath) - ); + this->RelativePathWithoutComponentPrefix(relativePath)); - if(installedFile) - { + if (installedFile) { shortcuts.CreateFromProperties(id, directoryId, *installedFile); - } + } std::string componentId = fileDefinitions.EmitComponentFile( directoryId, id, fullPath, *(this->Patch), installedFile); featureDefinitions.EmitComponentRef(componentId); - for(size_t j = 0; j < packageExecutables.size(); ++j) - { + for (size_t j = 0; j < packageExecutables.size(); ++j) { std::string const& executableName = packageExecutables[j++]; std::string const& textLabel = packageExecutables[j]; - if(cmSystemTools::LowerCase(fileName) == - cmSystemTools::LowerCase(executableName) + ".exe") - { + if (cmSystemTools::LowerCase(fileName) == + cmSystemTools::LowerCase(executableName) + ".exe") { cmWIXShortcut shortcut; - shortcut.label= textLabel; + shortcut.label = textLabel; shortcut.workingDirectoryId = directoryId; shortcuts.insert(cmWIXShortcuts::START_MENU, id, shortcut); - if(!desktopExecutables.empty() && - std::find(desktopExecutables.begin(), - desktopExecutables.end(), - executableName) - != desktopExecutables.end()) - { - shortcuts.insert(cmWIXShortcuts::DESKTOP, id, shortcut); - } + if (!desktopExecutables.empty() && + std::find(desktopExecutables.begin(), desktopExecutables.end(), + executableName) != desktopExecutables.end()) { + shortcuts.insert(cmWIXShortcuts::DESKTOP, id, shortcut); } } } } + } } -bool cmCPackWIXGenerator::RequireOption( - std::string const& name, std::string &value) const +bool cmCPackWIXGenerator::RequireOption(std::string const& name, + std::string& value) const { const char* tmp = GetOption(name.c_str()); - if(tmp) - { + if (tmp) { value = tmp; return true; - } - else - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Required variable " << name << " not set" << std::endl); + } else { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Required variable " + << name << " not set" << std::endl); return false; - } + } } std::string cmCPackWIXGenerator::GetArchitecture() const @@ -1057,14 +942,11 @@ std::string cmCPackWIXGenerator::GetArchitecture() const std::string void_p_size; RequireOption("CPACK_WIX_SIZEOF_VOID_P", void_p_size); - if(void_p_size == "8") - { + if (void_p_size == "8") { return "x64"; - } - else - { + } else { return "x86"; - } + } } std::string cmCPackWIXGenerator::GenerateGUID() @@ -1072,7 +954,7 @@ std::string cmCPackWIXGenerator::GenerateGUID() UUID guid; UuidCreate(&guid); - unsigned short *tmp = 0; + unsigned short* tmp = 0; UuidToStringW(&guid, &tmp); std::string result = @@ -1093,10 +975,9 @@ std::string cmCPackWIXGenerator::GetRightmostExtension( std::string extension; std::string::size_type i = filename.rfind("."); - if(i != std::string::npos) - { + if (i != std::string::npos) { extension = filename.substr(i); - } + } return cmSystemTools::LowerCase(extension); } @@ -1104,7 +985,8 @@ std::string cmCPackWIXGenerator::GetRightmostExtension( std::string cmCPackWIXGenerator::PathToId(std::string const& path) { id_map_t::const_iterator i = PathToIdMap.find(path); - if(i != PathToIdMap.end()) return i->second; + if (i != PathToIdMap.end()) + return i->second; std::string id = CreateNewIdForPath(path); return id; @@ -1120,41 +1002,37 @@ std::string cmCPackWIXGenerator::CreateNewIdForPath(std::string const& path) std::string identifier; std::string currentComponent; - for(size_t i = 1; i < components.size(); ++i) - { - if(i != 1) identifier += '.'; + for (size_t i = 1; i < components.size(); ++i) { + if (i != 1) + identifier += '.'; - currentComponent = NormalizeComponentForId( - components[i], replacementCount); + currentComponent = + NormalizeComponentForId(components[i], replacementCount); identifier += currentComponent; - } + } std::string idPrefix = "P"; size_t replacementPercent = replacementCount * 100 / identifier.size(); - if(replacementPercent > 33 || identifier.size() > 60) - { + if (replacementPercent > 33 || identifier.size() > 60) { identifier = CreateHashedId(path, currentComponent); idPrefix = "H"; - } + } std::stringstream result; result << idPrefix << "_" << identifier; size_t ambiguityCount = ++IdAmbiguityCounter[identifier]; - if(ambiguityCount > 999) - { + if (ambiguityCount > 999) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error while trying to generate a unique Id for '" << - path << "'" << std::endl); + "Error while trying to generate a unique Id for '" + << path << "'" << std::endl); return std::string(); - } - else if(ambiguityCount > 1) - { + } else if (ambiguityCount > 1) { result << "_" << ambiguityCount; - } + } std::string resultString = result.str(); @@ -1173,15 +1051,12 @@ std::string cmCPackWIXGenerator::CreateHashedId( identifier += hash.substr(0, 7) + "_"; const size_t maxFileNameLength = 52; - if(normalizedFilename.length() > maxFileNameLength) - { + if (normalizedFilename.length() > maxFileNameLength) { identifier += normalizedFilename.substr(0, maxFileNameLength - 3); identifier += "..."; - } - else - { + } else { identifier += normalizedFilename; - } + } return identifier; } @@ -1192,65 +1067,59 @@ std::string cmCPackWIXGenerator::NormalizeComponentForId( std::string result; result.resize(component.size()); - for(size_t i = 0; i < component.size(); ++i) - { + for (size_t i = 0; i < component.size(); ++i) { char c = component[i]; - if(IsLegalIdCharacter(c)) - { + if (IsLegalIdCharacter(c)) { result[i] = c; - } - else - { + } else { result[i] = '_'; - ++ replacementCount; - } + ++replacementCount; } + } return result; } bool cmCPackWIXGenerator::IsLegalIdCharacter(char c) { - return (c >= '0' && c <= '9') || - (c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - c == '_' || c == '.'; + return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || c == '_' || c == '.'; } -void cmCPackWIXGenerator::CollectExtensions( - std::string const& variableName, extension_set_t& extensions) +void cmCPackWIXGenerator::CollectExtensions(std::string const& variableName, + extension_set_t& extensions) { - const char *variableContent = GetOption(variableName.c_str()); - if(!variableContent) return; + const char* variableContent = GetOption(variableName.c_str()); + if (!variableContent) + return; std::vector<std::string> list; cmSystemTools::ExpandListArgument(variableContent, list); extensions.insert(list.begin(), list.end()); } -void cmCPackWIXGenerator::AddCustomFlags( - std::string const& variableName, std::ostream& stream) +void cmCPackWIXGenerator::AddCustomFlags(std::string const& variableName, + std::ostream& stream) { - const char *variableContent = GetOption(variableName.c_str()); - if(!variableContent) return; + const char* variableContent = GetOption(variableName.c_str()); + if (!variableContent) + return; std::vector<std::string> list; cmSystemTools::ExpandListArgument(variableContent, list); - for(std::vector<std::string>::const_iterator i = list.begin(); - i != list.end(); ++i) - { - stream << " " << QuotePath(*i); - } + for (std::vector<std::string>::const_iterator i = list.begin(); + i != list.end(); ++i) { + stream << " " << QuotePath(*i); + } } std::string cmCPackWIXGenerator::RelativePathWithoutComponentPrefix( std::string const& path) { - if(this->Components.empty()) - { + if (this->Components.empty()) { return path; - } + } std::string::size_type pos = path.find('/'); diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.h b/Source/CPack/WiX/cmCPackWIXGenerator.h index 871527b..9d3a522 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.h +++ b/Source/CPack/WiX/cmCPackWIXGenerator.h @@ -42,25 +42,16 @@ protected: virtual int PackageFiles(); - virtual const char* GetOutputExtension() - { - return ".msi"; - } + virtual const char* GetOutputExtension() { return ".msi"; } virtual enum CPackSetDestdirSupport SupportsSetDestdir() const - { + { return SETDESTDIR_UNSUPPORTED; - } + } - virtual bool SupportsAbsoluteDestination() const - { - return false; - } + virtual bool SupportsAbsoluteDestination() const { return false; } - virtual bool SupportsComponentInstallation() const - { - return true; - } + virtual bool SupportsComponentInstallation() const { return true; } private: typedef std::map<std::string, std::string> id_map_t; @@ -77,11 +68,10 @@ private: void CreateWiXProductFragmentIncludeFile(); - void CopyDefinition( - cmWIXSourceWriter &source, std::string const& name); + void CopyDefinition(cmWIXSourceWriter& source, std::string const& name); - void AddDefinition(cmWIXSourceWriter& source, - std::string const& name, std::string const& value); + void AddDefinition(cmWIXSourceWriter& source, std::string const& name, + std::string const& value); bool CreateWiXSourceFiles(); @@ -89,32 +79,25 @@ private: bool GenerateMainSourceFileFromTemplate(); - bool CreateFeatureHierarchy( - cmWIXFeaturesSourceWriter& featureDefinitions); + bool CreateFeatureHierarchy(cmWIXFeaturesSourceWriter& featureDefinitions); bool AddComponentsToFeature( - std::string const& rootPath, - std::string const& featureId, + std::string const& rootPath, std::string const& featureId, cmWIXDirectoriesSourceWriter& directoryDefinitions, cmWIXFilesSourceWriter& fileDefinitions, - cmWIXFeaturesSourceWriter& featureDefinitions, - cmWIXShortcuts& shortcuts); + cmWIXFeaturesSourceWriter& featureDefinitions, cmWIXShortcuts& shortcuts); - bool CreateShortcuts( - std::string const& cpackComponentName, - std::string const& featureId, - cmWIXShortcuts const& shortcuts, - bool emitUninstallShortcut, - cmWIXFilesSourceWriter& fileDefinitions, - cmWIXFeaturesSourceWriter& featureDefinitions); + bool CreateShortcuts(std::string const& cpackComponentName, + std::string const& featureId, + cmWIXShortcuts const& shortcuts, + bool emitUninstallShortcut, + cmWIXFilesSourceWriter& fileDefinitions, + cmWIXFeaturesSourceWriter& featureDefinitions); bool CreateShortcutsOfSpecificType( - cmWIXShortcuts::Type type, - std::string const& cpackComponentName, - std::string const& featureId, - std::string const& idPrefix, - cmWIXShortcuts const& shortcuts, - bool emitUninstallShortcut, + cmWIXShortcuts::Type type, std::string const& cpackComponentName, + std::string const& featureId, std::string const& idPrefix, + cmWIXShortcuts const& shortcuts, bool emitUninstallShortcut, cmWIXFilesSourceWriter& fileDefinitions, cmWIXFeaturesSourceWriter& featureDefinitions); @@ -126,13 +109,13 @@ private: bool RunWiXCommand(std::string const& command); - bool RunCandleCommand( - std::string const& sourceFile, std::string const& objectFile); + bool RunCandleCommand(std::string const& sourceFile, + std::string const& objectFile); bool RunLightCommand(std::string const& objectFiles); - void AddDirectoryAndFileDefinitons(std::string const& topdir, - std::string const& directoryId, + void AddDirectoryAndFileDefinitons( + std::string const& topdir, std::string const& directoryId, cmWIXDirectoriesSourceWriter& directoryDefinitions, cmWIXFilesSourceWriter& fileDefinitions, cmWIXFeaturesSourceWriter& featureDefinitions, @@ -154,22 +137,20 @@ private: std::string CreateNewIdForPath(std::string const& path); - static std::string CreateHashedId( - std::string const& path, std::string const& normalizedFilename); + static std::string CreateHashedId(std::string const& path, + std::string const& normalizedFilename); - std::string NormalizeComponentForId( - std::string const& component, size_t& replacementCount); + std::string NormalizeComponentForId(std::string const& component, + size_t& replacementCount); static bool IsLegalIdCharacter(char c); - void CollectExtensions( - std::string const& variableName, extension_set_t& extensions); + void CollectExtensions(std::string const& variableName, + extension_set_t& extensions); - void AddCustomFlags( - std::string const& variableName, std::ostream& stream); + void AddCustomFlags(std::string const& variableName, std::ostream& stream); - std::string RelativePathWithoutComponentPrefix( - std::string const& path); + std::string RelativePathWithoutComponentPrefix(std::string const& path); std::vector<std::string> WixSources; id_map_t PathToIdMap; diff --git a/Source/CPack/WiX/cmWIXAccessControlList.cxx b/Source/CPack/WiX/cmWIXAccessControlList.cxx index 16a71e0..043cdff 100644 --- a/Source/CPack/WiX/cmWIXAccessControlList.cxx +++ b/Source/CPack/WiX/cmWIXAccessControlList.cxx @@ -17,14 +17,12 @@ #include <cmSystemTools.h> cmWIXAccessControlList::cmWIXAccessControlList( - cmCPackLog *logger, - cmInstalledFile const& installedFile, - cmWIXSourceWriter &sourceWriter): - Logger(logger), - InstalledFile(installedFile), - SourceWriter(sourceWriter) + cmCPackLog* logger, cmInstalledFile const& installedFile, + cmWIXSourceWriter& sourceWriter) + : Logger(logger) + , InstalledFile(installedFile) + , SourceWriter(sourceWriter) { - } bool cmWIXAccessControlList::Apply() @@ -32,23 +30,20 @@ bool cmWIXAccessControlList::Apply() std::vector<std::string> entries; this->InstalledFile.GetPropertyAsList("CPACK_WIX_ACL", entries); - for(size_t i = 0; i < entries.size(); ++i) - { + for (size_t i = 0; i < entries.size(); ++i) { this->CreatePermissionElement(entries[i]); - } + } return true; } -void cmWIXAccessControlList::CreatePermissionElement( - std::string const& entry) +void cmWIXAccessControlList::CreatePermissionElement(std::string const& entry) { std::string::size_type pos = entry.find('='); - if(pos == std::string::npos) - { + if (pos == std::string::npos) { this->ReportError(entry, "Did not find mandatory '='"); return; - } + } std::string user_and_domain = entry.substr(0, pos); std::string permission_string = entry.substr(pos + 1); @@ -56,46 +51,38 @@ void cmWIXAccessControlList::CreatePermissionElement( pos = user_and_domain.find('@'); std::string user; std::string domain; - if(pos != std::string::npos) - { + if (pos != std::string::npos) { user = user_and_domain.substr(0, pos); domain = user_and_domain.substr(pos + 1); - } - else - { + } else { user = user_and_domain; - } + } std::vector<std::string> permissions = cmSystemTools::tokenize(permission_string, ","); this->SourceWriter.BeginElement("Permission"); this->SourceWriter.AddAttribute("User", user); - if(!domain.empty()) - { + if (!domain.empty()) { this->SourceWriter.AddAttribute("Domain", domain); - } - for(size_t i = 0; i < permissions.size(); ++i) - { + } + for (size_t i = 0; i < permissions.size(); ++i) { this->EmitBooleanAttribute(entry, - cmSystemTools::TrimWhitespace(permissions[i])); - } + cmSystemTools::TrimWhitespace(permissions[i])); + } this->SourceWriter.EndElement("Permission"); } -void cmWIXAccessControlList::ReportError( - std::string const& entry, - std::string const& message) +void cmWIXAccessControlList::ReportError(std::string const& entry, + std::string const& message) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Failed processing ACL entry '" << entry << - "': " << message << std::endl); + cmCPackLogger(cmCPackLog::LOG_ERROR, "Failed processing ACL entry '" + << entry << "': " << message << std::endl); } bool cmWIXAccessControlList::IsBooleanAttribute(std::string const& name) { - static const char* validAttributes[] = - { + static const char* validAttributes[] = { /* clang-format needs this comment to break after the opening brace */ "Append", "ChangePermission", @@ -128,23 +115,22 @@ bool cmWIXAccessControlList::IsBooleanAttribute(std::string const& name) }; size_t i = 0; - while(validAttributes[i]) - { - if(name == validAttributes[i++]) return true; - } + while (validAttributes[i]) { + if (name == validAttributes[i++]) + return true; + } return false; } -void cmWIXAccessControlList::EmitBooleanAttribute( - std::string const& entry, std::string const& name) +void cmWIXAccessControlList::EmitBooleanAttribute(std::string const& entry, + std::string const& name) { - if(!this->IsBooleanAttribute(name)) - { + if (!this->IsBooleanAttribute(name)) { std::stringstream message; message << "Unknown boolean attribute '" << name << "'"; this->ReportError(entry, message.str()); - } + } this->SourceWriter.AddAttribute(name, "yes"); } diff --git a/Source/CPack/WiX/cmWIXAccessControlList.h b/Source/CPack/WiX/cmWIXAccessControlList.h index 7293995..a1ac593 100644 --- a/Source/CPack/WiX/cmWIXAccessControlList.h +++ b/Source/CPack/WiX/cmWIXAccessControlList.h @@ -21,10 +21,9 @@ class cmWIXAccessControlList { public: - cmWIXAccessControlList( - cmCPackLog *logger, - cmInstalledFile const& installedFile, - cmWIXSourceWriter &sourceWriter); + cmWIXAccessControlList(cmCPackLog* logger, + cmInstalledFile const& installedFile, + cmWIXSourceWriter& sourceWriter); bool Apply(); @@ -35,12 +34,11 @@ private: bool IsBooleanAttribute(std::string const& name); - void EmitBooleanAttribute( - std::string const& entry, std::string const& name); + void EmitBooleanAttribute(std::string const& entry, std::string const& name); cmCPackLog* Logger; cmInstalledFile const& InstalledFile; - cmWIXSourceWriter &SourceWriter; + cmWIXSourceWriter& SourceWriter; }; #endif diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx index 7bd4315..60ecae6 100644 --- a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx @@ -12,11 +12,10 @@ #include "cmWIXDirectoriesSourceWriter.h" -cmWIXDirectoriesSourceWriter::cmWIXDirectoriesSourceWriter(cmCPackLog* logger, - std::string const& filename): - cmWIXSourceWriter(logger, filename) +cmWIXDirectoriesSourceWriter::cmWIXDirectoriesSourceWriter( + cmCPackLog* logger, std::string const& filename) + : cmWIXSourceWriter(logger, filename) { - } void cmWIXDirectoriesSourceWriter::EmitStartMenuFolder( @@ -60,25 +59,20 @@ size_t cmWIXDirectoriesSourceWriter::BeginInstallationPrefixDirectory( cmSystemTools::SplitPath(installRootString.c_str(), installRoot); - if(!installRoot.empty() && installRoot.back().empty()) - { + if (!installRoot.empty() && installRoot.back().empty()) { installRoot.pop_back(); - } + } - for(size_t i = 1; i < installRoot.size(); ++i) - { + for (size_t i = 1; i < installRoot.size(); ++i) { BeginElement("Directory"); - if(i == installRoot.size() - 1) - { + if (i == installRoot.size() - 1) { AddAttribute("Id", "INSTALL_ROOT"); - } - else - { + } else { std::stringstream tmp; tmp << "INSTALL_PREFIX_" << i; AddAttribute("Id", tmp.str()); - } + } AddAttribute("Name", installRoot[i]); } @@ -88,8 +82,7 @@ size_t cmWIXDirectoriesSourceWriter::BeginInstallationPrefixDirectory( void cmWIXDirectoriesSourceWriter::EndInstallationPrefixDirectory(size_t size) { - for(size_t i = 0; i < size; ++i) - { + for (size_t i = 0; i < size; ++i) { EndElement("Directory"); - } + } } diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h index f8c8166..023f4b8 100644 --- a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h +++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h @@ -26,7 +26,7 @@ class cmWIXDirectoriesSourceWriter : public cmWIXSourceWriter { public: cmWIXDirectoriesSourceWriter(cmCPackLog* logger, - std::string const& filename); + std::string const& filename); void EmitStartMenuFolder(std::string const& startMenuFolder); @@ -35,8 +35,8 @@ public: void EmitStartupFolder(); size_t BeginInstallationPrefixDirectory( - std::string const& programFilesFolderId, - std::string const& installRootString); + std::string const& programFilesFolderId, + std::string const& installRootString); void EndInstallationPrefixDirectory(size_t size); }; diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx index 0bcfc38..16dd0ab 100644 --- a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx @@ -12,16 +12,14 @@ #include "cmWIXFeaturesSourceWriter.h" -cmWIXFeaturesSourceWriter::cmWIXFeaturesSourceWriter(cmCPackLog* logger, - std::string const& filename): - cmWIXSourceWriter(logger, filename) +cmWIXFeaturesSourceWriter::cmWIXFeaturesSourceWriter( + cmCPackLog* logger, std::string const& filename) + : cmWIXSourceWriter(logger, filename) { - } void cmWIXFeaturesSourceWriter::CreateCMakePackageRegistryEntry( - std::string const& package, - std::string const& upgradeGuid) + std::string const& package, std::string const& upgradeGuid) { BeginElement("Component"); AddAttribute("Id", "CM_PACKAGE_REGISTRY"); @@ -29,7 +27,7 @@ void cmWIXFeaturesSourceWriter::CreateCMakePackageRegistryEntry( AddAttribute("Guid", "*"); std::string registryKey = - std::string("Software\\Kitware\\CMake\\Packages\\") + package; + std::string("Software\\Kitware\\CMake\\Packages\\") + package; BeginElement("RegistryValue"); AddAttribute("Root", "HKLM"); @@ -49,25 +47,24 @@ void cmWIXFeaturesSourceWriter::EmitFeatureForComponentGroup( BeginElement("Feature"); AddAttribute("Id", "CM_G_" + group.Name); - if(group.IsExpandedByDefault) - { + if (group.IsExpandedByDefault) { AddAttribute("Display", "expand"); - } + } AddAttributeUnlessEmpty("Title", group.DisplayName); AddAttributeUnlessEmpty("Description", group.Description); - for(std::vector<cmCPackComponentGroup*>::const_iterator - i = group.Subgroups.begin(); i != group.Subgroups.end(); ++i) - { + for (std::vector<cmCPackComponentGroup*>::const_iterator i = + group.Subgroups.begin(); + i != group.Subgroups.end(); ++i) { EmitFeatureForComponentGroup(**i); - } + } - for(std::vector<cmCPackComponent*>::const_iterator - i = group.Components.begin(); i != group.Components.end(); ++i) - { + for (std::vector<cmCPackComponent*>::const_iterator i = + group.Components.begin(); + i != group.Components.end(); ++i) { EmitFeatureForComponent(**i); - } + } EndElement("Feature"); } @@ -81,15 +78,13 @@ void cmWIXFeaturesSourceWriter::EmitFeatureForComponent( AddAttributeUnlessEmpty("Title", component.DisplayName); AddAttributeUnlessEmpty("Description", component.Description); - if(component.IsRequired) - { + if (component.IsRequired) { AddAttribute("Absent", "disallow"); - } + } - if(component.IsHidden) - { + if (component.IsHidden) { AddAttribute("Display", "hidden"); - } + } EndElement("Feature"); } diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h index ff12e6c..ee9c17a 100644 --- a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h +++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h @@ -23,12 +23,10 @@ class cmWIXFeaturesSourceWriter : public cmWIXSourceWriter { public: - cmWIXFeaturesSourceWriter(cmCPackLog* logger, - std::string const& filename); + cmWIXFeaturesSourceWriter(cmCPackLog* logger, std::string const& filename); - void CreateCMakePackageRegistryEntry( - std::string const& package, - std::string const& upgradeGuid); + void CreateCMakePackageRegistryEntry(std::string const& package, + std::string const& upgradeGuid); void EmitFeatureForComponentGroup(const cmCPackComponentGroup& group); diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx index 2833d53..1341fa5 100644 --- a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx @@ -21,25 +21,22 @@ #include <sys/stat.h> cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger, - std::string const& filename): - cmWIXSourceWriter(logger, filename) + std::string const& filename) + : cmWIXSourceWriter(logger, filename) { - } -void cmWIXFilesSourceWriter::EmitShortcut( - std::string const& id, - cmWIXShortcut const& shortcut, - std::string const& shortcutPrefix, - size_t shortcutIndex) +void cmWIXFilesSourceWriter::EmitShortcut(std::string const& id, + cmWIXShortcut const& shortcut, + std::string const& shortcutPrefix, + size_t shortcutIndex) { std::stringstream shortcutId; shortcutId << shortcutPrefix << id; - if(shortcutIndex > 0) - { - shortcutId << "_" << shortcutIndex; - } + if (shortcutIndex > 0) { + shortcutId << "_" << shortcutIndex; + } std::string fileId = std::string("CM_F") + id; @@ -61,15 +58,13 @@ void cmWIXFilesSourceWriter::EmitRemoveFolder(std::string const& id) } void cmWIXFilesSourceWriter::EmitInstallRegistryValue( - std::string const& registryKey, - std::string const& cpackComponentName, + std::string const& registryKey, std::string const& cpackComponentName, std::string const& suffix) { std::string valueName; - if(!cpackComponentName.empty()) - { - valueName = cpackComponentName + "_"; - } + if (!cpackComponentName.empty()) { + valueName = cpackComponentName + "_"; + } valueName += "installed"; valueName += suffix; @@ -97,12 +92,10 @@ void cmWIXFilesSourceWriter::EmitUninstallShortcut( } std::string cmWIXFilesSourceWriter::EmitComponentCreateFolder( - std::string const& directoryId, - std::string const& guid, + std::string const& directoryId, std::string const& guid, cmInstalledFile const* installedFile) { - std::string componentId = - std::string("CM_C_EMPTY_") + directoryId; + std::string componentId = std::string("CM_C_EMPTY_") + directoryId; BeginElement("DirectoryRef"); AddAttribute("Id", directoryId); @@ -113,11 +106,10 @@ std::string cmWIXFilesSourceWriter::EmitComponentCreateFolder( BeginElement("CreateFolder"); - if(installedFile) - { + if (installedFile) { cmWIXAccessControlList acl(Logger, *installedFile, *this); acl.Apply(); - } + } EndElement("CreateFolder"); EndElement("Component"); @@ -127,10 +119,8 @@ std::string cmWIXFilesSourceWriter::EmitComponentCreateFolder( } std::string cmWIXFilesSourceWriter::EmitComponentFile( - std::string const& directoryId, - std::string const& id, - std::string const& filePath, - cmWIXPatch &patch, + std::string const& directoryId, std::string const& id, + std::string const& filePath, cmWIXPatch& patch, cmInstalledFile const* installedFile) { std::string componentId = std::string("CM_C") + id; @@ -143,17 +133,14 @@ std::string cmWIXFilesSourceWriter::EmitComponentFile( AddAttribute("Id", componentId); AddAttribute("Guid", "*"); - if(installedFile) - { - if(installedFile->GetPropertyAsBool("CPACK_NEVER_OVERWRITE")) - { + if (installedFile) { + if (installedFile->GetPropertyAsBool("CPACK_NEVER_OVERWRITE")) { AddAttribute("NeverOverwrite", "yes"); - } - if(installedFile->GetPropertyAsBool("CPACK_PERMANENT")) - { + } + if (installedFile->GetPropertyAsBool("CPACK_PERMANENT")) { AddAttribute("Permanent", "yes"); - } } + } BeginElement("File"); AddAttribute("Id", fileId); @@ -163,16 +150,14 @@ std::string cmWIXFilesSourceWriter::EmitComponentFile( mode_t fileMode = 0; cmSystemTools::GetPermissions(filePath.c_str(), fileMode); - if(!(fileMode & S_IWRITE)) - { + if (!(fileMode & S_IWRITE)) { AddAttribute("ReadOnly", "yes"); - } + } - if(installedFile) - { + if (installedFile) { cmWIXAccessControlList acl(Logger, *installedFile, *this); acl.Apply(); - } + } patch.ApplyFragment(fileId, *this); EndElement("File"); diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.h b/Source/CPack/WiX/cmWIXFilesSourceWriter.h index 734f901..c577e5b 100644 --- a/Source/CPack/WiX/cmWIXFilesSourceWriter.h +++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.h @@ -26,36 +26,27 @@ class cmWIXFilesSourceWriter : public cmWIXSourceWriter { public: - cmWIXFilesSourceWriter(cmCPackLog* logger, - std::string const& filename); + cmWIXFilesSourceWriter(cmCPackLog* logger, std::string const& filename); - void EmitShortcut( - std::string const& id, - cmWIXShortcut const& shortcut, - std::string const& shortcutPrefix, - size_t shortcutIndex); + void EmitShortcut(std::string const& id, cmWIXShortcut const& shortcut, + std::string const& shortcutPrefix, size_t shortcutIndex); void EmitRemoveFolder(std::string const& id); - void EmitInstallRegistryValue( - std::string const& registryKey, - std::string const& cpackComponentName, - std::string const& suffix); + void EmitInstallRegistryValue(std::string const& registryKey, + std::string const& cpackComponentName, + std::string const& suffix); void EmitUninstallShortcut(std::string const& packageName); - std::string EmitComponentCreateFolder( - std::string const& directoryId, - std::string const& guid, - cmInstalledFile const* installedFile); - - std::string EmitComponentFile( - std::string const& directoryId, - std::string const& id, - std::string const& filePath, - cmWIXPatch &patch, - cmInstalledFile const* installedFile); -}; + std::string EmitComponentCreateFolder(std::string const& directoryId, + std::string const& guid, + cmInstalledFile const* installedFile); + std::string EmitComponentFile(std::string const& directoryId, + std::string const& id, + std::string const& filePath, cmWIXPatch& patch, + cmInstalledFile const* installedFile); +}; #endif diff --git a/Source/CPack/WiX/cmWIXPatch.cxx b/Source/CPack/WiX/cmWIXPatch.cxx index 07375da..c9d010e 100644 --- a/Source/CPack/WiX/cmWIXPatch.cxx +++ b/Source/CPack/WiX/cmWIXPatch.cxx @@ -14,31 +14,29 @@ #include <CPack/cmCPackGenerator.h> -cmWIXPatch::cmWIXPatch(cmCPackLog* logger): - Logger(logger) +cmWIXPatch::cmWIXPatch(cmCPackLog* logger) + : Logger(logger) { - } bool cmWIXPatch::LoadFragments(std::string const& patchFilePath) { cmWIXPatchParser parser(Fragments, Logger); - if(!parser.ParseFile(patchFilePath.c_str())) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Failed parsing XML patch file: '" << - patchFilePath << "'" << std::endl); + if (!parser.ParseFile(patchFilePath.c_str())) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Failed parsing XML patch file: '" + << patchFilePath << "'" << std::endl); return false; - } + } return true; } -void cmWIXPatch::ApplyFragment( - std::string const& id, cmWIXSourceWriter& writer) +void cmWIXPatch::ApplyFragment(std::string const& id, + cmWIXSourceWriter& writer) { cmWIXPatchParser::fragment_map_t::iterator i = Fragments.find(id); - if(i == Fragments.end()) return; + if (i == Fragments.end()) + return; const cmWIXPatchElement& fragment = i->second; @@ -47,36 +45,35 @@ void cmWIXPatch::ApplyFragment( Fragments.erase(i); } -void cmWIXPatch::ApplyElementChildren( - const cmWIXPatchElement& element, cmWIXSourceWriter& writer) +void cmWIXPatch::ApplyElementChildren(const cmWIXPatchElement& element, + cmWIXSourceWriter& writer) { - for(cmWIXPatchElement::child_list_t::const_iterator - j = element.children.begin(); j != element.children.end(); ++j) - { - cmWIXPatchNode *node = *j; - - switch(node->type()) - { - case cmWIXPatchNode::ELEMENT: - ApplyElement(dynamic_cast<const cmWIXPatchElement&>(*node), writer); - break; - case cmWIXPatchNode::TEXT: - writer.AddTextNode(dynamic_cast<const cmWIXPatchText&>(*node).text); - break; + for (cmWIXPatchElement::child_list_t::const_iterator j = + element.children.begin(); + j != element.children.end(); ++j) { + cmWIXPatchNode* node = *j; + + switch (node->type()) { + case cmWIXPatchNode::ELEMENT: + ApplyElement(dynamic_cast<const cmWIXPatchElement&>(*node), writer); + break; + case cmWIXPatchNode::TEXT: + writer.AddTextNode(dynamic_cast<const cmWIXPatchText&>(*node).text); + break; } } } -void cmWIXPatch::ApplyElement( - const cmWIXPatchElement& element, cmWIXSourceWriter& writer) +void cmWIXPatch::ApplyElement(const cmWIXPatchElement& element, + cmWIXSourceWriter& writer) { writer.BeginElement(element.name); - for(cmWIXPatchElement::attributes_t::const_iterator - i = element.attributes.begin(); i != element.attributes.end(); ++i) - { + for (cmWIXPatchElement::attributes_t::const_iterator i = + element.attributes.begin(); + i != element.attributes.end(); ++i) { writer.AddAttribute(i->first, i->second); - } + } this->ApplyElementChildren(element, writer); @@ -86,26 +83,23 @@ void cmWIXPatch::ApplyElement( bool cmWIXPatch::CheckForUnappliedFragments() { std::string fragmentList; - for(cmWIXPatchParser::fragment_map_t::const_iterator - i = Fragments.begin(); i != Fragments.end(); ++i) - { - if(!fragmentList.empty()) - { + for (cmWIXPatchParser::fragment_map_t::const_iterator i = Fragments.begin(); + i != Fragments.end(); ++i) { + if (!fragmentList.empty()) { fragmentList += ", "; - } + } fragmentList += "'"; fragmentList += i->first; fragmentList += "'"; - } + } - if(!fragmentList.empty()) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Some XML patch fragments did not have matching IDs: " << - fragmentList << std::endl); - return false; - } + if (!fragmentList.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Some XML patch fragments did not have matching IDs: " + << fragmentList << std::endl); + return false; + } return true; } diff --git a/Source/CPack/WiX/cmWIXPatch.h b/Source/CPack/WiX/cmWIXPatch.h index 5b0eb3b..57b74cd 100644 --- a/Source/CPack/WiX/cmWIXPatch.h +++ b/Source/CPack/WiX/cmWIXPatch.h @@ -34,15 +34,14 @@ public: private: void ApplyElementChildren(const cmWIXPatchElement& element, - cmWIXSourceWriter& writer); + cmWIXSourceWriter& writer); void ApplyElement(const cmWIXPatchElement& element, - cmWIXSourceWriter& writer); + cmWIXSourceWriter& writer); cmCPackLog* Logger; cmWIXPatchParser::fragment_map_t Fragments; }; - #endif diff --git a/Source/CPack/WiX/cmWIXPatchParser.cxx b/Source/CPack/WiX/cmWIXPatchParser.cxx index 14c5413..b750dcf 100644 --- a/Source/CPack/WiX/cmWIXPatchParser.cxx +++ b/Source/CPack/WiX/cmWIXPatchParser.cxx @@ -28,149 +28,124 @@ cmWIXPatchNode::Type cmWIXPatchElement::type() cmWIXPatchNode::~cmWIXPatchNode() { - } cmWIXPatchElement::~cmWIXPatchElement() { - for(child_list_t::iterator i = children.begin(); i != children.end(); ++i) - { + for (child_list_t::iterator i = children.begin(); i != children.end(); ++i) { delete *i; - } + } } -cmWIXPatchParser::cmWIXPatchParser( - fragment_map_t& fragments, cmCPackLog* logger): - Logger(logger), - State(BEGIN_DOCUMENT), - Valid(true), - Fragments(fragments) +cmWIXPatchParser::cmWIXPatchParser(fragment_map_t& fragments, + cmCPackLog* logger) + : Logger(logger) + , State(BEGIN_DOCUMENT) + , Valid(true) + , Fragments(fragments) { - } -void cmWIXPatchParser::StartElement(const std::string& name, const char **atts) +void cmWIXPatchParser::StartElement(const std::string& name, const char** atts) { - if(State == BEGIN_DOCUMENT) - { - if(name == "CPackWiXPatch") - { + if (State == BEGIN_DOCUMENT) { + if (name == "CPackWiXPatch") { State = BEGIN_FRAGMENTS; - } - else - { + } else { ReportValidationError("Expected root element 'CPackWiXPatch'"); - } } - else if(State == BEGIN_FRAGMENTS) - { - if(name == "CPackWiXFragment") - { - State = INSIDE_FRAGMENT; - StartFragment(atts); - } - else - { - ReportValidationError("Expected 'CPackWixFragment' element"); - } + } else if (State == BEGIN_FRAGMENTS) { + if (name == "CPackWiXFragment") { + State = INSIDE_FRAGMENT; + StartFragment(atts); + } else { + ReportValidationError("Expected 'CPackWixFragment' element"); } - else if(State == INSIDE_FRAGMENT) - { - cmWIXPatchElement &parent = *ElementStack.back(); - - cmWIXPatchElement *element = new cmWIXPatchElement; - parent.children.push_back(element); + } else if (State == INSIDE_FRAGMENT) { + cmWIXPatchElement& parent = *ElementStack.back(); - element->name = name; + cmWIXPatchElement* element = new cmWIXPatchElement; + parent.children.push_back(element); - for(size_t i = 0; atts[i]; i += 2) - { - std::string key = atts[i]; - std::string value = atts[i+1]; + element->name = name; - element->attributes[key] = value; - } + for (size_t i = 0; atts[i]; i += 2) { + std::string key = atts[i]; + std::string value = atts[i + 1]; - ElementStack.push_back(element); + element->attributes[key] = value; } + + ElementStack.push_back(element); + } } -void cmWIXPatchParser::StartFragment(const char **attributes) +void cmWIXPatchParser::StartFragment(const char** attributes) { - for(size_t i = 0; attributes[i]; i += 2) - { + for (size_t i = 0; attributes[i]; i += 2) { std::string key = attributes[i]; - std::string value = attributes[i+1]; + std::string value = attributes[i + 1]; - if(key == "Id") - { - if(Fragments.find(value) != Fragments.end()) - { + if (key == "Id") { + if (Fragments.find(value) != Fragments.end()) { std::stringstream tmp; tmp << "Invalid reuse of 'CPackWixFragment' 'Id': " << value; ReportValidationError(tmp.str()); - } + } ElementStack.push_back(&Fragments[value]); - } - else - { + } else { ReportValidationError( "The only allowed 'CPackWixFragment' attribute is 'Id'"); - } } + } } void cmWIXPatchParser::EndElement(const std::string& name) { - if(State == INSIDE_FRAGMENT) - { - if(name == "CPackWiXFragment") - { - State = BEGIN_FRAGMENTS; - ElementStack.clear(); - } - else - { - ElementStack.pop_back(); - } + if (State == INSIDE_FRAGMENT) { + if (name == "CPackWiXFragment") { + State = BEGIN_FRAGMENTS; + ElementStack.clear(); + } else { + ElementStack.pop_back(); } + } } void cmWIXPatchParser::CharacterDataHandler(const char* data, int length) { const char* whitespace = "\x20\x09\x0d\x0a"; - if(State == INSIDE_FRAGMENT) - { - cmWIXPatchElement &parent = *ElementStack.back(); + if (State == INSIDE_FRAGMENT) { + cmWIXPatchElement& parent = *ElementStack.back(); std::string text(data, length); std::string::size_type first = text.find_first_not_of(whitespace); std::string::size_type last = text.find_last_not_of(whitespace); - if(first != std::string::npos && last != std::string::npos) - { - cmWIXPatchText *text_node = new cmWIXPatchText; + if (first != std::string::npos && last != std::string::npos) { + cmWIXPatchText* text_node = new cmWIXPatchText; text_node->text = text.substr(first, last - first + 1); parent.children.push_back(text_node); - } } + } } void cmWIXPatchParser::ReportError(int line, int column, const char* msg) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error while processing XML patch file at " << line << ":" << column << - ": "<< msg << std::endl); + "Error while processing XML patch file at " + << line << ":" << column << ": " << msg << std::endl); Valid = false; } void cmWIXPatchParser::ReportValidationError(std::string const& message) { - ReportError(XML_GetCurrentLineNumber(static_cast<XML_Parser>(this->Parser)), + ReportError( + XML_GetCurrentLineNumber(static_cast<XML_Parser>(this->Parser)), XML_GetCurrentColumnNumber(static_cast<XML_Parser>(this->Parser)), message.c_str()); } diff --git a/Source/CPack/WiX/cmWIXPatchParser.h b/Source/CPack/WiX/cmWIXPatchParser.h index 8ce4026..f9b85bd 100644 --- a/Source/CPack/WiX/cmWIXPatchParser.h +++ b/Source/CPack/WiX/cmWIXPatchParser.h @@ -65,9 +65,9 @@ public: cmWIXPatchParser(fragment_map_t& Fragments, cmCPackLog* logger); private: - virtual void StartElement(const std::string& name, const char **atts); + virtual void StartElement(const std::string& name, const char** atts); - void StartFragment(const char **attributes); + void StartFragment(const char** attributes); virtual void EndElement(const std::string& name); diff --git a/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx b/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx index f27caa9..f3dbcb9 100644 --- a/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx +++ b/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx @@ -15,8 +15,8 @@ #include <cmVersion.h> cmWIXRichTextFormatWriter::cmWIXRichTextFormatWriter( - std::string const& filename): - File(filename.c_str(), std::ios::binary) + std::string const& filename) + : File(filename.c_str(), std::ios::binary) { StartGroup(); WriteHeader(); @@ -37,74 +37,50 @@ void cmWIXRichTextFormatWriter::AddText(std::string const& text) { typedef unsigned char rtf_byte_t; - for(size_t i = 0; i < text.size(); ++i) - { + for (size_t i = 0; i < text.size(); ++i) { rtf_byte_t c = rtf_byte_t(text[i]); - switch(c) - { - case '\\': - File << "\\\\"; - break; - case '{': - File << "\\{"; - break; - case '}': - File << "\\}"; - break; - case '\n': - File << "\\par\r\n"; - break; - case '\r': - continue; - default: - { - if(c <= 0x7F) - { + switch (c) { + case '\\': + File << "\\\\"; + break; + case '{': + File << "\\{"; + break; + case '}': + File << "\\}"; + break; + case '\n': + File << "\\par\r\n"; + break; + case '\r': + continue; + default: { + if (c <= 0x7F) { File << c; - } - else - { - if(c <= 0xC0) - { - EmitInvalidCodepoint(c); - } - else if(c < 0xE0 && i+1 < text.size()) - { - EmitUnicodeCodepoint( - (text[i+1] & 0x3F) | - ((c & 0x1F) << 6) - ); - i+= 1; - } - else if(c < 0xF0 && i+2 < text.size()) - { - EmitUnicodeCodepoint( - (text[i+2] & 0x3F) | - ((text[i+1] & 0x3F) << 6) | - ((c & 0xF) << 12) - ); - i += 2; - } - else if(c < 0xF8 && i+3 < text.size()) - { - EmitUnicodeCodepoint( - (text[i+3] & 0x3F) | - ((text[i+2] & 0x3F) << 6) | - ((text[i+1] & 0x3F) << 12) | - ((c & 0x7) << 18) - ); - i += 3; - } - else - { - EmitInvalidCodepoint(c); - } + } else { + if (c <= 0xC0) { + EmitInvalidCodepoint(c); + } else if (c < 0xE0 && i + 1 < text.size()) { + EmitUnicodeCodepoint((text[i + 1] & 0x3F) | ((c & 0x1F) << 6)); + i += 1; + } else if (c < 0xF0 && i + 2 < text.size()) { + EmitUnicodeCodepoint((text[i + 2] & 0x3F) | + ((text[i + 1] & 0x3F) << 6) | + ((c & 0xF) << 12)); + i += 2; + } else if (c < 0xF8 && i + 3 < text.size()) { + EmitUnicodeCodepoint( + (text[i + 3] & 0x3F) | ((text[i + 2] & 0x3F) << 6) | + ((text[i + 1] & 0x3F) << 12) | ((c & 0x7) << 18)); + i += 3; + } else { + EmitInvalidCodepoint(c); } } - break; - } + } break; } + } } void cmWIXRichTextFormatWriter::WriteHeader() @@ -190,33 +166,25 @@ void cmWIXRichTextFormatWriter::EndGroup() void cmWIXRichTextFormatWriter::EmitUnicodeCodepoint(int c) { // Do not emit byte order mark (BOM) - if(c == 0xFEFF) - { + if (c == 0xFEFF) { return; - } - else if(c <= 0xFFFF) - { + } else if (c <= 0xFFFF) { EmitUnicodeSurrogate(c); - } - else - { + } else { c -= 0x10000; EmitUnicodeSurrogate(((c >> 10) & 0x3FF) + 0xD800); EmitUnicodeSurrogate((c & 0x3FF) + 0xDC00); - } + } } void cmWIXRichTextFormatWriter::EmitUnicodeSurrogate(int c) { ControlWord("u"); - if(c <= 32767) - { + if (c <= 32767) { File << c; - } - else - { + } else { File << (c - 65536); - } + } File << "?"; } diff --git a/Source/CPack/WiX/cmWIXShortcut.cxx b/Source/CPack/WiX/cmWIXShortcut.cxx index d721872..2685a23 100644 --- a/Source/CPack/WiX/cmWIXShortcut.cxx +++ b/Source/CPack/WiX/cmWIXShortcut.cxx @@ -14,8 +14,8 @@ #include "cmWIXFilesSourceWriter.h" -void cmWIXShortcuts::insert( - Type type, std::string const& id, cmWIXShortcut const& shortcut) +void cmWIXShortcuts::insert(Type type, std::string const& id, + cmWIXShortcut const& shortcut) { this->Shortcuts[type][id].push_back(shortcut); } @@ -26,25 +26,22 @@ bool cmWIXShortcuts::empty(Type type) const } bool cmWIXShortcuts::EmitShortcuts( - Type type, - std::string const& registryKey, + Type type, std::string const& registryKey, std::string const& cpackComponentName, cmWIXFilesSourceWriter& fileDefinitions) const { shortcut_type_map_t::const_iterator i = this->Shortcuts.find(type); - if(i == this->Shortcuts.end()) - { + if (i == this->Shortcuts.end()) { return false; - } + } shortcut_id_map_t const& id_map = i->second; std::string shortcutPrefix; std::string registrySuffix; - switch(type) - { + switch (type) { case START_MENU: shortcutPrefix = "CM_S"; break; @@ -58,68 +55,61 @@ bool cmWIXShortcuts::EmitShortcuts( break; default: return false; - } + } - for(shortcut_id_map_t::const_iterator j = id_map.begin(); - j != id_map.end(); ++j) - { + for (shortcut_id_map_t::const_iterator j = id_map.begin(); j != id_map.end(); + ++j) { std::string const& id = j->first; shortcut_list_t const& shortcutList = j->second; - for(size_t shortcutListIndex = 0; - shortcutListIndex < shortcutList.size(); ++shortcutListIndex) - { + for (size_t shortcutListIndex = 0; shortcutListIndex < shortcutList.size(); + ++shortcutListIndex) { cmWIXShortcut const& shortcut = shortcutList[shortcutListIndex]; - fileDefinitions.EmitShortcut(id, shortcut, - shortcutPrefix, shortcutListIndex); - } + fileDefinitions.EmitShortcut(id, shortcut, shortcutPrefix, + shortcutListIndex); } + } - fileDefinitions.EmitInstallRegistryValue( - registryKey, cpackComponentName, registrySuffix); + fileDefinitions.EmitInstallRegistryValue(registryKey, cpackComponentName, + registrySuffix); return true; } void cmWIXShortcuts::AddShortcutTypes(std::set<Type>& types) { - for(shortcut_type_map_t::const_iterator i = this->Shortcuts.begin(); - i != this->Shortcuts.end(); ++i) - { + for (shortcut_type_map_t::const_iterator i = this->Shortcuts.begin(); + i != this->Shortcuts.end(); ++i) { types.insert(i->first); - } + } } -void cmWIXShortcuts::CreateFromProperties( - std::string const& id, - std::string const& directoryId, - cmInstalledFile const& installedFile) +void cmWIXShortcuts::CreateFromProperties(std::string const& id, + std::string const& directoryId, + cmInstalledFile const& installedFile) { - CreateFromProperty("CPACK_START_MENU_SHORTCUTS", - START_MENU, id, directoryId, installedFile); + CreateFromProperty("CPACK_START_MENU_SHORTCUTS", START_MENU, id, directoryId, + installedFile); - CreateFromProperty("CPACK_DESKTOP_SHORTCUTS", - DESKTOP, id, directoryId, installedFile); + CreateFromProperty("CPACK_DESKTOP_SHORTCUTS", DESKTOP, id, directoryId, + installedFile); - CreateFromProperty("CPACK_STARTUP_SHORTCUTS", - STARTUP, id, directoryId, installedFile); + CreateFromProperty("CPACK_STARTUP_SHORTCUTS", STARTUP, id, directoryId, + installedFile); } -void cmWIXShortcuts::CreateFromProperty( - std::string const& propertyName, - Type type, - std::string const& id, - std::string const& directoryId, - cmInstalledFile const& installedFile) +void cmWIXShortcuts::CreateFromProperty(std::string const& propertyName, + Type type, std::string const& id, + std::string const& directoryId, + cmInstalledFile const& installedFile) { std::vector<std::string> list; installedFile.GetPropertyAsList(propertyName, list); - for(size_t i = 0; i < list.size(); ++i) - { + for (size_t i = 0; i < list.size(); ++i) { cmWIXShortcut shortcut; shortcut.label = list[i]; shortcut.workingDirectoryId = directoryId; insert(type, id, shortcut); - } + } } diff --git a/Source/CPack/WiX/cmWIXShortcut.h b/Source/CPack/WiX/cmWIXShortcut.h index 598aa0d..593ba34 100644 --- a/Source/CPack/WiX/cmWIXShortcut.h +++ b/Source/CPack/WiX/cmWIXShortcut.h @@ -45,26 +45,23 @@ public: bool empty(Type type) const; - bool EmitShortcuts( - Type type, - std::string const& registryKey, - std::string const& cpackComponentName, - cmWIXFilesSourceWriter& fileDefinitions) const; + bool EmitShortcuts(Type type, std::string const& registryKey, + std::string const& cpackComponentName, + cmWIXFilesSourceWriter& fileDefinitions) const; void AddShortcutTypes(std::set<Type>& types); void CreateFromProperties(std::string const& id, - std::string const& directoryId, cmInstalledFile const& installedFile); + std::string const& directoryId, + cmInstalledFile const& installedFile); private: typedef std::map<Type, shortcut_id_map_t> shortcut_type_map_t; - void CreateFromProperty( - std::string const& propertyName, - Type type, - std::string const& id, - std::string const& directoryId, - cmInstalledFile const& installedFile); + void CreateFromProperty(std::string const& propertyName, Type type, + std::string const& id, + std::string const& directoryId, + cmInstalledFile const& installedFile); shortcut_type_map_t Shortcuts; shortcut_id_map_t EmptyIdMap; diff --git a/Source/CPack/WiX/cmWIXSourceWriter.cxx b/Source/CPack/WiX/cmWIXSourceWriter.cxx index 2e5194c..2c0384e 100644 --- a/Source/CPack/WiX/cmWIXSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXSourceWriter.cxx @@ -17,46 +17,41 @@ #include <windows.h> cmWIXSourceWriter::cmWIXSourceWriter(cmCPackLog* logger, - std::string const& filename, - bool isIncludeFile): - Logger(logger), - File(filename.c_str()), - State(DEFAULT), - SourceFilename(filename) + std::string const& filename, + bool isIncludeFile) + : Logger(logger) + , File(filename.c_str()) + , State(DEFAULT) + , SourceFilename(filename) { WriteXMLDeclaration(); - if(isIncludeFile) - { + if (isIncludeFile) { BeginElement("Include"); - } - else - { + } else { BeginElement("Wix"); - } + } AddAttribute("xmlns", "http://schemas.microsoft.com/wix/2006/wi"); } cmWIXSourceWriter::~cmWIXSourceWriter() { - if(Elements.size() > 1) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - Elements.size() - 1 << " WiX elements were still open when closing '" << - SourceFilename << "'" << std::endl); + if (Elements.size() > 1) { + cmCPackLogger(cmCPackLog::LOG_ERROR, Elements.size() - 1 + << " WiX elements were still open when closing '" + << SourceFilename << "'" << std::endl); return; - } + } EndElement(Elements.back()); } void cmWIXSourceWriter::BeginElement(std::string const& name) { - if(State == BEGIN) - { + if (State == BEGIN) { File << ">"; - } + } File << "\n"; Indent(Elements.size()); @@ -68,33 +63,27 @@ void cmWIXSourceWriter::BeginElement(std::string const& name) void cmWIXSourceWriter::EndElement(std::string const& name) { - if(Elements.empty()) - { + if (Elements.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "can not end WiX element with no open elements in '" << - SourceFilename << "'" << std::endl); + "can not end WiX element with no open elements in '" + << SourceFilename << "'" << std::endl); return; - } + } - if(Elements.back() != name) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "WiX element <" << Elements.back() << - "> can not be closed by </" << name << "> in '" << - SourceFilename << "'" << std::endl); + if (Elements.back() != name) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "WiX element <" + << Elements.back() << "> can not be closed by </" << name + << "> in '" << SourceFilename << "'" << std::endl); return; - } + } - if(State == DEFAULT) - { + if (State == DEFAULT) { File << "\n"; - Indent(Elements.size()-1); + Indent(Elements.size() - 1); File << "</" << Elements.back() << ">"; - } - else - { + } else { File << "/>"; - } + } Elements.pop_back(); State = DEFAULT; @@ -102,30 +91,27 @@ void cmWIXSourceWriter::EndElement(std::string const& name) void cmWIXSourceWriter::AddTextNode(std::string const& text) { - if(State == BEGIN) - { + if (State == BEGIN) { File << ">"; - } + } - if(Elements.empty()) - { + if (Elements.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "can not add text without open WiX element in '" << - SourceFilename << "'" << std::endl); + "can not add text without open WiX element in '" + << SourceFilename << "'" << std::endl); return; - } + } File << this->EscapeAttributeValue(text); State = DEFAULT; } -void cmWIXSourceWriter::AddProcessingInstruction( - std::string const& target, std::string const& content) +void cmWIXSourceWriter::AddProcessingInstruction(std::string const& target, + std::string const& content) { - if(State == BEGIN) - { + if (State == BEGIN) { File << ">"; - } + } File << "\n"; Indent(Elements.size()); @@ -134,21 +120,20 @@ void cmWIXSourceWriter::AddProcessingInstruction( State = DEFAULT; } -void cmWIXSourceWriter::AddAttribute( - std::string const& key, std::string const& value) +void cmWIXSourceWriter::AddAttribute(std::string const& key, + std::string const& value) { std::string utf8 = CMakeEncodingToUtf8(value); File << " " << key << "=\"" << EscapeAttributeValue(utf8) << '"'; } -void cmWIXSourceWriter::AddAttributeUnlessEmpty( - std::string const& key, std::string const& value) +void cmWIXSourceWriter::AddAttributeUnlessEmpty(std::string const& key, + std::string const& value) { - if(!value.empty()) - { + if (!value.empty()) { AddAttribute(key, value); - } + } } std::string cmWIXSourceWriter::CMakeEncodingToUtf8(std::string const& value) @@ -156,43 +141,38 @@ std::string cmWIXSourceWriter::CMakeEncodingToUtf8(std::string const& value) #ifdef CMAKE_ENCODING_UTF8 return value; #else - if(value.empty()) - { + if (value.empty()) { return std::string(); - } + } int characterCount = MultiByteToWideChar( CP_ACP, 0, value.c_str(), static_cast<int>(value.size()), 0, 0); - if(characterCount == 0) - { + if (characterCount == 0) { return std::string(); - } + } std::vector<wchar_t> utf16(characterCount); - MultiByteToWideChar( - CP_ACP, 0, value.c_str(), static_cast<int>(value.size()), - &utf16[0], static_cast<int>(utf16.size())); + MultiByteToWideChar(CP_ACP, 0, value.c_str(), static_cast<int>(value.size()), + &utf16[0], static_cast<int>(utf16.size())); int utf8ByteCount = WideCharToMultiByte( CP_UTF8, 0, &utf16[0], static_cast<int>(utf16.size()), 0, 0, 0, 0); - if(utf8ByteCount == 0) - { + if (utf8ByteCount == 0) { return std::string(); - } + } std::vector<char> utf8(utf8ByteCount); WideCharToMultiByte(CP_UTF8, 0, &utf16[0], static_cast<int>(utf16.size()), - &utf8[0], static_cast<int>(utf8.size()), 0, 0); + &utf8[0], static_cast<int>(utf8.size()), 0, 0); return std::string(&utf8[0], utf8.size()); #endif } - void cmWIXSourceWriter::WriteXMLDeclaration() { File << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl; @@ -200,41 +180,37 @@ void cmWIXSourceWriter::WriteXMLDeclaration() void cmWIXSourceWriter::Indent(size_t count) { - for(size_t i = 0; i < count; ++i) - { + for (size_t i = 0; i < count; ++i) { File << " "; - } + } } -std::string cmWIXSourceWriter::EscapeAttributeValue( - std::string const& value) +std::string cmWIXSourceWriter::EscapeAttributeValue(std::string const& value) { std::string result; result.reserve(value.size()); char c = 0; - for(size_t i = 0 ; i < value.size(); ++i) - { + for (size_t i = 0; i < value.size(); ++i) { c = value[i]; - switch(c) - { - case '<': - result += "<"; - break; - case '>': - result += ">"; - break; - case '&': - result +="&"; - break; - case '"': - result += """; - break; - default: - result += c; - break; - } - } + switch (c) { + case '<': + result += "<"; + break; + case '>': + result += ">"; + break; + case '&': + result += "&"; + break; + case '"': + result += """; + break; + default: + result += c; + break; + } + } return result; } diff --git a/Source/CPack/WiX/cmWIXSourceWriter.h b/Source/CPack/WiX/cmWIXSourceWriter.h index 2bf9674..4efc026 100644 --- a/Source/CPack/WiX/cmWIXSourceWriter.h +++ b/Source/CPack/WiX/cmWIXSourceWriter.h @@ -26,8 +26,8 @@ class cmWIXSourceWriter { public: - cmWIXSourceWriter(cmCPackLog* logger, - std::string const& filename, bool isIncludeFile = false); + cmWIXSourceWriter(cmCPackLog* logger, std::string const& filename, + bool isIncludeFile = false); ~cmWIXSourceWriter(); @@ -37,19 +37,18 @@ public: void AddTextNode(std::string const& text); - void AddProcessingInstruction( - std::string const& target, std::string const& content); + void AddProcessingInstruction(std::string const& target, + std::string const& content); - void AddAttribute( - std::string const& key, std::string const& value); + void AddAttribute(std::string const& key, std::string const& value); - void AddAttributeUnlessEmpty( - std::string const& key, std::string const& value); + void AddAttributeUnlessEmpty(std::string const& key, + std::string const& value); static std::string CMakeEncodingToUtf8(std::string const& value); protected: - cmCPackLog* Logger; + cmCPackLog* Logger; private: enum State |