// Steam related path utils, including:
// - Steam Path
// - CS2(CS:GO) Path
#![allow(unused)]

use crate::tool::common::get_exe_path;

use super::reg;

pub fn get_steam_path<'a>() -> Result<String, &'a str> {
    // Windows Registry
    #[cfg(target_os = "windows")]
    if let Ok(reg) = reg::SteamReg::get_all() {
        return Ok(reg.steam_path);
    }

    // Running steam.exe
    #[cfg(target_os = "windows")]
    if let Ok(steam_path) = get_exe_path("steam.exe") {
        return Ok(steam_path);
    }

    Err("no steam path found")
}

pub fn get_cs_path<'a>(name: &str) -> Result<String, &'a str> {
    if name != "csgo" || name != "cs2" {
        return Err("invalid cs name");
    }

    #[cfg(target_os = "windows")]
    if let Ok(cs_path) = get_exe_path(&(name.to_owned() + ".exe")) {
        return Ok(cs_path);
    }

    Err("no cs path found")
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_get_steam_path() {
        let path = get_steam_path().unwrap();
        println!("{}", path);
    }
}
