2022-08-02 11:51:15 +02:00
|
|
|
use std::fs::{self, File};
|
2023-07-31 21:42:46 +02:00
|
|
|
use std::io;
|
2022-08-02 11:51:15 +02:00
|
|
|
use std::io::Write;
|
2022-02-20 18:12:40 +01:00
|
|
|
|
2022-08-02 11:51:15 +02:00
|
|
|
use shadow_rs::SdResult;
|
|
|
|
|
|
|
|
fn main() -> SdResult<()> {
|
|
|
|
shadow_rs::new_hook(gen_presets_hook)?;
|
2022-02-20 18:12:40 +01:00
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
let mut res = winres::WindowsResource::new();
|
2022-06-02 22:26:10 +02:00
|
|
|
res.set_manifest_file("starship.exe.manifest")
|
|
|
|
.set_icon("media/icon.ico");
|
2022-02-20 18:12:40 +01:00
|
|
|
res.compile()?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
2021-01-22 20:14:51 +01:00
|
|
|
}
|
2022-08-02 11:51:15 +02:00
|
|
|
|
|
|
|
fn gen_presets_hook(mut file: &File) -> SdResult<()> {
|
2024-03-03 17:55:30 +01:00
|
|
|
println!("cargo:rerun-if-changed=docs/public/presets/toml");
|
|
|
|
let paths = fs::read_dir("docs/public/presets/toml")?;
|
2023-07-31 21:42:46 +02:00
|
|
|
let mut sortedpaths = paths.collect::<io::Result<Vec<_>>>()?;
|
2023-08-25 22:53:35 +02:00
|
|
|
sortedpaths.sort_by_key(std::fs::DirEntry::path);
|
2022-08-02 11:51:15 +02:00
|
|
|
|
|
|
|
let mut presets = String::new();
|
|
|
|
let mut match_arms = String::new();
|
2023-07-31 21:42:46 +02:00
|
|
|
for unwrapped in sortedpaths {
|
2022-08-02 11:51:15 +02:00
|
|
|
let file_name = unwrapped.file_name();
|
|
|
|
let full_path = dunce::canonicalize(unwrapped.path())?;
|
|
|
|
let full_path = full_path.to_str().expect("failed to convert to string");
|
|
|
|
let name = file_name
|
|
|
|
.to_str()
|
|
|
|
.and_then(|v| v.strip_suffix(".toml"))
|
|
|
|
.expect("Failed to process filename");
|
2022-11-05 12:40:46 +01:00
|
|
|
presets.push_str(format!("print::Preset(\"{name}\"),\n").as_str());
|
2023-03-03 11:46:16 +01:00
|
|
|
match_arms.push_str(format!(r#""{name}" => include_bytes!(r"{full_path}"),"#).as_str());
|
2022-08-02 11:51:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
writeln!(
|
|
|
|
file,
|
|
|
|
r#"
|
|
|
|
use crate::print;
|
|
|
|
|
|
|
|
pub fn get_preset_list<'a>() -> &'a [print::Preset] {{
|
|
|
|
&[
|
|
|
|
{presets}
|
|
|
|
]
|
|
|
|
}}
|
|
|
|
|
2023-03-03 11:46:16 +01:00
|
|
|
pub fn get_preset_content(name: &str) -> &[u8] {{
|
2022-08-02 11:51:15 +02:00
|
|
|
match name {{
|
|
|
|
{match_arms}
|
2023-03-03 11:46:16 +01:00
|
|
|
_ => unreachable!(),
|
2022-08-02 11:51:15 +02:00
|
|
|
}}
|
|
|
|
}}
|
|
|
|
"#
|
|
|
|
)?;
|
|
|
|
Ok(())
|
|
|
|
}
|