1 /*
2  * Copyright (C) 2011-2019 Daniel Scharrer
3  *
4  * This software is provided 'as-is', without any express or implied
5  * warranty.  In no event will the author(s) be held liable for any damages
6  * arising from the use of this software.
7  *
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  *    claim that you wrote the original software. If you use this software
14  *    in a product, an acknowledgment in the product documentation would be
15  *    appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  *    misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  */
20 
21 #include "setup/component.hpp"
22 
23 #include "setup/info.hpp"
24 #include "setup/version.hpp"
25 #include "util/load.hpp"
26 #include "util/storedenum.hpp"
27 
28 namespace setup {
29 
30 namespace {
31 
32 STORED_FLAGS_MAP(stored_component_flags_0,
33 	component_entry::Fixed,
34 	component_entry::Restart,
35 	component_entry::DisableNoUninstallWarning,
36 );
37 
38 // starting with version 3.0.8
39 STORED_FLAGS_MAP(stored_component_flags_1,
40 	component_entry::Fixed,
41 	component_entry::Restart,
42 	component_entry::DisableNoUninstallWarning,
43 	component_entry::Exclusive,
44 );
45 
46 // starting with version 4.2.3
47 STORED_FLAGS_MAP(stored_component_flags_2,
48 	component_entry::Fixed,
49 	component_entry::Restart,
50 	component_entry::DisableNoUninstallWarning,
51 	component_entry::Exclusive,
52 	component_entry::DontInheritCheck,
53 );
54 
55 } // anonymous namespace
56 
load(std::istream & is,const info & i)57 void component_entry::load(std::istream & is, const info & i) {
58 
59 	is >> util::encoded_string(name, i.codepage);
60 	is >> util::encoded_string(description, i.codepage);
61 	is >> util::encoded_string(types, i.codepage);
62 	if(i.version >= INNO_VERSION(4, 0, 1)) {
63 		is >> util::encoded_string(languages, i.codepage);
64 	} else {
65 		languages.clear();
66 	}
67 	if(i.version >= INNO_VERSION(4, 0, 0) || (i.version.is_isx() && i.version >= INNO_VERSION(1, 3, 24))) {
68 		is >> util::encoded_string(check, i.codepage);
69 	} else {
70 		check.clear();
71 	}
72 	if(i.version >= INNO_VERSION(4, 0, 0)) {
73 		extra_disk_pace_required = util::load<boost::uint64_t>(is);
74 	} else {
75 		extra_disk_pace_required = util::load<boost::uint32_t>(is);
76 	}
77 	if(i.version >= INNO_VERSION(4, 0, 0) || (i.version.is_isx() && i.version >= INNO_VERSION(3, 0, 3))) {
78 		level = util::load<boost::int32_t>(is);
79 	} else {
80 		level = 0;
81 	}
82 	if(i.version >= INNO_VERSION(4, 0, 0) || (i.version.is_isx() && i.version >= INNO_VERSION(3, 0, 4))) {
83 		used = util::load_bool(is);
84 	} else {
85 		used = true;
86 	}
87 
88 	winver.load(is, i.version);
89 
90 	if(i.version >= INNO_VERSION(4, 2, 3)) {
91 		options = stored_flags<stored_component_flags_2>(is).get();
92 	} else if(i.version >= INNO_VERSION(3, 0, 8) ||
93 		        (i.version.is_isx() && i.version >= INNO_VERSION_EXT(3, 0, 6, 1))) {
94 		options = stored_flags<stored_component_flags_1>(is).get();
95 	} else {
96 		options = stored_flags<stored_component_flags_0>(is).get();
97 	}
98 
99 	if(i.version >= INNO_VERSION(4, 0, 0)) {
100 		size = util::load<boost::uint64_t>(is);
101 	} else if(i.version >= INNO_VERSION(2, 0, 0) ||
102 		        (i.version.is_isx() && i.version >= INNO_VERSION(1, 3, 24))) {
103 		size = util::load<boost::uint32_t>(is);
104 	}
105 }
106 
107 } // namespace setup
108 
109 NAMES(setup::component_entry::flags, "Setup Component Option",
110 	"fixed",
111 	"restart",
112 	"disable no uninstall warning",
113 	"exclusive",
114 	"don't inherit check",
115 )
116