summaryrefslogtreecommitdiff
path: root/Source/exehead/components.c
blob: f7643e464efed714f0acb7a81435458b3c10764c (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * components.c
 * 
 * This file is a part of NSIS.
 * 
 * Copyright (C) 1999-2007 Nullsoft and Contributors
 * 
 * Licensed under the zlib/libpng license (the "License");
 * you may not use this file except in compliance with the License.
 * 
 * Licence details can be found in the file COPYING.
 * 
 * This software is provided 'as-is', without any express or implied
 * warranty.
 */

#include "../Platform.h"
#include "config.h"
#include "ui.h"
#include "fileform.h"

void NSISCALL SectionFlagsChanged(unsigned int index) {
  section *sections = g_sections;

  int flags = sections[index].flags;

  if (flags & SF_SECGRP) {
    unsigned int i = index + 1;
    unsigned int level = 0;

    for (; i < (unsigned int) num_sections; i++) {
      if (sections[i].flags & SF_SECGRP) {
        level++;
        continue;
      }

      if (sections[i].flags & SF_SECGRPEND) {
        if (level-- == 0) {
          break;
        }

        continue;
      }

      if ((sections[i].flags & SF_RO) == 0) {
        sections[i].flags &= ~SF_SELECTED;
        sections[i].flags |= (flags & SF_SELECTED);
      }
    }
  }
}

unsigned int NSISCALL _RefreshSectionGroups(unsigned int i, int not_first_call) {
  unsigned int selected = 0;
  unsigned int not_selected = 0;

  section *sections = g_sections;

  section *sec = &sections[i];

  if (sec->flags & SF_SECGRP) {
    if (not_first_call) {
      sec->flags &= ~(SF_SELECTED | SF_PSELECTED);
      i++;
    }
  }

  while (i < (unsigned int) num_sections) {
    int flags = sections[i].flags;
    int ni = i + 1;

    if (flags & SF_SECGRP) {
      ni = _RefreshSectionGroups(i, 1);
      flags = sections[i].flags;
    }

    if (flags & SF_SECGRPEND) {
      if (selected) {
        if (not_selected) {
          sec->flags |= SF_PSELECTED;
        } else {
          sec->flags |= SF_SELECTED;
          sec->flags &= ~SF_TOGGLED;
        }
      }

      return ni;
    }

    if (flags & SF_PSELECTED) {
      selected++;
    }

    if (flags & SF_SELECTED) {
      selected++;
    } else {
      not_selected++;
    }

    i = ni;
  }

  return 0;
}

#ifdef NSIS_CONFIG_COMPONENTPAGE

void NSISCALL SetInstType(int inst_type) {
  unsigned int i = 0;

  section *sections = g_sections;

  if ((unsigned int) inst_type >= NSIS_MAX_INST_TYPES) {
    return;
  }

  for (; i < (unsigned int) num_sections; i++) {
    if (sections[i].flags & (SF_SECGRP | SF_SECGRPEND)) {
      continue;
    }

    if (sections[i].install_types & (1 << inst_type)) {
      sections[i].flags |= SF_SELECTED;
    } else {
      sections[i].flags &= ~SF_SELECTED;
    }
  }
}

unsigned int NSISCALL GetInstType(HTREEITEM *items) {
  unsigned int i, j;

  section *sections = g_sections;

  for (i = 0; i < NSIS_MAX_INST_TYPES; i++) {
    if (!g_header->install_types[i]) {
      continue;
    }

    for (j = 0; j < (unsigned int) num_sections; j++) {
      if (sections[j].flags & (SF_SECGRP | SF_SECGRPEND)) {
        continue;
      }

      if (items && !items[j]) {
        continue;
      }

      if ((sections[j].install_types & (1 << i)) == ((sections[j].flags & SF_SELECTED) << i)) {
        continue;
      } else {
        break;
      }
    }

    if (j == (unsigned int) num_sections) {
      break;
    }
  }

  return i;
}

#endif//NSIS_CONFIG_COMPONENTPAGE