Skip to content

Commit b24a14c

Browse files
committed
add build arch setting + no clobber option #10
1 parent 3029a09 commit b24a14c

File tree

9 files changed

+83
-39
lines changed

9 files changed

+83
-39
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.3"
5+
version = "0.4.4"
66

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

README.md

+14-16
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ You can build from the included source by running `cargo build --release` (if yo
1616
-h print help/usage message then exit
1717

1818
-o x.y.z select OpenCore version number to use e.g. `-o 0.7.4`
19-
- without this option octool will make a quick guess as to which version to use based on the INPUT config.plist, if no INPUT config.plist is provided, octool will default to the latest version of OpenCore
19+
- without this option octool will make a quick guess as to which version to use based on the INPUT config.plist, if no INPUT config.plist is provided, octool will default to the latest OpenCore version
2020

2121
-v print octool version information and booted OpenCore version if the var is in NVRAM then exit
2222

2323
octool takes a path to a `config.plist` to use if desired.
24-
If you run octool with no path provided `./octool` will first look for a `config.plist` in the `INPUT` folder, if it doesn't find one there it will use the corresponding `OpenCorePkg/Docs/Sample.plist` file.
24+
If you run octool with no path provided `./octool` will look for `config.plist` in the `INPUT` folder, if it doesn't find it there it will use the `OpenCorePkg/Docs/Sample.plist` file.
2525

2626
## Here's a rundown of the current process octool uses. ##
2727

2828
At startup, octool checks for a local copy of [the builds branch of the Dortania/build-repo](https://github.com/dortania/build-repo/tree/builds) so it will know the urls and hashes of the prebuilt binary resources. Thank you [dhinakg](https://github.com/dhinakg), [hieplpvip](https://github.com/hieplpvip), and [khronokernel](https://github.com/khronokernel).
29-
- If it finds it locally it updates it if needed
30-
- If it doesn't find it locally octool downloads the `build-repo` into the `tool_config_files` folder.
29+
- It will update or download it to the `build-repo` into the `tool_config_files` folder as needed.
3130

3231
Next, octool does the same thing for [the master branch of the Acidanthera OpenCorePkg source files](https://github.com/acidanthera/OpenCorePkg), thanks to the [people of Acidanthera](https://github.com/acidanthera), in order to have the corresponding Sample.plist and Configuration.tex files, etc. for the version of OpenCore that you are building. They will be placed into the `resources` folder along with the corresponding binaries from the Dortania builds. This will allow `octool` to use Acidanthera tools while building the EFI, such as the ocvalitate and CreateVault tools. Thanks, again [dhinakg](https://github.com/dhinakg).
3332

34-
As a last step, octool will run the input config.plist through ocvalitade, display any errors, and give you the option to quit or continue.
33+
Lastly, octool will run the input config.plist through ocvalitade and give you the option to quit or continue.
3534
If you continue you then enter the config.plist editor...
3635
```
3736
Navigation: arrow keys or some standard vi keys
@@ -67,29 +66,29 @@ Usage:
6766

6867
'G' `go` (capital G) - make an OUTPUT/EFI/OC folder from the config.plist
6968
- if `OpenCanopy.efi` is enabled it will copy the OcBinaryData Resources to `OUTPUT/EFI/OC/Resources`
70-
- if Misc->Security->Vault is set to Basic or Secure, octool will compute the required files and sign the `OpenCore.efi` if needed
71-
- right now, octool will ignore resources that it doesn't know unless they are placed in the INPUT folder, it will print out a warning, but it will not make a change to the config.plist for the unknown resource
69+
- if `Misc > Security > Vault` is set to `Basic` or `Secure`, octool will compute the required files and sign the `OpenCore.efi` if needed
70+
- octool will ignore resources that it doesn't know unless they are placed in the INPUT folder, it will print out a warning, but it will not make a change to the config.plist for the unknown resource
7271
- any file placed in the `INPUT` folder will take priority and will be used for the `OUTPUT/EFI`, even if a more recent version of that resource is available elsewhere. This is good for using a specific version of a kext, for example, or for using a specific SSDT or USBMap
7372
- lastly, it will again validate the `OUTPUT/EFI/OC/config.plist` file with ocvalidate
7473

7574
'i' show `info` of highlighted item.
7675
- If item is resource such as a kext or driver, octool will show the source of the file it will place in the `OUTPUT/EFI` folder.
77-
- If the highlighted item is a field of the config.plist, octool will show the description and info from the corresponding [Acidanthera](https://github.com/acidanthera) `Configuration.tex` file.
76+
- Otherwise, octool will show the description and info from the corresponding [Acidanthera](https://github.com/acidanthera) `Configuration.tex` file.
7877

7978
'K' `Key` - capital K - edit the name of the highlighted key
8079

81-
'M' `merge` - capital M - will add missing fields to the `config.plist` if they are in the `Sample.plist` without changing any existing fields.
82-
- this command, coupled with its companion Purge command (capital P) will update a config.plist when any OpenCore plist format changes occur
80+
'M' `merge` - capital M - will add missing fields to the `config.plist` from the `Sample.plist` without changing any existing fields.
81+
- this command, coupled with its companion Purge command (capital P) will update a config.plist when OpenCore plist format changes occur
8382

8483
'n' `next` - jump to the next found item if more than one occurance was found
8584

86-
'P' `purge` - Capital P - removes fields from the config.plist that are not in the Sample.plist
87-
- this command, coupled with it's companion merge command (capital M) will update a config.plist when any OpenCore changes occur
85+
'P' `purge` - Capital P - removes fields from the `config.plist` that are not in the `Sample.plist`
86+
- this command, coupled with it's companion merge command (capital M) will update a config.plist when OpenCore plst format changes occur
8887

8988
'p' `paste` - places the last deleted or modified etc. item into the plist (for those familiar with vi commands)
9089
- if pasting into a dictionary, `octool` will append `-copy` to the pasted item
9190

92-
'q' `quit` - if unsaved changes were made to the `config.plist` octool will show a warning and allow changes to be saved or ignored
91+
'q' `quit` - if unsaved changes were made to the `config.plist` octool will show a warning so changes can be saved
9392

9493
'r' `reset` - if a single item is selected, reset its value to the same as the `Sample.plist` value
9594
- if a section is highlighted, reset the whole section to the same as the section in the `Sample.plist`
@@ -99,7 +98,7 @@ Usage:
9998
- the saved file will be checked with `ocvalidate` for any errors
10099

101100
'V' `Version` - Capital V - change the version of OpenCore that will be checked against and used in the `OUTPUT` EFI
102-
- if 'V' is used while a resource is highlighted, you can change the version of that specific resource
101+
- or, if 'V' is used while a resource is highlighted, you can change the version of that specific resource
103102

104103
'ctrl-x' `cut` - remove the highlighted field or section from the plist
105104

@@ -114,7 +113,7 @@ Usage:
114113
- `build-repo` folder - contains the `config.json` file from the Dortania builds repo with url, version, hash, date created, etc. info for the parent resources. octool will download this from Dortania if it doesn't exist
115114
- `other.json` - contains a list of additional parent resources not included in the Dortania `build--repo`, octool will create this if it doesn't exist
116115

117-
`INPUT` folder - place `config.plist` here along with other files to be included in the `OUTPUT EFI`, such as custom SSDT files, custom Drivers, custom OpenCanopy themes, etc.
116+
`INPUT` folder - place your `config.plist` here along with other files to be included in the `OUTPUT/EFI`, such as custom SSDT files, custom Drivers, custom OpenCanopy themes, etc.
118117
- `octool` will not overwrite the input config.plist on save, instead it will save a version called `modified_config.plist` in this folder so the original `config.plist` can still be used if needed
119118
- `octool` will also automatically save a config.plist titled `last_built_config.plist` when the build command is run for easy reference to a copy of the config.plist that is in the OUTPUT/EFI folder
120119

@@ -124,6 +123,5 @@ Usage:
124123

125124
## To Do: ##
126125
- change tool configuration from inside tool, the configuration file `tool_config_files/octool_config.json` contains vars to set up octool, for example the language versions of the audio files for OpenCanopy for e.g. `en`
127-
- add option to use IA32 versions instead of assuming X64
128126
- keep the highlighted item on screen while reading long info from the Configuration.tex so the user can edit the field while also reading the info
129127
- fix some style formatting of the info screens so underline, bold, etc. looks better when it crosses multiple lines

src/build.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ pub fn build_output(
2323

2424
let mut options = CopyOptions::new();
2525
options.overwrite = true;
26-
let in_path;
27-
if resources.open_core_binaries_path.join("X64/EFI").exists() {
28-
in_path = "X64/EFI"; // TODO: add settings for IA32 as well instead of assuming X64
29-
} else {
30-
in_path = "EFI"; // older OpenCorePkg versions
26+
let mut in_path = resources.octool_config["build_architecture"]
27+
.as_str()
28+
.unwrap_or("X64")
29+
.to_string();
30+
in_path.push_str("/EFI");
31+
if !resources.open_core_binaries_path.join(&in_path).exists() {
32+
in_path = "EFI".to_string(); // older OpenCorePkg versions
3133
}
3234
dir::copy(
3335
&resources.open_core_binaries_path.join(in_path),

src/draw.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@ fn display_value(
282282
let mut sec_sub = settings.sec_key[0].clone();
283283
sec_sub.push_str(&settings.sec_key[1]);
284284
if settings.resource_sections.contains(&sec_sub) {
285-
res::res_version(settings, &resources, &key)
285+
match res::res_version(settings, &resources, &key) {
286+
Some(s) => s,
287+
None => " \x1b[33m∆\x1b[0m ".to_string(),
288+
}
286289
} else {
287290
"".to_string()
288291
}

src/main.rs

+31-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod snake;
99
use fs_extra::dir::{copy, CopyOptions};
1010
use std::collections::HashMap;
1111

12-
use std::fs::File;
12+
use std::fs::{self, File, ReadDir};
1313
use std::io::{stdout, BufReader, Stdout, Write};
1414
use std::path::{Path, PathBuf};
1515
use std::process::exit;
@@ -26,7 +26,7 @@ use crate::edit::read_key;
2626
use crate::init::{guess_version, Manifest, Settings};
2727
use crate::res::Resources;
2828

29-
const OCTOOL_VERSION: &str = &"v0.4.3 2022-07-08";
29+
const OCTOOL_VERSION: &str = &"v0.4.4 2022-07-17";
3030

3131
fn process(
3232
config_plist: &mut PathBuf,
@@ -131,8 +131,10 @@ fn process(
131131
writeln!(stdout, "\n\x1B[32mFinished building OUTPUT/EFI\x1B[0m\r")?;
132132
if &env::current_dir().unwrap() != current_dir {
133133
writeln!(stdout, "Copying OUTPUT EFI folder to this directory\r")?;
134-
fs_extra::dir::remove(current_dir.join("EFI"))?;
135-
//are copy options needed anymore since the EFI is deleted first?
134+
135+
delete_dir_contents(fs::read_dir(current_dir.join("EFI")));
136+
fs::remove_dir_all(current_dir.join("EFI"))?;
137+
136138
let mut options = CopyOptions::new();
137139
options.overwrite = true;
138140
copy("OUTPUT/EFI", current_dir, &options)?;
@@ -359,7 +361,11 @@ fn process(
359361
if &parent_res != "OpenCorePkg" {
360362
let mut res_ver_name = String::new();
361363
settings.res_name(&mut res_ver_name);
362-
new_ver = res::res_version(settings, &resources, &res_ver_name);
364+
new_ver =
365+
match res::res_version(settings, &resources, &res_ver_name) {
366+
Some(s) => s,
367+
None => "".to_string(),
368+
}
363369
// versions[0].split("---").next().unwrap().trim().to_owned();
364370
} else {
365371
new_ver = settings.oc_build_version.to_owned();
@@ -498,11 +504,6 @@ fn process(
498504
stdout,
499505
)?;
500506
}
501-
write!(
502-
stdout,
503-
"\x1b[4m{}\x1B[0K",
504-
" ".repeat(terminal::size()?.0.into())
505-
)?;
506507
if !showing_info && empty_vec.len() == 0 {
507508
settings.res_name(&mut res_name);
508509
write!(
@@ -889,3 +890,23 @@ fn main() {
889890

890891
terminal::disable_raw_mode().unwrap();
891892
}
893+
894+
fn delete_dir_contents(read_dir_res: Result<ReadDir, std::io::Error>) {
895+
if let Ok(dir) = read_dir_res {
896+
for entry in dir {
897+
if let Ok(entry) = entry {
898+
let path = entry.path();
899+
900+
println!("removing {:?}", path);
901+
if path.exists() {
902+
if path.is_dir() {
903+
delete_dir_contents(fs::read_dir(&path));
904+
fs::remove_dir_all(path).expect("Failed to remove a dir");
905+
} else {
906+
fs::remove_file(path).expect("Failed to remove a file");
907+
}
908+
}
909+
};
910+
}
911+
};
912+
}

src/parse_tex.rs

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66

77
use crossterm::event::KeyCode;
88
use crossterm::terminal::size;
9+
use crossterm::cursor::position;
910

1011
use crate::{edit::read_key, init::Settings, res::Resources};
1112

@@ -279,6 +280,14 @@ pub fn show_info(
279280
}
280281
}
281282
}
283+
write!(stdout, "\x1b[4m{}\x1B[0K", " ".repeat(size()?.0.into()))?;
284+
write!(stdout, "\x1B8")?;
285+
stdout.flush()?;
286+
let bump_position = row + position()?.1 + 1;
287+
if bump_position > rows {
288+
write!(stdout, "\x1B8{}\x1B7", "\x1B[A".repeat(bump_position as usize - rows as usize))?;
289+
}
290+
// write!(stdout, " {} {} {} {} {}", bump_position, row, rows, position()?.0, position()?.1)?;
282291
stdout.flush()?;
283292
Ok(showing_info)
284293
}

src/res.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::process::{Command, Output};
77

88
use curl::easy::Easy;
99
use walkdir::WalkDir;
10+
use crossterm::terminal::size;
1011

1112
use sha2::Digest;
1213

@@ -300,7 +301,7 @@ pub fn show_res_info(resources: &Resources, settings: &Settings, stdout: &mut St
300301
stdout,
301302
"\r\n{}{}\r the first found resource will be used in the OUTPUT/EFI{}\r\n",
302303
"\x1b[4m",
303-
" ".repeat(crossterm::terminal::size().unwrap().0.into()),
304+
" ".repeat(size().unwrap().0.into()),
304305
bgc,
305306
)
306307
.unwrap();
@@ -430,6 +431,7 @@ pub fn show_res_info(resources: &Resources, settings: &Settings, stdout: &mut St
430431
}
431432
}
432433
}
434+
write!(stdout, "\x1b[4m{}\x1B[0K", " ".repeat(size().unwrap().0.into())).unwrap();
433435
}
434436

435437
/// Read the `path` file into a `serde_json::Value`
@@ -489,7 +491,7 @@ fn res_exists(
489491

490492
/// version number of resource that will be used based on its manifest info
491493
/// if no manifest info exists for the resource, it will be looked up and stored
492-
pub fn res_version(settings: &mut Settings, resources: &Resources, res: &str) -> String {
494+
pub fn res_version(settings: &mut Settings, resources: &Resources, res: &str) -> Option<String> {
493495
let mut ver = String::new();
494496
let res = res.split("/").last().unwrap_or("");
495497
if let Some(parent_res) = resources.resource_list[res]["parent"].as_str() {
@@ -541,9 +543,9 @@ pub fn res_version(settings: &mut Settings, resources: &Resources, res: &str) ->
541543
}
542544
}
543545
}
544-
ver
546+
Some(ver)
545547
} else {
546-
" \x1b[33m∆\x1b[0m ".to_owned()
548+
None
547549
}
548550
}
549551

tool_config_files/octool_config.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"octool_version": "v0.4.3 2022-07-08",
2+
"octool_version": "v0.4.4 2022-07-17",
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",
@@ -15,19 +15,28 @@
1515
"current_configuration_tex": "https://raw.githubusercontent.com/acidanthera/OpenCorePkg/master/Docs/Configuration.tex",
1616
"current_sample_plist": "https://raw.githubusercontent.com/acidanthera/OpenCorePkg/master/Docs/Sample.plist",
1717

18+
"//comm_can_lang": "only include language files containing 'canopy_language' when OpenCanopy is used",
1819
"canopy_language": "en",
20+
21+
"//comm_glob_audio": "always include these audio files when OpenCanopy is used",
1922
"global_audio_files": [
2023
"AXEFIAudio_Beep.mp3",
2124
"AXEFIAudio_Click.mp3",
2225
"AXEFIAudio_VoiceOver_Boot.mp3"
2326
],
2427

28+
"//comm_show_url": "show url in info screens in addition to link name",
2529
"show_url_in_info_screens": false,
2630

31+
"//comm_reset_ver": "when OpenCore version is changed, set other resource versions to match",
2732
"reset_res_versions": true,
2833

34+
"//comm_clob_local": "replace local res list with updated list when octool is run",
2935
"clobber_local_dyn_res_list": true,
3036

37+
"//comm_build": "set use of either 'X64' or 'IA32' build architecture",
38+
"build_architecture": "X64",
39+
3140
"resource_sections": [
3241
[
3342
"ACPI", "Add", "Path", "ACPI"

0 commit comments

Comments
 (0)