use std::{
ffi::OsString,
path::{Path, PathBuf},
};
use crate::keg_plist::KegPlist;
#[derive(Debug, Clone)]
pub struct Keg {
pub name: String,
pub config_file: PathBuf,
pub wineskin_launcher: OsString,
pub c_drive: PathBuf,
}
pub struct CurrentKeg {
pub name: String,
pub wineskin_launcher: OsString,
pub c_drive: PathBuf,
pub plist: KegPlist,
pub config_file: PathBuf,
}
impl Keg {
pub fn from_path(path: &Path) -> Self {
Self {
name: path
.file_name()
.expect("Missing Keg name")
.to_string_lossy()
.to_string(),
config_file: path.join("Contents/Info.plist"),
c_drive: path.join("Contents/drive_c"),
wineskin_launcher: path
.join("Contents/MacOS/wineskinLauncher")
.into_os_string(),
}
}
}
impl TryFrom<&Keg> for CurrentKeg {
type Error = plist::Error;
fn try_from(value: &Keg) -> Result<Self, Self::Error> {
Ok(Self {
name: value.name.clone(),
wineskin_launcher: value.wineskin_launcher.clone(),
c_drive: value.c_drive.clone(),
plist: plist::from_file(&value.config_file)?,
config_file: value.config_file.clone(),
})
}
}