the first wave of refactors

This commit is contained in:
leocth
2022-02-20 22:20:50 +08:00
parent 9d74e84c01
commit 14e8e92f46
9 changed files with 264 additions and 294 deletions

View File

@@ -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())
}