Skip to content

Commit e5ee41c

Browse files
committed
feat: add auto-administrator manifest for Windows (Closes #6)
1 parent c1ab429 commit e5ee41c

6 files changed

Lines changed: 67 additions & 86 deletions

File tree

Cargo.lock

Lines changed: 21 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ edition = "2024"
99
[dependencies]
1010
clap = { version = "4.5.57", features = ["derive"] }
1111
derive_more = { version = "2.1.1", features = ["from", "into", "from_str", "add"] }
12-
dirs = "6.0.0"
1312
efivar = "2.0.0"
1413
inquire = "0.9.2"
1514
miette = { version = "7.6.0", features = ["fancy"] }
@@ -30,3 +29,6 @@ windows-sys = { version = "0.59", features = [
3029
"Win32_System_Threading",
3130
"Win32_Foundation",
3231
] }
32+
33+
[target.'cfg(target_os = "windows")'.build-dependencies]
34+
winres = "0.1.12"

app.manifest

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<assemblyIdentity version="1.0.0.0" name="bootit"/>
4+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
5+
<security>
6+
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
7+
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
8+
</requestedPrivileges>
9+
</security>
10+
</trustInfo>
11+
</assembly>

build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[cfg(all(target_os = "windows"))]
2+
fn main() {
3+
let mut res = winres::WindowsResource::new();
4+
res.set_manifest(include_str!("app.manifest"));
5+
if let Err(error) = res.compile() {
6+
eprint!("{error}");
7+
std::process::exit(1);
8+
}
9+
}
10+

src/bin/it.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ use std::process::Command;
44
fn main() {
55
let args: Vec<String> = env::args().skip(1).collect();
66

7+
// do bootit scan and print result
8+
Command::new("bootit")
9+
.arg("scan")
10+
.status()
11+
.expect("Failed to execute 'bootit scan' command. Make sure 'bootit' is installed and in your PATH.");
12+
713
let status = match Command::new("bootit").arg("boot").args(&args).status() {
814
Ok(status) => status,
915
Err(e) => {

src/config.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,20 @@ pub fn determine_config_path(path: Option<PathBuf>) -> miette::Result<PathBuf> {
128128
}
129129

130130
fn default_config_path() -> PathBuf {
131-
// ~/.config/bootit.yaml
132-
let home_dir = dirs::home_dir().expect("Could not determine home directory");
133-
home_dir.join(".config").join("bootit.yaml")
131+
// HEURISTIC: BOOTIT_CONFIG_PATH, $HOME/.config/bootit.yaml,
132+
// C:\ProgramData\bootit\config.yaml
133+
134+
if let Ok(env_path) = std::env::var("BOOTIT_CONFIG_PATH") {
135+
return PathBuf::from(env_path);
136+
}
137+
138+
if cfg!(target_os = "windows") {
139+
let program_data =
140+
std::env::var("PROGRAMDATA").unwrap_or_else(|_| "C:\\ProgramData".to_string());
141+
return PathBuf::from(format!("{}\\bootit\\config.yaml", program_data));
142+
} else {
143+
// using HOME, to support SETUID
144+
let home_env = std::env::var("HOME").unwrap_or_else(|_| ".".to_string());
145+
return PathBuf::from(format!("{}/.config/bootit.yaml", home_env));
146+
}
134147
}

0 commit comments

Comments
 (0)