49 lines
1.0 KiB
Rust
49 lines
1.0 KiB
Rust
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<Path>) -> Self {
|
|
Self {
|
|
path: path.as_ref().to_owned(),
|
|
kind: GameType::default(),
|
|
}
|
|
}
|
|
|
|
pub fn export_links(&self) -> Result<HashSet<Link>, io::Error> {
|
|
let links: HashSet<Link> = 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
|
|
}
|
|
}
|