Skip to content

Commit

Permalink
Fix modpacks specifying non-existent overrides directory
Browse files Browse the repository at this point in the history
Don't swap remove when deleting profiles or modpacks
  • Loading branch information
theRookieCoder committed Feb 25, 2024
1 parent 40a1043 commit 1045cce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ pub async fn clean(
/// Construct a `to_install` vector from the `directory`
pub fn read_overrides(directory: &Path) -> Result<Vec<(OsString, PathBuf)>> {
let mut to_install = Vec::new();
for file in read_dir(directory)? {
let file = file?;
to_install.push((file.file_name(), file.path()));
if directory.exists() {
for file in read_dir(directory)? {
let file = file?;
to_install.push((file.file_name(), file.path()));
}
}
Ok(to_install)
}
Expand All @@ -104,7 +106,6 @@ pub async fn download(
to_download: Vec<Downloadable>,
to_install: Vec<(OsString, PathBuf)>,
) -> Result<()> {
create_dir_all(&output_dir).await?;
let progress_bar = Arc::new(Mutex::new(
ProgressBar::new(
to_download
Expand Down Expand Up @@ -159,20 +160,20 @@ pub async fn download(
.map_err(|_| anyhow!("Failed to run threads to completion"))?
.into_inner()?
.finish_and_clear();
for installable in to_install {
if installable.1.is_file() {
copy(installable.1, output_dir.join(&installable.0)).await?;
} else if installable.1.is_dir() {
for (name, path) in to_install {
if path.is_file() {
copy(path, output_dir.join(&name)).await?;
} else if path.is_dir() {
let mut copy_options = DirCopyOptions::new();
copy_options.overwrite = true;
copy_dir(installable.1, &*output_dir, &copy_options)?;
copy_dir(path, &*output_dir, &copy_options)?;
} else {
bail!("Could not determine whether installable is file/folder")
bail!("Could not determine whether installable is a file or folder")
}
println!(
"{} Installed {}",
&*TICK,
installable.0.to_string_lossy().dimmed()
name.to_string_lossy().dimmed()
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/modpack/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn delete(
return Ok(());
}
};
config.modpacks.swap_remove(selection);
config.modpacks.remove(selection);

// If the currently selected modpack is being removed
if config.active_modpack == selection {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/profile/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn delete(
return Ok(());
}
};
config.profiles.swap_remove(selection);
config.profiles.remove(selection);

// If the currently selected profile is being removed
if config.active_profile == selection {
Expand Down

0 comments on commit 1045cce

Please sign in to comment.