mirror of
https://github.com/WarrenHood/MCModpackManager.git
synced 2025-04-29 18:44:58 +01:00
Added an install button and switched back to using anyhow
This commit is contained in:
parent
6cc15eed68
commit
1ead48cbc2
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -143,6 +143,12 @@ dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.86"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "approx"
|
name = "approx"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
|
@ -2063,6 +2069,7 @@ dependencies = [
|
||||||
name = "mcmpmgr"
|
name = "mcmpmgr"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
"git2",
|
"git2",
|
||||||
"home",
|
"home",
|
||||||
|
@ -2165,6 +2172,7 @@ dependencies = [
|
||||||
name = "mmm"
|
name = "mmm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"iced",
|
"iced",
|
||||||
"mcmpmgr",
|
"mcmpmgr",
|
||||||
"rfd",
|
"rfd",
|
||||||
|
|
|
@ -5,6 +5,7 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0.86"
|
||||||
clap = { version = "4.5.15", features = ["derive"] }
|
clap = { version = "4.5.15", features = ["derive"] }
|
||||||
git2 = "0.19.0"
|
git2 = "0.19.0"
|
||||||
home = "0.5.9"
|
home = "0.5.9"
|
||||||
|
|
|
@ -4,12 +4,13 @@ mod profiles;
|
||||||
mod providers;
|
mod providers;
|
||||||
mod resolver;
|
mod resolver;
|
||||||
|
|
||||||
|
use anyhow::{Error, Result};
|
||||||
use clap::{Args, Parser, Subcommand};
|
use clap::{Args, Parser, Subcommand};
|
||||||
use mod_meta::{ModMeta, ModProvider};
|
use mod_meta::{ModMeta, ModProvider};
|
||||||
use modpack::ModpackMeta;
|
use modpack::ModpackMeta;
|
||||||
use profiles::{PackSource, Profile};
|
use profiles::{PackSource, Profile};
|
||||||
use providers::DownloadSide;
|
use providers::DownloadSide;
|
||||||
use std::{error::Error, path::PathBuf};
|
use std::path::PathBuf;
|
||||||
|
|
||||||
/// A Minecraft Modpack Manager
|
/// A Minecraft Modpack Manager
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
@ -152,7 +153,7 @@ enum ProfileCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main(flavor = "multi_thread")]
|
#[tokio::main(flavor = "multi_thread")]
|
||||||
async fn main() -> Result<(), Box<dyn Error>> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
if let Some(command) = cli.command {
|
if let Some(command) = cli.command {
|
||||||
|
@ -168,13 +169,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let pack_name = if let Some(name) = name {
|
let pack_name = if let Some(name) = name {
|
||||||
name
|
name
|
||||||
} else {
|
} else {
|
||||||
dir.file_name()
|
let dir_name = dir.file_name();
|
||||||
.ok_or(format!(
|
if let Some(dir_name) = dir_name {
|
||||||
|
dir_name.to_string_lossy().to_string()
|
||||||
|
} else {
|
||||||
|
anyhow::bail!(
|
||||||
"Cannot find pack name based on directory '{}'",
|
"Cannot find pack name based on directory '{}'",
|
||||||
dir.display()
|
dir.display()
|
||||||
))?
|
)
|
||||||
.to_string_lossy()
|
}
|
||||||
.into()
|
|
||||||
};
|
};
|
||||||
println!(
|
println!(
|
||||||
"Initializing project '{}' at '{}'...",
|
"Initializing project '{}' at '{}'...",
|
||||||
|
@ -392,9 +395,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
ProfileCommands::Install { name } => {
|
ProfileCommands::Install { name } => {
|
||||||
let userdata = profiles::Data::load()?;
|
let userdata = profiles::Data::load()?;
|
||||||
let profile = userdata
|
let profile = userdata.get_profile(&name);
|
||||||
.get_profile(&name)
|
|
||||||
.ok_or(format!("Profile '{name}' does not exist"))?;
|
let profile = if let Some(profile) = profile {
|
||||||
|
profile
|
||||||
|
} else {
|
||||||
|
anyhow::bail!("Profile '{name}' does not exist")
|
||||||
|
};
|
||||||
|
|
||||||
println!("Installing profile '{name}'...");
|
println!("Installing profile '{name}'...");
|
||||||
profile.install().await?;
|
profile.install().await?;
|
||||||
println!("Installed profile '{name}' successfully");
|
println!("Installed profile '{name}' successfully");
|
||||||
|
@ -406,9 +414,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
ProfileCommands::Show { name } => {
|
ProfileCommands::Show { name } => {
|
||||||
let userdata = profiles::Data::load()?;
|
let userdata = profiles::Data::load()?;
|
||||||
let profile = userdata
|
let profile = userdata.get_profile(&name);
|
||||||
.get_profile(&name)
|
|
||||||
.ok_or(format!("Profile '{name}' does not exist"))?;
|
let profile = if let Some(profile) = profile {
|
||||||
|
profile
|
||||||
|
} else {
|
||||||
|
anyhow::bail!("Profile '{name}' does not exist")
|
||||||
|
};
|
||||||
println!("Profile name : {name}");
|
println!("Profile name : {name}");
|
||||||
println!("Mods folder : {}", profile.mods_folder.display());
|
println!("Mods folder : {}", profile.mods_folder.display());
|
||||||
println!("Modpack source: {}", profile.pack_source);
|
println!("Modpack source: {}", profile.pack_source);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{borrow::BorrowMut, error::Error};
|
use anyhow::Result;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{borrow::BorrowMut, error::Error};
|
||||||
|
|
||||||
use crate::modpack::ModLoader;
|
use crate::modpack::ModLoader;
|
||||||
|
|
||||||
|
@ -15,14 +15,14 @@ pub enum ModProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for ModProvider {
|
impl std::str::FromStr for ModProvider {
|
||||||
type Err = String;
|
type Err = anyhow::Error;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
match s.to_lowercase().as_str() {
|
match s.to_lowercase().as_str() {
|
||||||
"curseforge" => Ok(ModProvider::CurseForge),
|
"curseforge" => Ok(ModProvider::CurseForge),
|
||||||
"modrinth" => Ok(ModProvider::Modrinth),
|
"modrinth" => Ok(ModProvider::Modrinth),
|
||||||
"raw" => Ok(ModProvider::Raw),
|
"raw" => Ok(ModProvider::Raw),
|
||||||
_ => Err(format!("Invalid mod launcher: {}", s)),
|
_ => anyhow::bail!("Invalid mod provider: {}", s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,11 @@ impl PartialEq for ModMeta {
|
||||||
impl Eq for ModMeta {}
|
impl Eq for ModMeta {}
|
||||||
|
|
||||||
impl ModMeta {
|
impl ModMeta {
|
||||||
pub fn new(mod_name: &str) -> Result<Self, Box<dyn Error>> {
|
pub fn new(mod_name: &str) -> Result<Self> {
|
||||||
if mod_name.contains("@") {
|
if mod_name.contains("@") {
|
||||||
let mod_name_and_version: Vec<&str> = mod_name.split("@").collect();
|
let mod_name_and_version: Vec<&str> = mod_name.split("@").collect();
|
||||||
if mod_name_and_version.len() != 2 {
|
if mod_name_and_version.len() != 2 {
|
||||||
return Err(format!("Invalid mod with version constraint: '{}'", &mod_name).into());
|
anyhow::bail!("Invalid mod with version constraint: '{}'", &mod_name)
|
||||||
}
|
}
|
||||||
return Ok(Self {
|
return Ok(Self {
|
||||||
name: mod_name_and_version[0].into(),
|
name: mod_name_and_version[0].into(),
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::mod_meta::{ModMeta, ModProvider};
|
use crate::mod_meta::{ModMeta, ModProvider};
|
||||||
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
error::Error,
|
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,13 +25,13 @@ impl ToString for ModLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for ModLoader {
|
impl std::str::FromStr for ModLoader {
|
||||||
type Err = String;
|
type Err = anyhow::Error;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
match s {
|
match s {
|
||||||
"Fabric" => Ok(Self::Fabric),
|
"Fabric" => Ok(Self::Fabric),
|
||||||
"Forge" => Ok(Self::Forge),
|
"Forge" => Ok(Self::Forge),
|
||||||
_ => Err(format!("Invalid mod launcher: {}", s)),
|
_ => anyhow::bail!("Invalid mod launcher: {}", s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,20 +60,19 @@ impl ModpackMeta {
|
||||||
self.mods.values().into_iter()
|
self.mods.values().into_iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_from_directory(directory: &Path) -> Result<Self, Box<dyn Error>> {
|
pub fn load_from_directory(directory: &Path) -> Result<Self> {
|
||||||
let modpack_meta_file_path = directory.join(PathBuf::from(MODPACK_FILENAME));
|
let modpack_meta_file_path = directory.join(PathBuf::from(MODPACK_FILENAME));
|
||||||
if !modpack_meta_file_path.exists() {
|
if !modpack_meta_file_path.exists() {
|
||||||
return Err(format!(
|
anyhow::bail!(
|
||||||
"Directory '{}' does not seem to be a valid modpack project directory.",
|
"Directory '{}' does not seem to be a valid modpack project directory.",
|
||||||
directory.display()
|
directory.display()
|
||||||
)
|
)
|
||||||
.into());
|
|
||||||
};
|
};
|
||||||
let modpack_contents = std::fs::read_to_string(modpack_meta_file_path)?;
|
let modpack_contents = std::fs::read_to_string(modpack_meta_file_path)?;
|
||||||
Ok(toml::from_str(&modpack_contents)?)
|
Ok(toml::from_str(&modpack_contents)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_from_current_directory() -> Result<Self, Box<dyn Error>> {
|
pub fn load_from_current_directory() -> Result<Self> {
|
||||||
Self::load_from_directory(&std::env::current_dir()?)
|
Self::load_from_directory(&std::env::current_dir()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +83,9 @@ impl ModpackMeta {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_mod(mut self, mod_meta: &ModMeta) -> Result<Self, Box<dyn Error>> {
|
pub fn add_mod(mut self, mod_meta: &ModMeta) -> Result<Self> {
|
||||||
if self.forbidden_mods.contains(&mod_meta.name) {
|
if self.forbidden_mods.contains(&mod_meta.name) {
|
||||||
return Err(format!("Cannot add forbidden mod {} to modpack", mod_meta.name).into());
|
anyhow::bail!("Cannot add forbidden mod {} to modpack", mod_meta.name)
|
||||||
} else {
|
} else {
|
||||||
self.mods
|
self.mods
|
||||||
.insert(mod_meta.name.to_string(), mod_meta.clone());
|
.insert(mod_meta.name.to_string(), mod_meta.clone());
|
||||||
|
@ -104,14 +103,13 @@ impl ModpackMeta {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_project(&self, directory: &Path) -> Result<(), Box<dyn Error>> {
|
pub fn init_project(&self, directory: &Path) -> Result<()> {
|
||||||
let modpack_meta_file_path = directory.join(PathBuf::from(MODPACK_FILENAME));
|
let modpack_meta_file_path = directory.join(PathBuf::from(MODPACK_FILENAME));
|
||||||
if modpack_meta_file_path.exists() {
|
if modpack_meta_file_path.exists() {
|
||||||
return Err(format!(
|
anyhow::bail!(
|
||||||
"{MODPACK_FILENAME} already exists at {}",
|
"{MODPACK_FILENAME} already exists at {}",
|
||||||
modpack_meta_file_path.display()
|
modpack_meta_file_path.display()
|
||||||
)
|
)
|
||||||
.into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.save_to_file(&modpack_meta_file_path)?;
|
self.save_to_file(&modpack_meta_file_path)?;
|
||||||
|
@ -119,7 +117,7 @@ impl ModpackMeta {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_to_file(&self, path: &PathBuf) -> Result<(), Box<dyn Error>> {
|
pub fn save_to_file(&self, path: &PathBuf) -> Result<()> {
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
path,
|
path,
|
||||||
toml::to_string(self).expect("MC Modpack Meta should be serializable"),
|
toml::to_string(self).expect("MC Modpack Meta should be serializable"),
|
||||||
|
@ -128,7 +126,7 @@ impl ModpackMeta {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_current_dir_project(&self) -> Result<(), Box<dyn Error>> {
|
pub fn save_current_dir_project(&self) -> Result<()> {
|
||||||
let modpack_meta_file_path = std::env::current_dir()?.join(PathBuf::from(MODPACK_FILENAME));
|
let modpack_meta_file_path = std::env::current_dir()?.join(PathBuf::from(MODPACK_FILENAME));
|
||||||
self.save_to_file(&modpack_meta_file_path)?;
|
self.save_to_file(&modpack_meta_file_path)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
@ -57,7 +58,7 @@ impl Profile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn install(&self) -> Result<(), Box<dyn Error>> {
|
pub async fn install(&self) -> Result<()> {
|
||||||
let (pack_lock, temp_dir) = match &self.pack_source {
|
let (pack_lock, temp_dir) = match &self.pack_source {
|
||||||
PackSource::Git { url } => {
|
PackSource::Git { url } => {
|
||||||
let (pack_lock, packdir) = PinnedPackMeta::load_from_git_repo(&url, true).await?;
|
let (pack_lock, packdir) = PinnedPackMeta::load_from_git_repo(&url, true).await?;
|
||||||
|
@ -112,13 +113,19 @@ impl Data {
|
||||||
self.profiles.remove(profile_name);
|
self.profiles.remove(profile_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_config_folder_path() -> Result<PathBuf, Box<dyn Error>> {
|
fn get_config_folder_path() -> Result<PathBuf> {
|
||||||
home::home_dir()
|
let home_dir = home::home_dir()
|
||||||
.and_then(|home_dir| Some(home_dir.join(format!(".config/{CONFIG_DIR_NAME}"))))
|
.and_then(|home_dir| Some(home_dir.join(format!(".config/{CONFIG_DIR_NAME}"))));
|
||||||
.ok_or("Unable to locate home directory".into())
|
|
||||||
|
if let Some(home_dir) = home_dir {
|
||||||
|
Ok(home_dir)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
anyhow::bail!("Unable to locate home directory")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load() -> Result<Self, Box<dyn Error>> {
|
pub fn load() -> Result<Self> {
|
||||||
let config_dir = Self::get_config_folder_path()?;
|
let config_dir = Self::get_config_folder_path()?;
|
||||||
if !config_dir.exists() {
|
if !config_dir.exists() {
|
||||||
println!("Creating config directory {config_dir:#?}...");
|
println!("Creating config directory {config_dir:#?}...");
|
||||||
|
@ -135,7 +142,7 @@ impl Data {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self) -> Result<(), Box<dyn Error>> {
|
pub fn save(&self) -> Result<()> {
|
||||||
let config_dir = Self::get_config_folder_path()?;
|
let config_dir = Self::get_config_folder_path()?;
|
||||||
if !config_dir.exists() {
|
if !config_dir.exists() {
|
||||||
println!("Creating config directory {config_dir:#?}...");
|
println!("Creating config directory {config_dir:#?}...");
|
||||||
|
|
|
@ -29,17 +29,14 @@ pub enum DownloadSide {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for DownloadSide {
|
impl FromStr for DownloadSide {
|
||||||
type Err = String;
|
type Err = anyhow::Error;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
match s.to_ascii_lowercase().as_str() {
|
match s.to_ascii_lowercase().as_str() {
|
||||||
"both" => Ok(DownloadSide::Both),
|
"both" => Ok(DownloadSide::Both),
|
||||||
"client" => Ok(DownloadSide::Client),
|
"client" => Ok(DownloadSide::Client),
|
||||||
"server" => Ok(DownloadSide::Server),
|
"server" => Ok(DownloadSide::Server),
|
||||||
_ => Err(format!(
|
_ => anyhow::bail!("Invalid side {}. Expected one of: both, server, clide", s),
|
||||||
"Invalid side {}. Expected one of: both, server, clide",
|
|
||||||
s
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
use anyhow::{Error, Result};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashSet, error::Error};
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use super::PinnedMod;
|
use super::PinnedMod;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -65,7 +66,7 @@ impl Modrinth {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_project(&self, project_id: &str) -> Result<ModrinthProject, Box<dyn Error>> {
|
async fn get_project(&self, project_id: &str) -> Result<ModrinthProject> {
|
||||||
let project: ModrinthProject = self
|
let project: ModrinthProject = self
|
||||||
.client
|
.client
|
||||||
.get(format!("https://api.modrinth.com/v2/project/{project_id}"))
|
.get(format!("https://api.modrinth.com/v2/project/{project_id}"))
|
||||||
|
@ -84,7 +85,7 @@ impl Modrinth {
|
||||||
pack_meta: &ModpackMeta,
|
pack_meta: &ModpackMeta,
|
||||||
loader_override: Option<ModLoader>,
|
loader_override: Option<ModLoader>,
|
||||||
game_version_override: Option<String>,
|
game_version_override: Option<String>,
|
||||||
) -> Result<ModMeta, Box<dyn Error>> {
|
) -> Result<ModMeta> {
|
||||||
let project_versions = self
|
let project_versions = self
|
||||||
.get_project_versions(
|
.get_project_versions(
|
||||||
project_id,
|
project_id,
|
||||||
|
@ -113,20 +114,15 @@ impl Modrinth {
|
||||||
return Ok(mod_meta);
|
return Ok(mod_meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(format!(
|
anyhow::bail!(
|
||||||
"Couldn't find project '{}' with version '{}'",
|
"Couldn't find project '{}' with version '{}'",
|
||||||
project_id,
|
project_id,
|
||||||
project_version.unwrap_or("*")
|
project_version.unwrap_or("*")
|
||||||
)
|
)
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve a list of mod candidates in order of newest to oldest
|
/// Resolve a list of mod candidates in order of newest to oldest
|
||||||
pub async fn resolve(
|
pub async fn resolve(&self, mod_meta: &ModMeta, pack_meta: &ModpackMeta) -> Result<PinnedMod> {
|
||||||
&self,
|
|
||||||
mod_meta: &ModMeta,
|
|
||||||
pack_meta: &ModpackMeta,
|
|
||||||
) -> Result<PinnedMod, Box<dyn Error>> {
|
|
||||||
let versions = self
|
let versions = self
|
||||||
.get_project_versions(
|
.get_project_versions(
|
||||||
&mod_meta.name,
|
&mod_meta.name,
|
||||||
|
@ -138,21 +134,28 @@ impl Modrinth {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let package = if mod_meta.version == "*" {
|
let package = if mod_meta.version == "*" {
|
||||||
versions.first().ok_or(format!(
|
let version = versions.first();
|
||||||
"Cannot find package {} for loader={} and mc version={}",
|
if let Some(version) = version {
|
||||||
mod_meta.name,
|
version
|
||||||
pack_meta.modloader.to_string().to_lowercase(),
|
} else {
|
||||||
pack_meta.mc_version
|
anyhow::bail!(
|
||||||
))?
|
"Cannot find package {} for loader={} and mc version={}",
|
||||||
|
mod_meta.name,
|
||||||
|
pack_meta.modloader.to_string().to_lowercase(),
|
||||||
|
pack_meta.mc_version
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
versions
|
let version = versions
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|v| v.version_number == mod_meta.version)
|
.filter(|v| v.version_number == mod_meta.version)
|
||||||
.nth(0)
|
.nth(0);
|
||||||
.ok_or(format!(
|
|
||||||
"Cannot find package {}@{}",
|
if let Some(version) = version {
|
||||||
mod_meta.name, mod_meta.version
|
version
|
||||||
))?
|
} else {
|
||||||
|
anyhow::bail!("Cannot find package {}@{}", mod_meta.name, mod_meta.version)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut deps_meta = HashSet::new();
|
let mut deps_meta = HashSet::new();
|
||||||
|
@ -207,7 +210,7 @@ impl Modrinth {
|
||||||
ignore_game_version_and_loader: bool, // For deps we might as well let them use anything
|
ignore_game_version_and_loader: bool, // For deps we might as well let them use anything
|
||||||
loader_override: Option<ModLoader>,
|
loader_override: Option<ModLoader>,
|
||||||
game_version_override: Option<String>,
|
game_version_override: Option<String>,
|
||||||
) -> Result<Vec<ModrinthProjectVersion>, Box<dyn Error>> {
|
) -> Result<Vec<ModrinthProjectVersion>> {
|
||||||
let loader = loader_override
|
let loader = loader_override
|
||||||
.unwrap_or(pack_meta.modloader.clone())
|
.unwrap_or(pack_meta.modloader.clone())
|
||||||
.to_string()
|
.to_string()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::{Digest, Sha512};
|
use sha2::{Digest, Sha512};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -35,7 +36,7 @@ impl PinnedPackMeta {
|
||||||
&self,
|
&self,
|
||||||
mods_dir: &PathBuf,
|
mods_dir: &PathBuf,
|
||||||
download_side: DownloadSide,
|
download_side: DownloadSide,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<()> {
|
||||||
let files = std::fs::read_dir(mods_dir)?;
|
let files = std::fs::read_dir(mods_dir)?;
|
||||||
let mut pinned_files_cache = HashSet::new();
|
let mut pinned_files_cache = HashSet::new();
|
||||||
for file in files.into_iter() {
|
for file in files.into_iter() {
|
||||||
|
@ -80,11 +81,12 @@ impl PinnedPackMeta {
|
||||||
"Sha512 hash mismatch for file {}\nExpected:\n{}\nGot:\n{}",
|
"Sha512 hash mismatch for file {}\nExpected:\n{}\nGot:\n{}",
|
||||||
filename, sha512, sha512_hash
|
filename, sha512, sha512_hash
|
||||||
);
|
);
|
||||||
return Err(format!(
|
anyhow::bail!(
|
||||||
"Sha512 hash mismatch for file {}\nExpected:\n{}\nGot:\n{}",
|
"Sha512 hash mismatch for file {}\nExpected:\n{}\nGot:\n{}",
|
||||||
filename, sha512, sha512_hash
|
filename,
|
||||||
|
sha512,
|
||||||
|
sha512_hash
|
||||||
)
|
)
|
||||||
.into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tokio::fs::write(mods_dir.join(filename), file_contents).await?;
|
tokio::fs::write(mods_dir.join(filename), file_contents).await?;
|
||||||
|
@ -154,7 +156,7 @@ impl PinnedPackMeta {
|
||||||
mod_metadata: &ModMeta,
|
mod_metadata: &ModMeta,
|
||||||
pack_metadata: &ModpackMeta,
|
pack_metadata: &ModpackMeta,
|
||||||
ignore_transitive_versions: bool,
|
ignore_transitive_versions: bool,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<()> {
|
||||||
if let Some(mod_meta) = self.mods.get(&mod_metadata.name) {
|
if let Some(mod_meta) = self.mods.get(&mod_metadata.name) {
|
||||||
if mod_metadata.version != "*" && mod_metadata.version == mod_meta.version {
|
if mod_metadata.version != "*" && mod_metadata.version == mod_meta.version {
|
||||||
// Skip already pinned mods
|
// Skip already pinned mods
|
||||||
|
@ -199,7 +201,7 @@ impl PinnedPackMeta {
|
||||||
&mut self,
|
&mut self,
|
||||||
mod_metadata: &ModMeta,
|
mod_metadata: &ModMeta,
|
||||||
pack_metadata: &ModpackMeta,
|
pack_metadata: &ModpackMeta,
|
||||||
) -> Result<Vec<ModMeta>, Box<dyn Error>> {
|
) -> Result<Vec<ModMeta>> {
|
||||||
if pack_metadata.forbidden_mods.contains(&mod_metadata.name) {
|
if pack_metadata.forbidden_mods.contains(&mod_metadata.name) {
|
||||||
println!("Skipping adding forbidden mod {}...", mod_metadata.name);
|
println!("Skipping adding forbidden mod {}...", mod_metadata.name);
|
||||||
return Ok(vec![]);
|
return Ok(vec![]);
|
||||||
|
@ -247,11 +249,12 @@ impl PinnedPackMeta {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(format!(
|
anyhow::bail!(
|
||||||
"Failed to pin mod '{}' (providers={:#?}) with constraint {} and all its deps",
|
"Failed to pin mod '{}' (providers={:#?}) with constraint {} and all its deps",
|
||||||
mod_metadata.name, mod_metadata.providers, mod_metadata.version
|
mod_metadata.name,
|
||||||
|
mod_metadata.providers,
|
||||||
|
mod_metadata.version
|
||||||
)
|
)
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_dependent_mods(&self, mod_name: &str) -> HashSet<String> {
|
fn get_dependent_mods(&self, mod_name: &str) -> HashSet<String> {
|
||||||
|
@ -274,7 +277,7 @@ impl PinnedPackMeta {
|
||||||
mod_name: &str,
|
mod_name: &str,
|
||||||
pack_metadata: &ModpackMeta,
|
pack_metadata: &ModpackMeta,
|
||||||
force: bool,
|
force: bool,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<()> {
|
||||||
if !self.mods.contains_key(mod_name) {
|
if !self.mods.contains_key(mod_name) {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"Skipping removing non-existent mod {} from modpack",
|
"Skipping removing non-existent mod {} from modpack",
|
||||||
|
@ -288,11 +291,11 @@ impl PinnedPackMeta {
|
||||||
if force {
|
if force {
|
||||||
println!("Forcefully removing mod {} even though it is depended on by the following mods:\n{:#?}", mod_name, dependent_mods);
|
println!("Forcefully removing mod {} even though it is depended on by the following mods:\n{:#?}", mod_name, dependent_mods);
|
||||||
} else {
|
} else {
|
||||||
return Err(format!(
|
anyhow::bail!(
|
||||||
"Cannot remove mod {}.The following mods depend on it:\n{:#?}",
|
"Cannot remove mod {}.The following mods depend on it:\n{:#?}",
|
||||||
mod_name, dependent_mods
|
mod_name,
|
||||||
|
dependent_mods
|
||||||
)
|
)
|
||||||
.into());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let removed_mod = self.mods.remove(mod_name);
|
let removed_mod = self.mods.remove(mod_name);
|
||||||
|
@ -304,7 +307,7 @@ impl PinnedPackMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove all mods from lockfile that aren't in the pack metadata or depended on by another mod
|
/// Remove all mods from lockfile that aren't in the pack metadata or depended on by another mod
|
||||||
fn prune_mods(&mut self, pack_metadata: &ModpackMeta) -> Result<(), Box<dyn Error>> {
|
fn prune_mods(&mut self, pack_metadata: &ModpackMeta) -> Result<()> {
|
||||||
let mods_to_remove: HashSet<String> = self
|
let mods_to_remove: HashSet<String> = self
|
||||||
.mods
|
.mods
|
||||||
.keys()
|
.keys()
|
||||||
|
@ -329,7 +332,7 @@ impl PinnedPackMeta {
|
||||||
&mut self,
|
&mut self,
|
||||||
modpack_meta: &ModpackMeta,
|
modpack_meta: &ModpackMeta,
|
||||||
ignore_transitive_versions: bool,
|
ignore_transitive_versions: bool,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<()> {
|
||||||
for mod_meta in modpack_meta.iter_mods() {
|
for mod_meta in modpack_meta.iter_mods() {
|
||||||
self.pin_mod_and_deps(mod_meta, modpack_meta, ignore_transitive_versions)
|
self.pin_mod_and_deps(mod_meta, modpack_meta, ignore_transitive_versions)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -337,7 +340,7 @@ impl PinnedPackMeta {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_to_file(&self, path: &PathBuf) -> Result<(), Box<dyn Error>> {
|
pub fn save_to_file(&self, path: &PathBuf) -> Result<()> {
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
path,
|
path,
|
||||||
toml::to_string(self).expect("Pinned pack meta should be serializable"),
|
toml::to_string(self).expect("Pinned pack meta should be serializable"),
|
||||||
|
@ -346,12 +349,12 @@ impl PinnedPackMeta {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_current_dir_lock(&self) -> Result<(), Box<dyn Error>> {
|
pub fn save_current_dir_lock(&self) -> Result<()> {
|
||||||
self.save_to_dir(&std::env::current_dir()?)?;
|
self.save_to_dir(&std::env::current_dir()?)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_to_dir(&self, dir: &PathBuf) -> Result<(), Box<dyn Error>> {
|
pub fn save_to_dir(&self, dir: &PathBuf) -> Result<()> {
|
||||||
let modpack_lock_file_path = dir.join(PathBuf::from(MODPACK_LOCK_FILENAME));
|
let modpack_lock_file_path = dir.join(PathBuf::from(MODPACK_LOCK_FILENAME));
|
||||||
self.save_to_file(&modpack_lock_file_path)?;
|
self.save_to_file(&modpack_lock_file_path)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -360,7 +363,7 @@ impl PinnedPackMeta {
|
||||||
pub async fn load_from_directory(
|
pub async fn load_from_directory(
|
||||||
directory: &Path,
|
directory: &Path,
|
||||||
ignore_transitive_versions: bool,
|
ignore_transitive_versions: bool,
|
||||||
) -> Result<Self, Box<dyn Error>> {
|
) -> Result<Self> {
|
||||||
let modpack_lock_file_path = directory.join(PathBuf::from(MODPACK_LOCK_FILENAME));
|
let modpack_lock_file_path = directory.join(PathBuf::from(MODPACK_LOCK_FILENAME));
|
||||||
if !modpack_lock_file_path.exists() {
|
if !modpack_lock_file_path.exists() {
|
||||||
let mut new_modpack_lock = Self::new();
|
let mut new_modpack_lock = Self::new();
|
||||||
|
@ -378,7 +381,7 @@ impl PinnedPackMeta {
|
||||||
|
|
||||||
pub async fn load_from_current_directory(
|
pub async fn load_from_current_directory(
|
||||||
ignore_transitive_versions: bool,
|
ignore_transitive_versions: bool,
|
||||||
) -> Result<Self, Box<dyn Error>> {
|
) -> Result<Self> {
|
||||||
Self::load_from_directory(&std::env::current_dir()?, ignore_transitive_versions).await
|
Self::load_from_directory(&std::env::current_dir()?, ignore_transitive_versions).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,7 +389,7 @@ impl PinnedPackMeta {
|
||||||
pub async fn load_from_git_repo(
|
pub async fn load_from_git_repo(
|
||||||
git_url: &str,
|
git_url: &str,
|
||||||
ignore_transitive_versions: bool,
|
ignore_transitive_versions: bool,
|
||||||
) -> Result<(Self, tempfile::TempDir), Box<dyn Error>> {
|
) -> Result<(Self, tempfile::TempDir)> {
|
||||||
let pack_dir = tempfile::tempdir()?;
|
let pack_dir = tempfile::tempdir()?;
|
||||||
println!(
|
println!(
|
||||||
"Cloning modpack from git repo {} to {:#?}...",
|
"Cloning modpack from git repo {} to {:#?}...",
|
||||||
|
|
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0.86"
|
||||||
iced = { version = "0.12.1", features = ["tokio"] }
|
iced = { version = "0.12.1", features = ["tokio"] }
|
||||||
mcmpmgr = { version = "0.1.0", path = "../mcmpmgr" }
|
mcmpmgr = { version = "0.1.0", path = "../mcmpmgr" }
|
||||||
rfd = "0.14.1"
|
rfd = "0.14.1"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::fmt::format;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ struct ManagerGUI {
|
||||||
previous_view: ManagerView,
|
previous_view: ManagerView,
|
||||||
profile_edit_settings: ProfileSettings,
|
profile_edit_settings: ProfileSettings,
|
||||||
profile_save_error: Option<String>,
|
profile_save_error: Option<String>,
|
||||||
|
current_install_status: ProfileInstallStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -84,6 +86,22 @@ enum Message {
|
||||||
EditPackSource(String),
|
EditPackSource(String),
|
||||||
SaveProfile,
|
SaveProfile,
|
||||||
DeleteProfile(String),
|
DeleteProfile(String),
|
||||||
|
InstallProfile(String),
|
||||||
|
ProfileInstalled(ProfileInstallStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
enum ProfileInstallStatus {
|
||||||
|
NotStarted,
|
||||||
|
Installing,
|
||||||
|
Success,
|
||||||
|
Error(String)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ProfileInstallStatus {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::NotStarted
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for ManagerGUI {
|
impl Application for ManagerGUI {
|
||||||
|
@ -206,6 +224,34 @@ impl Application for ManagerGUI {
|
||||||
|
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
|
Message::InstallProfile(name) => {
|
||||||
|
self.current_install_status = ProfileInstallStatus::Installing;
|
||||||
|
let profile_name = name.clone();
|
||||||
|
let profile = self.userdata.get_profile(&name).cloned();
|
||||||
|
Command::perform(
|
||||||
|
async move {
|
||||||
|
if let Some(profile) = profile {
|
||||||
|
let result = profile.install().await;
|
||||||
|
if let Err(err) = result {
|
||||||
|
ProfileInstallStatus::Error(format!("{}", err))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ProfileInstallStatus::Success
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ProfileInstallStatus::Error(format!("Profile '{}' doesn't exist", name))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Message::ProfileInstalled
|
||||||
|
)
|
||||||
|
},
|
||||||
|
Message::ProfileInstalled(result) => {
|
||||||
|
self.current_install_status = result;
|
||||||
|
|
||||||
|
Command::none()
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,6 +329,7 @@ impl ManagerGUI {
|
||||||
]
|
]
|
||||||
.spacing(20),
|
.spacing(20),
|
||||||
row!["Mods to download", text(profile.side),].spacing(5),
|
row!["Mods to download", text(profile.side),].spacing(5),
|
||||||
|
button("Install").on_press(Message::InstallProfile(profile_name.into())),
|
||||||
row![
|
row![
|
||||||
button("Back").on_press(Message::SwitchView(ManagerView::ProfileSelect)),
|
button("Back").on_press(Message::SwitchView(ManagerView::ProfileSelect)),
|
||||||
button("Edit profile").on_press(Message::SwitchView(
|
button("Edit profile").on_press(Message::SwitchView(
|
||||||
|
@ -305,6 +352,19 @@ impl ManagerGUI {
|
||||||
profile_view = profile_view.push(text(err));
|
profile_view = profile_view.push(text(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match &self.current_install_status {
|
||||||
|
ProfileInstallStatus::NotStarted => {},
|
||||||
|
ProfileInstallStatus::Installing => {
|
||||||
|
profile_view = profile_view.push(text("Installing..."));
|
||||||
|
},
|
||||||
|
ProfileInstallStatus::Success => {
|
||||||
|
profile_view = profile_view.push(text("Installed"));
|
||||||
|
},
|
||||||
|
ProfileInstallStatus::Error(err) => {
|
||||||
|
profile_view = profile_view.push(text(format!("Failed to install profile: {}", err)));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
profile_view
|
profile_view
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
|
|
Loading…
Reference in a new issue