Skip to content

Commit da48cd0

Browse files
committed
disable duplicate kexts with 'O' command
1 parent 2c3c695 commit da48cd0

File tree

1 file changed

+49
-18
lines changed

1 file changed

+49
-18
lines changed

src/res.rs

+49-18
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,7 @@ pub fn purge_whole_plist(settings: &mut Settings, resources: &mut Resources, std
11131113
stdout.flush().unwrap();
11141114
}
11151115

1116+
//return true if order is okay
11161117
pub fn check_order(
11171118
settings: &mut Settings,
11181119
resources: &mut Resources,
@@ -1130,46 +1131,68 @@ pub fn check_order(
11301131
{
11311132
return true;
11321133
}
1133-
for res in resources
1134+
let reses = resources
11341135
.config_plist
1135-
.as_dictionary()
1136-
.unwrap()
1137-
.get("Kernel")
1136+
.as_dictionary_mut()
11381137
.unwrap()
1139-
.as_dictionary()
1138+
.get_mut("Kernel")
11401139
.unwrap()
1141-
.get("Add")
1140+
.as_dictionary_mut()
11421141
.unwrap()
1143-
.as_array()
1142+
.get_mut("Add")
11441143
.unwrap()
1145-
.iter()
1146-
{
1147-
let res_bundle = res
1144+
.as_array_mut()
1145+
.unwrap();
1146+
1147+
//build list of kexts from Kernel > Add Section
1148+
for res in reses {
1149+
let bundle_path = res
11481150
.as_dictionary()
11491151
.unwrap()
11501152
.get("BundlePath")
11511153
.unwrap()
11521154
.as_string()
11531155
.unwrap_or("")
11541156
.to_owned();
1155-
let res_version = res_version(settings, resources, &res_bundle).unwrap_or("".to_owned());
1156-
// let res_version = res_version(settings, resources, &res_bundle);
11571157
let res_enabled = res
11581158
.as_dictionary()
11591159
.unwrap()
11601160
.get("Enabled")
11611161
.unwrap()
11621162
.as_boolean()
11631163
.unwrap_or(false);
1164-
// if res_version.is_some() {
1165-
// kext_list.push((res_bundle, res_version.unwrap(), res_enabled));
1166-
kext_list.push((res_bundle, res_version, res_enabled));
1167-
// }
1164+
let mut new_res = (bundle_path.split('/').last().unwrap_or("").to_string(), "Unknown".to_owned(), res_enabled);
1165+
if kext_list.contains(&new_res) && res_enabled {
1166+
write!(
1167+
stdout,
1168+
"\x1b[2KResource {} already enabled!!\r\n",
1169+
new_res.0
1170+
)
1171+
.unwrap();
1172+
if !check_only {
1173+
write!(stdout, "\x1b[2KDisabling duplicate\r\n").unwrap();
1174+
match res {
1175+
Value::Boolean(b) => *b = !*b,
1176+
Value::Dictionary(d) => match d.get_mut("Enabled") {
1177+
Some(Value::Boolean(b)) => *b = !*b,
1178+
_ => (),
1179+
},
1180+
_ => (),
1181+
}
1182+
}
1183+
new_res.2 = false;
1184+
}
1185+
kext_list.push(new_res);
1186+
}
1187+
1188+
//add version numbers to list
1189+
for i in 0..kext_list.len() {
1190+
kext_list[i].1 = res_version(settings, resources, &kext_list[i].0).unwrap_or("".to_owned());
11681191
}
11691192

11701193
#[cfg(debug_assertions)]
11711194
{
1172-
write!(stdout, "\x1b[0J{:?}\r\n", kext_list).unwrap();
1195+
write!(stdout, "\x1b[0J{} {:?}\r\n", kext_list.len(), kext_list).unwrap();
11731196
}
11741197

11751198
//iterate kext_list and build bundle_list
@@ -1210,6 +1233,8 @@ pub fn check_order(
12101233
let mut buns = vec![];
12111234
for val in d.iter() {
12121235
if !val.0.contains("com.apple") {
1236+
//add requirement if it is
1237+
//not from apple
12131238
buns.push((
12141239
val.0.to_owned(),
12151240
val.1.as_string().unwrap().to_owned(),
@@ -1240,12 +1265,14 @@ pub fn check_order(
12401265

12411266
#[cfg(debug_assertions)]
12421267
{
1243-
write!(stdout, "\r\n{:?}\r\n", bundle_list).unwrap();
1268+
write!(stdout, "\r\n{} {:?}\r\n", bundle_list.len(), bundle_list).unwrap();
12441269
}
12451270

1271+
//enable or add requirements
12461272
for (i, bun) in bundle_list.iter().enumerate() {
12471273
if kext_list[i].2 {
12481274
if bun.2.len() > 0 {
1275+
//has requirements
12491276
for (j, required) in bun.2.iter().enumerate() {
12501277
let mut requirement_exists = false;
12511278
let mut requirement_index = 0;
@@ -1257,6 +1284,10 @@ pub fn check_order(
12571284
if k > i {
12581285
requirement_out_of_order = true;
12591286
}
1287+
if kext_list[k].2 {
1288+
break;
1289+
//found enabled requirement
1290+
}
12601291
}
12611292
}
12621293
if requirement_exists {

0 commit comments

Comments
 (0)