Create shortcuts
This commit is contained in:
parent
41f06ef557
commit
ba5a8ac31b
|
@ -6,7 +6,8 @@ use tokio::io::AsyncWriteExt;
|
||||||
|
|
||||||
use crate::Context;
|
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.
|
/// A sequential pipeline of [`Step`]s.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -62,9 +63,6 @@ pub enum Step<'a> {
|
||||||
/// Target of the shortcut (i.e. what is points to).
|
/// Target of the shortcut (i.e. what is points to).
|
||||||
target: ShortcutTarget<'a>,
|
target: ShortcutTarget<'a>,
|
||||||
|
|
||||||
/// Optional icon of the shortcut.
|
|
||||||
icon: Option<Cow<'a, Path>>,
|
|
||||||
|
|
||||||
/// Path of the created shortcut file.
|
/// Path of the created shortcut file.
|
||||||
file: Cow<'a, Path>,
|
file: Cow<'a, Path>,
|
||||||
},
|
},
|
||||||
|
@ -174,7 +172,7 @@ impl<'a> Step<'a> {
|
||||||
.wrap_err(EXECUTE_COMMAND_ERROR_MSG)?;
|
.wrap_err(EXECUTE_COMMAND_ERROR_MSG)?;
|
||||||
ensure!(status.success(), 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.";
|
const CREATE_SHORTCUT_ERROR_MSG: &'static str = "Creating shortcut failed.";
|
||||||
mkdir_all(
|
mkdir_all(
|
||||||
file.parent().ok_or_else(|| {
|
file.parent().ok_or_else(|| {
|
||||||
|
@ -338,7 +336,9 @@ async fn fetch_latest_release<'a, 'b>(
|
||||||
.await
|
.await
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
.wrap_err(FETCH_META_ERROR_MSG)?;
|
.wrap_err(FETCH_META_ERROR_MSG)?;
|
||||||
let body = resp.text().await
|
let body = resp
|
||||||
|
.text()
|
||||||
|
.await
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
.wrap_err(FETCH_META_ERROR_MSG)?;
|
.wrap_err(FETCH_META_ERROR_MSG)?;
|
||||||
let release: GitHubRelease = serde_json::from_str(&body)
|
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 miette::{IntoDiagnostic, Result, WrapErr};
|
||||||
|
|
||||||
use install::{Pipeline, RemoteResource, Step};
|
use install::{Pipeline, RemoteResource, ShortcutTarget, Step};
|
||||||
|
|
||||||
const SWTOOLS_PATH: &'static str = "C:\\SWTools";
|
const SWTOOLS_PATH: &'static str = "C:\\SWTools";
|
||||||
|
|
||||||
|
@ -18,6 +18,10 @@ pub fn swtools_path() -> &'static Path {
|
||||||
Path::new(SWTOOLS_PATH)
|
Path::new(SWTOOLS_PATH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn desktop_path() -> PathBuf {
|
||||||
|
Path::new("H:\\Profile\\Desktop").to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
pub reqwest: reqwest::Client,
|
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_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_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 = [
|
let utilities = [
|
||||||
Pipeline::new(
|
Pipeline::new(
|
||||||
|
@ -50,7 +59,15 @@ async fn main() -> Result<()> {
|
||||||
},
|
},
|
||||||
Step::ExtractFile {
|
Step::ExtractFile {
|
||||||
file: nppp_zip.as_path().into(),
|
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 {
|
Step::ExtractFile {
|
||||||
file: epp_zip.as_path().into(),
|
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(
|
Pipeline::new(
|
||||||
"Install Minecraft (Java Edition)",
|
"Install Minecraft (Java Edition)",
|
||||||
vec![Step::DownloadFile {
|
vec![
|
||||||
file: swtools_path()
|
Step::DownloadFile {
|
||||||
.join("minecraft")
|
file: minecraft_dir.join("Minecraft.exe").into(),
|
||||||
.join("Minecraft.exe")
|
res: RemoteResource::Url("https://launcher.mojang.com/download/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