Skip to content

Commit

Permalink
Fix dependencies with mods-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Feb 5, 2024
1 parent 6bf4fc8 commit d21a3d6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ pub fn read_dir_recursive(src: &PathBuf) -> Result<Vec<PathBuf>, io::Error> {
for item in fs::read_dir(src)? {
let path = item?.path();
if path.is_dir() {
res.extend(read_dir_recursive(src)?);
res.extend(read_dir_recursive(&path)?);
res.push(path);
} else {
res.push(path);
}
Expand Down
14 changes: 8 additions & 6 deletions src/index.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::Config;
use crate::file::copy_dir_recursive;
use crate::file::{copy_dir_recursive, read_dir_recursive};
use crate::util::logging::ask_value;
use crate::util::mod_file::{parse_mod_info, try_parse_mod_info};
use crate::{done, fatal, info, warn, NiceUnwrap};
Expand Down Expand Up @@ -180,11 +180,12 @@ pub fn index_mods_dir(config: &Config) -> PathBuf {
}

pub fn get_entry(config: &Config, id: &String, version: &VersionReq) -> Option<Entry> {
for dir in index_mods_dir(config)
.read_dir()
.nice_unwrap("Unable to read index")
{
let path = dir.unwrap().path();
let dir = index_mods_dir(config).join(id);

for path in {
read_dir_recursive(&dir)
.nice_unwrap("Unable to read index")
} {
let Ok(mod_info) = try_parse_mod_info(&path) else {
continue;
};
Expand All @@ -198,6 +199,7 @@ pub fn get_entry(config: &Config, id: &String, version: &VersionReq) -> Option<E
);
}
}

None
}

Expand Down
19 changes: 15 additions & 4 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,25 @@ impl Found {
fn find_dependency(
dep: &Dependency,
dir: &PathBuf,
search_recursive: bool
search_recursive: bool,
mods_v2: bool
) -> Result<Found, std::io::Error> {
// for checking if the id was possibly misspelled, it must be at most 3
// steps away from the searched one
let mut closest_score = 4usize;
let mut found = Found::None;
let mut dir = dir.clone();

// this doesnt work with the fuzzy search misspelling check or whatever
// someone else can fix it i dont care kthx
if mods_v2 {
dir = dir.join(&dep.id);
if !dir.exists() {
return Ok(Found::None);
}
}
for dir in if search_recursive {
read_dir_recursive(dir)?
read_dir_recursive(&dir)?
} else {
dir.read_dir()?.map(|d| d.unwrap().path()).collect()
} {
Expand Down Expand Up @@ -273,12 +284,12 @@ pub fn check_dependencies(

// check index
let found_in_index = find_dependency(
&dep, &index_mods_dir(config), false
&dep, &index_mods_dir(config), true, true
).nice_unwrap("Unable to read index");

// check installed mods
let found_in_installed = find_dependency(
&dep, &config.get_current_profile().mods_dir(), true
&dep, &config.get_current_profile().mods_dir(), true, false
).nice_unwrap("Unable to read installed mods");

// if not found in either hjfod code
Expand Down

0 comments on commit d21a3d6

Please sign in to comment.