Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modda-cli/src/subcommands/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use modda_lib::tp2::find_tp2_str;


pub fn reset(args: &Reset, weidu_context: &WeiduContext) -> Result<()> {
let installed = extract_bare_mods()?;
let installed = extract_bare_mods(weidu_context.current_dir)?;
let manifest = Manifest::read_path(&args.manifest_path,)?;

let reset_index = args.to_index;
Expand Down
3 changes: 3 additions & 0 deletions modda-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ tempfile = "3.10.1"
url = "2.5.0"
zip = "4.3.0"
void = "1.0.2"
ignore = "0.4.25"
walkdir = "2.5.0"
globset = "0.4.18"

[dev-dependencies]
faux = "0.1.10"
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions modda-lib/resources/test/file_lookup/MiXed/Mod1/File1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text
5 changes: 5 additions & 0 deletions modda-lib/resources/test/file_lookup/MiXed/WeiDu.Log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Log of Currently Installed WeiDU Mods
// The top of the file is the 'oldest' mod
// ~TP2_File~ #language_number #component_number // [Subcomponent Name -> ] Component Name [ : Version]
// Recently Uninstalled: ~DLCMERGER/DLCMERGER.TP2~ #0 #1 // Merge DLC into game -> Merge "Siege of Dragonspear" DLC: 1.7
~DLCMERGER/DLCMERGER.TP2~ #0 #1 // Merge DLC into game -> Merge "Siege of Dragonspear" DLC: 1.7
1 change: 1 addition & 0 deletions modda-lib/resources/test/file_lookup/MiXed/WeiDu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lang_dir = fr_fr
Binary file not shown.
1 change: 1 addition & 0 deletions modda-lib/resources/test/file_lookup/UPPER/MOD1/FILE1.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text
1 change: 1 addition & 0 deletions modda-lib/resources/test/file_lookup/UPPER/WEIDU.CONF
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lang_dir = fr_fr
5 changes: 5 additions & 0 deletions modda-lib/resources/test/file_lookup/UPPER/WEIDU.LOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Log of Currently Installed WeiDU Mods
// The top of the file is the 'oldest' mod
// ~TP2_File~ #language_number #component_number // [Subcomponent Name -> ] Component Name [ : Version]
// Recently Uninstalled: ~DLCMERGER/DLCMERGER.TP2~ #0 #1 // Merge DLC into game -> Merge "Siege of Dragonspear" DLC: 1.7
~DLCMERGER/DLCMERGER.TP2~ #0 #1 // Merge DLC into game -> Merge "Siege of Dragonspear" DLC: 1.7
Binary file not shown.
1 change: 1 addition & 0 deletions modda-lib/resources/test/file_lookup/lower/mod1/file1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text
1 change: 1 addition & 0 deletions modda-lib/resources/test/file_lookup/lower/weidu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lang_dir = fr_fr
5 changes: 5 additions & 0 deletions modda-lib/resources/test/file_lookup/lower/weidu.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Log of Currently Installed WeiDU Mods
// The top of the file is the 'oldest' mod
// ~TP2_File~ #language_number #component_number // [Subcomponent Name -> ] Component Name [ : Version]
// Recently Uninstalled: ~DLCMERGER/DLCMERGER.TP2~ #0 #1 // Merge DLC into game -> Merge "Siege of Dragonspear" DLC: 1.7
~DLCMERGER/DLCMERGER.TP2~ #0 #1 // Merge DLC into game -> Merge "Siege of Dragonspear" DLC: 1.7
1 change: 1 addition & 0 deletions modda-lib/resources/test/file_lookup/multiple/File2.Txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text
1 change: 1 addition & 0 deletions modda-lib/resources/test/file_lookup/multiple/File2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text
1 change: 1 addition & 0 deletions modda-lib/resources/test/file_lookup/multiple/Mod1/File1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some data
1 change: 1 addition & 0 deletions modda-lib/resources/test/file_lookup/multiple/mod1/file1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some data
1 change: 1 addition & 0 deletions modda-lib/resources/test/file_lookup/multiple/mod2/file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some data
19 changes: 10 additions & 9 deletions modda-lib/src/log_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use lazy_static::lazy_static;
use log::{info, warn};
use regex::{Regex, RegexBuilder};

use crate::canon_path::CanonPath;
use crate::lowercase::LwcString;
use crate::module::components::Components;
use crate::module::module::Module;
Expand All @@ -32,8 +33,8 @@ lazy_static! {
.case_insensitive(true).build().unwrap();
}

pub fn parse_weidu_log(mod_filter: Option<&LwcString>) -> Result<Vec<LogRow>> {
let weidu_log_path = match find_insensitive(".", "weidu.log") {
pub fn parse_weidu_log(game_dir: &CanonPath,mod_filter: Option<&LwcString>) -> Result<Vec<LogRow>> {
let weidu_log_path = match find_insensitive(game_dir, "weidu.log") {
Ok(None) =>return Ok(vec![]),
Ok(Some(path)) => path,
Err(error) => bail!("could not find weidu.log file\n {:?}", error)
Expand Down Expand Up @@ -91,29 +92,29 @@ pub fn parse_weidu_log(mod_filter: Option<&LwcString>) -> Result<Vec<LogRow>> {
result
}

pub fn check_install_complete(module: &Module) -> Result<()> {
pub fn check_install_complete(game_dir: &CanonPath, module: &Module) -> Result<()> {
match module {
Module::Mod { weidu_mod } => check_install_weidu_mod(weidu_mod),
Module::Generated { generated } => check_install_weidu_mod(&generated.as_weidu()),
Module::Mod { weidu_mod } => check_install_weidu_mod(game_dir, weidu_mod),
Module::Generated { generated } => check_install_weidu_mod(game_dir, &generated.as_weidu()),
}
}

fn check_install_weidu_mod(weidu_mod: &WeiduMod) -> Result<()> {
match check_installed_components(weidu_mod) {
fn check_install_weidu_mod(game_dir: &CanonPath, weidu_mod: &WeiduMod) -> Result<()> {
match check_installed_components(game_dir, weidu_mod) {
Err(err) => return Err(err),
Ok(missing) => if !missing.is_empty() {
bail!("All requested components for mod {} could not be installed.\nMissing: {:?}", weidu_mod.name , missing);
} else { Ok(()) }
}
}

fn check_installed_components(module: &WeiduMod) -> Result<Vec<u32>> {
fn check_installed_components(game_dir: &CanonPath, module: &WeiduMod) -> Result<Vec<u32>> {
match &module.components {
Components::None => Ok(vec![]),
Components::Ask => Ok(vec![]),
Components::All => Ok(vec![]),
Components::List(components) => {
let log_rows = match parse_weidu_log(Some(&module.name)) {
let log_rows = match parse_weidu_log(game_dir, Some(&module.name)) {
Ok(log_rows) => log_rows,
Err(err) => bail!("Could not check installed components\n -> {:?}", err),
};
Expand Down
2 changes: 1 addition & 1 deletion modda-lib/src/obtain/get_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ mod test_retrieve_location {
use crate::module::location::location::{ConcreteLocation, Location};
use crate::module::location::source::Source;
use crate::module::weidu_mod::WeiduMod;
use crate:: config::{Config, DefaultOptions};
use crate:: config::Config;
use crate::canon_path::CanonPath;
use crate::cache::Cache;
use crate::obtain::get_module::ModuleDownload;
Expand Down
13 changes: 9 additions & 4 deletions modda-lib/src/process_weidu_mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

use std::io::BufWriter;
use std::io::Write;
use std::path::Path;


use nu_ansi_term::Color;
Expand All @@ -26,6 +25,7 @@ use crate::tp2::find_tp2;
use crate::tp2_template::create_tp2;
use crate::run_weidu::run_weidu_install;
use crate::modda_context::ModdaContext;
use crate::utils::insensitive::find_insensitive;

pub struct ProcessResult {
pub was_disabled: bool,
Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn process_weidu_mod(weidu_mod: &WeiduMod, modda_context: &ModdaContext, man
return Err(error)
}
Ok(setup_log) => {
configure_module(weidu_mod)?;
configure_module(weidu_mod, modda_context)?;
SetupTimeline {
configured: Some(Local::now()),
..setup_log
Expand Down Expand Up @@ -185,9 +185,14 @@ fn fail_warnings(module: &WeiduMod, index: usize, total: usize) -> (String, Colo
(message, Red)
}

fn configure_module(module: &WeiduMod) -> Result<()> {
fn configure_module(module: &WeiduMod, modda_context: &ModdaContext) -> Result<()> {
if let Some(conf) = &module.add_conf {
let conf_path = Path::new(module.name.as_ref()).join(&conf.file_name);
let mod_dir = match find_insensitive(modda_context.current_dir, module.name.as_ref()) {
Ok(Some(path)) => path,
Ok(None) => bail!("Could not find mod directory {}", module.name),
Err(err) => bail!("Error looking for mod directory {} - {err:?}", module.name),
};
let conf_path = mod_dir.join(&conf.file_name);
let file = match std::fs::OpenOptions::new()
.create(true).write(true).truncate(true)
.open(&conf_path) {
Expand Down
10 changes: 5 additions & 5 deletions modda-lib/src/sub/extract_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::module::weidu_mod::BareMod;
use crate::unique_component::UniqueComponent;
use crate::weidu_conf::read_weidu_conf_lang_dir;

pub fn extract_bare_mods() -> Result<Vec<BareMod>> {
let log_rows = parse_weidu_log(None)?;
pub fn extract_bare_mods(game_dir: &CanonPath) -> Result<Vec<BareMod>> {
let log_rows = parse_weidu_log(game_dir, None)?;
let init: Vec<BareMod> = vec![];
let mod_fragments = log_rows.iter().fold(init, |mut accumulator, row| {
let current_mod = row.module.to_lowercase();
Expand All @@ -47,7 +47,7 @@ fn format_modules(bare_mods: Vec<BareMod>, export_component_name: Option<bool>,
}

pub fn extract_manifest(args: &Reverse, game_dir: &CanonPath) -> Result<()> {
let mods = extract_bare_mods()?;
let mods = extract_bare_mods(game_dir)?;
let mods = format_modules(mods, args.export_component_name, args.export_language);
let manifest = generate_manifest(game_dir, mods)?;

Expand Down Expand Up @@ -98,8 +98,8 @@ fn bare_mod_from_log_row(row: &LogRow) -> BareMod {
}
}

pub fn extract_unique_components() -> Result<HashSet<UniqueComponent>> {
let log_rows = parse_weidu_log(None)?;
pub fn extract_unique_components(game_dir: &CanonPath) -> Result<HashSet<UniqueComponent>> {
let log_rows = parse_weidu_log(game_dir, None)?;
log_rows.iter().try_fold(HashSet::new(), |mut set, row| {
let unique_component = UniqueComponent {
mod_key: lwc!(&row.module),
Expand Down
26 changes: 13 additions & 13 deletions modda-lib/src/sub/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn install(opts: &Install, settings: &Config, game_dir: &CanonPath, cache: &
info!("module {} - {}", real_index, module.describe());
debug!("{:?}", module);

match check_safely_installable(module)? {
match check_safely_installable(&game_dir, module)? {
SafetyResult::Abort => bail!("Aborted"),
SafetyResult::Safe => {}
SafetyResult::Conflicts(matches) if matches.is_empty() => {}
Expand All @@ -91,7 +91,7 @@ pub fn install(opts: &Install, settings: &Config, game_dir: &CanonPath, cache: &
}
match module {
Module::Mod { weidu_mod } =>
install_weidu(weidu_mod, &modda_context, &manifest, opts, index, real_index)?,
install_weidu(weidu_mod, &modda_context, &manifest, &modda_context, index, real_index)?,
Module::Generated { generated } =>
process_generated_mod(generated, &modda_context, &manifest, real_index)?,
}
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn install(opts: &Install, settings: &Config, game_dir: &CanonPath, cache: &
// Now check we actually installed all requested components
// if dry_run, nothing will have been installed at all so don't check
if !opts.dry_run && !was_disabled {
check_install_complete(&module)?
check_install_complete(game_dir, &module)?
}
}
if !opts.dry_run {
Expand All @@ -148,12 +148,12 @@ pub fn install(opts: &Install, settings: &Config, game_dir: &CanonPath, cache: &
}

fn install_weidu(weidu_mod: &WeiduMod, modda_context: &ModdaContext, manifest: &Manifest,
opts: &Install, index: usize, real_index: usize) -> Result<ProcessResult> {
context: &ModdaContext, index: usize, real_index: usize) -> Result<ProcessResult> {
let result = process_weidu_mod(weidu_mod, &modda_context, &manifest, real_index)?;
if weidu_mod.components.is_ask() {
if let Some(output_path) = &opts.record {
let manifest_path = PathBuf::from(&opts.manifest_path);
record_selection(index, weidu_mod, &output_path, &manifest_path, opts)?;
if let Some(output_path) = &context.opts.record {
let manifest_path = PathBuf::from(&context.opts.manifest_path);
record_selection(index, weidu_mod, &output_path, &manifest_path, context)?;
}
}
Ok(result)
Expand Down Expand Up @@ -189,8 +189,8 @@ fn get_modules_range<'a>(modules: &'a[Module], opts: &Install) -> Result<&'a [M
Ok(result)
}

fn check_safely_installable(module: &Module) -> Result<SafetyResult> {
let installed = extract_unique_components()?;
fn check_safely_installable(game_dir: &CanonPath, module: &Module) -> Result<SafetyResult> {
let installed = extract_unique_components(game_dir)?;
match module.get_components() {
Components::None => Ok(SafetyResult::Safe),
Components::Ask | Components::All => {
Expand Down Expand Up @@ -266,8 +266,8 @@ pub enum SafetyResult {
Abort,
}

fn record_selection(index: usize, module: &WeiduMod, output_file: &str, original_manifest_path: &Path, opts: &Install) -> Result<()> {
let log_rows = parse_weidu_log(None)?;
fn record_selection(index: usize, module: &WeiduMod, output_file: &str, original_manifest_path: &Path, context: &ModdaContext) -> Result<()> {
let log_rows = parse_weidu_log(&context.current_dir, None)?;
let output_path = PathBuf::from(output_file);
let mut record_manifest = if output_path.exists() {
Manifest::read_path_convert_comments(&output_path)?
Expand Down Expand Up @@ -311,7 +311,7 @@ fn record_selection(index: usize, module: &WeiduMod, output_file: &str, original
Component::Full(FullComponent { index: row.component_index, component_name: row.component_name.to_owned() })
).collect_vec();

if confirm_record(opts.record_no_confirm, &selection_rows, &module.name)? {
if confirm_record(context.opts.record_no_confirm, &selection_rows, &module.name)? {
// update manifest with new component selection
let components = if selection.is_empty() {
Components::None
Expand All @@ -325,7 +325,7 @@ fn record_selection(index: usize, module: &WeiduMod, output_file: &str, original
} };

// write updated manifest to new file
record_manifest.write(&output_path, opts.record_with_comment_as_field)?;
record_manifest.write(&output_path, context.opts.record_with_comment_as_field)?;

}

Expand Down
Loading