1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
pub mod add;
pub mod config;
pub mod file_picker;
pub mod modpack;
pub mod scan;
pub mod upgrade;
pub mod version_ext;

pub use add::add;
pub use scan::scan;

use once_cell::sync::Lazy;
use std::path::PathBuf;
use tokio::io::{AsyncReadExt, Result};

pub static HOME: Lazy<PathBuf> =
    Lazy::new(|| home::home_dir().expect("Could not get user's home directory"));

/// Get the default Minecraft instance directory based on the current compilation `target_os`.
/// If the `target_os` doesn't match `"macos"`, `"linux"`, or `"windows"`, this function will not compile.
pub fn get_minecraft_dir() -> PathBuf {
    #[cfg(target_os = "windows")]
    return HOME.join("AppData").join("Roaming").join(".minecraft");

    #[cfg(target_os = "macos")]
    return HOME
        .join("Library")
        .join("Application Support")
        .join("minecraft");

    #[cfg(target_os = "linux")]
    return HOME.join(".minecraft");
}

/// Read `source` and return the data as a string
///
/// A wrapper for dealing with the read buffer.
pub async fn read_wrapper(mut source: impl AsyncReadExt + Unpin) -> Result<String> {
    let mut buffer = String::new();
    source.read_to_string(&mut buffer).await?;
    Ok(buffer)
}

pub struct APIs<'a> {
    pub mr: &'a ferinth::Ferinth,
    pub cf: &'a furse::Furse,
    pub gh: &'a octocrab::Octocrab,
}

impl<'a> APIs<'a> {
    pub fn new(mr: &'a ferinth::Ferinth, cf: &'a furse::Furse, gh: &'a octocrab::Octocrab) -> Self {
        Self { mr, cf, gh }
    }
}