use std::path::PathBuf;
use crate::{error::LocateError, Error, Result};
use winreg::{
enums::{HKEY_LOCAL_MACHINE, KEY_READ},
RegKey,
};
pub fn locate_steam_dir_helper() -> Result<PathBuf> {
let io_to_locate_err = |io_err| Error::locate(LocateError::winreg(io_err));
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let installation_regkey = hklm
.open_subkey_with_flags("SOFTWARE\\Wow6432Node\\Valve\\Steam", KEY_READ)
.or_else(|_| {
hklm.open_subkey_with_flags("SOFTWARE\\Valve\\Steam", KEY_READ)
})
.map_err(io_to_locate_err)?;
let install_path_str: String = installation_regkey
.get_value("InstallPath")
.map_err(io_to_locate_err)?;
let install_path = PathBuf::from(install_path_str);
Ok(install_path)
}