Vanilla works but fabric doesn't

This commit is contained in:
2025-08-24 14:16:09 +02:00
commit 997cf37d31
19 changed files with 2919 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
use std::{ffi, fs, io, path};
use crate::*;
pub(crate) fn create_or_open_file<S: AsRef<ffi::OsStr>>(path: &S) -> Result<fs::File, io::Error> {
let path = path::Path::new(path);
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
Ok(fs::File::create(&path)?)
}
pub(crate) fn file_hash<P: AsRef<path::Path>>(hash: &str, path: &P) -> Result<bool, error::Error> {
use sha1::Digest;
let mut file = fs::File::open(path)?;
let mut hasher = sha1::Sha1::new();
io::copy(&mut file, &mut hasher)?;
let reader_hash = hex::encode(hasher.finalize());
Ok(reader_hash == hash)
}
#[inline(always)]
pub(crate) fn from_json_file<T: serde::de::DeserializeOwned, P: AsRef<path::Path>>(path: P) -> Result<T, error::Error> {
Ok(serde_json::from_str(&fs::read_to_string(path)?)?)
}
#[macro_export]
macro_rules! path {
() => {
std::path::PathBuf::new()
};
($($segment:expr),+ $(,)?) => {
{
let mut path = std::path::PathBuf::new();
$(
path.push($segment);
)+
path
}
};
}
#[macro_export]
macro_rules! osStr {
() => {
std::ffi::OsString::new()
};
($($segment:expr),+ $(,)?) => {
{
let mut string = std::ffi::OsString::new();
$(
string.push($segment);
)+
string
}
};
}