Create shortcuts
This commit is contained in:
parent
41f06ef557
commit
ba5a8ac31b
|
@ -6,7 +6,8 @@ use tokio::io::AsyncWriteExt;
|
|||
|
||||
use crate::Context;
|
||||
|
||||
const USER_AGENT_STR: &'static str = "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0";
|
||||
const USER_AGENT_STR: &'static str =
|
||||
"Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0";
|
||||
|
||||
/// A sequential pipeline of [`Step`]s.
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -62,9 +63,6 @@ pub enum Step<'a> {
|
|||
/// Target of the shortcut (i.e. what is points to).
|
||||
target: ShortcutTarget<'a>,
|
||||
|
||||
/// Optional icon of the shortcut.
|
||||
icon: Option<Cow<'a, Path>>,
|
||||
|
||||
/// Path of the created shortcut file.
|
||||
file: Cow<'a, Path>,
|
||||
},
|
||||
|
@ -174,7 +172,7 @@ impl<'a> Step<'a> {
|
|||
.wrap_err(EXECUTE_COMMAND_ERROR_MSG)?;
|
||||
ensure!(status.success(), EXECUTE_COMMAND_ERROR_MSG);
|
||||
}
|
||||
Self::CreateShortcut { target, icon, file } => {
|
||||
Self::CreateShortcut { target, file } => {
|
||||
const CREATE_SHORTCUT_ERROR_MSG: &'static str = "Creating shortcut failed.";
|
||||
mkdir_all(
|
||||
file.parent().ok_or_else(|| {
|
||||
|
@ -338,7 +336,9 @@ async fn fetch_latest_release<'a, 'b>(
|
|||
.await
|
||||
.into_diagnostic()
|
||||
.wrap_err(FETCH_META_ERROR_MSG)?;
|
||||
let body = resp.text().await
|
||||
let body = resp
|
||||
.text()
|
||||
.await
|
||||
.into_diagnostic()
|
||||
.wrap_err(FETCH_META_ERROR_MSG)?;
|
||||
let release: GitHubRelease = serde_json::from_str(&body)
|
||||
|
|
70
src/main.rs
70
src/main.rs
|
@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use miette::{IntoDiagnostic, Result, WrapErr};
|
||||
|
||||
use install::{Pipeline, RemoteResource, Step};
|
||||
use install::{Pipeline, RemoteResource, ShortcutTarget, Step};
|
||||
|
||||
const SWTOOLS_PATH: &'static str = "C:\\SWTools";
|
||||
|
||||
|
@ -18,6 +18,10 @@ pub fn swtools_path() -> &'static Path {
|
|||
Path::new(SWTOOLS_PATH)
|
||||
}
|
||||
|
||||
pub fn desktop_path() -> PathBuf {
|
||||
Path::new("H:\\Profile\\Desktop").to_owned()
|
||||
}
|
||||
|
||||
pub struct Context {
|
||||
pub reqwest: reqwest::Client,
|
||||
}
|
||||
|
@ -35,7 +39,12 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
|
||||
let nppp_zip = swtools_path().join("temp").join("notepad-plus-plus.zip");
|
||||
let nppp_dir = swtools_path().join("notepad-plus-plus");
|
||||
|
||||
let epp_zip = swtools_path().join("temp").join("explorer-plus-plus.zip");
|
||||
let epp_dir = swtools_path().join("explorer-plus-plus");
|
||||
|
||||
let minecraft_dir = swtools_path().join("minecraft");
|
||||
|
||||
let utilities = [
|
||||
Pipeline::new(
|
||||
|
@ -50,7 +59,15 @@ async fn main() -> Result<()> {
|
|||
},
|
||||
Step::ExtractFile {
|
||||
file: nppp_zip.as_path().into(),
|
||||
dest: swtools_path().join("notepad-plus-plus").into(),
|
||||
dest: nppp_dir.as_path().into(),
|
||||
},
|
||||
Step::CreateShortcut {
|
||||
target: ShortcutTarget::Executable {
|
||||
file: nppp_dir.join("notepad++.exe").into(),
|
||||
|
||||
args: &[],
|
||||
},
|
||||
file: desktop_path().join("Notepad++.lnk").into(),
|
||||
},
|
||||
],
|
||||
),
|
||||
|
@ -65,18 +82,53 @@ async fn main() -> Result<()> {
|
|||
},
|
||||
Step::ExtractFile {
|
||||
file: epp_zip.as_path().into(),
|
||||
dest: swtools_path().join("explorer-plus-plus").into(),
|
||||
dest: epp_dir.as_path().into(),
|
||||
},
|
||||
Step::CreateShortcut {
|
||||
target: ShortcutTarget::Executable {
|
||||
file: epp_dir.join("Explorer++.exe").into(),
|
||||
|
||||
args: &[],
|
||||
},
|
||||
file: desktop_path().join("Explorer++.lnk").into(),
|
||||
},
|
||||
],
|
||||
),
|
||||
Pipeline::new(
|
||||
"Install Minecraft (Java Edition)",
|
||||
vec![Step::DownloadFile {
|
||||
file: swtools_path()
|
||||
.join("minecraft")
|
||||
.join("Minecraft.exe")
|
||||
.into(),
|
||||
res: RemoteResource::Url("https://launcher.mojang.com/download/Minecraft.exe"),
|
||||
vec![
|
||||
Step::DownloadFile {
|
||||
file: minecraft_dir.join("Minecraft.exe").into(),
|
||||
res: RemoteResource::Url("https://launcher.mojang.com/download/Minecraft.exe"),
|
||||
},
|
||||
Step::CreateShortcut {
|
||||
target: ShortcutTarget::Executable {
|
||||
file: minecraft_dir.join("Minecraft.exe").into(),
|
||||
|
||||
args: &[],
|
||||
},
|
||||
file: desktop_path().join("Minecraft.lnk").into(),
|
||||
},
|
||||
],
|
||||
),
|
||||
Pipeline::new(
|
||||
"Create C:\\ Shortcut",
|
||||
vec![Step::CreateShortcut {
|
||||
target: ShortcutTarget::Path {
|
||||
path: Path::new("C:\\").into(),
|
||||
},
|
||||
file: desktop_path().join("OSDisk (C).lnk").into(),
|
||||
}],
|
||||
),
|
||||
Pipeline::new(
|
||||
"Create PowerShell Shortcut",
|
||||
vec![Step::CreateShortcut {
|
||||
target: ShortcutTarget::Executable {
|
||||
file: Path::new("C:\\WINDOWS\\system32\\cmd.exe").into(),
|
||||
|
||||
args: &["/C", "powershell"],
|
||||
},
|
||||
file: desktop_path().join("PowerShell.lnk").into(),
|
||||
}],
|
||||
),
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue