the great refactor
This commit is contained in:
33
src/types/game.rs
Normal file
33
src/types/game.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use std::{
|
||||
io,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{types::link::Link, utils::walk_all_files};
|
||||
|
||||
/// Available game
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||
pub struct Game {
|
||||
install_location: PathBuf,
|
||||
}
|
||||
|
||||
impl Game {
|
||||
pub fn export_links(&self) -> Result<Vec<Link>, io::Error> {
|
||||
let links: Vec<Link> = walk_all_files(&self.install_location)?
|
||||
.map(|entry| {
|
||||
Link::new(
|
||||
entry.path(),
|
||||
entry.path().strip_prefix(&self.install_location).unwrap(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(links)
|
||||
}
|
||||
|
||||
pub fn install_location(&self) -> &Path {
|
||||
&self.install_location
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user