use minecraft_folder_path

This commit is contained in:
mat 2023-12-06 23:23:18 -06:00
parent 3f341aa114
commit 98f2c54c26
5 changed files with 10 additions and 65 deletions

7
Cargo.lock generated
View file

@ -300,6 +300,7 @@ dependencies = [
"bevy_time",
"derive_more",
"futures",
"minecraft_folder_path",
"nohash-hasher",
"once_cell",
"parking_lot",
@ -1704,6 +1705,12 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "minecraft_folder_path"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b886139d261301cf5f8c1c41b915ce66fe1de5d601e05d02ccaac079b48375"
[[package]]
name = "miniz_oxide"
version = "0.7.1"

View file

@ -42,6 +42,7 @@ uuid = "^1.6.1"
azalea-entity = { version = "0.9.0", path = "../azalea-entity" }
serde_json = "1.0.108"
serde = "1.0.193"
minecraft_folder_path = "0.1.1"
[features]
default = ["log"]

View file

@ -2,7 +2,6 @@
use std::sync::Arc;
use crate::get_mc_dir;
use azalea_auth::certs::{Certificates, FetchCertificatesError};
use azalea_auth::AccessTokenResponse;
use bevy_ecs::component::Component;
@ -91,10 +90,10 @@ impl Account {
/// a key for the cache, but it's recommended to use the real email to
/// avoid confusion.
pub async fn microsoft(email: &str) -> Result<Self, azalea_auth::AuthError> {
let minecraft_dir = get_mc_dir::minecraft_dir().unwrap_or_else(|| {
let minecraft_dir = minecraft_folder_path::minecraft_dir().unwrap_or_else(|| {
panic!(
"No {} environment variable found",
get_mc_dir::home_env_var()
minecraft_folder_path::home_env_var()
)
});
let auth_result = azalea_auth::auth(

View file

@ -1,61 +0,0 @@
//! Find out where the user's .minecraft directory is.
//!
//! Used for the auth cache.
use std::path::PathBuf;
/// Return the location of the user's .minecraft directory.
///
/// Windows: `%appdata%\.minecraft`\
/// Mac: `$HOME/Library/Application Support/minecraft`\
/// Linux: `$HOME/.minecraft`
///
/// If the environment variable is not set, this will return `None`.
pub fn minecraft_dir() -> Option<PathBuf> {
let env_var = home_env_var();
let home = std::env::var(env_var).ok()?;
let path = PathBuf::from(home).join(minecraft_dir_relative());
Some(path)
}
/// Return the name of the environment variable that's used for the home folder
/// on the user's operating system.
pub fn home_env_var() -> &'static str {
#[cfg(target_os = "windows")]
{
"APPDATA"
}
#[cfg(target_os = "macos")]
{
"HOME"
}
#[cfg(target_os = "linux")]
{
"HOME"
}
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
{
"HOME"
}
}
/// Return the path relative to the home folder where we expect to find the
/// .minecraft directory.
pub fn minecraft_dir_relative() -> &'static str {
#[cfg(target_os = "windows")]
{
".minecraft"
}
#[cfg(target_os = "macos")]
{
"Library/Application Support/minecraft"
}
#[cfg(target_os = "linux")]
{
".minecraft"
}
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
{
".minecraft"
}
}

View file

@ -16,7 +16,6 @@ mod client;
pub mod disconnect;
mod entity_query;
mod events;
mod get_mc_dir;
pub mod interact;
pub mod inventory;
mod local_player;