refactored linking game
This commit is contained in:
@@ -13,6 +13,7 @@ use crate::{
|
|||||||
utils::walk_files_recursive,
|
utils::walk_files_recursive,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// A link between a file from a mod and a destination in a ModdedInstance
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
|
||||||
#[serde(from = "(PathBuf, PathBuf)", into = "(PathBuf,PathBuf)")]
|
#[serde(from = "(PathBuf, PathBuf)", into = "(PathBuf,PathBuf)")]
|
||||||
pub struct Link {
|
pub struct Link {
|
||||||
@@ -106,13 +107,14 @@ pub struct Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Game {
|
impl Game {
|
||||||
// pub fn export_links(&self) -> Result<, io::Error> {
|
pub fn export_links(&self) -> Result<Vec<Link>, io::Error> {
|
||||||
// walk_files_recursive(&self.install_location)
|
let links: Vec<Link> = walk_files_recursive(&self.install_location)
|
||||||
// .unwrap()
|
.unwrap()
|
||||||
// .map(|file| file.path())
|
.map(|file| file.path())
|
||||||
// .map(|path| ());
|
.map(|path| Link::new(&path, path.strip_prefix(&self.install_location).unwrap()))
|
||||||
// todo!()
|
.collect();
|
||||||
// }
|
Ok(links)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
basic_types::{ModdedInstance, RootConfig},
|
basic_types::{Game, Link, ModdedInstance, RootConfig},
|
||||||
utils::walk_files_recursive,
|
utils::walk_files_recursive,
|
||||||
};
|
};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
@@ -27,18 +27,12 @@ pub fn link_instance_to_target(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link_game_to_target(
|
pub fn link_game_to_target(game: &Game, target: impl AsRef<Path>) -> Result<(), io::Error> {
|
||||||
game_dir: impl AsRef<Path>,
|
for link in game.export_links()? {
|
||||||
target: impl AsRef<Path>,
|
link_file(&link.src, &target.as_ref().join(&link.dst))?;
|
||||||
) -> Result<(), io::Error> {
|
}
|
||||||
debug!("Linking install to {}", target.as_ref().to_string_lossy());
|
|
||||||
walk_files_recursive(&game_dir)?.try_for_each(|file| {
|
Ok(())
|
||||||
let link_target = file.path();
|
|
||||||
let link_name = target
|
|
||||||
.as_ref()
|
|
||||||
.join(file.path().strip_prefix(&game_dir).unwrap());
|
|
||||||
link_file(&link_target, &link_name)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn link_file(target: &Path, link_name: &Path) -> Result<(), io::Error> {
|
fn link_file(target: &Path, link_name: &Path) -> Result<(), io::Error> {
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ pub fn activate_instance(
|
|||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
let instance_config = root_config.load_instance_by_id(instance_id)?;
|
let instance_config = root_config.load_instance_by_id(instance_id)?;
|
||||||
|
|
||||||
link_game_to_target(&root_config.games.first().unwrap().install_location, target)?;
|
link_game_to_target(root_config.games.first().unwrap(), target)?;
|
||||||
link_instance_to_target(root_config, &instance_config, target)?;
|
link_instance_to_target(root_config, &instance_config, target)?;
|
||||||
create_plugins_txt(&instance_config, target)?;
|
create_plugins_txt(&instance_config, target)?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user