mirror of
https://github.com/alterware/alterware-launcher.git
synced 2025-12-04 07:17:50 +00:00
backport extend
This commit is contained in:
31
src/misc.rs
31
src/misc.rs
@@ -1,26 +1,9 @@
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
io::Read,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use crate::{global, structs};
|
||||
|
||||
pub fn file_blake3(file: &Path) -> std::io::Result<String> {
|
||||
let mut blake3 = blake3::Hasher::new();
|
||||
let mut file = File::open(file)?;
|
||||
let mut buffer = [0; 1024];
|
||||
loop {
|
||||
let n = file.read(&mut buffer)?;
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
blake3.update(&buffer[..n]);
|
||||
}
|
||||
Ok(blake3.finalize().to_string())
|
||||
}
|
||||
|
||||
pub fn stdin() -> String {
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_line(&mut input).unwrap();
|
||||
@@ -34,12 +17,6 @@ pub fn rev_to_int(rev: &str) -> u16 {
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
pub fn fatal_error(error: &str) {
|
||||
crate::println_error!("{}: {error}", prefix("error"));
|
||||
stdin();
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
pub fn human_readable_bytes(bytes: u64) -> String {
|
||||
let mut bytes = bytes as f64;
|
||||
let mut i = 0;
|
||||
@@ -62,10 +39,6 @@ pub fn pb_style_download(pb: &ProgressBar, state: bool) {
|
||||
pb.set_style(style.unwrap());
|
||||
}
|
||||
|
||||
pub fn cute_path(path: &Path) -> String {
|
||||
path.to_str().unwrap().replace('\\', "/")
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn is_program_in_path(program: &str) -> bool {
|
||||
std::env::var_os("PATH")
|
||||
|
||||
Reference in New Issue
Block a user