Compare commits
4 Commits
c9b1895e0c
...
1a292c6316
Author | SHA1 | Date | |
---|---|---|---|
1a292c6316 | |||
e4ff89fee9 | |||
e03a107d83 | |||
c549f7def5 |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
Cargo.lock -merge linguist-generated=false
|
12
crates/fsv-sys/src/bindings.rs
Normal file
12
crates/fsv-sys/src/bindings.rs
Normal file
@ -0,0 +1,12 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(unused)]
|
||||
|
||||
pub mod BINDINGS_V1_40_14 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.14.rs"));
|
||||
}
|
||||
|
||||
pub mod BINDINGS_V1_40_13 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.13.rs"));
|
||||
}
|
@ -1,16 +1,17 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
mod bindings;
|
||||
use bindings::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SUPPORTED_FSV_VERSIONS {
|
||||
pub enum SupportedFsvVersion {
|
||||
V1_40_14, // 1.40.14
|
||||
V1_40_13, // 1.40.13
|
||||
}
|
||||
|
||||
impl SUPPORTED_FSV_VERSIONS {
|
||||
impl SupportedFsvVersion {
|
||||
fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::V1_40_14 => "1.40.14",
|
||||
@ -19,14 +20,6 @@ impl SUPPORTED_FSV_VERSIONS {
|
||||
}
|
||||
}
|
||||
|
||||
mod BINDINGS_V1_40_14 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.14.rs"));
|
||||
}
|
||||
|
||||
mod BINDINGS_V1_40_13 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.13.rs"));
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
@ -66,26 +59,26 @@ mod sealed { pub trait Sealed {}}
|
||||
/// Wrapper around the SESAM-VITALE library
|
||||
/// This struct is responsible for loading the library and providing an interface to call its functions.
|
||||
/// The library is loaded at creation and kept in memory until the struct is dropped.
|
||||
pub trait SSVLibrary_Common {
|
||||
pub trait SSVLibraryCommon {
|
||||
fn new(path: &str) -> Result<Self, Error> where Self: Sized;
|
||||
}
|
||||
|
||||
pub trait SSVLibrary_Version: sealed::Sealed {}
|
||||
pub trait SSVLibraryVersion: sealed::Sealed {}
|
||||
|
||||
pub struct V1_40_13 {}
|
||||
impl sealed::Sealed for V1_40_13 {}
|
||||
impl SSVLibrary_Version for V1_40_13 {}
|
||||
impl SSVLibraryVersion for V1_40_13 {}
|
||||
|
||||
pub struct V1_40_14 {}
|
||||
impl sealed::Sealed for V1_40_14 {}
|
||||
impl SSVLibrary_Version for V1_40_14 {}
|
||||
impl SSVLibraryVersion for V1_40_14 {}
|
||||
|
||||
pub struct SSVLibrary<Version: SSVLibrary_Version> {
|
||||
pub struct SSVLibrary<Version: SSVLibraryVersion> {
|
||||
_version: PhantomData<Version>,
|
||||
library: libloading::Library,
|
||||
}
|
||||
|
||||
impl<Version: SSVLibrary_Version> SSVLibrary_Common for SSVLibrary<Version> {
|
||||
impl<Version: SSVLibraryVersion> SSVLibraryCommon for SSVLibrary<Version> {
|
||||
fn new(path: &str) -> Result<Self, Error> {
|
||||
let library = unsafe { libloading::Library::new(path)?};
|
||||
Ok(Self {
|
||||
@ -137,14 +130,14 @@ impl SSVLibrary<V1_40_13> {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_library_path(version: &SUPPORTED_FSV_VERSIONS) -> String {
|
||||
pub fn get_library_path(version: &SupportedFsvVersion) -> String {
|
||||
let root_path = get_library_root_path();
|
||||
let library_name = get_library_name();
|
||||
let version = version.as_str();
|
||||
format!("{root_path}/{version}/lib/{library_name}")
|
||||
}
|
||||
|
||||
pub fn sesam_ini_path(version: &SUPPORTED_FSV_VERSIONS) -> String {
|
||||
pub fn sesam_ini_path(version: &SupportedFsvVersion) -> String {
|
||||
let root_path = get_sesam_ini_root_path();
|
||||
let version = version.as_str();
|
||||
format!("{root_path}/{version}/conf/sesam.ini")
|
||||
@ -171,22 +164,22 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_initlib2() {
|
||||
let lib_path = &get_library_path(&SUPPORTED_FSV_VERSIONS::V1_40_13);
|
||||
let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
|
||||
let ssv_library = SSVLibrary::<V1_40_13>::new(lib_path).expect("SSVLibrary::new failed");
|
||||
|
||||
let sesam_ini_str =
|
||||
CString::new(sesam_ini_path(&SUPPORTED_FSV_VERSIONS::V1_40_13)).expect("CString::new failed");
|
||||
CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed");
|
||||
let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lire_config_and_carte_ps() {
|
||||
let lib_path = &get_library_path(&SUPPORTED_FSV_VERSIONS::V1_40_13);
|
||||
let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
|
||||
let ssv_library = SSVLibrary::<V1_40_13>::new(lib_path).expect("SSVLibrary::new failed");
|
||||
|
||||
let sesam_ini_str =
|
||||
CString::new(sesam_ini_path(&SUPPORTED_FSV_VERSIONS::V1_40_13)).expect("CString::new failed");
|
||||
CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed");
|
||||
let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user