1use crate::fs::get_rigela_program_directory;
15use log::error;
16use std::{
17 fs::{create_dir, OpenOptions},
18 io::Write,
19 path::PathBuf,
20};
21
22pub fn get_rigela_library_path() -> PathBuf {
26 let path = get_rigela_program_directory().join("libs");
27 if !path.exists() {
28 create_dir(&path).unwrap();
29 }
30 path
31}
32
33pub fn setup_library(path: &PathBuf, lib_bin: &[u8]) {
39 if path.exists() {
40 return;
41 }
42
43 match OpenOptions::new().write(true).create(true).open(&path) {
44 Ok(mut f) => match f.write_all(lib_bin) {
45 Ok(_) => {}
46 Err(e) => error!("Can't setup the `{}` library. {}", path.display(), e),
47 },
48 Err(e) => error!("Can't setup the `{}` library. {}", path.display(), e),
49 }
50}
51
52#[macro_export]
53macro_rules! call_proc {
54 ($module:expr,$name:ident,$def:ty,$($arg:expr),*) => {{
55 let f = get_proc_address($module, stringify!($name));
56 if !f.is_none() {
57 unsafe {
58 let r = (&*((&f) as *const FARPROC as *const $def)) ($($arg),*);
59 Some(r)
60 }
61 } else {
62 None
63 }
64 }};
65}