| 1 |
/* |
| 2 |
* components.c |
| 3 |
* |
| 4 |
* This file is a part of NSIS. |
| 5 |
* |
| 6 |
* Copyright (C) 1999-2026 Nullsoft and Contributors |
| 7 |
* |
| 8 |
* Licensed under the zlib/libpng license (the "License"); |
| 9 |
* you may not use this file except in compliance with the License. |
| 10 |
* |
| 11 |
* Licence details can be found in the file COPYING. |
| 12 |
* |
| 13 |
* This software is provided 'as-is', without any express or implied |
| 14 |
* warranty. |
| 15 |
* |
| 16 |
* Reviewed for Unicode support by Jim Park -- 08/22/2007 |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "../Platform.h" |
| 20 |
#include "config.h" |
| 21 |
#include "ui.h" |
| 22 |
#include "fileform.h" |
| 23 |
|
| 24 |
void NSISCALL SectionFlagsChanged(unsigned int index) { |
| 25 |
section *sections = g_sections; |
| 26 |
|
| 27 |
int flags = sections[index].flags; |
| 28 |
|
| 29 |
if (flags & SF_SECGRP) { |
| 30 |
unsigned int i = index + 1; |
| 31 |
unsigned int level = 0; |
| 32 |
|
| 33 |
for (; i < (unsigned int) num_sections; i++) { |
| 34 |
if (sections[i].flags & SF_SECGRP) { |
| 35 |
level++; |
| 36 |
continue; |
| 37 |
} |
| 38 |
|
| 39 |
if (sections[i].flags & SF_SECGRPEND) { |
| 40 |
if (level-- == 0) { |
| 41 |
break; |
| 42 |
} |
| 43 |
|
| 44 |
continue; |
| 45 |
} |
| 46 |
|
| 47 |
if ((sections[i].flags & SF_RO) == 0) { |
| 48 |
sections[i].flags &= ~SF_SELECTED; |
| 49 |
sections[i].flags |= (flags & SF_SELECTED); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
unsigned int NSISCALL _RefreshSectionGroups(unsigned int i, int not_first_call) { |
| 56 |
unsigned int selected = 0; |
| 57 |
unsigned int not_selected = 0; |
| 58 |
|
| 59 |
section *sections = g_sections; |
| 60 |
|
| 61 |
section *sec = §ions[i]; |
| 62 |
|
| 63 |
if (sec->flags & SF_SECGRP) { |
| 64 |
if (not_first_call) { |
| 65 |
sec->flags &= ~(SF_SELECTED | SF_PSELECTED); |
| 66 |
i++; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
while (i < (unsigned int) num_sections) { |
| 71 |
int flags = sections[i].flags; |
| 72 |
int ni = i + 1; |
| 73 |
|
| 74 |
if (flags & SF_SECGRP) { |
| 75 |
ni = _RefreshSectionGroups(i, 1); |
| 76 |
flags = sections[i].flags; |
| 77 |
} |
| 78 |
|
| 79 |
if (flags & SF_SECGRPEND) { |
| 80 |
if (selected) { |
| 81 |
if (not_selected) { |
| 82 |
sec->flags |= SF_PSELECTED; |
| 83 |
} else { |
| 84 |
sec->flags |= SF_SELECTED; |
| 85 |
sec->flags &= ~SF_TOGGLED; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
return ni; |
| 90 |
} |
| 91 |
|
| 92 |
if (flags & SF_PSELECTED) { |
| 93 |
selected++; |
| 94 |
} |
| 95 |
|
| 96 |
if (flags & SF_SELECTED) { |
| 97 |
selected++; |
| 98 |
} else { |
| 99 |
not_selected++; |
| 100 |
} |
| 101 |
|
| 102 |
i = ni; |
| 103 |
} |
| 104 |
|
| 105 |
return 0; |
| 106 |
} |
| 107 |
|
| 108 |
#ifdef NSIS_CONFIG_COMPONENTPAGE |
| 109 |
|
| 110 |
void NSISCALL SetInstType(int inst_type) { |
| 111 |
unsigned int i = 0; |
| 112 |
|
| 113 |
section *sections = g_sections; |
| 114 |
|
| 115 |
if ((unsigned int) inst_type >= NSIS_MAX_INST_TYPES) { |
| 116 |
return; |
| 117 |
} |
| 118 |
|
| 119 |
for (; i < (unsigned int) num_sections; i++) { |
| 120 |
if (sections[i].flags & (SF_SECGRP | SF_SECGRPEND)) { |
| 121 |
continue; |
| 122 |
} |
| 123 |
|
| 124 |
if (sections[i].install_types & (1 << inst_type)) { |
| 125 |
sections[i].flags |= SF_SELECTED; |
| 126 |
} else { |
| 127 |
sections[i].flags &= ~SF_SELECTED; |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
unsigned int NSISCALL GetInstType(HTREEITEM *items) { |
| 133 |
unsigned int i, j; |
| 134 |
|
| 135 |
section *sections = g_sections; |
| 136 |
|
| 137 |
for (i = 0; i < NSIS_MAX_INST_TYPES; i++) { |
| 138 |
if (!g_header->install_types[i]) { |
| 139 |
continue; |
| 140 |
} |
| 141 |
|
| 142 |
for (j = 0; j < (unsigned int) num_sections; j++) { |
| 143 |
if (sections[j].flags & (SF_SECGRP | SF_SECGRPEND)) { |
| 144 |
continue; |
| 145 |
} |
| 146 |
|
| 147 |
if (items && !items[j]) { |
| 148 |
continue; |
| 149 |
} |
| 150 |
|
| 151 |
if ((sections[j].install_types & (1 << i)) == ((sections[j].flags & SF_SELECTED) << i)) { |
| 152 |
continue; |
| 153 |
} else { |
| 154 |
break; |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
if (j == (unsigned int) num_sections) { |
| 159 |
break; |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
return i; |
| 164 |
} |
| 165 |
|
| 166 |
#endif//NSIS_CONFIG_COMPONENTPAGE |