Skip to content

Commit f6145f1

Browse files
committed
added Insert command to insert fields from specified file
1 parent 808dd74 commit f6145f1

File tree

9 files changed

+140
-27
lines changed

9 files changed

+140
-27
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
authors = ["rusty-bits <[email protected]>"]
33
edition = "2021"
44
name = "octool"
5-
version = "0.4.6"
5+
version = "0.4.7"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

src/draw.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn update_screen(
3131
stdout,
3232
" {inv}D{res}/{inv}^x{res}cut {inv}^c{res}op{inv}y{res} {inv}^v{res}/{inv}p{res}aste {inv}f{res}ind {inv}n{res}ext \
3333
{inv}a{res}dd {inv}d{res}el {inv}M{res}erge {inv}P{res}urge {inv}r{res}eset {inv}O{res}rder(Kernel>Add)\x1B[0K\r\n {inv}s{res}ave\
34-
+validate {inv}q{res}uit {inv}G{res}o build EFI {inv}K{res}ey {inv}{red} {grn} {res}boolean {inv}{mag} {res}data {inv}{blu} \
34+
+validate {inv}q{res}uit {inv}G{res}o build EFI {inv}K{res}ey {inv}I{res}nsert {inv}{red} {grn} {res}boolean {inv}{mag} {res}data {inv}{blu} \
3535
{res}integer {inv} {res}string\x1B[0K",
3636
inv = "\x1b[7m",
3737
// res = &settings.bg_col,
@@ -67,7 +67,11 @@ pub fn update_screen(
6767
write!(
6868
stdout,
6969
"debug-> {:?} {} {:?} array? {} {:?}",
70-
settings.sec_length, settings.depth, settings.sec_num, settings.inside_an_array, settings.sec_key
70+
settings.sec_length,
71+
settings.depth,
72+
settings.sec_num,
73+
settings.inside_an_array,
74+
settings.sec_key
7175
)?;
7276

7377
let mut blanks = screen_rows - row_being_drawn - 1;
@@ -377,21 +381,16 @@ fn get_array_key(key: &mut String, v: &plist::Value, i: usize) -> Option<bool> {
377381
match d.get("Enabled") {
378382
Some(Value::Boolean(b)) => {
379383
return Some(*b);
380-
// if *b {
381-
// return Some(true);
382-
// } else {
383-
// return Some(false);
384-
// }
385384
}
386385
_ => (),
387386
}
388387

389388
match d.get("Load") {
390389
Some(Value::String(s)) => {
391390
if *s == "Disabled" {
392-
return Some(false)
391+
return Some(false);
393392
} else {
394-
return Some(true)
393+
return Some(true);
395394
}
396395
}
397396
_ => (),

src/edit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ pub fn add_item(
445445
item.as_dictionary_mut()
446446
.unwrap()
447447
.insert("Path".to_string(), plist::Value::String(selected_res));
448-
item.as_dictionary_mut()
449-
.unwrap()
450-
.insert("Enabled".to_string(), plist::Value::Boolean(true));
448+
item.as_dictionary_mut()
449+
.unwrap()
450+
.insert("Enabled".to_string(), plist::Value::Boolean(true));
451451
} else {
452452
settings.held_item = Some(plist::Value::String(selected_res));
453453
}

src/init.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ pub fn init_static(
185185
}
186186
write!(stdout, "\x1b[32mdone\x1b[0m\r\n")?
187187
} else if old_size == 0 {
188-
write!(stdout, "Could not retrieve config.json info from Github API at this time.\r\n")?;
188+
write!(
189+
stdout,
190+
"Could not retrieve config.json info from Github API at this time.\r\n"
191+
)?;
189192
} else {
190193
write!(stdout, "Already up to date.\r\n")?;
191194
}
@@ -323,7 +326,7 @@ pub fn init_oc_build(
323326
true,
324327
true,
325328
stdout,
326-
false
329+
false,
327330
)?;
328331

329332
match path {

src/main.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::edit::read_key;
2727
use crate::init::{guess_version, Manifest, Settings};
2828
use crate::res::Resources;
2929

30-
const OCTOOL_VERSION: &str = &"v0.4.6 2022-07-27";
30+
const OCTOOL_VERSION: &str = &"v0.4.7 2022-07-31";
3131

3232
fn process(
3333
config_plist: &mut PathBuf,
@@ -253,8 +253,12 @@ fn process(
253253
while !res::check_order(settings, resources, stdout, false) {
254254
order_attempts += 1;
255255
if order_attempts > 10 {
256-
write!(stdout, "\x1b[2K\x1b[33mHmm, I just looped 10 times. \
257-
Am I broken or is it just many fixes?\x1b[0m\r\n").unwrap();
256+
write!(
257+
stdout,
258+
"\x1b[2K\x1b[33mHmm, I just looped 10 times. \
259+
Am I broken or is it just many fixes?\x1b[0m\r\n"
260+
)
261+
.unwrap();
258262
break;
259263
}
260264
}
@@ -528,7 +532,13 @@ fn process(
528532
}
529533
}
530534
KeyCode::Char('M') => {
531-
res::merge_whole_plist(settings, resources, stdout);
535+
res::merge_whole_plist(settings, resources, stdout, false);
536+
stdout.flush().unwrap();
537+
showing_info = true;
538+
}
539+
KeyCode::Char('I') => {
540+
res::merge_whole_plist(settings, resources, stdout, true);
541+
stdout.flush().unwrap();
532542
showing_info = true;
533543
}
534544
KeyCode::Char('i') => {
@@ -630,6 +640,7 @@ fn process(
630640
&& key != KeyCode::Char('M')
631641
&& key != KeyCode::Char('P')
632642
&& key != KeyCode::Char('O')
643+
&& key != KeyCode::Char('I')
633644
{
634645
showing_info = false;
635646
}

src/parse_tex.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::{
44
io::{Stdout, Write},
55
};
66

7+
use crossterm::cursor::position;
78
use crossterm::event::KeyCode;
89
use crossterm::terminal::size;
9-
use crossterm::cursor::position;
1010

1111
use crate::{edit::read_key, init::Settings, res::Resources};
1212

@@ -285,9 +285,13 @@ pub fn show_info(
285285
stdout.flush()?;
286286
let bump_position = row + position()?.1 + 1;
287287
if bump_position > rows {
288-
write!(stdout, "\x1B8{}\x1B7", "\x1B[A".repeat(bump_position as usize - rows as usize))?;
288+
write!(
289+
stdout,
290+
"\x1B8{}\x1B7",
291+
"\x1B[A".repeat(bump_position as usize - rows as usize)
292+
)?;
289293
}
290-
// write!(stdout, " {} {} {} {} {}", bump_position, row, rows, position()?.0, position()?.1)?;
294+
// write!(stdout, " {} {} {} {} {}", bump_position, row, rows, position()?.0, position()?.1)?;
291295
stdout.flush()?;
292296
Ok(showing_info)
293297
}

src/res.rs

+99-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::edit;
12
use crate::init::{Manifest, Settings};
23
use std::error::Error;
34
use std::fs::File;
@@ -745,11 +746,65 @@ pub fn get_latest_ver(resources: &Resources) -> Result<String, Box<dyn Error>> {
745746
}
746747
}
747748

748-
pub fn merge_whole_plist(settings: &mut Settings, resources: &mut Resources, stdout: &mut Stdout) {
749+
pub fn merge_whole_plist(
750+
settings: &mut Settings,
751+
resources: &mut Resources,
752+
stdout: &mut Stdout,
753+
use_other_sample: bool,
754+
) {
749755
let mut changed = false;
750-
for sample_sec in resources.sample_plist.as_dictionary().unwrap() {
756+
let sample;
757+
if use_other_sample {
758+
write!(
759+
stdout,
760+
"\x1b[2K\r\n\x1b[2KEnter 'path of file' to Insert or drop file here: \x1b7\r\n\x1b[2K\x1b8"
761+
)
762+
.unwrap();
763+
let mut file_name = String::new();
764+
edit::edit_string(&mut file_name, None, stdout).unwrap();
765+
let file_name = PathBuf::from(&file_name.trim());
766+
if file_name.exists() {
767+
sample = match Value::from_file(&file_name) {
768+
Ok(v) => v,
769+
Err(_) => {
770+
write!(
771+
stdout,
772+
"\r\n\x1b[2K\x1b[31mERROR: \x1b[0m{:?} is not a valid plist file\r\n\x1b[2K",
773+
file_name
774+
)
775+
.unwrap();
776+
return;
777+
}
778+
};
779+
} else {
780+
write!(
781+
stdout,
782+
"\r\n\x1b[2K\x1b[31mERROR: \x1b[0mFile {:?} does not exist\r\n\x1b[2K",
783+
file_name
784+
)
785+
.unwrap();
786+
return;
787+
}
788+
} else {
789+
sample = resources.sample_plist.clone();
790+
}
791+
// for sample_sec in resources.sample_plist.as_dictionary().unwrap() {
792+
for sample_sec in sample.as_dictionary().unwrap() {
751793
if sample_sec.0 == "DeviceProperties" {
752794
// do not modify DeviceProperties
795+
if !resources
796+
.config_plist
797+
.as_dictionary()
798+
.unwrap()
799+
.contains_key("DeviceProperties")
800+
{
801+
resources
802+
.config_plist
803+
.as_dictionary_mut()
804+
.unwrap()
805+
.insert("DeviceProperties".to_string(), sample_sec.1.clone());
806+
settings.sec_length[0] += 1;
807+
}
753808
continue;
754809
}
755810
match sample_sec.1 {
@@ -823,6 +878,40 @@ pub fn merge_whole_plist(settings: &mut Settings, resources: &mut Resources, std
823878
if a.len() > 0 {
824879
match &a[0] {
825880
plist::Value::Dictionary(sample_dict) => {
881+
if use_other_sample {
882+
//insert dict from other_sample into
883+
//config.plist
884+
for b in 0..a.len() {
885+
match &a[b] {
886+
plist::Value::Dictionary(sample_all) => {
887+
resources
888+
.config_plist
889+
.as_dictionary_mut()
890+
.unwrap()
891+
.get_mut(sample_sec.0)
892+
.unwrap()
893+
.as_dictionary_mut()
894+
.unwrap()
895+
.get_mut(sample_sub.0)
896+
.unwrap()
897+
.as_array_mut()
898+
.unwrap()
899+
.insert(
900+
0,
901+
Value::Dictionary(
902+
sample_all.clone(),
903+
),
904+
);
905+
changed = true;
906+
write!(stdout,
907+
"\r\n\x1b[7mAdded\x1b[0m {}->{} item\x1b[0K"
908+
,sample_sec.0, sample_sub.0).unwrap();
909+
stdout.flush().unwrap();
910+
}
911+
_ => {}
912+
}
913+
}
914+
}
826915
for (i, item) in resources
827916
.config_plist
828917
.as_dictionary_mut()
@@ -891,7 +980,6 @@ pub fn merge_whole_plist(settings: &mut Settings, resources: &mut Resources, std
891980
settings.modified = true;
892981
}
893982
write!(stdout, "\r\n\x1b[2K").unwrap();
894-
stdout.flush().unwrap();
895983
}
896984

897985
pub fn purge_whole_plist(settings: &mut Settings, resources: &mut Resources, stdout: &mut Stdout) {
@@ -1033,6 +1121,14 @@ pub fn check_order(
10331121
let mut bundle_list = vec![];
10341122
let mut kext_list = vec![];
10351123
//run through Kernel Add section and add to kext_list
1124+
if !resources
1125+
.config_plist
1126+
.as_dictionary()
1127+
.unwrap()
1128+
.contains_key("Kernel")
1129+
{
1130+
return true;
1131+
}
10361132
for res in resources
10371133
.config_plist
10381134
.as_dictionary()

tool_config_files/octool_config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"octool_version": "v0.4.6 2022-07-27",
2+
"octool_version": "v0.4.7 2022-07-31",
33
"octool_releases_url": "https://github.com/rusty-bits/octool/releases",
44
"octool_latest_config_url": "https://raw.githubusercontent.com/rusty-bits/octool/main/tool_config_files/octool_config.json",
55
"octool_latest_dyn_res_list_url": "https://raw.githubusercontent.com/rusty-bits/octool/main/tool_config_files/dyn_res_list.zip",

0 commit comments

Comments
 (0)