Compare commits

...

2 commits

Author SHA1 Message Date
snow flurry 0a4a401953 VdfValue::into_vec: better error handling 2023-07-10 14:46:19 -07:00
snow flurry 3e6d025b74 explain get_steamdir 2023-07-10 14:34:25 -07:00
3 changed files with 5 additions and 3 deletions

View file

@ -149,6 +149,7 @@ fn get_shortcuts(path: PathBuf) -> Result<Vec<NonSteamGame>, String> {
let vec: Result<Vec<NonSteamGame>, String> = vdf_map["shortcuts"]
.clone()
.into_vec()
.map_or_else(|| Err("Malformed shortcuts.vdf".to_owned()), Ok)?
.into_iter()
.map(|x| {
if let vdf::VdfValue::Dict(dict) = x {

View file

@ -21,6 +21,7 @@ impl HeuristicError {
}
}
/// Gets the Steam local directory
pub fn get_steamdir() -> Result<PathBuf, Box<dyn std::error::Error>> {
let mut dir = dirs::data_local_dir().unwrap_or_else(|| {
let mut dir = dirs::home_dir().unwrap();

View file

@ -28,12 +28,12 @@ pub enum VdfValue {
}
impl VdfValue {
pub fn into_vec(self) -> Vec<VdfValue> {
pub fn into_vec(self) -> Option<Vec<VdfValue>> {
if let VdfValue::Dict(dict) = self {
// lazily assuming this is an array of strings
dict.into_values().collect()
Some(dict.into_values().collect())
} else {
panic!("Not a Dict! (maybe this should be less brutal of error mgmt!)");
None
}
}
}