Skip to content

Commit

Permalink
refactor: Replace dirs with home
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev committed Sep 8, 2024
1 parent 94c7ca5 commit 551767d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
8 changes: 4 additions & 4 deletions src/locate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ fn locate_steam_dir_helper() -> Result<PathBuf> {
#[cfg(target_os = "macos")]
fn locate_steam_dir_helper() -> Result<PathBuf> {
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");
Expand All @@ -65,10 +65,10 @@ fn locate_steam_dir_helper() -> Result<PathBuf> {

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"),
Expand Down

0 comments on commit 551767d

Please sign in to comment.