You've already forked AstralRinth
forked from didirus/AstralRinth
the first wave of refactors
This commit is contained in:
@@ -1,30 +1,17 @@
|
||||
use crate::launcher::LauncherError;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use std::process::Command;
|
||||
|
||||
lazy_static! {
|
||||
static ref JAVA_VERSION_REGEX: Regex = Regex::new(r#""(.*?)""#).unwrap();
|
||||
}
|
||||
|
||||
pub fn check_java() -> Result<Option<String>, LauncherError> {
|
||||
pub fn check_java() -> Result<String, LauncherError> {
|
||||
let child = Command::new("java")
|
||||
.arg("-version")
|
||||
.output()
|
||||
.map_err(|err| LauncherError::ProcessError {
|
||||
inner: err,
|
||||
process: "java".to_string(),
|
||||
.map_err(|inner| LauncherError::ProcessError {
|
||||
inner,
|
||||
process: "java".into(),
|
||||
})?;
|
||||
|
||||
let output = &*String::from_utf8_lossy(&*child.stderr);
|
||||
|
||||
if let Some(version_raw) = JAVA_VERSION_REGEX.find(output) {
|
||||
let mut raw = version_raw.as_str().chars();
|
||||
raw.next();
|
||||
raw.next_back();
|
||||
|
||||
return Ok(Some(raw.as_str().to_string()));
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
let output = String::from_utf8_lossy(&child.stderr);
|
||||
let output = output.trim_matches('\"');
|
||||
Ok(output.into())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user