feat(modpacks): check discovered pack updates
This commit is contained in:
1 parent
f049904466
commit
695ba5a758
25 files changed
+191
-38
No files matched your search
@@ -368,6 +368,16 @@ pub struct ProviderRegistry {
|
||||
providers: Vec<Box<dyn ContentProvider>>,
|
||||
}
|
||||
|
||||
pub(crate) fn has_newer_compatible_version(
|
||||
versions: &[VersionInfo],
|
||||
installed_version_id: &str,
|
||||
) -> bool {
|
||||
versions
|
||||
.iter()
|
||||
.position(|version| version.id == installed_version_id)
|
||||
.is_some_and(|position| position > 0)
|
||||
}
|
||||
|
||||
impl ProviderRegistry {
|
||||
pub(crate) fn new(providers: Vec<Box<dyn ContentProvider>>) -> Self {
|
||||
Self { providers }
|
||||
|
||||
@@ -104,6 +104,7 @@ pub fn build_summary(path: &Path) -> Result<ImportSummary, String> {
|
||||
override_count,
|
||||
format: PackFormat::CurseForge,
|
||||
archive_path: path.to_owned(),
|
||||
source: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ pub fn build_summary(path: &Path) -> Result<ImportSummary, String> {
|
||||
override_count,
|
||||
format: PackFormat::Mmc,
|
||||
archive_path: path.to_path_buf(),
|
||||
source: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ pub struct ImportSummary {
|
||||
pub override_count: usize,
|
||||
pub format: PackFormat,
|
||||
pub archive_path: PathBuf,
|
||||
pub source: Option<crate::instance::ProviderProject>,
|
||||
}
|
||||
|
||||
// peeks inside a zip to figure out what format it is.
|
||||
@@ -175,11 +176,16 @@ pub async fn execute_import(
|
||||
summary.name,
|
||||
summary.archive_path.display()
|
||||
);
|
||||
match summary.format {
|
||||
let mut config = match summary.format {
|
||||
PackFormat::CurseForge => curseforge::execute_import(summary, manager).await,
|
||||
PackFormat::Mrpack => mrpack::execute_import(summary, manager).await,
|
||||
PackFormat::Mmc => mmc::execute_import(summary, manager).await,
|
||||
}?;
|
||||
if summary.source.is_some() {
|
||||
config.modpack_source = summary.source.clone();
|
||||
manager.save(&config)?;
|
||||
}
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
fn cleanup_failed_import(manager: &InstanceManager, name: &str) {
|
||||
|
||||
@@ -125,6 +125,7 @@ pub fn build_summary(path: &Path) -> Result<ImportSummary, String> {
|
||||
override_count,
|
||||
format: PackFormat::Mrpack,
|
||||
archive_path: path.to_path_buf(),
|
||||
source: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -272,6 +272,7 @@ impl InstanceManager {
|
||||
jvm_args: vec![],
|
||||
resolution: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
};
|
||||
|
||||
self.save(&config)?;
|
||||
|
||||
@@ -49,6 +49,8 @@ pub struct InstanceConfig {
|
||||
pub resolution: Option<(u32, u32)>,
|
||||
#[serde(default)]
|
||||
pub config_sync_profile: Option<String>,
|
||||
#[serde(default)]
|
||||
pub modpack_source: Option<crate::instance::ProviderProject>,
|
||||
}
|
||||
|
||||
pub fn normalize_memory_value(raw: &str) -> Option<String> {
|
||||
|
||||
@@ -200,6 +200,7 @@ fn instance() -> InstanceConfig {
|
||||
jvm_args: Vec::new(),
|
||||
resolution: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,3 +5,24 @@ fn registry_falls_back_to_first_capable_provider() {
|
||||
let registry = ProviderRegistry::modrinth(crate::net::HttpClient::new());
|
||||
assert_eq!(registry.preferred("unknown").unwrap().id(), "modrinth");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_check_requires_the_installed_version_behind_a_newer_result() {
|
||||
let version = |id: &str| VersionInfo {
|
||||
id: id.to_owned(),
|
||||
project_id: "project".to_owned(),
|
||||
name: id.to_owned(),
|
||||
version_number: id.to_owned(),
|
||||
game_versions: vec!["1.21.1".to_owned()],
|
||||
loaders: vec!["fabric".to_owned()],
|
||||
version_type: crate::net::modrinth::VersionType::Release,
|
||||
dependencies: Vec::new(),
|
||||
date_published: String::new(),
|
||||
files: Vec::new(),
|
||||
};
|
||||
let versions = vec![version("new"), version("installed")];
|
||||
|
||||
assert!(has_newer_compatible_version(&versions, "installed"));
|
||||
assert!(!has_newer_compatible_version(&versions, "new"));
|
||||
assert!(!has_newer_compatible_version(&versions, "missing"));
|
||||
}
|
||||
@@ -23,6 +23,7 @@ fn job(name: &str) -> ReconcileJob {
|
||||
jvm_args: Vec::new(),
|
||||
resolution: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
},
|
||||
instances_dir: PathBuf::new(),
|
||||
client: crate::net::HttpClient::new(),
|
||||
|
||||
@@ -179,6 +179,7 @@ async fn migrate_legacy_loader_profile_skips_modern_with_inherits_from() {
|
||||
jvm_args: Vec::new(),
|
||||
resolution: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
};
|
||||
|
||||
let result =
|
||||
@@ -227,6 +228,7 @@ async fn migrate_legacy_loader_profile_skips_fabric() {
|
||||
jvm_args: Vec::new(),
|
||||
resolution: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
};
|
||||
|
||||
let result = migrate_legacy_loader_profile_if_needed(
|
||||
|
||||
@@ -26,6 +26,7 @@ fn dummy_config(name: &str) -> InstanceConfig {
|
||||
jvm_args: vec![],
|
||||
resolution: None,
|
||||
config_sync_profile: None,
|
||||
modpack_source: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ fn instance_config_roundtrips_through_json() {
|
||||
jvm_args: vec![],
|
||||
resolution: Some((1920, 1080)),
|
||||
config_sync_profile: None,
|
||||
modpack_source: Some(crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
project_id: "pack".to_owned(),
|
||||
version_id: "version".to_owned(),
|
||||
}),
|
||||
};
|
||||
let json = serde_json::to_string_pretty(&config).expect("serialize");
|
||||
let parsed: InstanceConfig = serde_json::from_str(&json).expect("deserialize");
|
||||
@@ -22,6 +27,7 @@ fn instance_config_roundtrips_through_json() {
|
||||
assert_eq!(parsed.game_version, config.game_version);
|
||||
assert_eq!(parsed.loader, config.loader);
|
||||
assert_eq!(parsed.resolution, config.resolution);
|
||||
assert_eq!(parsed.modpack_source, config.modpack_source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user