use lief_ffi as ffi;
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Version {
pub major: u32,
pub minor: u32,
pub patch: u32,
}
impl Version {
pub fn new(major: u32, minor: u32, patch: u32) -> Self {
Self {
major,
minor,
patch,
}
}
fn from_ffi(v: cxx::UniquePtr<ffi::runtime_osx_Host_version_t>) -> Self {
Self {
major: v.get_major(),
minor: v.get_minor(),
patch: v.get_patch(),
}
}
pub fn big_sur() -> Self {
Self::from_ffi(ffi::runtime_osx_Host_version_t::big_sur())
}
pub fn monterey() -> Self {
Self::from_ffi(ffi::runtime_osx_Host_version_t::monterey())
}
pub fn ventura() -> Self {
Self::from_ffi(ffi::runtime_osx_Host_version_t::ventura())
}
pub fn sonoma() -> Self {
Self::from_ffi(ffi::runtime_osx_Host_version_t::sonoma())
}
pub fn sequoia() -> Self {
Self::from_ffi(ffi::runtime_osx_Host_version_t::sequoia())
}
pub fn tahoe() -> Self {
Self::from_ffi(ffi::runtime_osx_Host_version_t::tahoe())
}
}
impl PartialOrd for Version {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Version {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
(self.major, self.minor, self.patch).cmp(&(other.major, other.minor, other.patch))
}
}
impl fmt::Display for Version {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
}
}
pub struct Host {}
impl Host {
pub fn os_version_name() -> String {
ffi::runtime_osx_Host::os_version_name().to_string()
}
pub fn os_version() -> Version {
Version::from_ffi(ffi::runtime_osx_Host_version_t::os_version())
}
pub fn is_sip_enabled() -> bool {
ffi::runtime_osx_Host::is_sip_enabled()
}
}