Simplify shortcut args

This commit is contained in:
Michael Pfaff 2022-06-10 13:05:12 -04:00
parent ba5a8ac31b
commit 3e7149f880
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
2 changed files with 6 additions and 15 deletions

View File

@ -194,18 +194,9 @@ impl<'a> Step<'a> {
}
ShortcutTarget::Executable { file: exec_file, args } => {
use std::fmt::Write;
let mut args_str = String::new();
let mut args = args.into_iter();
if let Some(arg) = args.next() {
// TODO: quote properly
write!(args_str, "{:?}", arg).unwrap();
}
for arg in args {
write!(args_str, " {:?}", arg).unwrap();
}
tokio::process::Command::new("powershell")
.arg("-Command")
.arg(format!(r#"$shell = New-Object -ComObject WScript.Shell; $shortcut = $shell.CreateShortcut({file:?}); $shortcut.TargetPath = {exec_file:?}; $shortcut.Arguments = {args_str:?}; $shortcut.Save()"#))
.arg(format!(r#"$shell = New-Object -ComObject WScript.Shell; $shortcut = $shell.CreateShortcut({file:?}); $shortcut.TargetPath = {exec_file:?}; $shortcut.Arguments = {args:?}; $shortcut.Save()"#))
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
@ -249,7 +240,7 @@ pub enum ShortcutTarget<'a> {
file: Cow<'a, Path>,
/// Arguments to the executable.
args: &'a [&'a str],
args: &'a str,
},
/// A file or folder shortcut. Please use [`Self::Executable`] for shortcuts to binaries.

View File

@ -65,7 +65,7 @@ async fn main() -> Result<()> {
target: ShortcutTarget::Executable {
file: nppp_dir.join("notepad++.exe").into(),
args: &[],
args: "",
},
file: desktop_path().join("Notepad++.lnk").into(),
},
@ -88,7 +88,7 @@ async fn main() -> Result<()> {
target: ShortcutTarget::Executable {
file: epp_dir.join("Explorer++.exe").into(),
args: &[],
args: "",
},
file: desktop_path().join("Explorer++.lnk").into(),
},
@ -105,7 +105,7 @@ async fn main() -> Result<()> {
target: ShortcutTarget::Executable {
file: minecraft_dir.join("Minecraft.exe").into(),
args: &[],
args: "",
},
file: desktop_path().join("Minecraft.lnk").into(),
},
@ -126,7 +126,7 @@ async fn main() -> Result<()> {
target: ShortcutTarget::Executable {
file: Path::new("C:\\WINDOWS\\system32\\cmd.exe").into(),
args: &["/C", "powershell"],
args: "/C powershell",
},
file: desktop_path().join("PowerShell.lnk").into(),
}],