mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-06-27 14:14:50 +02:00
40 lines
852 B
Rust
40 lines
852 B
Rust
use std::{
|
|
env::current_exe,
|
|
ffi::{OsStr, OsString},
|
|
path::{Path, PathBuf},
|
|
time::SystemTime,
|
|
};
|
|
|
|
use libloading::library_filename;
|
|
|
|
use crate::Result;
|
|
|
|
pub fn from_name(name: &str) -> Result<OsString> {
|
|
let root = PathBuf::new();
|
|
let exe_path = current_exe()?;
|
|
let exe_dir = exe_path.parent().unwrap_or(&root);
|
|
let mut mod_path = exe_dir.to_path_buf();
|
|
let mod_file = library_filename(name);
|
|
mod_path.push(mod_file);
|
|
|
|
Ok(mod_path.into_os_string())
|
|
}
|
|
|
|
pub fn to_name(path: &OsStr) -> Result<String> {
|
|
let path = Path::new(path);
|
|
let name = path
|
|
.file_stem()
|
|
.expect("path file stem")
|
|
.to_str()
|
|
.expect("name string");
|
|
let name = name.strip_prefix("lib").unwrap_or(name).to_owned();
|
|
|
|
Ok(name)
|
|
}
|
|
|
|
pub fn mtime(path: &OsStr) -> Result<SystemTime> {
|
|
let meta = std::fs::metadata(path)?;
|
|
let mtime = meta.modified()?;
|
|
|
|
Ok(mtime)
|
|
}
|