use std::ffi::*;
use serde::Deserialize;
use std::sync::{LazyLock, Mutex};
mod extern_functions;
use extern_functions::*;
pub mod error_codes;
pub use error_codes::*;
mod string_utils;
use string_utils::*;
type LicenseCallback = dyn Fn(LexActivatorCode) + Send + 'static;
static CALLBACK_FUNCTION: LazyLock<Mutex<Option<Box<LicenseCallback>>>> =
LazyLock::new(|| Mutex::new(None));
extern "C" fn wrapper(code: i32) {
let callback_status = LexActivatorCode::from_i32(code);
let callback = CALLBACK_FUNCTION.lock().unwrap();
if let Some(callback) = callback.as_ref() {
callback(callback_status);
}
}
#[derive(Debug)]
pub struct LicenseMeterAttribute {
pub name: String,
pub allowed_uses: i64,
pub total_uses: u64,
pub gross_uses: u64
}
#[derive(Debug)]
pub struct ProductVersionFeatureFlag {
pub name: String,
pub enabled: bool,
pub data: String
}
#[derive(Debug)]
pub struct ActivationMode {
pub initial_mode: String,
pub current_mode: String
}
#[derive(Debug, Deserialize, Default)]
pub struct Metadata {
pub key: String,
pub value: String,
}
#[derive(Debug, Deserialize, Default)]
pub struct OrganizationAddress {
#[serde(rename = "addressLine1")]
pub address_line_1: String,
#[serde(rename = "addressLine2")]
pub address_line_2: String,
pub city: String,
pub state: String,
pub country: String,
#[serde(rename = "postalCode")]
pub postal_code: String
}
#[derive(Debug, Deserialize)]
pub struct UserLicense {
#[serde(rename = "allowedActivations")]
pub allowed_activations: i64,
#[serde(rename = "allowedDeactivations")]
pub allowed_deactivations: i64,
pub key: String,
#[serde(rename = "totalActivations")]
pub total_activations: u32,
#[serde(rename = "totalDeactivations")]
pub total_deactivations: u32,
#[serde(rename = "type")]
pub license_type: String,
pub metadata: Vec<Metadata>
}
#[derive(Debug, Deserialize)]
pub struct FeatureEntitlement {
#[serde(rename = "featureName")]
pub feature_name: String,
#[serde(rename = "featureDisplayName")]
pub feature_display_name: String,
#[serde(rename = "value")]
pub value: String,
#[serde(rename = "baseValue")]
pub baseValue: String,
#[serde(rename = "expiresAt")]
pub expires_at : i64,
}
#[repr(u32)]
pub enum PermissionFlags {
LA_USER = 1,
LA_SYSTEM = 2,
LA_ALL_USERS = 3,
LA_IN_MEMORY = 4,
}
pub fn set_product_data(product_data: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_product_data = to_utf16(product_data);
status = unsafe { SetProductData(c_product_data.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_product_data = string_to_cstring(product_data)?;
status = unsafe { SetProductData(c_product_data.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_product_id(product_id: String, permission_flags: PermissionFlags) -> Result<(), LexActivatorError> {
let status: i32;
let c_flags: c_uint = permission_flags as u32 as c_uint;
#[cfg(windows)]
{
let c_product_id = to_utf16(product_id);
status = unsafe { SetProductId(c_product_id.as_ptr(), c_flags) };
}
#[cfg(not(windows))]
{
let c_product_id = string_to_cstring(product_id)?;
status = unsafe { SetProductId(c_product_id.as_ptr(), c_flags) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_data_directory(data_dir: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_data_dir = to_utf16(data_dir);
status = unsafe { SetDataDirectory(c_data_dir.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_data_dir = string_to_cstring(data_dir)?;
status = unsafe { SetDataDirectory(c_data_dir.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_debug_mode(enable: u32) {
let c_enable: c_uint = enable as c_uint;
unsafe { SetDebugMode(c_enable) };
}
pub fn set_cache_mode(mode: bool) -> Result<(), LexActivatorError> {
let c_mode: c_uint = if mode { 1 } else { 0 };
let status = unsafe { SetCacheMode(c_mode) };
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_custom_device_fingerprint(device_fingerprint: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_device_fingerprint = to_utf16(device_fingerprint);
status = unsafe { SetCustomDeviceFingerprint(c_device_fingerprint.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_device_fingerprint = string_to_cstring(device_fingerprint)?;
status = unsafe { SetCustomDeviceFingerprint(c_device_fingerprint.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_license_key(license_key: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_license_key = to_utf16(license_key);
status = unsafe { SetLicenseKey(c_license_key.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_license_key = string_to_cstring(license_key)?;
status = unsafe { SetLicenseKey(c_license_key.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_license_user_credential(email: String, password: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_email = to_utf16(email);
let c_password = to_utf16(password);
status = unsafe { SetLicenseUserCredential(c_email.as_ptr(), c_password.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_email = string_to_cstring(email)?;
let c_password = string_to_cstring(password)?;
status = unsafe { SetLicenseUserCredential(c_email.as_ptr(), c_password.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_license_callback<F>(closure: F) -> Result<(), LexActivatorError>
where
F: Fn(LexActivatorCode) + Clone + Send + 'static,
{
let mut callback_function = CALLBACK_FUNCTION.lock().unwrap();
callback_function.replace(Box::new(closure));
let status: i32 = unsafe { SetLicenseCallback(wrapper) };
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn unset_license_callback() {
let mut callback_function = CALLBACK_FUNCTION.lock().unwrap();
*callback_function = None;
}
pub fn set_activation_lease_duration(lease_duration: i64) -> Result<(), LexActivatorError> {
let c_lease_duration: c_longlong = lease_duration as c_longlong;
let status = unsafe { SetActivationLeaseDuration(c_lease_duration) };
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_activation_metadata(key: String, value: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_key = to_utf16(key);
let c_value = to_utf16(value);
status = unsafe { SetActivationMetadata(c_key.as_ptr(), c_value.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_key = string_to_cstring(key)?;
let c_value = string_to_cstring(value)?;
status = unsafe { SetActivationMetadata(c_key.as_ptr(), c_value.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_trial_activation_metadata(key: String, value: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_key = to_utf16(key);
let c_value = to_utf16(value);
status = unsafe { SetTrialActivationMetadata(c_key.as_ptr(), c_value.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_key = string_to_cstring(key)?;
let c_value = string_to_cstring(value)?;
status = unsafe { SetTrialActivationMetadata(c_key.as_ptr(), c_value.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_release_version(version: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_version = to_utf16(version);
status = unsafe { SetReleaseVersion(c_version.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_version = string_to_cstring(version)?;
status = unsafe { SetReleaseVersion(c_version.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_release_published_date(release_published_date: u32) -> Result<(), LexActivatorError>{
let c_release_published_date: c_uint = release_published_date as c_uint;
let status = unsafe { SetReleasePublishedDate(c_release_published_date) };
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_release_platform(platform: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_platform = to_utf16(platform);
status = unsafe { SetReleasePlatform(c_platform.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_platform = string_to_cstring(platform)?;
status = unsafe { SetReleasePlatform(c_platform.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_release_channel(channel: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_channel = to_utf16(channel);
status = unsafe { SetReleaseChannel(c_channel.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_channel = string_to_cstring(channel)?;
status = unsafe { SetReleaseChannel(c_channel.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_offline_activation_request_meter_attribute_uses(name: String, uses: i32) -> Result<(), LexActivatorError>{
let status: i32;
let c_uses: c_uint = uses as c_uint;
#[cfg(windows)]
{
let c_name = to_utf16(name);
status = unsafe { SetOfflineActivationRequestMeterAttributeUses(c_name.as_ptr(), c_uses) };
}
#[cfg(not(windows))]
{
let c_name = string_to_cstring(name)?;
status = unsafe { SetOfflineActivationRequestMeterAttributeUses(c_name.as_ptr(), c_uses) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_network_proxy(proxy: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_proxy = to_utf16(proxy);
status = unsafe { SetNetworkProxy(c_proxy.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_proxy = string_to_cstring(proxy)?;
status = unsafe { SetNetworkProxy(c_proxy.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_cryptlex_host(host: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_host = to_utf16(host);
status = unsafe { SetCryptlexHost(c_host.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_host = string_to_cstring(host)?;
status = unsafe { SetCryptlexHost(c_host.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn set_two_factor_authentication_code(two_factor_authentication_code: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_two_factor_authentication_code = to_utf16(two_factor_authentication_code);
status = unsafe { SetTwoFactorAuthenticationCode(c_two_factor_authentication_code.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_two_factor_authentication_code = string_to_cstring(two_factor_authentication_code)?;
status = unsafe { SetTwoFactorAuthenticationCode(c_two_factor_authentication_code.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_product_metadata(key: String) -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256;
let product_metadata_value: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
let utf16_ptr = to_utf16(key);
status = unsafe { GetProductMetadata(utf16_ptr.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
product_metadata_value = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
let key_cstring: CString = string_to_cstring(key)?;
status = unsafe { GetProductMetadata(key_cstring.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
product_metadata_value = c_char_to_string(&buffer);
}
if status == 0 {
Ok(product_metadata_value)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_product_version_name() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256;
let product_version_name: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetProductVersionName(buffer.as_mut_ptr(), LENGTH as c_uint) };
product_version_name = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetProductVersionName(buffer.as_mut_ptr(), LENGTH as c_uint) };
product_version_name = c_char_to_string(&buffer);
}
if status == 0 {
Ok(product_version_name)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_product_version_display_name() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let product_version_display_name: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetProductVersionDisplayName(buffer.as_mut_ptr(), LENGTH as c_uint) };
product_version_display_name = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetProductVersionDisplayName(buffer.as_mut_ptr(), LENGTH as c_uint) };
product_version_display_name = c_char_to_string(&buffer);
}
if status == 0 {
Ok(product_version_display_name)
} else {
Err(LexActivatorError::from(status))
}
}
pub fn get_product_version_feature_flag(name: String) -> Result<ProductVersionFeatureFlag, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let feature_name: String = name.clone();
let data: String;
let mut c_enabled: c_uint = 0;
#[cfg(windows)]
{
let c_name = to_utf16(name);
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetProductVersionFeatureFlag(c_name.as_ptr(), &mut c_enabled, buffer.as_mut_ptr(), LENGTH as c_uint) };
data = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let c_name = string_to_cstring(name)?;
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetProductVersionFeatureFlag(c_name.as_ptr(), &mut c_enabled, buffer.as_mut_ptr(), LENGTH as c_uint) };
data = c_char_to_string(&buffer);
}
let product_version_feature_flag = ProductVersionFeatureFlag {
name: feature_name,
enabled: u32_to_bool(c_enabled),
data: data
};
if status == 0 {
Ok(product_version_feature_flag)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_metadata(key: String) -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let license_metadata: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
let c_key = to_utf16(key);
status = unsafe { GetLicenseMetadata(c_key.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
license_metadata = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
let c_key: CString = string_to_cstring(key)?;
status = unsafe { GetLicenseMetadata(c_key.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
license_metadata = c_char_to_string(&buffer);
}
if status == 0 {
Ok(license_metadata)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_meterattribute(name: String) -> Result<LicenseMeterAttribute, LexActivatorError> {
let status: i32;
let meter_attribute_name: String = name.clone();
let mut c_allowed_uses: c_longlong = 0;
let mut c_total_uses: c_ulonglong = 0;
let mut c_gross_uses: c_ulonglong = 0;
#[cfg(windows)]
{
let c_name = to_utf16(name);
status = unsafe { GetLicenseMeterAttribute(c_name.as_ptr(), &mut c_allowed_uses, &mut c_total_uses, &mut c_gross_uses) };
}
#[cfg(not(windows))]
{
let c_name = string_to_cstring(name)?;
status = unsafe { GetLicenseMeterAttribute(c_name.as_ptr(), &mut c_allowed_uses, &mut c_total_uses, &mut c_gross_uses) };
}
let meter_attribute = LicenseMeterAttribute {
name: meter_attribute_name,
allowed_uses: c_allowed_uses,
total_uses: c_total_uses,
gross_uses: c_gross_uses,
};
if status == 0 {
Ok(meter_attribute)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_key() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let license_key: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseKey(buffer.as_mut_ptr(), LENGTH as c_uint) };
license_key = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseKey(buffer.as_mut_ptr(), LENGTH as c_uint) };
license_key = c_char_to_string(&buffer);
}
if status == 0 {
Ok(license_key)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_allowed_activations() -> Result<i64, LexActivatorError> {
let mut allowed_activations: c_longlong = 0;
let status = unsafe { GetLicenseAllowedActivations(&mut allowed_activations) };
if status == 0 {
Ok(allowed_activations)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_total_activations() -> Result<u32, LexActivatorError> {
let mut total_activations: c_uint = 0;
let status = unsafe { GetLicenseTotalActivations(&mut total_activations) };
if status == 0 {
Ok(total_activations)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_allowed_deactivations() -> Result<i64, LexActivatorError> {
let mut allowed_deactivations: c_longlong = 0;
let status = unsafe { GetLicenseAllowedDeactivations(&mut allowed_deactivations) };
if status == 0 {
Ok(allowed_deactivations)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_total_deactivations() -> Result<u32, LexActivatorError> {
let mut total_deactivations: c_uint = 0;
let status = unsafe { GetLicenseTotalDeactivations(&mut total_deactivations) };
if status == 0 {
Ok(total_deactivations)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_creation_date() -> Result<u32, LexActivatorError> {
let mut creation_date:c_uint = 0;
let status = unsafe { GetLicenseCreationDate(&mut creation_date) };
if status == 0 {
Ok(creation_date)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_activation_date() -> Result<u32, LexActivatorError> {
let mut activation_date:c_uint = 0;
let status = unsafe { GetLicenseActivationDate(&mut activation_date) };
if status == 0 {
Ok(activation_date)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_activation_last_synced_date() -> Result<u32, LexActivatorError> {
let mut last_synced_date: c_uint = 0;
let status = unsafe { GetActivationLastSyncedDate(&mut last_synced_date) };
if status == 0 {
Ok(last_synced_date)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_expiry_date() -> Result<u32, LexActivatorError> {
let mut expiry_date: c_uint = 0;
let status = unsafe { GetLicenseExpiryDate(&mut expiry_date) };
if status == 0 {
Ok(expiry_date)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_maintenance_expiry_date() -> Result<u32, LexActivatorError> {
let mut expiry_date: c_uint = 0;
let status = unsafe { GetLicenseMaintenanceExpiryDate(&mut expiry_date) };
if status == 0 {
Ok(expiry_date)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_max_allowed_release_version() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let max_allowed_release_version: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseMaxAllowedReleaseVersion(buffer.as_mut_ptr(), LENGTH as c_uint) };
max_allowed_release_version = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseMaxAllowedReleaseVersion(buffer.as_mut_ptr(), LENGTH as c_uint) };
max_allowed_release_version = c_char_to_string(&buffer);
}
if status == 0 {
Ok(max_allowed_release_version)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_user_email() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let user_email: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseUserEmail(buffer.as_mut_ptr(), LENGTH as c_uint) };
user_email = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseUserEmail(buffer.as_mut_ptr(), LENGTH as c_uint) };
user_email = c_char_to_string(&buffer);
}
if status == 0 {
Ok(user_email)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_user_name() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let user_name: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseUserName(buffer.as_mut_ptr(), LENGTH as c_uint) };
user_name = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseUserName(buffer.as_mut_ptr(), LENGTH as c_uint) };
user_name = c_char_to_string(&buffer);
}
if status == 0 {
Ok(user_name)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_user_company() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let user_company: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseUserCompany(buffer.as_mut_ptr(), LENGTH as c_uint) };
user_company = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseUserCompany(buffer.as_mut_ptr(), LENGTH as c_uint) };
user_company = c_char_to_string(&buffer);
}
if status == 0 {
Ok(user_company)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_user_metadata(key: String) -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let user_metadata: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
let c_key = to_utf16(key);
status = unsafe { GetLicenseUserMetadata(c_key.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
user_metadata = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
let c_key: CString = string_to_cstring(key)?;
status = unsafe { GetLicenseUserMetadata(c_key.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
user_metadata = c_char_to_string(&buffer);
}
if status == 0 {
Ok(user_metadata)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_organization_name() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let organization_name: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseOrganizationName(buffer.as_mut_ptr(), LENGTH as c_uint) };
organization_name = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseOrganizationName(buffer.as_mut_ptr(), LENGTH as c_uint) };
organization_name = c_char_to_string(&buffer);
}
if status == 0 {
Ok(organization_name)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_organization_address() -> Result<OrganizationAddress, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let org_address_json: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseOrganizationAddressInternal(buffer.as_mut_ptr(), LENGTH as c_uint) };
org_address_json = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseOrganizationAddressInternal(buffer.as_mut_ptr(), LENGTH as c_uint) };
org_address_json = c_char_to_string(&buffer);
}
if status == 0 {
if org_address_json.trim().is_empty() {
Ok(OrganizationAddress::default())
} else {
let org_address: OrganizationAddress = serde_json::from_str(&org_address_json).expect("Failed to parse JSON");
Ok(org_address)
}
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_user_licenses() -> Result<Vec<UserLicense>, LexActivatorError> {
let status: i32;
const LENGTH: usize = 1024;
let user_licenses_json: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetUserLicensesInternal(buffer.as_mut_ptr(), LENGTH as c_uint) };
user_licenses_json = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetUserLicensesInternal(buffer.as_mut_ptr(), LENGTH as c_uint) };
user_licenses_json = c_char_to_string(&buffer);
}
if status == 0 {
if user_licenses_json.is_empty() {
Ok(Vec::new())
} else {
let user_licenses: Vec<UserLicense> = serde_json::from_str(&user_licenses_json).expect("Failed to parse JSON");
Ok(user_licenses)
}
} else {
Err(LexActivatorError::from(status))
}
}
pub fn get_license_entitlement_set_name() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256;
let license_entitlement_set_name: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseEntitlementSetName(buffer.as_mut_ptr(), LENGTH as c_uint) };
license_entitlement_set_name = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseEntitlementSetName(buffer.as_mut_ptr(), LENGTH as c_uint) };
license_entitlement_set_name = c_char_to_string(&buffer);
}
if status == 0 {
Ok(license_entitlement_set_name)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_entitlement_set_display_name() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256;
let license_entitlement_set_display_name: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseEntitlementSetDisplayName(buffer.as_mut_ptr(), LENGTH as c_uint) };
license_entitlement_set_display_name = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseEntitlementSetDisplayName(buffer.as_mut_ptr(), LENGTH as c_uint) };
license_entitlement_set_display_name = c_char_to_string(&buffer);
}
if status == 0 {
Ok(license_entitlement_set_display_name)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_license_entitlement_set_tier() -> Result<i64, LexActivatorError> {
let mut tier: c_longlong = 0;
let status = unsafe { GetLicenseEntitlementSetTier(&mut tier) };
if status == 0 {
Ok(tier)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_feature_entitlements() -> Result<Vec<FeatureEntitlement>, LexActivatorError> {
let status: i32;
const LENGTH: usize = 4096;
let feature_entitlements_json: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetFeatureEntitlementsInternal(buffer.as_mut_ptr(), LENGTH as c_uint) };
feature_entitlements_json = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetFeatureEntitlementsInternal(buffer.as_mut_ptr(), LENGTH as c_uint) };
feature_entitlements_json = c_char_to_string(&buffer);
}
if status == 0 {
if feature_entitlements_json.is_empty() {
Ok(Vec::new())
} else {
let feature_entitlements: Vec<FeatureEntitlement> = serde_json::from_str(&feature_entitlements_json).expect("Failed to parse JSON");
Ok(feature_entitlements)
}
} else {
Err(LexActivatorError::from(status))
}
}
pub fn get_feature_entitlement(feature_name: String) -> Result<FeatureEntitlement, LexActivatorError> {
let status: i32;
const LENGTH: usize = 1024;
let feature_entitlement_json: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
let c_name = to_utf16(feature_name);
status = unsafe { GetFeatureEntitlementInternal(c_name.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
feature_entitlement_json = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let c_name = string_to_cstring(feature_name)?;
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetFeatureEntitlementInternal(c_name.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
feature_entitlement_json = c_char_to_string(&buffer);
}
if status == 0 {
let feature_entitlement: FeatureEntitlement = serde_json::from_str(&feature_entitlement_json).expect("Failed to parse JSON");
Ok(feature_entitlement)
} else {
Err(LexActivatorError::from(status))
}
}
pub fn get_license_type() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let license_type: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseType(buffer.as_mut_ptr(), LENGTH as c_uint) };
license_type = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetLicenseType(buffer.as_mut_ptr(), LENGTH as c_uint) };
license_type = c_char_to_string(&buffer);
}
if status == 0 {
Ok(license_type)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_activation_id() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256;
let activation_id: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetActivationId(buffer.as_mut_ptr(), LENGTH as c_uint) };
activation_id = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetActivationId(buffer.as_mut_ptr(), LENGTH as c_uint) };
activation_id = c_char_to_string(&buffer);
}
if status == 0 {
Ok(activation_id)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_activation_metadata(key: String) -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let activation_metadata: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
let c_key = to_utf16(key);
status = unsafe { GetActivationMetadata(c_key.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
activation_metadata = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
let c_key: CString = string_to_cstring(key)?;
status = unsafe { GetActivationMetadata(c_key.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
activation_metadata = c_char_to_string(&buffer);
}
if status == 0 {
Ok(activation_metadata)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_activation_mode() -> Result<ActivationMode, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let initial_activation_mode: String;
let current_activation_mode: String;
#[cfg(windows)]
{
let mut initial_mode_buffer: [u16; LENGTH] = [0; LENGTH];
let mut current_mode_buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetActivationMode(initial_mode_buffer.as_mut_ptr(), LENGTH as c_uint, current_mode_buffer.as_mut_ptr(), LENGTH as c_uint) };
initial_activation_mode = utf16_to_string(&initial_mode_buffer);
current_activation_mode = utf16_to_string(¤t_mode_buffer);
}
#[cfg(not(windows))]
{
let mut initial_mode_buffer: [c_char; LENGTH] = [0; LENGTH];
let mut current_mode_buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetActivationMode(initial_mode_buffer.as_mut_ptr(), LENGTH as c_uint, current_mode_buffer.as_mut_ptr(), LENGTH as c_uint) };
initial_activation_mode = c_char_to_string(&initial_mode_buffer);
current_activation_mode = c_char_to_string(¤t_mode_buffer);
}
let activation_mode = ActivationMode {
initial_mode: initial_activation_mode,
current_mode: current_activation_mode,
};
if status == 0 {
Ok(activation_mode)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_activation_meter_attribute_uses(name: String) -> Result<u32, LexActivatorError> {
let status: i32;
let mut count: c_uint = 0;
#[cfg(windows)]
{
let c_name = to_utf16(name);
status = unsafe { GetActivationMeterAttributeUses(c_name.as_ptr(), &mut count,) };
}
#[cfg(not(windows))]
{
let c_name: CString = string_to_cstring(name)?;
status = unsafe { GetActivationMeterAttributeUses(c_name.as_ptr(), &mut count) };
}
if status == 0 {
Ok(count)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_server_sync_grace_period_expiry_date() -> Result<u32, LexActivatorError> {
let status: i32;
let mut expiry_date: c_uint = 0;
status = unsafe { GetServerSyncGracePeriodExpiryDate(&mut expiry_date) };
if status == 0 {
Ok(expiry_date)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_last_activation_error() -> Result<u32, LexActivatorError> {
let status: i32;
let mut error_code: c_uint = 0;
status = unsafe { GetLastActivationError(&mut error_code) };
if status == 0 {
Ok(error_code)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_trial_activation_metadata(key: String) -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let trial_activation_metadata: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
let c_key = to_utf16(key);
status = unsafe { GetTrialActivationMetadata(c_key.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
trial_activation_metadata = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
let c_key: CString = string_to_cstring(key)?;
status = unsafe { GetTrialActivationMetadata(c_key.as_ptr(), buffer.as_mut_ptr(), LENGTH as c_uint) };
trial_activation_metadata = c_char_to_string(&buffer);
}
if status == 0 {
Ok(trial_activation_metadata)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_trial_expiry_date() -> Result<u32, LexActivatorError> {
let status: i32;
let mut trial_expiry_date: c_uint = 0;
status = unsafe { GetTrialExpiryDate(&mut trial_expiry_date) };
if status == 0 {
Ok(trial_expiry_date)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_trial_id() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let trial_id: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetTrialId(buffer.as_mut_ptr(), LENGTH as c_uint) };
trial_id = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetTrialId(buffer.as_mut_ptr(), LENGTH as c_uint) };
trial_id = c_char_to_string(&buffer);
}
if status == 0 {
Ok(trial_id)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_local_trial_expiry_date() -> Result<u32, LexActivatorError> {
let status: i32;
let mut trial_expiry_date: c_uint = 0;
status = unsafe { GetLocalTrialExpiryDate(&mut trial_expiry_date) };
if status == 0 {
Ok(trial_expiry_date)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn get_library_version() -> Result<String, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256; let library_version: String;
#[cfg(windows)]
{
let mut buffer: [u16; LENGTH] = [0; LENGTH];
status = unsafe { GetLibraryVersion(buffer.as_mut_ptr(), LENGTH as c_uint) };
library_version = utf16_to_string(&buffer);
}
#[cfg(not(windows))]
{
let mut buffer: [c_char; LENGTH] = [0; LENGTH];
status = unsafe { GetLibraryVersion(buffer.as_mut_ptr(), LENGTH as c_uint) };
library_version = c_char_to_string(&buffer);
}
if status == 0 {
Ok(library_version)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn authenticate_user(email: String, password: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_email = to_utf16(email);
let c_password = to_utf16(password);
status = unsafe { AuthenticateUser(c_email.as_ptr(), c_password.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_email = string_to_cstring(email)?;
let c_password = string_to_cstring(password)?;
status = unsafe { AuthenticateUser(c_email.as_ptr(), c_password.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn authenticate_user_with_id_token(id_token: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_id_token = to_utf16(id_token);
status = unsafe { AuthenticateUserWithIdToken(c_id_token.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_id_token = string_to_cstring(id_token)?;
status = unsafe { AuthenticateUserWithIdToken(c_id_token.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn activate_license() -> Result<LexActivatorStatus, LexActivatorError> {
let status = unsafe { ActivateLicense() };
match status {
0 => Ok(LexActivatorStatus::LA_OK),
20 => Ok(LexActivatorStatus::LA_EXPIRED),
21 => Ok(LexActivatorStatus::LA_SUSPENDED),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn activate_license_offline(file_path: String) -> Result<LexActivatorStatus, LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_file_path = to_utf16(file_path);
status = unsafe { ActivateLicenseOffline(c_file_path.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_file_path: CString = string_to_cstring(file_path)?;
status = unsafe { ActivateLicenseOffline(c_file_path.as_ptr()) };
}
match status {
0 => Ok(LexActivatorStatus::LA_OK),
20 => Ok(LexActivatorStatus::LA_EXPIRED),
21 => Ok(LexActivatorStatus::LA_SUSPENDED),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn generate_offline_activation_request(file_path: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_file_path = to_utf16(file_path);
status = unsafe { GenerateOfflineActivationRequest(c_file_path.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_file_path: CString = string_to_cstring(file_path)?;
status = unsafe { GenerateOfflineActivationRequest(c_file_path.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn deactivate_license() -> Result<LexActivatorStatus, LexActivatorError> {
let status = unsafe { DeactivateLicense() };
match status {
0 => Ok(LexActivatorStatus::LA_OK),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn generate_offline_deactivation_request(file_path: String) -> Result<LexActivatorStatus, LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_file_path = to_utf16(file_path);
status = unsafe { GenerateOfflineDeactivationRequest(c_file_path.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_file_path: CString = string_to_cstring(file_path)?;
status = unsafe { GenerateOfflineDeactivationRequest(c_file_path.as_ptr()) };
}
match status {
0 => Ok(LexActivatorStatus::LA_OK),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn is_license_genuine() -> Result<LexActivatorStatus, LexActivatorError> {
let status = unsafe { IsLicenseGenuine() };
match status {
0 => Ok(LexActivatorStatus::LA_OK),
20 => Ok(LexActivatorStatus::LA_EXPIRED),
21 => Ok(LexActivatorStatus::LA_SUSPENDED),
22 => Ok(LexActivatorStatus::LA_GRACE_PERIOD_OVER),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn is_license_valid() -> Result<LexActivatorStatus, LexActivatorError> {
let status = unsafe { IsLicenseValid() };
match status {
0 => Ok(LexActivatorStatus::LA_OK),
20 => Ok(LexActivatorStatus::LA_EXPIRED),
21 => Ok(LexActivatorStatus::LA_SUSPENDED),
22 => Ok(LexActivatorStatus::LA_GRACE_PERIOD_OVER),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn sync_license_activation() -> Result<LexActivatorStatus, LexActivatorError> {
let status = unsafe { SyncLicenseActivation() };
match status {
0 => Ok(LexActivatorStatus::LA_OK),
20 => Ok(LexActivatorStatus::LA_EXPIRED),
21 => Ok(LexActivatorStatus::LA_SUSPENDED),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn activate_trial() -> Result<LexActivatorStatus, LexActivatorError> {
let status = unsafe { ActivateTrial() };
match status {
0 => Ok(LexActivatorStatus::LA_OK),
25 => Ok(LexActivatorStatus::LA_TRIAL_EXPIRED),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn sync_trial_activation() -> Result<LexActivatorStatus, LexActivatorError> {
let status = unsafe { SyncTrialActivation() };
match status {
0 => Ok(LexActivatorStatus::LA_OK),
25 => Ok(LexActivatorStatus::LA_TRIAL_EXPIRED),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn activate_trial_offline(file_path: String) -> Result<LexActivatorStatus, LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_file_path = to_utf16(file_path);
status = unsafe { ActivateTrialOffline(c_file_path.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_file_path: CString = string_to_cstring(file_path)?;
status = unsafe { ActivateTrialOffline(c_file_path.as_ptr()) };
}
match status {
0 => Ok(LexActivatorStatus::LA_OK),
25 => Ok(LexActivatorStatus::LA_TRIAL_EXPIRED),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn generate_offline_trial_activation_request(file_path: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_file_path = to_utf16(file_path);
status = unsafe { GenerateOfflineTrialActivationRequest(c_file_path.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_file_path: CString = string_to_cstring(file_path)?;
status = unsafe { GenerateOfflineTrialActivationRequest(c_file_path.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn is_trial_genuine() -> Result<LexActivatorStatus, LexActivatorError> {
let status = unsafe { IsTrialGenuine() };
match status {
0 => Ok(LexActivatorStatus::LA_OK),
25 => Ok(LexActivatorStatus::LA_TRIAL_EXPIRED),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn activate_local_trial(trial_length: u32) -> Result<LexActivatorStatus, LexActivatorError> {
let c_trial_length: c_uint = trial_length as c_uint;
let status = unsafe { ActivateLocalTrial(c_trial_length) };
match status {
0 => Ok(LexActivatorStatus::LA_OK),
26 => Ok(LexActivatorStatus::LA_LOCAL_TRIAL_EXPIRED),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn is_local_trial_genuine() -> Result<LexActivatorStatus, LexActivatorError> {
let status = unsafe { IsLocalTrialGenuine() };
match status {
0 => Ok(LexActivatorStatus::LA_OK),
26 => Ok(LexActivatorStatus::LA_LOCAL_TRIAL_EXPIRED),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn extend_local_trial(trial_extension_length: u32) -> Result<LexActivatorStatus, LexActivatorError> {
let c_trial_extension_length: c_uint = trial_extension_length as c_uint;
let status = unsafe { ExtendLocalTrial(c_trial_extension_length) };
match status {
0 => Ok(LexActivatorStatus::LA_OK),
1 => Ok(LexActivatorStatus::LA_FAIL),
_ => Err(LexActivatorError::from(status)),
}
}
pub fn increment_activation_meter_attribute_uses(name: String, increment: u32) -> Result<(), LexActivatorError> {
let status: i32;
let c_increment: c_uint = increment as c_uint;
#[cfg(windows)]
{
let c_name = to_utf16(name);
status = unsafe { IncrementActivationMeterAttributeUses(c_name.as_ptr(), c_increment) };
}
#[cfg(not(windows))]
{
let c_name: CString = string_to_cstring(name)?;
status = unsafe { IncrementActivationMeterAttributeUses(c_name.as_ptr(), c_increment) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn decrement_activation_meter_attribute_uses(name: String, decrement: u32) -> Result<(), LexActivatorError> {
let status: i32;
let c_decrement: c_uint = decrement as c_uint;
#[cfg(windows)]
{
let c_name = to_utf16(name);
status = unsafe { DecrementActivationMeterAttributeUses(c_name.as_ptr(), c_decrement) };
}
#[cfg(not(windows))]
{
let c_name: CString = string_to_cstring(name)?;
status = unsafe { DecrementActivationMeterAttributeUses(c_name.as_ptr(), c_decrement) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn reset_activation_meter_attribute_uses(name: String) -> Result<(), LexActivatorError> {
let status: i32;
#[cfg(windows)]
{
let c_name = to_utf16(name);
status = unsafe { ResetActivationMeterAttributeUses(c_name.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_name: CString = string_to_cstring(name)?;
status = unsafe { ResetActivationMeterAttributeUses(c_name.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn migrate_to_system_wide_activation(old_permission_flag: PermissionFlags) -> Result<LexActivatorStatus, LexActivatorError> {
let c_old_permission_flag: c_uint = old_permission_flag as c_uint;
let status = unsafe { MigrateToSystemWideActivation(c_old_permission_flag) };
if status == 0 {
Ok(LexActivatorStatus::LA_OK)
} else {
return Err(LexActivatorError::from(status));
}
}
pub fn reset() -> Result<(), LexActivatorError> {
let status = unsafe { Reset() };
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}