Skip to content

Commit 821b1ee

Browse files
committed
fix java detection for weird formats
1 parent 7f901dc commit 821b1ee

File tree

5 files changed

+35
-40
lines changed

5 files changed

+35
-40
lines changed

Cargo.lock

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "mcvcli"
33
description = "A command line interface for managing Minecraft servers."
4-
version = "2.3.3"
4+
version = "2.3.4"
55
edition = "2024"
66
license = "MIT"
77
homepage = "https://github.com/mcjars/mcvcli"
@@ -35,3 +35,4 @@ sysinfo = "0.34.0"
3535
rand = "0.9.0"
3636
ipipe = "0.11.7"
3737
xz2 = "0.1.7"
38+
atoi = "2.0.0"

src/jar.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::api::Progress;
21
use crate::api::{
3-
self,
2+
self, Progress,
43
mcjars::{Build, InstallationStep, Version},
54
modrinth::Project,
65
};
@@ -16,7 +15,7 @@ use zip::ZipArchive;
1615

1716
pub async fn install(build: &Build, directory: &str, spaces: usize) -> Result<(), reqwest::Error> {
1817
if Path::new(directory).join("libraries").exists() {
19-
std::fs::remove_dir_all(Path::new(directory).join("libraries")).unwrap_or(());
18+
std::fs::remove_dir_all(Path::new(directory).join("libraries")).unwrap_or_default();
2019
}
2120

2221
for group in build.installation.iter() {

src/java.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ struct Package {
2424
static LOCATION: LazyLock<String> =
2525
LazyLock::new(|| format!("{}/.mcvcli/java", home_dir().unwrap().to_str().unwrap()));
2626

27+
fn parse_version_stderr(stderr: &str) -> u8 {
28+
let line = stderr.lines().next().unwrap();
29+
let version = line
30+
.split_whitespace()
31+
.find(|s| s.chars().any(|c| c.is_numeric()))
32+
.unwrap()
33+
.trim_matches(|c: char| !c.is_numeric())
34+
.replace("1.8", "8");
35+
36+
atoi::atoi(version.as_bytes()).unwrap()
37+
}
38+
2739
pub fn installed() -> Vec<(u8, String)> {
2840
let mut installed: Vec<(u8, String)> = Vec::new();
2941

@@ -72,20 +84,7 @@ pub fn find_local() -> Option<(u8, String, String)> {
7284
.stderr;
7385

7486
if let Ok(version) = String::from_utf8(version) {
75-
let version = version
76-
.lines()
77-
.next()
78-
.unwrap()
79-
.split_whitespace()
80-
.nth(2)
81-
.unwrap()
82-
.replace("\"", "")
83-
.replace("1.8", "8")
84-
.split('.')
85-
.next()
86-
.unwrap()
87-
.parse()
88-
.unwrap();
87+
let version = parse_version_stderr(&version);
8988

9089
return Some((version, binary, java_home));
9190
}
@@ -103,20 +102,7 @@ pub fn find_local() -> Option<(u8, String, String)> {
103102
.stderr;
104103

105104
if let Ok(version) = String::from_utf8(version) {
106-
let version = version
107-
.lines()
108-
.next()
109-
.unwrap()
110-
.split_whitespace()
111-
.nth(2)
112-
.unwrap()
113-
.replace("\"", "")
114-
.replace("1.8", "8")
115-
.split('.')
116-
.next()
117-
.unwrap()
118-
.parse()
119-
.unwrap();
105+
let version = parse_version_stderr(&version);
120106

121107
return Some((version, binary, "".to_string()));
122108
}

src/modpack.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ pub async fn install(directory: &str, version: &Version) {
104104
std::fs::remove_file(Path::new(directory).join("modrinth.index.json")).unwrap_or_default();
105105

106106
if let Ok(files) = std::fs::read_dir(Path::new(directory).join("overrides")) {
107-
for file in files {
108-
let file = file.unwrap();
107+
for file in files.flatten() {
109108
let file_path = file.path();
110109
let new_path =
111110
Path::new(directory).join(file_path.file_name().unwrap().to_str().unwrap());
@@ -137,7 +136,7 @@ pub async fn install(directory: &str, version: &Version) {
137136
let terminal_width = term_size::dimensions().unwrap().0 as usize;
138137
for files in index.files.chunks(10) {
139138
let progress = Arc::new(Mutex::new(ProgressBar::with_capacity(10)));
140-
let mut handles = vec![];
139+
let mut handles = Vec::new();
141140

142141
for file in files {
143142
if file

0 commit comments

Comments
 (0)