From 551767de7a98714ed2ec1010663bbe932408731d Mon Sep 17 00:00:00 2001 From: Cosmic Horror Date: Sun, 8 Sep 2024 00:09:27 -0600 Subject: [PATCH] refactor: Replace `dirs` with `home` --- Cargo.lock | 1 + Cargo.toml | 8 ++++++-- src/locate.rs | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8dab8fd..887068e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -334,6 +334,7 @@ dependencies = [ "keyvalues-parser", "keyvalues-serde", "serde", + "serde_derive", "wasm-bindgen-test", "winreg", ] diff --git a/Cargo.toml b/Cargo.toml index bf0b79a..b2727e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,12 @@ serde = { version = "1.0.0", features = ["derive"] } # Platform-specific dependencies used for locating the steam dir [target."cfg(target_os=\"windows\")".dependencies] locate_backend = { package = "winreg", version = "0.51", optional = true } -[target."cfg(not(target_os=\"windows\"))".dependencies] -locate_backend = { package = "dirs", version = "5", optional = true } +[target."cfg(any(target_os=\"macos\", target_os=\"linux\"))".dependencies] +locate_backend = { package = "home", version = "0.5.9", optional = true } +# Other platforms aren't supported for locating, so we use a dummy package that +# we already depend on since it won't be used for anything +[target."cfg(not(any(target_os=\"windows\", target_os=\"macos\", target_os=\"linux\")))".dependencies] +locate_backend = { package = "serde_derive", version = "1.0.0", optional = true } [dev-dependencies] insta = { version = "1.34.0", features = ["ron"] } diff --git a/src/locate.rs b/src/locate.rs index 318fad1..de6ecc7 100644 --- a/src/locate.rs +++ b/src/locate.rs @@ -49,10 +49,10 @@ fn locate_steam_dir_helper() -> Result { #[cfg(target_os = "macos")] fn locate_steam_dir_helper() -> Result { use crate::{error::LocateError, Error}; - use locate_backend as dirs; + use locate_backend as home; // Steam's installation location is pretty easy to find on macOS, as it's always in // $USER/Library/Application Support - let home_dir = dirs::home_dir().ok_or_else(|| Error::locate(LocateError::no_home()))?; + let home_dir = home::home_dir().ok_or_else(|| Error::locate(LocateError::no_home()))?; // Find Library/Application Support/Steam let install_path = home_dir.join("Library/Application Support/Steam"); @@ -65,10 +65,10 @@ fn locate_steam_dir_helper() -> Result { use crate::error::{Error, LocateError, ValidationError}; - use locate_backend as dirs; + use locate_backend as home; // Steam's installation location is pretty easy to find on Linux, too, thanks to the symlink in $USER - let home_dir = dirs::home_dir().ok_or_else(|| Error::locate(LocateError::no_home()))?; + let home_dir = home::home_dir().ok_or_else(|| Error::locate(LocateError::no_home()))?; let snap_dir = match env::var("SNAP_USER_DATA") { Ok(snap_dir) => PathBuf::from(snap_dir), Err(_) => home_dir.join("snap"),