mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-09-13 01:23:58 +02:00
Hot-Reloading Refactor
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
ae1a4fd283
commit
6c1434c165
212 changed files with 5679 additions and 4206 deletions
40
src/core/mods/path.rs
Normal file
40
src/core/mods/path.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue