summaryrefslogtreecommitdiffstats
path: root/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx
blob: 975dffb4f5a161aae6c6f5e84e702719d1bcf70a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
#include "cmWIXDirectoriesSourceWriter.h"

cmWIXDirectoriesSourceWriter::cmWIXDirectoriesSourceWriter(
  cmCPackLog* logger, std::string const& filename, GuidType componentGuidType)
  : cmWIXSourceWriter(logger, filename, componentGuidType)
{
}

void cmWIXDirectoriesSourceWriter::EmitStartMenuFolder(
  std::string const& startMenuFolder)
{
  BeginElement("Directory");
  AddAttribute("Id", "ProgramMenuFolder");

  BeginElement("Directory");
  AddAttribute("Id", "PROGRAM_MENU_FOLDER");
  AddAttribute("Name", startMenuFolder);
  EndElement("Directory");

  EndElement("Directory");
}

void cmWIXDirectoriesSourceWriter::EmitDesktopFolder()
{
  BeginElement("Directory");
  AddAttribute("Id", "DesktopFolder");
  AddAttribute("Name", "Desktop");
  EndElement("Directory");
}

void cmWIXDirectoriesSourceWriter::EmitStartupFolder()
{
  BeginElement("Directory");
  AddAttribute("Id", "StartupFolder");
  AddAttribute("Name", "Startup");
  EndElement("Directory");
}

size_t cmWIXDirectoriesSourceWriter::BeginInstallationPrefixDirectory(
  std::string const& programFilesFolderId,
  std::string const& installRootString)
{
  size_t offset = 1;
  if (!programFilesFolderId.empty()) {
    BeginElement("Directory");
    AddAttribute("Id", programFilesFolderId);
    offset = 0;
  }

  std::vector<std::string> installRoot;

  cmSystemTools::SplitPath(installRootString.c_str(), installRoot);

  if (!installRoot.empty() && installRoot.back().empty()) {
    installRoot.pop_back();
  }

  for (size_t i = 1; i < installRoot.size(); ++i) {
    BeginElement("Directory");

    if (i == installRoot.size() - 1) {
      AddAttribute("Id", "INSTALL_ROOT");
    } else {
      std::ostringstream tmp;
      tmp << "INSTALL_PREFIX_" << i;
      AddAttribute("Id", tmp.str());
    }

    AddAttribute("Name", installRoot[i]);
  }

  return installRoot.size() - offset;
}

void cmWIXDirectoriesSourceWriter::EndInstallationPrefixDirectory(size_t size)
{
  for (size_t i = 0; i < size; ++i) {
    EndElement("Directory");
  }
}