From 1c798dbcae0c130f21efed9006a4f540d2dcf0a9 Mon Sep 17 00:00:00 2001 From: Michael Pfaff Date: Fri, 10 Jun 2022 13:52:44 -0400 Subject: [PATCH] Hopefully fix desktop path resolution --- Cargo.lock | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/main.rs | 12 +++++++++++- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf70c62..b35f783 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,6 +135,26 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "encoding_rs" version = "0.8.31" @@ -223,6 +243,17 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "getrandom" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", +] + [[package]] name = "gimli" version = "0.26.1" @@ -510,7 +541,7 @@ checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" dependencies = [ "libc", "log", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys", ] @@ -711,6 +742,17 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall", + "thiserror", +] + [[package]] name = "regex" version = "1.5.6" @@ -799,6 +841,7 @@ dependencies = [ name = "school-computer-toolkit" version = "0.1.0" dependencies = [ + "dirs", "miette", "ramhorns", "reqwest", @@ -1184,6 +1227,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 427879a..5569dc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +dirs = "4" miette = { version = "4.7", features = [ "fancy" ] } ramhorns = "0.14" reqwest = { version = "0.11.10", features = [ "json" ] } diff --git a/src/main.rs b/src/main.rs index 370949b..9a1aa2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,13 @@ pub fn swtools_path() -> &'static Path { } pub fn desktop_path() -> PathBuf { - Path::new("H:\\Profile\\Desktop").to_owned() + let mut dir = dirs::home_dir() + .expect("Could not find your home directory.") + .join("Desktop"); + if !dir.exists() { + dir = Path::new("H:\\Profile\\Desktop").to_owned(); + } + dir } pub struct Context { @@ -38,6 +44,10 @@ async fn main() -> Result<()> { bail!("Could not find or access {}", SWTOOLS_PATH); } + if !desktop_path().exists() { + bail!("Could not find your desktop directory."); + } + let nppp_zip = swtools_path().join("temp").join("notepad-plus-plus.zip"); let nppp_dir = swtools_path().join("notepad-plus-plus");