Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand libium's heuristic for github to use release name if only one jar is associated with the release #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 50 additions & 16 deletions src/upgrade/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,59 @@ pub fn github<'a>(
should_check_mod_loader: Option<bool>,
) -> Option<&'a Asset> {
for release in releases {
for asset in &release.assets {
if asset.name.contains("jar")
// Sources JARs should not be used with the regular game
&& !asset.name.contains("sources")
&& (Some(false) == should_check_game_version
|| asset.name.contains(game_version_to_check))
&& (Some(false) == should_check_mod_loader
|| check_mod_loader(
&asset
.name
.split('-')
.map(str::to_string)
.collect::<Vec<_>>(),
mod_loader_to_check,
))
{
let candidate_assets: Vec<&Asset> = release
.assets
.iter()
.filter(|asset| asset.name.contains("jar") && !asset.name.contains("sources"))
.collect();

if let Some(asset) = candidate_assets
.iter()
.filter(|asset| {
github_name_check_heuristic(
&asset.name,
game_version_to_check,
mod_loader_to_check,
should_check_game_version,
should_check_mod_loader,
)
})
.next()
{
return Some(asset);
}

if let &[asset] = candidate_assets.as_slice() {
if github_name_check_heuristic(
release
.name
.as_ref()
.unwrap_or(&"".to_string())
.to_lowercase()
.as_str(),
game_version_to_check,
mod_loader_to_check,
should_check_game_version,
should_check_mod_loader,
) {
return Some(asset);
}
}
}
None
}

fn github_name_check_heuristic<'a>(
name: &str,
game_version_to_check: &str,
mod_loader_to_check: &ModLoader,
should_check_game_version: Option<bool>,
should_check_mod_loader: Option<bool>,
) -> bool {
return (Some(false) == should_check_game_version || name.contains(game_version_to_check))
&& (Some(false) == should_check_mod_loader
|| check_mod_loader(
&name.split('-').map(str::to_string).collect::<Vec<_>>(),
mod_loader_to_check,
));
}