aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-11-06 23:01:52 +0100
committerDaniel Schadt <kingdread@gmx.de>2021-11-06 23:01:52 +0100
commitb7d13549d4ce961b9384611844e62a7156b321c7 (patch)
tree9ff39ad4e5f16598794598f1b35c00c48661476a /src/main.rs
parent20c8574ab6b9db586ccc88e453cdb84fe44f1004 (diff)
downloadmodderbaas-b7d13549d4ce961b9384611844e62a7156b321c7.tar.gz
modderbaas-b7d13549d4ce961b9384611844e62a7156b321c7.tar.bz2
modderbaas-b7d13549d4ce961b9384611844e62a7156b321c7.zip
support installing modpacks
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index bff0fe0..da04f9c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,7 +11,9 @@ use itertools::Itertools;
use log::debug;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
-use modderbaas::{Baas, ContentDb, Downloader, MineMod, Snapshot, Source, World};
+use modderbaas::{
+ minemod::ModContainer, Baas, ContentDb, Downloader, MineMod, Snapshot, Source, World,
+};
fn main() -> Result<()> {
stderrlog::new()
@@ -200,7 +202,7 @@ fn install_mods(
.map(|&s| Source::from_str(s))
.collect::<Result<Vec<_>, _>>()?;
- let mut to_install = Vec::<MineMod>::new();
+ let mut to_install = Vec::<Box<dyn ModContainer>>::new();
let mut to_enable = Vec::<MineMod>::new();
let game = snapshot
@@ -213,7 +215,7 @@ fn install_mods(
.map(|m| m.mod_id())
.collect::<Result<Vec<_>, _>>()?;
- while !wanted.is_empty() {
+ 'modloop: while !wanted.is_empty() {
let next_mod = wanted.remove(0);
// Special handling for mods specified by their ID, as those could already exist.
@@ -229,9 +231,11 @@ fn install_mods(
}
// Is this a mod that is already queued for installation?
- for m in &to_install {
- if &m.mod_id()? == id {
- continue;
+ for mod_or_pack in &to_install {
+ for m in mod_or_pack.mods()? {
+ if &m.name()? == id {
+ continue 'modloop;
+ }
}
}
@@ -264,7 +268,9 @@ fn install_mods(
let downloaded = downloader
.download(&next_mod)
.context("Failed to download mod")?;
- wanted.extend(downloaded.dependencies()?.into_iter().map(Source::ModId));
+ for m in downloaded.mods()? {
+ wanted.extend(m.dependencies()?.into_iter().map(Source::ModId));
+ }
to_install.push(downloaded);
}
}
@@ -276,20 +282,25 @@ fn install_mods(
if dry_run {
for m in to_install {
- let mod_id = m.mod_id()?;
+ let mod_id = m.name()?;
let mod_dir = target_dir.join(&mod_id);
- writeln!(output, "Installing {} to {:?}", mod_id, mod_dir)?;
+ writeln!(output, "Installing {} to {:?}", m, mod_dir)?;
+ to_enable.extend(m.mods()?);
+ }
+ for m in to_enable {
+ let mod_id = m.mod_id()?;
+ writeln!(output, "Enabling {}", mod_id)?;
}
return Ok(());
}
for m in to_install {
- let mod_id = m.mod_id()?;
+ let mod_id = m.name()?;
writeln!(output, "Installing {}", mod_id)?;
let installed = m
- .copy_to(target_dir)
+ .install_to(target_dir)
.context(format!("Error installing '{}'", mod_id))?;
- to_enable.push(installed);
+ to_enable.extend(installed.mods()?);
}
for m in to_enable {