improve documentation of some functions and more readme work

This commit is contained in:
2025-10-19 20:23:55 -07:00
parent f5f431458c
commit 9b8ba30f56
6 changed files with 128 additions and 57 deletions

40
src/config/loader.rs Normal file
View File

@@ -0,0 +1,40 @@
use std::ops::Deref;
use anyhow::{bail, Context, Result};
use toml::Value;
use uefi::proto::device_path::LoadedImageDevicePath;
use crate::config::{latest_version, RootConfiguration};
use crate::utils;
fn load_raw_config() -> Result<Vec<u8>> {
let current_image_device_path_protocol =
uefi::boot::open_protocol_exclusive::<LoadedImageDevicePath>(uefi::boot::image_handle())
.context("unable to get loaded image device path")?;
let path = current_image_device_path_protocol.deref().to_boxed();
let content = utils::read_file_contents(&path, "sprout.toml")
.context("unable to read sprout.toml file")?;
Ok(content)
}
pub fn load() -> Result<RootConfiguration> {
let content = load_raw_config()?;
let value: Value = toml::from_slice(&content).context("unable to parse sprout.toml file")?;
let version = value
.get("version")
.cloned()
.unwrap_or_else(|| Value::Integer(latest_version() as i64));
let version: u32 = version
.try_into()
.context("unable to get configuration version")?;
if version != latest_version() {
bail!("unsupported configuration version: {}", version);
}
let config: RootConfiguration = value
.try_into()
.context("unable to parse sprout.toml file")?;
Ok(config)
}