Since I now found a way to obtain a version of the Oodle library compiled for Linux, I don't need to bother with Wine anymore, and can instead load the library directly. This removes the need for the extra utility completely. I still have to load the library at runtime, though, as Rust only supports static linking, and I probably don't have a lincense to do that with Oodle.
74 lines
1.9 KiB
Rust
74 lines
1.9 KiB
Rust
use std::sync::Arc;
|
|
|
|
use tokio::sync::RwLock;
|
|
|
|
use crate::murmur::{Dictionary, HashGroup, Murmur32, Murmur64};
|
|
use crate::oodle::Oodle;
|
|
|
|
pub struct Context {
|
|
pub lookup: Dictionary,
|
|
pub oodle: Option<Oodle>,
|
|
pub ljd: Option<String>,
|
|
pub revorb: Option<String>,
|
|
pub ww2ogg: Option<String>,
|
|
}
|
|
|
|
impl Context {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
lookup: Dictionary::new(),
|
|
oodle: None,
|
|
ljd: None,
|
|
revorb: None,
|
|
ww2ogg: None,
|
|
}
|
|
}
|
|
|
|
pub fn lookup_hash<M>(&self, hash: M, group: HashGroup) -> String
|
|
where
|
|
M: Into<Murmur64>,
|
|
{
|
|
let hash = hash.into();
|
|
if let Some(s) = self.lookup.lookup(hash, group) {
|
|
tracing::debug!(%hash, string = s, "Murmur64 lookup successful");
|
|
s.to_owned()
|
|
} else {
|
|
tracing::debug!(%hash, "Murmur64 lookup failed");
|
|
format!("{:016X}", hash)
|
|
}
|
|
}
|
|
|
|
pub fn lookup_hash_short<M>(&self, hash: M, group: HashGroup) -> String
|
|
where
|
|
M: Into<Murmur32>,
|
|
{
|
|
let hash = hash.into();
|
|
if let Some(s) = self.lookup.lookup_short(hash, group) {
|
|
tracing::debug!(%hash, string = s, "Murmur32 lookup successful");
|
|
s.to_owned()
|
|
} else {
|
|
tracing::debug!(%hash, "Murmur32 lookup failed");
|
|
format!("{:08X}", hash)
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for Context {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
pub async fn lookup_hash<M>(ctx: Arc<RwLock<Context>>, hash: M, group: HashGroup) -> String
|
|
where
|
|
M: Into<Murmur64>,
|
|
{
|
|
let hash = hash.into();
|
|
if let Some(s) = ctx.read().await.lookup.lookup(hash, group) {
|
|
tracing::debug!(%hash, string = s, "Murmur64 lookup successful");
|
|
s.to_owned()
|
|
} else {
|
|
tracing::debug!(%hash, "Murmur64 lookup failed");
|
|
format!("{:016X}", hash)
|
|
}
|
|
}
|