Skip to content

Commit

Permalink
✨ Support for disabling mods
Browse files Browse the repository at this point in the history
  • Loading branch information
mleduque committed Jun 13, 2024
1 parent c6e00ef commit 938eed3
Show file tree
Hide file tree
Showing 16 changed files with 753 additions and 26 deletions.
2 changes: 1 addition & 1 deletion modda-cli/src/subcommands/config_edit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

use std::fs::OpenOptions;
use std::path::PathBuf;
use std::io::{BufWriter, Result as IoResult, Write};
use std::io::{Result as IoResult, Write};

use anyhow::{bail, Result};
use handlebars::Handlebars;
Expand Down
1 change: 1 addition & 0 deletions modda-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ void = "1.0.2"
faux = "0.1.10"
function_name = "0.3.0"
env_logger = "0.11.3"
temp-env = "0.3.6"
8 changes: 8 additions & 0 deletions modda-lib/resources/test/disable/example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

my_key_1 = true
my_key_2=false
my_key_3 = true; I don't want this
my_key_4 = false ; but this one is ok
my_key_5 = false ; this one is kept
my_key_5 = true ; this one is ignored
my_key_6 = invalid
1 change: 1 addition & 0 deletions modda-lib/resources/test/disable/subdir/example2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my_key = true
6 changes: 3 additions & 3 deletions modda-lib/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ pub struct Install {
}

impl Install {
pub fn get_manifest_root(&self, game_dir: &CanonPath) -> PathBuf {
pub fn get_manifest_root(&self, game_dir: &CanonPath) -> CanonPath {
let manifest = PathBuf::from(&self.manifest_path);
match manifest.parent() {
None => PathBuf::from(game_dir),
Some(path) => PathBuf::from(path),
None => game_dir.to_owned(),
Some(path) => CanonPath::new(path).unwrap_or_else(|_| game_dir.to_owned()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion modda-lib/src/canon_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{fmt::Debug, path::{Path, PathBuf}, ffi::OsStr};
use anyhow::Result;
use path_absolutize::*;

#[derive(PartialEq)]
#[derive(PartialEq, Clone)]
pub struct CanonPath (PathBuf);
impl CanonPath {
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self> { Ok(Self((path.as_ref().absolutize()?).into_owned())) }
Expand Down
5 changes: 3 additions & 2 deletions modda-lib/src/file_installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl <'a> FileInstaller<'a> {
}

fn get_local_base_path(&self, file_path: &String) -> Result<PathBuf, anyhow::Error> {
let manifest_path = self.opts.get_manifest_root(self.game_dir).clean();
let manifest_path = self.opts.get_manifest_root(self.game_dir);
let local_files = match &self.global.local_files {
None => PathBuf::new(),
Some(path) => PathBuf::from(path).clean(),
Expand All @@ -66,7 +66,8 @@ impl <'a> FileInstaller<'a> {
if file_path.is_absolute() || local_files.starts_with("..") {
bail!("Invalid local value");
}
Ok(manifest_path.join(local_files).join(file_path))
let relative_path = local_files.join(file_path);
Ok(manifest_path.join(relative_path)?.to_path_buf())
}

fn copy_from_globs(&self, globs: &[CopyGlob], target: &PathBuf, allow_overwrite: bool) -> Result<()> {
Expand Down
6 changes: 2 additions & 4 deletions modda-lib/src/get_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl <'a> ModuleDownload<'a> {
}

fn get_local_mod_path(&self, local_mod_name: &String) -> Result<PathBuf, anyhow::Error> {
let manifest_path = self.opts.get_manifest_root(self.game_dir).clean();
let manifest_path = self.opts.get_manifest_root(self.game_dir);
let local_mods = match &self.global.local_mods {
None => PathBuf::new(),
Some(path) => PathBuf::from(path).clean(),
Expand All @@ -121,7 +121,7 @@ impl <'a> ModuleDownload<'a> {
if mod_name.is_absolute() || local_mods.starts_with("..") {
bail!("Invalid local value");
}
Ok(manifest_path.join(local_mods).join(mod_name))
Ok(manifest_path.join(local_mods)?.join(mod_name)?.to_path_buf())
}
}

Expand Down Expand Up @@ -149,8 +149,6 @@ mod test_retrieve_location {
use crate::get_module::ModuleDownload;
use crate::lowercase::lwc;
use crate::module::global_locations::GlobalLocations;
use crate::module::location::github::Github;
use crate::module::location::github::GithubDescriptor::Release;
use crate::module::location::http::Http;
use crate::module::location::{ConcreteLocation, Location};
use crate::module::location::source::Source;
Expand Down
Loading

0 comments on commit 938eed3

Please sign in to comment.