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
5 changes: 5 additions & 0 deletions .changeset/reinstall_enables_mod.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

Reinstalling a disabled mod now turns it back on
3 changes: 1 addition & 2 deletions packages/oneclient_app/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,12 @@ pub async fn install_package(
oneclient_events::TaskCategory::Packages,
);

let result = PackageStore::install_to_cluster(
let result = oneclient_content::bundles::install_package_enabled(
provider,
&project,
&version,
cluster_id,
incompatible == IncompatibleMode::Allow,
false,
Some(&child),
&state.services.content(),
)
Expand Down
38 changes: 36 additions & 2 deletions packages/oneclient_content/src/bundles/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use oneclient_db::dao::applied_migration as migration_dao;
use oneclient_db::dao::artifact as artifact_dao;
use oneclient_db::dao::cluster_bisect as bisect_dao;
use oneclient_db::dao::cluster_bundle as bundle_dao;
use oneclient_db::models::{ClusterArtifactRow, ClusterRow};
use oneclient_db::models::{ArtifactRow, ClusterArtifactRow, ClusterRow};
use oneclient_db::models::OverrideType;

use crate::bundles::error::BundleError;
Expand All @@ -21,7 +21,7 @@ use crate::packages::store::{
LiveSync, PackageStore, artifact_absolute_path, drop_unmanaged_mod, evict_if_unused,
try_unlink_materialized,
};
use crate::packages::types::{ExternalFile, LinkedArtifactInfo, VersionDetail};
use crate::packages::types::{ExternalFile, LinkedArtifactInfo, ProjectDetail, VersionDetail};
use oneclient_common::domain::{ContentType, GameLoader, ProviderId};
use oneclient_events::{GroupedProgressChild, GroupedProgressSession, TaskCategory, TaskPhase};

Expand Down Expand Up @@ -1511,6 +1511,40 @@ pub async fn set_artifact_enabled_to(
Ok(live)
}

#[allow(clippy::too_many_arguments)]
#[tracing::instrument(skip(project, version, child, ctx), fields(project_id = %project.id, version_id = %version.version_id))]
pub async fn install_package_enabled(
provider: ProviderId,
project: &ProjectDetail,
version: &VersionDetail,
cluster_id: i64,
skip_compatibility: bool,
child: Option<&GroupedProgressChild>,
ctx: &ContentCtx,
) -> ContentResult<(ArtifactRow, LiveSync)> {
let (artifact, live) = PackageStore::install_to_cluster(
provider,
project,
version,
cluster_id,
skip_compatibility,
false,
child,
ctx,
)
.await?;

let disabled = artifact_dao::get_cluster_artifact(&ctx.db, cluster_id, &artifact.hash)
.await?
.is_some_and(|link| link.enabled == 0);
if !disabled {
return Ok((artifact, live));
}

let live = set_artifact_enabled_to(cluster_id, &artifact.hash, true, ctx).await?;
Ok((artifact, live))
}

// which clusters have to record what the user just did
async fn override_scope(cluster_id: i64, hash: &str, ctx: &ContentCtx) -> ContentResult<Vec<i64>> {
Ok(sharing_scope(cluster_id, hash, ctx)
Expand Down
2 changes: 1 addition & 1 deletion packages/oneclient_content/src/bundles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use install::{
detach_undo_artifacts, effective_enabled, enabled_bundle_bytes,
enabled_bundle_projects, extract_bundle_overrides_for_cluster, heal_bundle_activity,
inherit_bundle_choices, install_bundle, install_cluster_bundles, install_enabled_bundle_files,
install_package_from_bundle, list_cluster_bundle_overrides, on_user_disable_artifact,
install_package_enabled, install_package_from_bundle, list_cluster_bundle_overrides, on_user_disable_artifact,
on_user_enable_artifact, on_user_remove_artifact, pending_bundle_choices,
remove_artifact_from_cluster, set_artifact_enabled_to, set_bundle_choices,
set_bundle_package_enabled, set_bundle_package_opt_in, set_bundle_package_override,
Expand Down
120 changes: 120 additions & 0 deletions packages/oneclient_core/tests/reinstall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
use oneclient_common::domain::{ContentType, GameLoader, ProviderId};
use oneclient_content::packages::store::{cache_file_path, relative_cache_path};
use oneclient_content::packages::{
PackageStore, VersionDetail, VersionFile, cached_project_detail,
};
use oneclient_core::clusters::{ClusterKind, CreateClusterOptions};
use oneclient_db::dao::artifact as artifact_dao;

#[tokio::test]
async fn reinstalling_a_disabled_mod_switches_it_on() {
let state = oneclient_core::dev::ephemeral_state().await.unwrap();
let global = state.settings.read().global_game_settings.clone();
let mut options = CreateClusterOptions::new("Reinstall", "1.21.1", GameLoader::Fabric)
.kind(ClusterKind::Modded);
options.mc_loader_version = Some("0.16.5".into());
let cluster = state.clusters.create(&global, options).await.unwrap();
let ctx = state.services.content();
let db = &state.services.db;

let bytes = b"PK\x05\x06reinstall".to_vec();
let hash = polyio::sha1_bytes(&bytes);
let file_name = "reinstall.jar";
let cached = cache_file_path(
ContentType::Mod,
ProviderId::Modrinth,
"Proj",
"Ver",
file_name,
)
.unwrap();
std::fs::create_dir_all(cached.parent().unwrap()).unwrap();
std::fs::write(&cached, &bytes).unwrap();
artifact_dao::insert_artifact(
db,
&hash,
ContentType::Mod as i64,
&relative_cache_path(&cached).unwrap(),
file_name,
Some(bytes.len() as i64),
)
.await
.unwrap();

let project = cached_project_detail(&ctx, ProviderId::Modrinth, "Proj", ContentType::Mod).await;
let version = VersionDetail {
version_id: "Ver".into(),
project_id: "Proj".into(),
name: String::new(),
version_number: "1.0".into(),
changelog: None,
game_versions: Vec::new(),
loaders: Vec::new(),
published: chrono::Utc::now(),
downloads: 0,
files: vec![VersionFile {
sha1: hash.clone(),
url: "https://example.invalid/reinstall.jar".into(),
file_name: file_name.into(),
primary: true,
size: bytes.len() as u64,
fingerprint: None,
}],
dependencies: Vec::new(),
};

let enabled = || async {
artifact_dao::get_cluster_artifact(db, cluster.id, &hash)
.await
.unwrap()
.unwrap()
.enabled
};

PackageStore::install_to_cluster(
ProviderId::Modrinth,
&project,
&version,
cluster.id,
true,
false,
None,
&ctx,
)
.await
.unwrap();
oneclient_content::bundles::set_artifact_enabled_to(cluster.id, &hash, false, &ctx)
.await
.unwrap();

PackageStore::install_to_cluster(
ProviderId::Modrinth,
&project,
&version,
cluster.id,
true,
false,
None,
&ctx,
)
.await
.unwrap();
assert_eq!(enabled().await, 0, "a sync relink keeps the user's choice");

oneclient_content::bundles::install_package_enabled(
ProviderId::Modrinth,
&project,
&version,
cluster.id,
true,
None,
&ctx,
)
.await
.unwrap();
assert_eq!(
enabled().await,
1,
"an explicit reinstall switches it back on"
);
}
Loading