cmCPackInnoSetupGenerator.cxx 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCPackInnoSetupGenerator.h"
  4. #include <algorithm>
  5. #include <cctype>
  6. #include <cstdlib>
  7. #include <ostream>
  8. #include <utility>
  9. #include "cmsys/RegularExpression.hxx"
  10. #include "cmCPackComponentGroup.h"
  11. #include "cmCPackLog.h"
  12. #include "cmDuration.h"
  13. #include "cmGeneratedFileStream.h"
  14. #include "cmList.h"
  15. #include "cmStringAlgorithms.h"
  16. #include "cmSystemTools.h"
  17. cmCPackInnoSetupGenerator::cmCPackInnoSetupGenerator() = default;
  18. cmCPackInnoSetupGenerator::~cmCPackInnoSetupGenerator() = default;
  19. bool cmCPackInnoSetupGenerator::CanGenerate()
  20. {
  21. return true;
  22. }
  23. int cmCPackInnoSetupGenerator::InitializeInternal()
  24. {
  25. if (GetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY").IsOn()) {
  26. cmCPackLogger(cmCPackLog::LOG_WARNING,
  27. "Inno Setup Generator cannot work with "
  28. "CPACK_INCLUDE_TOPLEVEL_DIRECTORY set. "
  29. "This option will be reset to 0 (for this generator only)."
  30. << std::endl);
  31. SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", nullptr);
  32. }
  33. std::vector<std::string> path;
  34. #ifdef _WIN32
  35. path.push_back("C:\\Program Files (x86)\\Inno Setup 5");
  36. path.push_back("C:\\Program Files (x86)\\Inno Setup 6");
  37. #endif
  38. SetOptionIfNotSet("CPACK_INNOSETUP_EXECUTABLE", "ISCC");
  39. std::string const& isccPath = cmSystemTools::FindProgram(
  40. GetOption("CPACK_INNOSETUP_EXECUTABLE"), path, false);
  41. if (isccPath.empty()) {
  42. cmCPackLogger(cmCPackLog::LOG_ERROR,
  43. "Cannot find Inno Setup compiler ISCC: "
  44. "likely it is not installed, or not in your PATH"
  45. << std::endl);
  46. return 0;
  47. }
  48. std::string const isccCmd =
  49. cmStrCat(QuotePath(isccPath, PathType::Native), "/?");
  50. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  51. "Test Inno Setup version: " << isccCmd << std::endl);
  52. std::string output;
  53. cmSystemTools::RunSingleCommand(isccCmd, &output, &output, nullptr, nullptr,
  54. this->GeneratorVerbose, cmDuration::zero());
  55. cmsys::RegularExpression vRex("Inno Setup ([0-9]+)");
  56. if (!vRex.find(output)) {
  57. cmCPackLogger(cmCPackLog::LOG_ERROR,
  58. "Problem checking Inno Setup version with command: "
  59. << isccCmd << std::endl
  60. << "Have you downloaded Inno Setup from "
  61. "https://jrsoftware.org/isinfo.php?"
  62. << std::endl);
  63. return 0;
  64. }
  65. int const isccVersion = atoi(vRex.match(1).c_str());
  66. int const minIsccVersion = 6;
  67. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  68. "Inno Setup Version: " << isccVersion << std::endl);
  69. if (isccVersion < minIsccVersion) {
  70. cmCPackLogger(cmCPackLog::LOG_ERROR,
  71. "CPack requires Inno Setup Version 6 or greater. "
  72. "Inno Setup found on the system was: "
  73. << isccVersion << std::endl);
  74. return 0;
  75. }
  76. SetOption("CPACK_INSTALLER_PROGRAM", isccPath);
  77. return this->Superclass::InitializeInternal();
  78. }
  79. int cmCPackInnoSetupGenerator::PackageFiles()
  80. {
  81. // Includes
  82. if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_EXTRA_SCRIPTS")) {
  83. cmList const extraScripts(*v);
  84. for (std::string const& i : extraScripts) {
  85. includeDirectives.emplace_back(cmStrCat(
  86. "#include ", QuotePath(cmSystemTools::CollapseFullPath(i, toplevel))));
  87. }
  88. }
  89. // [Languages] section
  90. SetOptionIfNotSet("CPACK_INNOSETUP_LANGUAGES", "english");
  91. cmList const languages(GetOption("CPACK_INNOSETUP_LANGUAGES"));
  92. for (std::string i : languages) {
  93. cmCPackInnoSetupKeyValuePairs params;
  94. params["Name"] = Quote(i);
  95. if (cmSystemTools::LowerCase(i) == "english") {
  96. params["MessagesFile"] = "\"compiler:Default.isl\"";
  97. } else {
  98. i[0] = static_cast<char>(std::toupper(i[0]));
  99. params["MessagesFile"] = cmStrCat("\"compiler:Languages\\", i, ".isl\"");
  100. }
  101. languageInstructions.push_back(ISKeyValueLine(params));
  102. }
  103. if (!Components.empty() && !ProcessComponents()) {
  104. return false;
  105. }
  106. if (!(ProcessSetupSection() && ProcessFiles())) {
  107. return false;
  108. }
  109. // [Code] section
  110. if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_CODE_FILES")) {
  111. cmList const codeFiles(*v);
  112. for (std::string const& i : codeFiles) {
  113. codeIncludes.emplace_back(cmStrCat(
  114. "#include ", QuotePath(cmSystemTools::CollapseFullPath(i, toplevel))));
  115. }
  116. }
  117. return ConfigureISScript() && Compile();
  118. }
  119. bool cmCPackInnoSetupGenerator::ProcessSetupSection()
  120. {
  121. if (!RequireOption("CPACK_PACKAGE_INSTALL_REGISTRY_KEY")) {
  122. return false;
  123. }
  124. setupDirectives["AppId"] = GetOption("CPACK_PACKAGE_INSTALL_REGISTRY_KEY");
  125. if (!RequireOption("CPACK_PACKAGE_NAME")) {
  126. return false;
  127. }
  128. setupDirectives["AppName"] = GetOption("CPACK_PACKAGE_NAME");
  129. setupDirectives["UninstallDisplayName"] = GetOption("CPACK_PACKAGE_NAME");
  130. if (!RequireOption("CPACK_PACKAGE_VERSION")) {
  131. return false;
  132. }
  133. setupDirectives["AppVersion"] = GetOption("CPACK_PACKAGE_VERSION");
  134. if (!RequireOption("CPACK_PACKAGE_VENDOR")) {
  135. return false;
  136. }
  137. setupDirectives["AppPublisher"] = GetOption("CPACK_PACKAGE_VENDOR");
  138. if (cmValue v = GetOptionIfSet("CPACK_PACKAGE_HOMEPAGE_URL")) {
  139. setupDirectives["AppPublisherURL"] = *v;
  140. setupDirectives["AppSupportURL"] = *v;
  141. setupDirectives["AppUpdatesURL"] = *v;
  142. }
  143. SetOptionIfNotSet("CPACK_INNOSETUP_IGNORE_LICENSE_PAGE", "OFF");
  144. if (!GetOption("CPACK_INNOSETUP_IGNORE_LICENSE_PAGE").IsOn()) {
  145. if (cmValue v = GetOptionIfSet("CPACK_RESOURCE_FILE_LICENSE")) {
  146. setupDirectives["LicenseFile"] =
  147. cmSystemTools::ConvertToWindowsOutputPath(*v);
  148. }
  149. }
  150. SetOptionIfNotSet("CPACK_INNOSETUP_IGNORE_README_PAGE", "ON");
  151. if (!GetOption("CPACK_INNOSETUP_IGNORE_README_PAGE").IsOn()) {
  152. if (cmValue v = GetOptionIfSet("CPACK_RESOURCE_FILE_README")) {
  153. setupDirectives["InfoBeforeFile"] =
  154. cmSystemTools::ConvertToWindowsOutputPath(*v);
  155. }
  156. }
  157. SetOptionIfNotSet("CPACK_INNOSETUP_USE_MODERN_WIZARD", "OFF");
  158. if (GetOption("CPACK_INNOSETUP_USE_MODERN_WIZARD").IsOn()) {
  159. setupDirectives["WizardStyle"] = "modern";
  160. } else {
  161. setupDirectives["WizardStyle"] = "classic";
  162. setupDirectives["WizardSmallImageFile"] =
  163. "compiler:WizClassicSmallImage.bmp";
  164. setupDirectives["WizardImageFile"] = "compiler:WizClassicImage.bmp";
  165. setupDirectives["SetupIconFile"] = "compiler:SetupClassicIcon.ico";
  166. }
  167. if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_ICON_FILE")) {
  168. setupDirectives["SetupIconFile"] =
  169. cmSystemTools::ConvertToWindowsOutputPath(*v);
  170. }
  171. if (cmValue v = GetOptionIfSet("CPACK_PACKAGE_ICON")) {
  172. setupDirectives["WizardSmallImageFile"] =
  173. cmSystemTools::ConvertToWindowsOutputPath(*v);
  174. }
  175. if (!RequireOption("CPACK_PACKAGE_INSTALL_DIRECTORY")) {
  176. return false;
  177. }
  178. SetOptionIfNotSet("CPACK_INNOSETUP_INSTALL_ROOT", "{autopf}");
  179. setupDirectives["DefaultDirName"] =
  180. cmSystemTools::ConvertToWindowsOutputPath(
  181. cmStrCat(GetOption("CPACK_INNOSETUP_INSTALL_ROOT"), '\\',
  182. GetOption("CPACK_PACKAGE_INSTALL_DIRECTORY")));
  183. SetOptionIfNotSet("CPACK_INNOSETUP_ALLOW_CUSTOM_DIRECTORY", "ON");
  184. if (GetOption("CPACK_INNOSETUP_ALLOW_CUSTOM_DIRECTORY").IsOff()) {
  185. setupDirectives["DisableDirPage"] = "yes";
  186. }
  187. SetOptionIfNotSet("CPACK_INNOSETUP_PROGRAM_MENU_FOLDER",
  188. GetOption("CPACK_PACKAGE_NAME"));
  189. if (GetOption("CPACK_INNOSETUP_PROGRAM_MENU_FOLDER") == ".") {
  190. setupDirectives["DisableProgramGroupPage"] = "yes";
  191. toplevelProgramFolder = true;
  192. } else {
  193. setupDirectives["DefaultGroupName"] =
  194. GetOption("CPACK_INNOSETUP_PROGRAM_MENU_FOLDER");
  195. toplevelProgramFolder = false;
  196. }
  197. if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_PASSWORD")) {
  198. setupDirectives["Password"] = *v;
  199. setupDirectives["Encryption"] = "yes";
  200. }
  201. /*
  202. * These directives can only be modified using the
  203. * CPACK_INNOSETUP_SETUP_<directive> variables
  204. */
  205. setupDirectives["ShowLanguageDialog"] = "auto";
  206. setupDirectives["AllowNoIcons"] = "yes";
  207. setupDirectives["Compression"] = "lzma";
  208. setupDirectives["SolidCompression"] = "yes";
  209. // Output file and directory
  210. if (!RequireOption("CPACK_PACKAGE_FILE_NAME")) {
  211. return false;
  212. }
  213. setupDirectives["OutputBaseFilename"] = GetOption("CPACK_PACKAGE_FILE_NAME");
  214. if (!RequireOption("CPACK_TOPLEVEL_DIRECTORY")) {
  215. return false;
  216. }
  217. setupDirectives["OutputDir"] = cmSystemTools::ConvertToWindowsOutputPath(
  218. GetOption("CPACK_TOPLEVEL_DIRECTORY"));
  219. setupDirectives["SourceDir"] =
  220. cmSystemTools::ConvertToWindowsOutputPath(toplevel);
  221. // Target architecture
  222. if (!RequireOption("CPACK_INNOSETUP_ARCHITECTURE")) {
  223. return false;
  224. }
  225. cmValue const architecture = GetOption("CPACK_INNOSETUP_ARCHITECTURE");
  226. if (architecture != "x86" && architecture != "x64" &&
  227. architecture != "arm64" && architecture != "ia64") {
  228. cmCPackLogger(cmCPackLog::LOG_ERROR,
  229. "CPACK_INNOSETUP_ARCHITECTURE must be either x86, x64, "
  230. "arm64 or ia64"
  231. << std::endl);
  232. return false;
  233. }
  234. // The following directives must not be set to target x86
  235. if (architecture != "x86") {
  236. setupDirectives["ArchitecturesAllowed"] = architecture;
  237. setupDirectives["ArchitecturesInstallIn64BitMode"] = architecture;
  238. }
  239. /*
  240. * Handle custom directives (they have higher priority than other variables,
  241. * so they have to be processed after all other variables)
  242. */
  243. for (std::string const& i : GetOptions()) {
  244. if (cmHasPrefix(i, "CPACK_INNOSETUP_SETUP_")) {
  245. std::string const& directive =
  246. i.substr(cmStrLen("CPACK_INNOSETUP_SETUP_"));
  247. setupDirectives[directive] = GetOption(i);
  248. }
  249. }
  250. return true;
  251. }
  252. bool cmCPackInnoSetupGenerator::ProcessFiles()
  253. {
  254. std::map<std::string, std::string> customFileInstructions;
  255. if (cmValue v =
  256. GetOptionIfSet("CPACK_INNOSETUP_CUSTOM_INSTALL_INSTRUCTIONS")) {
  257. cmList const instructions(*v);
  258. if (instructions.size() % 2 != 0) {
  259. cmCPackLogger(cmCPackLog::LOG_ERROR,
  260. "CPACK_INNOSETUP_CUSTOM_INSTALL_INSTRUCTIONS should "
  261. "contain pairs of <path> and <instruction>"
  262. << std::endl);
  263. return false;
  264. }
  265. for (auto it = instructions.begin(); it != instructions.end(); ++it) {
  266. std::string const& key =
  267. QuotePath(cmSystemTools::CollapseFullPath(*it, toplevel));
  268. customFileInstructions[key] = *(++it);
  269. }
  270. }
  271. std::string const& iconsPrefix =
  272. toplevelProgramFolder ? "{autoprograms}\\" : "{group}\\";
  273. std::map<std::string, std::string> icons;
  274. if (cmValue v = GetOptionIfSet("CPACK_PACKAGE_EXECUTABLES")) {
  275. cmList const executables(*v);
  276. if (executables.size() % 2 != 0) {
  277. cmCPackLogger(cmCPackLog::LOG_ERROR,
  278. "CPACK_PACKAGE_EXECUTABLES should should contain pairs of "
  279. "<executable> and <text label>"
  280. << std::endl);
  281. return false;
  282. }
  283. for (auto it = executables.begin(); it != executables.end(); ++it) {
  284. std::string const& key = *it;
  285. icons[key] = *(++it);
  286. }
  287. }
  288. std::vector<std::string> desktopIcons;
  289. if (cmValue v = GetOptionIfSet("CPACK_CREATE_DESKTOP_LINKS")) {
  290. cmExpandList(*v, desktopIcons);
  291. }
  292. std::vector<std::string> runExecutables;
  293. if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_RUN_EXECUTABLES")) {
  294. cmExpandList(*v, runExecutables);
  295. }
  296. for (std::string const& i : files) {
  297. cmCPackInnoSetupKeyValuePairs params;
  298. std::string toplevelDirectory;
  299. std::string outputDir;
  300. cmCPackComponent* component = nullptr;
  301. std::string componentParam;
  302. if (!Components.empty()) {
  303. std::string const& fileName = cmSystemTools::RelativePath(toplevel, i);
  304. std::string::size_type const pos = fileName.find('/');
  305. // Use the custom component install directory if we have one
  306. if (pos != std::string::npos) {
  307. std::string const& componentName = fileName.substr(0, pos);
  308. component = &Components[componentName];
  309. toplevelDirectory =
  310. cmSystemTools::CollapseFullPath(componentName, toplevel);
  311. outputDir = CustomComponentInstallDirectory(component);
  312. componentParam =
  313. CreateRecursiveComponentPath(component->Group, component->Name);
  314. if (component->IsHidden && component->IsDisabledByDefault) {
  315. continue;
  316. }
  317. if (component->IsHidden) {
  318. componentParam.clear();
  319. }
  320. } else {
  321. // Don't install component directories
  322. continue;
  323. }
  324. } else {
  325. toplevelDirectory = toplevel;
  326. outputDir = "{app}";
  327. }
  328. if (!componentParam.empty()) {
  329. params["Components"] = componentParam;
  330. }
  331. if (cmSystemTools::FileIsDirectory(i)) {
  332. // Custom instructions replace the automatic generated instructions
  333. if (customFileInstructions.count(QuotePath(i))) {
  334. dirInstructions.push_back(customFileInstructions[QuotePath(i)]);
  335. } else {
  336. std::string destDir = cmSystemTools::ConvertToWindowsOutputPath(
  337. cmStrCat(outputDir, '\\',
  338. cmSystemTools::RelativePath(toplevelDirectory, i)));
  339. cmStripSuffixIfExists(destDir, '\\');
  340. params["Name"] = QuotePath(destDir);
  341. dirInstructions.push_back(ISKeyValueLine(params));
  342. }
  343. } else {
  344. // Custom instructions replace the automatic generated instructions
  345. if (customFileInstructions.count(QuotePath(i))) {
  346. fileInstructions.push_back(customFileInstructions[QuotePath(i)]);
  347. } else {
  348. std::string destDir = cmSystemTools::ConvertToWindowsOutputPath(
  349. cmStrCat(outputDir, '\\',
  350. cmSystemTools::GetParentDirectory(
  351. cmSystemTools::RelativePath(toplevelDirectory, i))));
  352. cmStripSuffixIfExists(destDir, '\\');
  353. params["DestDir"] = QuotePath(destDir);
  354. if (component && component->IsDownloaded) {
  355. std::string const& archiveName =
  356. cmSystemTools::GetFilenameWithoutLastExtension(
  357. component->ArchiveFile);
  358. std::string const& relativePath =
  359. cmSystemTools::RelativePath(toplevelDirectory, i);
  360. params["Source"] =
  361. QuotePath(cmStrCat("{tmp}\\", archiveName, '\\', relativePath));
  362. params["ExternalSize"] =
  363. std::to_string(cmSystemTools::FileLength(i));
  364. params["Flags"] = "external ignoreversion";
  365. params["BeforeInstall"] =
  366. cmStrCat("CPackExtractFile('", archiveName, "', '",
  367. cmRemoveQuotes(cmSystemTools::ConvertToWindowsOutputPath(
  368. relativePath)),
  369. "')");
  370. } else {
  371. params["Source"] = QuotePath(i);
  372. params["Flags"] = "ignoreversion";
  373. }
  374. fileInstructions.push_back(ISKeyValueLine(params));
  375. // Icon
  376. std::string const& name =
  377. cmSystemTools::GetFilenameWithoutLastExtension(i);
  378. std::string const& extension =
  379. cmSystemTools::GetFilenameLastExtension(i);
  380. if ((extension == ".exe" || extension == ".com") && // only .exe, .com
  381. icons.count(name)) {
  382. cmCPackInnoSetupKeyValuePairs iconParams;
  383. iconParams["Name"] = QuotePath(cmStrCat(iconsPrefix, icons[name]));
  384. iconParams["Filename"] =
  385. QuotePath(cmStrCat(destDir, '\\', name, extension));
  386. if (!componentParam.empty()) {
  387. iconParams["Components"] = componentParam;
  388. }
  389. iconInstructions.push_back(ISKeyValueLine(iconParams));
  390. // Desktop icon
  391. if (std::find(desktopIcons.begin(), desktopIcons.end(), name) !=
  392. desktopIcons.end()) {
  393. iconParams["Name"] =
  394. QuotePath(cmStrCat("{autodesktop}\\", icons[name]));
  395. iconParams["Tasks"] = "desktopicon";
  396. if (!componentParam.empty() &&
  397. std::find(desktopIconComponents.begin(),
  398. desktopIconComponents.end(),
  399. componentParam) == desktopIconComponents.end()) {
  400. desktopIconComponents.push_back(componentParam);
  401. }
  402. iconInstructions.push_back(ISKeyValueLine(iconParams));
  403. }
  404. // [Run] section
  405. if (std::find(runExecutables.begin(), runExecutables.end(), name) !=
  406. runExecutables.end()) {
  407. cmCPackInnoSetupKeyValuePairs runParams;
  408. runParams["Filename"] = iconParams["Filename"];
  409. runParams["Description"] = cmStrCat(
  410. "\"{cm:LaunchProgram,", PrepareForConstant(icons[name]), "}\"");
  411. runParams["Flags"] = "nowait postinstall skipifsilent";
  412. if (!componentParam.empty()) {
  413. runParams["Components"] = componentParam;
  414. }
  415. runInstructions.push_back(ISKeyValueLine(runParams));
  416. }
  417. }
  418. }
  419. }
  420. }
  421. // Additional icons
  422. static cmsys::RegularExpression urlRegex(
  423. "^(mailto:|(ftps?|https?|news)://).*$");
  424. if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_MENU_LINKS")) {
  425. cmList const menuIcons(*v);
  426. if (menuIcons.size() % 2 != 0) {
  427. cmCPackLogger(cmCPackLog::LOG_ERROR,
  428. "CPACK_INNOSETUP_MENU_LINKS should "
  429. "contain pairs of <shortcut target> and <shortcut label>"
  430. << std::endl);
  431. return false;
  432. }
  433. for (auto it = menuIcons.begin(); it != menuIcons.end(); ++it) {
  434. std::string const& target = *it;
  435. std::string const& label = *(++it);
  436. cmCPackInnoSetupKeyValuePairs params;
  437. params["Name"] = QuotePath(cmStrCat(iconsPrefix, label));
  438. if (urlRegex.find(target)) {
  439. params["Filename"] = Quote(target);
  440. } else {
  441. std::string dir = "{app}";
  442. std::string componentName;
  443. for (auto const& i : Components) {
  444. if (cmSystemTools::FileExists(cmSystemTools::CollapseFullPath(
  445. cmStrCat(i.second.Name, '\\', target), toplevel))) {
  446. dir = CustomComponentInstallDirectory(&i.second);
  447. componentName =
  448. CreateRecursiveComponentPath(i.second.Group, i.second.Name);
  449. if (i.second.IsHidden && i.second.IsDisabledByDefault) {
  450. goto continueOuterLoop;
  451. } else if (i.second.IsHidden) {
  452. componentName.clear();
  453. }
  454. break;
  455. }
  456. }
  457. params["Filename"] = QuotePath(cmStrCat(dir, '\\', target));
  458. if (!componentName.empty()) {
  459. params["Components"] = componentName;
  460. }
  461. }
  462. iconInstructions.push_back(ISKeyValueLine(params));
  463. continueOuterLoop:;
  464. }
  465. }
  466. SetOptionIfNotSet("CPACK_INNOSETUP_CREATE_UNINSTALL_LINK", "OFF");
  467. if (GetOption("CPACK_INNOSETUP_CREATE_UNINSTALL_LINK").IsOn()) {
  468. cmCPackInnoSetupKeyValuePairs params;
  469. params["Name"] = QuotePath(
  470. cmStrCat(iconsPrefix, "{cm:UninstallProgram,",
  471. PrepareForConstant(GetOption("CPACK_PACKAGE_NAME")), '}'));
  472. params["Filename"] = "\"{uninstallexe}\"";
  473. iconInstructions.push_back(ISKeyValueLine(params));
  474. }
  475. return true;
  476. }
  477. bool cmCPackInnoSetupGenerator::ProcessComponents()
  478. {
  479. codeIncludes.emplace_back(
  480. "{ The following lines are required by CPack because "
  481. "this script uses components }");
  482. // Installation types
  483. std::vector<cmCPackInstallationType*> types(InstallationTypes.size());
  484. for (auto& i : InstallationTypes) {
  485. types[i.second.Index - 1] = &i.second;
  486. }
  487. std::vector<std::string> allTypes; // For required components
  488. for (cmCPackInstallationType* i : types) {
  489. cmCPackInnoSetupKeyValuePairs params;
  490. params["Name"] = Quote(i->Name);
  491. params["Description"] = Quote(i->DisplayName);
  492. allTypes.push_back(i->Name);
  493. typeInstructions.push_back(ISKeyValueLine(params));
  494. }
  495. // Inno Setup requires the additional "custom" type
  496. cmCPackInnoSetupKeyValuePairs customTypeParams;
  497. customTypeParams["Name"] = "\"custom\"";
  498. customTypeParams["Description"] =
  499. "\"{code:CPackGetCustomInstallationMessage}\"";
  500. customTypeParams["Flags"] = "iscustom";
  501. allTypes.emplace_back("custom");
  502. typeInstructions.push_back(ISKeyValueLine(customTypeParams));
  503. // Components
  504. std::vector<cmCPackComponent*> downloadedComponents;
  505. for (auto& i : Components) {
  506. cmCPackInnoSetupKeyValuePairs params;
  507. cmCPackComponent* component = &i.second;
  508. if (component->IsHidden) {
  509. continue;
  510. }
  511. CreateRecursiveComponentGroups(component->Group);
  512. params["Name"] =
  513. Quote(CreateRecursiveComponentPath(component->Group, component->Name));
  514. params["Description"] = Quote(component->DisplayName);
  515. if (component->IsRequired) {
  516. params["Types"] = cmJoin(allTypes, " ");
  517. params["Flags"] = "fixed";
  518. } else if (!component->InstallationTypes.empty()) {
  519. std::vector<std::string> installationTypes;
  520. installationTypes.reserve(component->InstallationTypes.size());
  521. for (cmCPackInstallationType* j : component->InstallationTypes) {
  522. installationTypes.push_back(j->Name);
  523. }
  524. params["Types"] = cmJoin(installationTypes, " ");
  525. }
  526. componentInstructions.push_back(ISKeyValueLine(params));
  527. if (component->IsDownloaded) {
  528. downloadedComponents.push_back(component);
  529. if (component->ArchiveFile.empty()) {
  530. // Compute the name of the archive.
  531. if (!RequireOption("CPACK_TEMPORARY_DIRECTORY")) {
  532. return false;
  533. }
  534. std::string packagesDir =
  535. cmStrCat(GetOption("CPACK_TEMPORARY_DIRECTORY"), ".dummy");
  536. component->ArchiveFile =
  537. cmStrCat(cmSystemTools::GetFilenameWithoutLastExtension(packagesDir),
  538. '-', component->Name, ".zip");
  539. } else if (!cmHasSuffix(component->ArchiveFile, ".zip")) {
  540. component->ArchiveFile = cmStrCat(component->ArchiveFile, ".zip");
  541. }
  542. }
  543. }
  544. // Downloaded components
  545. if (!downloadedComponents.empty()) {
  546. // Create the directory for the upload area
  547. cmValue userUploadDirectory = GetOption("CPACK_UPLOAD_DIRECTORY");
  548. std::string uploadDirectory;
  549. if (cmNonempty(userUploadDirectory)) {
  550. uploadDirectory = *userUploadDirectory;
  551. } else {
  552. if (!RequireOption("CPACK_PACKAGE_DIRECTORY")) {
  553. return false;
  554. }
  555. uploadDirectory =
  556. cmStrCat(GetOption("CPACK_PACKAGE_DIRECTORY"), "/CPackUploads");
  557. }
  558. if (!cmSystemTools::FileExists(uploadDirectory)) {
  559. if (!cmSystemTools::MakeDirectory(uploadDirectory)) {
  560. cmCPackLogger(cmCPackLog::LOG_ERROR,
  561. "Unable to create Inno Setup upload directory "
  562. << uploadDirectory << std::endl);
  563. return false;
  564. }
  565. }
  566. if (!RequireOption("CPACK_DOWNLOAD_SITE")) {
  567. return false;
  568. }
  569. SetOptionIfNotSet("CPACK_INNOSETUP_VERIFY_DOWNLOADS", "ON");
  570. bool const verifyDownloads =
  571. GetOption("CPACK_INNOSETUP_VERIFY_DOWNLOADS").IsOn();
  572. std::string const& urlPrefix =
  573. cmHasSuffix(GetOption("CPACK_DOWNLOAD_SITE").GetCStr(), '/')
  574. ? GetOption("CPACK_DOWNLOAD_SITE")
  575. : cmStrCat(GetOption("CPACK_DOWNLOAD_SITE"), '/');
  576. std::vector<std::string> archiveUrls;
  577. std::vector<std::string> archiveFiles;
  578. std::vector<std::string> archiveHashes;
  579. std::vector<std::string> archiveComponents;
  580. for (cmCPackComponent* i : downloadedComponents) {
  581. std::string hash;
  582. if (!BuildDownloadedComponentArchive(
  583. i, uploadDirectory, (verifyDownloads ? &hash : nullptr))) {
  584. return false;
  585. }
  586. archiveUrls.push_back(Quote(cmStrCat(urlPrefix, i->ArchiveFile)));
  587. archiveFiles.push_back(
  588. Quote(cmSystemTools::GetFilenameWithoutLastExtension(i->ArchiveFile)));
  589. archiveHashes.push_back(Quote(hash));
  590. archiveComponents.push_back(
  591. Quote(CreateRecursiveComponentPath(i->Group, i->Name)));
  592. }
  593. SetOption("CPACK_INNOSETUP_DOWNLOAD_COUNT_INTERNAL",
  594. std::to_string(archiveFiles.size()));
  595. SetOption("CPACK_INNOSETUP_DOWNLOAD_URLS_INTERNAL",
  596. cmJoin(archiveUrls, ", "));
  597. SetOption("CPACK_INNOSETUP_DOWNLOAD_ARCHIVES_INTERNAL",
  598. cmJoin(archiveFiles, ", "));
  599. SetOption("CPACK_INNOSETUP_DOWNLOAD_HASHES_INTERNAL",
  600. cmJoin(archiveHashes, ", "));
  601. SetOption("CPACK_INNOSETUP_DOWNLOAD_COMPONENTS_INTERNAL",
  602. cmJoin(archiveComponents, ", "));
  603. static std::string const& downloadLines =
  604. "#define protected CPackDownloadCount "
  605. "@CPACK_INNOSETUP_DOWNLOAD_COUNT_INTERNAL@\n"
  606. "#dim protected CPackDownloadUrls[CPackDownloadCount] "
  607. "{@CPACK_INNOSETUP_DOWNLOAD_URLS_INTERNAL@}\n"
  608. "#dim protected CPackDownloadArchives[CPackDownloadCount] "
  609. "{@CPACK_INNOSETUP_DOWNLOAD_ARCHIVES_INTERNAL@}\n"
  610. "#dim protected CPackDownloadHashes[CPackDownloadCount] "
  611. "{@CPACK_INNOSETUP_DOWNLOAD_HASHES_INTERNAL@}\n"
  612. "#dim protected CPackDownloadComponents[CPackDownloadCount] "
  613. "{@CPACK_INNOSETUP_DOWNLOAD_COMPONENTS_INTERNAL@}";
  614. std::string output;
  615. if (!ConfigureString(downloadLines, output)) {
  616. return false;
  617. }
  618. codeIncludes.push_back(output);
  619. }
  620. // Add the required script
  621. std::string const& componentsScriptTemplate =
  622. FindTemplate("ISComponents.pas");
  623. if (componentsScriptTemplate.empty()) {
  624. cmCPackLogger(cmCPackLog::LOG_ERROR,
  625. "Could not find additional Inno Setup script file."
  626. << std::endl);
  627. return false;
  628. }
  629. codeIncludes.push_back("#include " + QuotePath(componentsScriptTemplate) +
  630. "\n");
  631. return true;
  632. }
  633. bool cmCPackInnoSetupGenerator::ConfigureISScript()
  634. {
  635. std::string const& isScriptTemplate = FindTemplate("ISScript.template.in");
  636. std::string const& isScriptFile =
  637. cmStrCat(GetOption("CPACK_TOPLEVEL_DIRECTORY"), "/ISScript.iss");
  638. if (isScriptTemplate.empty()) {
  639. cmCPackLogger(cmCPackLog::LOG_ERROR,
  640. "Could not find Inno Setup installer template file."
  641. << std::endl);
  642. return false;
  643. }
  644. // Create internal variables
  645. std::vector<std::string> setupSection;
  646. for (auto const& i : setupDirectives) {
  647. setupSection.emplace_back(cmStrCat(i.first, '=', TranslateBool(i.second)));
  648. }
  649. // Also create comments if the sections are empty
  650. std::string const& defaultMessage =
  651. "; CPack didn't find any entries for this section";
  652. if (!IsSetToEmpty("CPACK_CREATE_DESKTOP_LINKS")) {
  653. cmCPackInnoSetupKeyValuePairs tasks;
  654. tasks["Name"] = "\"desktopicon\"";
  655. tasks["Description"] = "\"{cm:CreateDesktopIcon}\"";
  656. tasks["GroupDescription"] = "\"{cm:AdditionalIcons}\"";
  657. tasks["Flags"] = "unchecked";
  658. if (!desktopIconComponents.empty()) {
  659. tasks["Components"] = cmJoin(desktopIconComponents, " ");
  660. }
  661. SetOption("CPACK_INNOSETUP_TASKS_INTERNAL", ISKeyValueLine(tasks));
  662. } else {
  663. SetOption("CPACK_INNOSETUP_TASKS_INTERNAL", defaultMessage);
  664. }
  665. SetOption("CPACK_INNOSETUP_INCLUDES_INTERNAL",
  666. includeDirectives.empty() ? "; No extra script files specified"
  667. : cmJoin(includeDirectives, "\n"));
  668. SetOption("CPACK_INNOSETUP_SETUP_INTERNAL",
  669. setupSection.empty() ? defaultMessage
  670. : cmJoin(setupSection, "\n"));
  671. SetOption("CPACK_INNOSETUP_LANGUAGES_INTERNAL",
  672. languageInstructions.empty() ? defaultMessage
  673. : cmJoin(languageInstructions, "\n"));
  674. SetOption("CPACK_INNOSETUP_DIRS_INTERNAL",
  675. dirInstructions.empty() ? defaultMessage
  676. : cmJoin(dirInstructions, "\n"));
  677. SetOption("CPACK_INNOSETUP_FILES_INTERNAL",
  678. fileInstructions.empty() ? defaultMessage
  679. : cmJoin(fileInstructions, "\n"));
  680. SetOption("CPACK_INNOSETUP_TYPES_INTERNAL",
  681. typeInstructions.empty() ? defaultMessage
  682. : cmJoin(typeInstructions, "\n"));
  683. SetOption("CPACK_INNOSETUP_COMPONENTS_INTERNAL",
  684. componentInstructions.empty()
  685. ? defaultMessage
  686. : cmJoin(componentInstructions, "\n"));
  687. SetOption("CPACK_INNOSETUP_ICONS_INTERNAL",
  688. iconInstructions.empty() ? defaultMessage
  689. : cmJoin(iconInstructions, "\n"));
  690. SetOption("CPACK_INNOSETUP_RUN_INTERNAL",
  691. runInstructions.empty() ? defaultMessage
  692. : cmJoin(runInstructions, "\n"));
  693. SetOption("CPACK_INNOSETUP_CODE_INTERNAL",
  694. codeIncludes.empty() ? "{ No extra code files specified }"
  695. : cmJoin(codeIncludes, "\n"));
  696. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  697. "Configure file: " << isScriptTemplate << " to "
  698. << isScriptFile << std::endl);
  699. return ConfigureFile(isScriptTemplate, isScriptFile);
  700. }
  701. bool cmCPackInnoSetupGenerator::Compile()
  702. {
  703. std::string const& isScriptFile =
  704. cmStrCat(GetOption("CPACK_TOPLEVEL_DIRECTORY"), "/ISScript.iss");
  705. std::string const& isccLogFile =
  706. cmStrCat(GetOption("CPACK_TOPLEVEL_DIRECTORY"), "/ISCCOutput.log");
  707. std::vector<std::string> isccArgs;
  708. // Custom defines
  709. for (std::string const& i : GetOptions()) {
  710. if (cmHasPrefix(i, "CPACK_INNOSETUP_DEFINE_")) {
  711. std::string const& name = i.substr(cmStrLen("CPACK_INNOSETUP_DEFINE_"));
  712. isccArgs.push_back(
  713. cmStrCat("\"/D", name, '=', TranslateBool(GetOption(i)), '"'));
  714. }
  715. }
  716. if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_EXECUTABLE_ARGUMENTS")) {
  717. cmList const args(*v);
  718. isccArgs.insert(isccArgs.end(), args.begin(), args.end());
  719. }
  720. std::string const& isccCmd =
  721. cmStrCat(QuotePath(GetOption("CPACK_INSTALLER_PROGRAM"), PathType::Native),
  722. ' ', cmJoin(isccArgs, " "), ' ', QuotePath(isScriptFile));
  723. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << isccCmd << std::endl);
  724. std::string output;
  725. int retVal = 1;
  726. bool const res = cmSystemTools::RunSingleCommand(
  727. isccCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose,
  728. cmDuration::zero());
  729. if (!res || retVal) {
  730. cmGeneratedFileStream ofs(isccLogFile);
  731. ofs << "# Run command: " << isccCmd << std::endl
  732. << "# Output:" << std::endl
  733. << output << std::endl;
  734. cmCPackLogger(cmCPackLog::LOG_ERROR,
  735. "Problem running ISCC. Please check "
  736. << isccLogFile << " for errors." << std::endl);
  737. return false;
  738. }
  739. return true;
  740. }
  741. bool cmCPackInnoSetupGenerator::BuildDownloadedComponentArchive(
  742. cmCPackComponent* component, std::string const& uploadDirectory,
  743. std::string* hash)
  744. {
  745. // Remove the old archive, if one exists
  746. std::string const& archiveFile =
  747. uploadDirectory + '/' + component->ArchiveFile;
  748. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  749. "- Building downloaded component archive: " << archiveFile
  750. << std::endl);
  751. if (cmSystemTools::FileExists(archiveFile, true)) {
  752. if (!cmSystemTools::RemoveFile(archiveFile)) {
  753. cmCPackLogger(cmCPackLog::LOG_ERROR,
  754. "Unable to remove archive file " << archiveFile
  755. << std::endl);
  756. return false;
  757. }
  758. }
  759. // Find a ZIP program
  760. if (!IsSet("ZIP_EXECUTABLE")) {
  761. ReadListFile("Internal/CPack/CPackZIP.cmake");
  762. if (!IsSet("ZIP_EXECUTABLE")) {
  763. cmCPackLogger(cmCPackLog::LOG_ERROR,
  764. "Unable to find ZIP program" << std::endl);
  765. return false;
  766. }
  767. }
  768. if (!RequireOption("CPACK_TOPLEVEL_DIRECTORY") ||
  769. !RequireOption("CPACK_TEMPORARY_DIRECTORY") ||
  770. !RequireOption("CPACK_ZIP_NEED_QUOTES") ||
  771. !RequireOption("CPACK_ZIP_COMMAND")) {
  772. return false;
  773. }
  774. // The directory where this component's files reside
  775. std::string const& dirName =
  776. cmStrCat(GetOption("CPACK_TEMPORARY_DIRECTORY"), '/', component->Name);
  777. // Build the list of files to go into this archive
  778. std::string const& zipListFileName =
  779. cmStrCat(GetOption("CPACK_TEMPORARY_DIRECTORY"), "/winZip.filelist");
  780. bool const needQuotesInFile = GetOption("CPACK_ZIP_NEED_QUOTES").IsOn();
  781. { // the scope is needed for cmGeneratedFileStream
  782. cmGeneratedFileStream out(zipListFileName);
  783. for (std::string const& i : component->Files) {
  784. out << (needQuotesInFile ? Quote(i) : i) << std::endl;
  785. }
  786. }
  787. // Build the archive in the upload area
  788. std::string cmd = GetOption("CPACK_ZIP_COMMAND");
  789. cmsys::SystemTools::ReplaceString(cmd, "<ARCHIVE>", archiveFile.c_str());
  790. cmsys::SystemTools::ReplaceString(cmd, "<FILELIST>",
  791. zipListFileName.c_str());
  792. std::string output;
  793. int retVal = -1;
  794. bool const res = cmSystemTools::RunSingleCommand(
  795. cmd, &output, &output, &retVal, dirName.c_str(), this->GeneratorVerbose,
  796. cmDuration::zero());
  797. if (!res || retVal) {
  798. std::string tmpFile =
  799. cmStrCat(GetOption("CPACK_TOPLEVEL_DIRECTORY"), "/CompressZip.log");
  800. cmGeneratedFileStream ofs(tmpFile);
  801. ofs << "# Run command: " << cmd << std::endl
  802. << "# Output:" << std::endl
  803. << output << std::endl;
  804. cmCPackLogger(cmCPackLog::LOG_ERROR,
  805. "Problem running zip command: " << cmd << std::endl
  806. << "Please check " << tmpFile
  807. << " for errors"
  808. << std::endl);
  809. return false;
  810. }
  811. // Try to get the SHA256 hash of the archive file
  812. if (!hash) {
  813. return true;
  814. }
  815. #ifdef _WIN32
  816. std::string const& hashCmd =
  817. cmStrCat("certutil -hashfile ", QuotePath(archiveFile), " SHA256");
  818. std::string hashOutput;
  819. int hashRetVal = -1;
  820. bool const hashRes = cmSystemTools::RunSingleCommand(
  821. hashCmd, &hashOutput, &hashOutput, &hashRetVal, nullptr,
  822. this->GeneratorVerbose, cmDuration::zero());
  823. if (!hashRes || hashRetVal) {
  824. cmCPackLogger(cmCPackLog::LOG_WARNING,
  825. "Problem running certutil command: " << hashCmd
  826. << std::endl);
  827. }
  828. *hash = cmTrimWhitespace(cmTokenizedView(hashOutput, '\n').at(1));
  829. if (hash->length() != 64) {
  830. cmCPackLogger(cmCPackLog::LOG_WARNING,
  831. "Problem parsing certutil output of command: " << hashCmd
  832. << std::endl);
  833. hash->clear();
  834. }
  835. #endif
  836. return true;
  837. }
  838. cmValue cmCPackInnoSetupGenerator::RequireOption(std::string const& key)
  839. {
  840. cmValue value = GetOption(key);
  841. if (!value) {
  842. cmCPackLogger(cmCPackLog::LOG_ERROR,
  843. "Required variable " << key << " not set" << std::endl);
  844. }
  845. return value;
  846. }
  847. std::string cmCPackInnoSetupGenerator::CustomComponentInstallDirectory(
  848. cmCPackComponent const* component)
  849. {
  850. cmValue outputDir = GetOption(
  851. cmStrCat("CPACK_INNOSETUP_", component->Name, "_INSTALL_DIRECTORY"));
  852. if (outputDir) {
  853. std::string destDir = cmSystemTools::ConvertToWindowsOutputPath(outputDir);
  854. cmStripSuffixIfExists(destDir, '\\');
  855. /*
  856. * Add a dir instruction for the custom directory
  857. * (only once and not for Inno Setup constants ending with '}')
  858. */
  859. static std::vector<std::string> customDirectories;
  860. if (!cmHasSuffix(destDir, '}') &&
  861. std::find(customDirectories.begin(), customDirectories.end(),
  862. component->Name) == customDirectories.end()) {
  863. cmCPackInnoSetupKeyValuePairs params;
  864. params["Name"] = QuotePath(destDir);
  865. params["Components"] =
  866. CreateRecursiveComponentPath(component->Group, component->Name);
  867. dirInstructions.push_back(ISKeyValueLine(params));
  868. customDirectories.push_back(component->Name);
  869. }
  870. return destDir;
  871. }
  872. return "{app}";
  873. }
  874. std::string cmCPackInnoSetupGenerator::TranslateBool(std::string const& value)
  875. {
  876. if (value.empty()) {
  877. return value;
  878. }
  879. SetOptionIfNotSet("CPACK_INNOSETUP_USE_CMAKE_BOOL_FORMAT", "ON");
  880. if (GetOption("CPACK_INNOSETUP_USE_CMAKE_BOOL_FORMAT").IsOn()) {
  881. if (cmIsOn(value)) {
  882. return "yes";
  883. }
  884. if (cmIsOff(value)) {
  885. return "no";
  886. }
  887. }
  888. return value;
  889. }
  890. std::string cmCPackInnoSetupGenerator::ISKeyValueLine(
  891. cmCPackInnoSetupKeyValuePairs const& params)
  892. {
  893. /*
  894. * To simplify readability of the generated code, the keys are sorted.
  895. * Unknown keys are ignored to avoid errors during compilation.
  896. */
  897. static char const* const availableKeys[] = {
  898. "Source", "DestDir", "Name", "Filename",
  899. "Description", "GroupDescription", "MessagesFile", "Types",
  900. "ExternalSize", "BeforeInstall", "Flags", "Components",
  901. "Tasks"
  902. };
  903. std::vector<std::string> keys;
  904. for (char const* i : availableKeys) {
  905. if (params.count(i)) {
  906. keys.emplace_back(cmStrCat(i, ": ", params.at(i)));
  907. }
  908. }
  909. return cmJoin(keys, "; ");
  910. }
  911. std::string cmCPackInnoSetupGenerator::CreateRecursiveComponentPath(
  912. cmCPackComponentGroup* group, std::string const& path)
  913. {
  914. if (!group) {
  915. return path;
  916. }
  917. std::string const& newPath =
  918. path.empty() ? group->Name : cmStrCat(group->Name, '\\', path);
  919. return CreateRecursiveComponentPath(group->ParentGroup, newPath);
  920. }
  921. void cmCPackInnoSetupGenerator::CreateRecursiveComponentGroups(
  922. cmCPackComponentGroup* group)
  923. {
  924. if (!group) {
  925. return;
  926. }
  927. CreateRecursiveComponentGroups(group->ParentGroup);
  928. static std::vector<cmCPackComponentGroup*> processedGroups;
  929. if (std::find(processedGroups.begin(), processedGroups.end(), group) ==
  930. processedGroups.end()) {
  931. processedGroups.push_back(group);
  932. cmCPackInnoSetupKeyValuePairs params;
  933. params["Name"] = Quote(CreateRecursiveComponentPath(group));
  934. params["Description"] = Quote(group->DisplayName);
  935. componentInstructions.push_back(ISKeyValueLine(params));
  936. }
  937. }
  938. std::string cmCPackInnoSetupGenerator::Quote(std::string const& string)
  939. {
  940. if (cmHasPrefix(string, '"') && cmHasSuffix(string, '"')) {
  941. return Quote(string.substr(1, string.length() - 2));
  942. }
  943. // Double quote syntax
  944. std::string nString = string;
  945. cmSystemTools::ReplaceString(nString, "\"", "\"\"");
  946. return cmStrCat('"', nString, '"');
  947. }
  948. std::string cmCPackInnoSetupGenerator::QuotePath(std::string const& path,
  949. PathType type)
  950. {
  951. #ifdef _WIN32
  952. static_cast<void>(type);
  953. #else
  954. if (type == PathType::Native) {
  955. return Quote(cmSystemTools::ConvertToUnixOutputPath(path));
  956. }
  957. #endif
  958. return Quote(cmSystemTools::ConvertToWindowsOutputPath(path));
  959. }
  960. std::string cmCPackInnoSetupGenerator::PrepareForConstant(
  961. std::string const& string)
  962. {
  963. std::string nString = string;
  964. cmSystemTools::ReplaceString(nString, "%", "%25"); // First replacement!
  965. cmSystemTools::ReplaceString(nString, "\"", "%22");
  966. cmSystemTools::ReplaceString(nString, ",", "%2c");
  967. cmSystemTools::ReplaceString(nString, "|", "%7c");
  968. cmSystemTools::ReplaceString(nString, "}", "%7d");
  969. return nString;
  970. }