diff --git a/Cargo.lock b/Cargo.lock index 14989b73..b547015b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -943,6 +943,19 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "parselnk" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d098204d9ef47f80312460c1555a152972ea9f0a67487a77b2ab7e03fd510d4f" +dependencies = [ + "bitflags 1.2.1", + "byteorder", + "chrono", + "thiserror", + "widestring", +] + [[package]] name = "percent-encoding" version = "2.1.0" @@ -1700,6 +1713,7 @@ dependencies = [ "nix", "notify-rust", "openssl-probe", + "parselnk", "pretty_env_logger", "regex", "rust-ini", @@ -1958,6 +1972,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "widestring" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index b80fba44..13b7a985 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,7 @@ self_update_crate = { version = "0.23.0", optional = true, package = "self_upda [target.'cfg(windows)'.dependencies] self_update_crate = { version = "0.23.0", optional = true, package = "self_update", features = ["archive-zip", "compression-zip-deflate"] } winapi = "0.3.9" +parselnk = "0.1" [target.'cfg(target_os = "linux")'.dependencies] rust-ini = "0.16.0" diff --git a/src/main.rs b/src/main.rs index bca6f2af..e506b55c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -222,6 +222,9 @@ fn run() -> Result<()> { .join("Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState"), ); + #[cfg(windows)] + windows::insert_startup_scripts(&ctx, &mut git_repos).ok(); + if let Some(profile) = powershell.profile() { git_repos.insert_if_repo(profile); } diff --git a/src/steps/os/windows.rs b/src/steps/os/windows.rs index dacc3f77..e7bee518 100644 --- a/src/steps/os/windows.rs +++ b/src/steps/os/windows.rs @@ -1,11 +1,14 @@ -use crate::error::SkipStep; use crate::execution_context::ExecutionContext; use crate::executor::{CommandExt, RunType}; use crate::powershell; use crate::terminal::print_separator; use crate::utils::require; +use crate::{error::SkipStep, steps::git::Repositories}; use anyhow::Result; -use std::process::Command; +use log::debug; +use std::convert::TryFrom; +use std::path::Path; +use std::{ffi::OsStr, process::Command}; pub fn run_chocolatey(ctx: &ExecutionContext) -> Result<()> { let choco = require("choco")?; @@ -85,3 +88,25 @@ pub fn windows_update(ctx: &ExecutionContext) -> Result<()> { pub fn reboot() { Command::new("shutdown").args(&["/R", "/T", "0"]).spawn().ok(); } + +pub fn insert_startup_scripts(ctx: &ExecutionContext, git_repos: &mut Repositories) -> Result<()> { + let startup_dir = ctx + .base_dirs() + .data_dir() + .join("Microsoft\\Windows\\Start Menu\\Programs\\Startup"); + for entry in std::fs::read_dir(&startup_dir)? { + if let Ok(entry) = entry { + let path = entry.path(); + if path.extension().and_then(OsStr::to_str) == Some("lnk") { + if let Ok(lnk) = parselnk::Lnk::try_from(Path::new(&path)) { + debug!("Startup link: {:?}", lnk); + if let Some(path) = lnk.relative_path() { + git_repos.insert_if_repo(&startup_dir.join(path)); + } + } + } + } + } + + Ok(()) +}