electron_hook/
paths.rs

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
//! Path utilities

fn cache_dir() -> std::path::PathBuf {
    dirs::cache_dir()
        .expect("Failed to get cache directory")
        .join("electron-hook")
}

fn asar_cache_dir() -> std::path::PathBuf {
    ensure_dir(cache_dir().join("asar"))
}

/// The path to a specific .asar file
pub fn asar_cache_path(asar_id: &str) -> std::path::PathBuf {
    asar_cache_dir().join(format!("{asar_id}.asar"))
}

fn mod_artifacts_dir() -> std::path::PathBuf {
    ensure_dir(cache_dir().join("mods"))
}

/// The path to a specific mod artifact folder
pub fn mod_artifact_dir(mod_name: &str) -> std::path::PathBuf {
    mod_artifacts_dir().join(mod_name)
}

fn data_dir() -> std::path::PathBuf {
    dirs::data_dir()
        .expect("Failed to get data directory")
        .join("electron-hook")
}

fn data_profiles_dir() -> std::path::PathBuf {
    ensure_dir(data_dir().join("profiles"))
}

/// The path to a specific profile directory
pub fn data_profile_dir(profile_id: &str) -> std::path::PathBuf {
    data_profiles_dir().join(profile_id)
}

/// Ensure a directory exists, recursively creating it if it doesn't
pub fn ensure_dir(path: std::path::PathBuf) -> std::path::PathBuf {
    if !path.exists() {
        std::fs::create_dir_all(&path)
            .map_err(|e| format!("Failed to create directory: {e}"))
            .unwrap();
    }
    path
}