feat: rename shader config file on version change (#5636)

* feat: rename shader settings sidecar file on version switch

* fix: cleanup

---------

Co-authored-by: Calum H. <calum@modrinth.com>
Co-authored-by: Calum H. (IMB11) <contact@cal.engineer>
This commit is contained in:
Artyom Ezri
2026-07-14 09:58:07 +00:00
committed by GitHub
co-authored by Calum H. Calum H.
parent 818a9db9f7
commit 1884912126
2 changed files with 58 additions and 1 deletions
@@ -285,6 +285,13 @@ pub(crate) async fn switch_project_version_with_dependencies(
}
if new_path != project_path {
rename_project_companion_file(
instance_id,
project_path,
&new_path,
state,
)
.await?;
remove_project(instance_id, project_path, state).await?;
}
@@ -724,6 +731,42 @@ pub(crate) async fn remove_project(
Ok(())
}
pub(crate) async fn rename_project_companion_file(
instance_id: &str,
old_project_path: &str,
new_project_path: &str,
state: &State,
) -> crate::Result<()> {
let project_type = ProjectType::get_from_parent_folder(new_project_path);
if project_type == Some(ProjectType::ShaderPack) {
let scope = resolve_content_scope(instance_id, None, state).await?;
let base = instance_full_path(state, &scope.instance);
let old_txt_path = base.join(format!(
"{}.txt",
old_project_path.trim_end_matches(".disabled")
));
let new_txt_path = base.join(format!(
"{}.txt",
new_project_path.trim_end_matches(".disabled")
));
if old_txt_path.exists() {
if new_txt_path.exists()
&& io::canonicalize(&old_txt_path)?
== io::canonicalize(&new_txt_path)?
{
return Ok(());
}
io::copy(&old_txt_path, &new_txt_path).await?;
io::remove_file(&old_txt_path).await?;
}
}
Ok(())
}
pub(crate) async fn list_project_files(
instance_id: &str,
state: &State,
@@ -13,7 +13,7 @@ use std::collections::{HashMap, HashSet};
use super::apply_content_install::{
DownloadedProjectVersion, add_downloaded_project_version,
add_project_from_version, download_project_version, remove_project,
toggle_disable_project,
rename_project_companion_file, toggle_disable_project,
};
use super::check_content_updates::{ContentUpdate, check_content_updates};
@@ -108,6 +108,13 @@ async fn apply_content_update(
}
if new_path != project_path {
rename_project_companion_file(
instance_id,
project_path,
&new_path,
state,
)
.await?;
remove_project(instance_id, project_path, state).await?;
}
@@ -162,6 +169,13 @@ pub(crate) async fn update_all_projects(
}
if new_path != update.relative_path {
rename_project_companion_file(
instance_id,
&update.relative_path,
&new_path,
state,
)
.await?;
remove_project(instance_id, &update.relative_path, state)
.await?;
}