use std::{ collections::HashSet, io, path::{Path, PathBuf}, }; use serde::{Deserialize, Serialize}; use crate::{ types::{GameType, link::Link}, utils::walk_all_files, }; /// Available game #[derive(Debug, Clone, Deserialize, Serialize)] pub struct Game { path: PathBuf, kind: GameType, } impl Game { pub fn new(path: impl AsRef) -> Self { Self { path: path.as_ref().to_owned(), kind: GameType::default(), } } pub fn export_links(&self) -> Result, io::Error> { let links: HashSet = walk_all_files(&self.path)? .map(|entry| { Link::new( entry.path(), entry .path() .strip_prefix(&self.path) .expect("Can't transform path back to relative. Should not happen."), ) }) .collect(); Ok(links) } pub fn install_location(&self) -> &Path { &self.path } }