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
/*!
 Contains functions that generate the correct path to the default iMessage database location.
*/

use std::env::var;

use crate::tables::table::DEFAULT_PATH;

/// Get the user's home directory (MacOS only)
///
/// # Example:
///
/// ```
/// use imessage_database::util::dirs::home;
///
/// let path = home();
/// println!("{path}");
/// ```
pub fn home() -> String {
    match var("HOME") {
        Ok(path) => path,
        Err(why) => panic!("Unable to resolve user home directory: {why}"),
    }
}

/// Get the default path the iMessage database is located at
///
/// # Example:
///
/// ```
/// use imessage_database::util::dirs::default_db_path;
///
/// let path = default_db_path();
/// println!("{path}");
/// ```
pub fn default_db_path() -> String {
    format!("{}/{DEFAULT_PATH}", home())
}