cmCPackIFWInstaller.cxx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCPackIFWInstaller.h"
  11. #include "cmCPackIFWGenerator.h"
  12. #include <CPack/cmCPackLog.h>
  13. #include <cmGeneratedFileStream.h>
  14. #include <cmXMLWriter.h>
  15. #ifdef cmCPackLogger
  16. # undef cmCPackLogger
  17. #endif
  18. #define cmCPackLogger(logType, msg) \
  19. do { \
  20. std::ostringstream cmCPackLog_msg; \
  21. cmCPackLog_msg << msg; \
  22. if(Generator) { \
  23. Generator->Logger->Log(logType, __FILE__, __LINE__, \
  24. cmCPackLog_msg.str().c_str()); \
  25. } \
  26. } while ( 0 )
  27. //----------------------------------------------------------------------------
  28. cmCPackIFWInstaller::cmCPackIFWInstaller() :
  29. Generator(0)
  30. {
  31. }
  32. //----------------------------------------------------------------------------
  33. const char *cmCPackIFWInstaller::GetOption(const std::string &op) const
  34. {
  35. return Generator ? Generator->GetOption(op) : 0;
  36. }
  37. //----------------------------------------------------------------------------
  38. bool cmCPackIFWInstaller::IsOn(const std::string &op) const
  39. {
  40. return Generator ? Generator->IsOn(op) : false;
  41. }
  42. //----------------------------------------------------------------------------
  43. bool cmCPackIFWInstaller::IsVersionLess(const char *version)
  44. {
  45. return Generator ? Generator->IsVersionLess(version) : false;
  46. }
  47. //----------------------------------------------------------------------------
  48. bool cmCPackIFWInstaller::IsVersionGreater(const char *version)
  49. {
  50. return Generator ? Generator->IsVersionGreater(version) : false;
  51. }
  52. //----------------------------------------------------------------------------
  53. bool cmCPackIFWInstaller::IsVersionEqual(const char *version)
  54. {
  55. return Generator ? Generator->IsVersionEqual(version) : false;
  56. }
  57. //----------------------------------------------------------------------------
  58. void cmCPackIFWInstaller::ConfigureFromOptions()
  59. {
  60. // Name;
  61. if (const char* optIFW_PACKAGE_NAME =
  62. this->GetOption("CPACK_IFW_PACKAGE_NAME"))
  63. {
  64. Name = optIFW_PACKAGE_NAME;
  65. }
  66. else if (const char* optPACKAGE_NAME =
  67. this->GetOption("CPACK_PACKAGE_NAME"))
  68. {
  69. Name = optPACKAGE_NAME;
  70. }
  71. else
  72. {
  73. Name = "Your package";
  74. }
  75. // Title;
  76. if (const char* optIFW_PACKAGE_TITLE =
  77. GetOption("CPACK_IFW_PACKAGE_TITLE"))
  78. {
  79. Title = optIFW_PACKAGE_TITLE;
  80. }
  81. else if (const char* optPACKAGE_DESCRIPTION_SUMMARY =
  82. GetOption("CPACK_PACKAGE_DESCRIPTION_SUMMARY"))
  83. {
  84. Title = optPACKAGE_DESCRIPTION_SUMMARY;
  85. }
  86. else
  87. {
  88. Title = "Your package description";
  89. }
  90. // Version;
  91. if (const char* option = GetOption("CPACK_PACKAGE_VERSION"))
  92. {
  93. Version = option;
  94. }
  95. else
  96. {
  97. Version = "1.0.0";
  98. }
  99. // Publisher
  100. if(const char* optIFW_PACKAGE_PUBLISHER =
  101. GetOption("CPACK_IFW_PACKAGE_PUBLISHER"))
  102. {
  103. Publisher = optIFW_PACKAGE_PUBLISHER;
  104. }
  105. else if(const char* optPACKAGE_VENDOR = GetOption("CPACK_PACKAGE_VENDOR"))
  106. {
  107. Publisher = optPACKAGE_VENDOR;
  108. }
  109. // ProductUrl
  110. if(const char* option = GetOption("CPACK_IFW_PRODUCT_URL"))
  111. {
  112. ProductUrl = option;
  113. }
  114. // ApplicationIcon
  115. if(const char* option = GetOption("CPACK_IFW_PACKAGE_ICON"))
  116. {
  117. if(cmSystemTools::FileExists(option))
  118. {
  119. InstallerApplicationIcon = option;
  120. }
  121. else
  122. {
  123. // TODO: implement warning
  124. }
  125. }
  126. // WindowIcon
  127. if(const char* option = GetOption("CPACK_IFW_PACKAGE_WINDOW_ICON"))
  128. {
  129. if(cmSystemTools::FileExists(option))
  130. {
  131. InstallerWindowIcon = option;
  132. }
  133. else
  134. {
  135. // TODO: implement warning
  136. }
  137. }
  138. // Logo
  139. if(const char* option = GetOption("CPACK_IFW_PACKAGE_LOGO"))
  140. {
  141. if(cmSystemTools::FileExists(option))
  142. {
  143. Logo = option;
  144. }
  145. else
  146. {
  147. // TODO: implement warning
  148. }
  149. }
  150. // Start menu
  151. if (const char* optIFW_START_MENU_DIR =
  152. this->GetOption("CPACK_IFW_PACKAGE_START_MENU_DIRECTORY"))
  153. {
  154. StartMenuDir = optIFW_START_MENU_DIR;
  155. }
  156. else
  157. {
  158. StartMenuDir = Name;
  159. }
  160. // Default target directory for installation
  161. if (const char* optIFW_TARGET_DIRECTORY =
  162. GetOption("CPACK_IFW_TARGET_DIRECTORY"))
  163. {
  164. TargetDir = optIFW_TARGET_DIRECTORY;
  165. }
  166. else if (const char *optPACKAGE_INSTALL_DIRECTORY =
  167. GetOption("CPACK_PACKAGE_INSTALL_DIRECTORY"))
  168. {
  169. TargetDir = "@ApplicationsDir@/";
  170. TargetDir += optPACKAGE_INSTALL_DIRECTORY;
  171. }
  172. else
  173. {
  174. TargetDir = "@RootDir@/usr/local";
  175. }
  176. // Default target directory for installation with administrator rights
  177. if (const char* option = GetOption("CPACK_IFW_ADMIN_TARGET_DIRECTORY"))
  178. {
  179. AdminTargetDir = option;
  180. }
  181. // Repositories
  182. Repositories.clear();
  183. RepositoryStruct Repo;
  184. if(const char *site = this->GetOption("CPACK_DOWNLOAD_SITE"))
  185. {
  186. Repo.Url = site;
  187. Repositories.push_back(Repo);
  188. }
  189. if(const char *RepoAllStr = this->GetOption("CPACK_IFW_REPOSITORIES_ALL"))
  190. {
  191. std::vector<std::string> RepoAllVector;
  192. cmSystemTools::ExpandListArgument(RepoAllStr,
  193. RepoAllVector);
  194. for(std::vector<std::string>::iterator
  195. rit = RepoAllVector.begin(); rit != RepoAllVector.end(); ++rit)
  196. {
  197. std::string prefix = "CPACK_IFW_REPOSITORY_"
  198. + cmsys::SystemTools::UpperCase(*rit)
  199. + "_";
  200. // Url
  201. if (const char* url = GetOption(prefix + "URL"))
  202. {
  203. Repo.Url = url;
  204. }
  205. else
  206. {
  207. Repo.Url = "";
  208. }
  209. // Enabled
  210. if (IsOn(prefix + "DISABLED"))
  211. {
  212. Repo.Enabled = "0";
  213. }
  214. else
  215. {
  216. Repo.Enabled = "";
  217. }
  218. // Username
  219. if (const char* username = GetOption(prefix + "USERNAME"))
  220. {
  221. Repo.Username = username;
  222. }
  223. else
  224. {
  225. Repo.Username = "";
  226. }
  227. // Password
  228. if (const char* password = GetOption(prefix + "PASSWORD"))
  229. {
  230. Repo.Password = password;
  231. }
  232. else
  233. {
  234. Repo.Password = "";
  235. }
  236. // DisplayName
  237. if (const char* displayName = GetOption(prefix + "DISPLAY_NAME"))
  238. {
  239. Repo.DisplayName = displayName;
  240. }
  241. else
  242. {
  243. Repo.DisplayName = "";
  244. }
  245. if(!Repo.Url.empty())
  246. {
  247. Repositories.push_back(Repo);
  248. }
  249. }
  250. }
  251. // Maintenance tool
  252. if(const char* optIFW_MAINTENANCE_TOOL =
  253. this->GetOption("CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_NAME"))
  254. {
  255. MaintenanceToolName = optIFW_MAINTENANCE_TOOL;
  256. }
  257. // Maintenance tool ini file
  258. if(const char* optIFW_MAINTENANCE_TOOL_INI =
  259. this->GetOption("CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_INI_FILE"))
  260. {
  261. MaintenanceToolIniFile = optIFW_MAINTENANCE_TOOL_INI;
  262. }
  263. // Allow non-ASCII characters
  264. if(this->GetOption("CPACK_IFW_PACKAGE_ALLOW_NON_ASCII_CHARACTERS"))
  265. {
  266. if(IsOn("CPACK_IFW_PACKAGE_ALLOW_NON_ASCII_CHARACTERS"))
  267. {
  268. AllowNonAsciiCharacters = "true";
  269. }
  270. else
  271. {
  272. AllowNonAsciiCharacters = "false";
  273. }
  274. }
  275. // Space in path
  276. if(this->GetOption("CPACK_IFW_PACKAGE_ALLOW_SPACE_IN_PATH"))
  277. {
  278. if(IsOn("CPACK_IFW_PACKAGE_ALLOW_SPACE_IN_PATH"))
  279. {
  280. AllowSpaceInPath = "true";
  281. }
  282. else
  283. {
  284. AllowSpaceInPath = "false";
  285. }
  286. }
  287. // Control script
  288. if(const char* optIFW_CONTROL_SCRIPT =
  289. this->GetOption("CPACK_IFW_PACKAGE_CONTROL_SCRIPT"))
  290. {
  291. ControlScript = optIFW_CONTROL_SCRIPT;
  292. }
  293. }
  294. //----------------------------------------------------------------------------
  295. void cmCPackIFWInstaller::GenerateInstallerFile()
  296. {
  297. // Lazy directory initialization
  298. if(Directory.empty() && Generator)
  299. {
  300. Directory = Generator->toplevel;
  301. }
  302. // Output stream
  303. cmGeneratedFileStream fout((Directory + "/config/config.xml").data());
  304. cmXMLWriter xout(fout);
  305. xout.StartDocument();
  306. WriteGeneratedByToStrim(xout);
  307. xout.StartElement("Installer");
  308. xout.Element("Name", Name);
  309. xout.Element("Version", Version);
  310. xout.Element("Title", Title);
  311. if(!Publisher.empty())
  312. {
  313. xout.Element("Publisher", Publisher);
  314. }
  315. if(!ProductUrl.empty())
  316. {
  317. xout.Element("ProductUrl", ProductUrl);
  318. }
  319. // ApplicationIcon
  320. if(!InstallerApplicationIcon.empty())
  321. {
  322. std::string name =
  323. cmSystemTools::GetFilenameName(InstallerApplicationIcon);
  324. std::string path = Directory + "/config/" + name;
  325. name = cmSystemTools::GetFilenameWithoutExtension(name);
  326. cmsys::SystemTools::CopyFileIfDifferent(
  327. InstallerApplicationIcon.data(), path.data());
  328. xout.Element("InstallerApplicationIcon", name);
  329. }
  330. // WindowIcon
  331. if(!InstallerWindowIcon.empty())
  332. {
  333. std::string name = cmSystemTools::GetFilenameName(InstallerWindowIcon);
  334. std::string path = Directory + "/config/" + name;
  335. cmsys::SystemTools::CopyFileIfDifferent(
  336. InstallerWindowIcon.data(), path.data());
  337. xout.Element("InstallerWindowIcon", name);
  338. }
  339. // Logo
  340. if(!Logo.empty())
  341. {
  342. std::string name = cmSystemTools::GetFilenameName(Logo);
  343. std::string path = Directory + "/config/" + name;
  344. cmsys::SystemTools::CopyFileIfDifferent(Logo.data(), path.data());
  345. xout.Element("Logo", name);
  346. }
  347. // Start menu
  348. if(!IsVersionLess("2.0"))
  349. {
  350. xout.Element("StartMenuDir", StartMenuDir);
  351. }
  352. // Target dir
  353. if(!TargetDir.empty())
  354. {
  355. xout.Element("TargetDir", TargetDir);
  356. }
  357. // Admin target dir
  358. if(!AdminTargetDir.empty())
  359. {
  360. xout.Element("AdminTargetDir", AdminTargetDir);
  361. }
  362. // Remote repositories
  363. if (!Repositories.empty())
  364. {
  365. xout.StartElement("RemoteRepositories");
  366. for(std::vector<RepositoryStruct>::iterator
  367. rit = Repositories.begin(); rit != Repositories.end(); ++rit)
  368. {
  369. xout.StartElement("Repository");
  370. // Url
  371. xout.Element("Url", rit->Url);
  372. // Enabled
  373. if(!rit->Enabled.empty())
  374. {
  375. xout.Element("Enabled", rit->Enabled);
  376. }
  377. // Username
  378. if(!rit->Username.empty())
  379. {
  380. xout.Element("Username", rit->Username);
  381. }
  382. // Password
  383. if(!rit->Password.empty())
  384. {
  385. xout.Element("Password", rit->Password);
  386. }
  387. // DisplayName
  388. if(!rit->DisplayName.empty())
  389. {
  390. xout.Element("DisplayName", rit->DisplayName);
  391. }
  392. xout.EndElement();
  393. }
  394. xout.EndElement();
  395. }
  396. // Maintenance tool
  397. if(!IsVersionLess("2.0") && !MaintenanceToolName.empty())
  398. {
  399. xout.Element("MaintenanceToolName", MaintenanceToolName);
  400. }
  401. // Maintenance tool ini file
  402. if(!IsVersionLess("2.0") && !MaintenanceToolIniFile.empty())
  403. {
  404. xout.Element("MaintenanceToolIniFile", MaintenanceToolIniFile);
  405. }
  406. // Different allows
  407. if(IsVersionLess("2.0"))
  408. {
  409. // CPack IFW default policy
  410. xout.Comment("CPack IFW default policy for QtIFW less 2.0");
  411. xout.Element("AllowNonAsciiCharacters", "true");
  412. xout.Element("AllowSpaceInPath", "true");
  413. }
  414. else
  415. {
  416. if(!AllowNonAsciiCharacters.empty())
  417. {
  418. xout.Element("AllowNonAsciiCharacters", AllowNonAsciiCharacters);
  419. }
  420. if(!AllowSpaceInPath.empty())
  421. {
  422. xout.Element("AllowSpaceInPath", AllowSpaceInPath);
  423. }
  424. }
  425. // Control script (copy to config dir)
  426. if(!IsVersionLess("2.0") && !ControlScript.empty())
  427. {
  428. std::string name = cmSystemTools::GetFilenameName(ControlScript);
  429. std::string path = Directory + "/config/" + name;
  430. cmsys::SystemTools::CopyFileIfDifferent(ControlScript.data(), path.data());
  431. xout.Element("ControlScript", name);
  432. }
  433. xout.EndElement();
  434. xout.EndDocument();
  435. }
  436. //----------------------------------------------------------------------------
  437. void cmCPackIFWInstaller::GeneratePackageFiles()
  438. {
  439. if (Packages.empty() || Generator->IsOnePackage())
  440. {
  441. // Generate default package
  442. cmCPackIFWPackage package;
  443. package.Generator = Generator;
  444. package.Installer = this;
  445. // Check package group
  446. if (const char* option = GetOption("CPACK_IFW_PACKAGE_GROUP"))
  447. {
  448. package.ConfigureFromGroup(option);
  449. package.ForcedInstallation = "true";
  450. }
  451. else
  452. {
  453. package.ConfigureFromOptions();
  454. }
  455. package.GeneratePackageFile();
  456. return;
  457. }
  458. // Generate packages meta information
  459. for(PackagesMap::iterator pit = Packages.begin();
  460. pit != Packages.end(); ++pit)
  461. {
  462. cmCPackIFWPackage* package = pit->second;
  463. package->GeneratePackageFile();
  464. }
  465. }
  466. void cmCPackIFWInstaller::WriteGeneratedByToStrim(cmXMLWriter &xout)
  467. {
  468. if(Generator) Generator->WriteGeneratedByToStrim(xout);
  469. }