use num_enum::IntoPrimitive;
use num_enum::TryFromPrimitive;
use serde::Serialize;
use strum_macros::{EnumIter, EnumMessage};
use crate::files::project::compilesettings::CompilationType;
#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Default, Hash, PartialOrd, Ord)]
pub struct ProjectProperties<'a> {
pub unused_control_info: UnusedControlInfo,
pub upgrade_controls: UpgradeControls,
pub res_file_32_path: &'a str,
pub icon_form: &'a str,
pub startup: &'a str,
pub help_file_path: &'a str,
pub title: &'a str,
pub exe_32_file_name: &'a str,
pub exe_32_compatible: &'a str,
pub dll_base_address: u32,
pub path_32: &'a str,
pub command_line_arguments: &'a str,
pub name: &'a str,
pub description: &'a str,
pub debug_startup_component: &'a str,
pub help_context_id: &'a str,
pub compatibility_mode: CompatibilityMode,
pub version_32_compatibility: &'a str,
pub version_info: VersionInformation<'a>,
pub server_support_files: ServerSupportFiles,
pub conditional_compile: &'a str,
pub compilation_type: CompilationType,
pub start_mode: StartMode,
pub unattended: InteractionMode,
pub retained: Retained,
pub thread_per_object: u16,
pub threading_model: ThreadingModel,
pub max_number_of_threads: u16,
pub debug_startup_option: DebugStartupOption,
pub use_existing_browser: ExistingBrowser,
}
#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Serialize,
Default,
TryFromPrimitive,
IntoPrimitive,
EnumIter,
EnumMessage,
Hash,
PartialOrd,
Ord,
)]
#[repr(i16)]
pub enum Retained {
#[default]
#[strum(message = "Unload the DLL when no longer in use")]
UnloadOnExit = 0,
#[strum(message = "Retain the DLL in memory")]
RetainedInMemory = 1,
}
impl TryFrom<&str> for Retained {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.as_bytes() {
b"0" => Ok(Retained::UnloadOnExit),
b"1" => Ok(Retained::RetainedInMemory),
_ => Err(format!("Unknown Retained value: '{value}'")),
}
}
}
#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Serialize,
Default,
TryFromPrimitive,
IntoPrimitive,
EnumIter,
EnumMessage,
Hash,
PartialOrd,
Ord,
)]
#[repr(i16)]
pub enum ExistingBrowser {
#[strum(message = "Do not use an existing browser instance")]
DoNotUse = 0,
#[default]
#[strum(message = "Use an existing browser instance if available")]
Use = -1,
}
impl TryFrom<&str> for ExistingBrowser {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.as_bytes() {
b"0" => Ok(ExistingBrowser::DoNotUse),
b"-1" => Ok(ExistingBrowser::Use),
_ => Err(format!("Unknown ExistingBrowser value: '{value}'")),
}
}
}
#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Serialize,
Default,
TryFromPrimitive,
IntoPrimitive,
EnumIter,
EnumMessage,
Hash,
PartialOrd,
Ord,
)]
#[repr(i16)]
pub enum StartMode {
#[default]
#[strum(message = "Stand-alone Application")]
StandAlone = 0,
#[strum(message = "ActiveX Automation Component")]
Automation = 1,
}
impl TryFrom<&str> for StartMode {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.as_bytes() {
b"0" => Ok(StartMode::StandAlone),
b"1" => Ok(StartMode::Automation),
_ => Err(format!("Unknown StartMode value: '{value}'")),
}
}
}
#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Serialize,
Default,
TryFromPrimitive,
IntoPrimitive,
EnumIter,
EnumMessage,
Hash,
PartialOrd,
Ord,
)]
#[repr(i16)]
pub enum InteractionMode {
#[default]
#[strum(message = "The program can show dialogs and interacts with the user.")]
Interactive = 0,
#[strum(message = "The program cannot show dialogs and will not interact with the user.")]
Unattended = -1,
}
impl TryFrom<&str> for InteractionMode {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.as_bytes() {
b"0" => Ok(InteractionMode::Interactive),
b"-1" => Ok(InteractionMode::Unattended),
_ => Err(format!("Unknown InteractionMode value: '{value}'")),
}
}
}
#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Serialize,
Default,
TryFromPrimitive,
IntoPrimitive,
EnumIter,
EnumMessage,
Hash,
PartialOrd,
Ord,
)]
#[repr(i16)]
pub enum ServerSupportFiles {
#[default]
#[strum(message = "Do not produce VBR and TLB files")]
Local = 0,
#[strum(message = "Produce VBR and TLB files for packaging")]
Remote = 1,
}
impl TryFrom<&str> for ServerSupportFiles {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.as_bytes() {
b"0" => Ok(ServerSupportFiles::Local),
b"1" => Ok(ServerSupportFiles::Remote),
_ => Err(format!("Unknown ServerSupportFiles value: '{value}'")),
}
}
}
#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Serialize,
Default,
TryFromPrimitive,
IntoPrimitive,
EnumIter,
EnumMessage,
Hash,
PartialOrd,
Ord,
)]
#[repr(i16)]
pub enum UpgradeControls {
#[strum(message = "Update project to use upgraded control")]
#[default]
Upgrade = 0,
#[strum(message = "Leave project untouched with older control")]
NoUpgrade = 1,
}
impl TryFrom<&str> for UpgradeControls {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.as_bytes() {
b"0" => Ok(UpgradeControls::Upgrade),
b"1" => Ok(UpgradeControls::NoUpgrade),
_ => Err(format!("Unknown UpgradeControls value: '{value}'")),
}
}
}
#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Serialize,
Default,
TryFromPrimitive,
IntoPrimitive,
EnumIter,
EnumMessage,
Hash,
PartialOrd,
Ord,
)]
#[repr(i16)]
pub enum UnusedControlInfo {
#[strum(message = "Retain License Information")]
Retain = 0,
#[default]
#[strum(message = "Remove License Information")]
Remove = 1,
}
impl TryFrom<&str> for UnusedControlInfo {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.as_bytes() {
b"0" => Ok(UnusedControlInfo::Retain),
b"1" => Ok(UnusedControlInfo::Remove),
_ => Err(format!("Unknown UnusedControlInfo value: '{value}'")),
}
}
}
#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Serialize,
Default,
TryFromPrimitive,
EnumIter,
EnumMessage,
Hash,
PartialOrd,
Ord,
IntoPrimitive,
)]
#[repr(i16)]
pub enum CompatibilityMode {
#[strum(message = "No Compatibility")]
NoCompatibility = 0,
#[default]
#[strum(message = "Project Compatibility")]
Project = 1,
#[strum(message = "Compatible Exe Mode")]
CompatibleExe = 2,
}
impl TryFrom<&str> for CompatibilityMode {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.as_bytes() {
b"0" => Ok(CompatibilityMode::NoCompatibility),
b"1" => Ok(CompatibilityMode::Project),
b"2" => Ok(CompatibilityMode::CompatibleExe),
_ => Err(format!("Unknown CompatibilityMode value: '{value}'")),
}
}
}
#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Serialize,
Default,
TryFromPrimitive,
IntoPrimitive,
EnumIter,
EnumMessage,
Hash,
PartialOrd,
Ord,
)]
#[repr(i16)]
pub enum DebugStartupOption {
#[default]
#[strum(message = "Wait for Component Creation")]
WaitForComponentCreation = 0,
#[strum(message = "A Start Component is specified")]
StartComponent = 1,
#[strum(message = "A Start Program is specified")]
StartProgram = 2,
#[strum(message = "Start Browser is specified")]
StartBrowser = 3,
}
impl TryFrom<&str> for DebugStartupOption {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.as_bytes() {
b"0" => Ok(DebugStartupOption::WaitForComponentCreation),
b"1" => Ok(DebugStartupOption::StartComponent),
b"2" => Ok(DebugStartupOption::StartProgram),
b"3" => Ok(DebugStartupOption::StartBrowser),
_ => Err(format!("Unknown DebugStartupOption value: '{value}'")),
}
}
}
#[derive(Debug, PartialEq, Eq, Default, Copy, Clone, Serialize, Hash, PartialOrd, Ord)]
pub struct VersionInformation<'a> {
pub major: u16,
pub minor: u16,
pub revision: u16,
pub auto_increment_revision: u16,
pub company_name: &'a str,
pub file_description: &'a str,
pub copyright: &'a str,
pub trademark: &'a str,
pub product_name: &'a str,
pub comments: &'a str,
}
#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Serialize,
EnumIter,
EnumMessage,
Default,
Hash,
PartialOrd,
Ord,
)]
pub enum CompileTargetType {
#[strum(message = "A Standard Exe")]
#[default]
Exe,
#[strum(message = "A UserControl")]
Control,
#[strum(message = "Ole Exe")]
OleExe,
#[strum(message = "Ole Dll")]
OleDll,
}
impl TryFrom<&str> for CompileTargetType {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"Exe" => Ok(CompileTargetType::Exe),
"Control" => Ok(CompileTargetType::Control),
"OleExe" => Ok(CompileTargetType::OleExe),
"OleDll" => Ok(CompileTargetType::OleDll),
_ => Err(format!("Unknown CompileTargetType value: '{value}'")),
}
}
}
#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Serialize,
Default,
TryFromPrimitive,
IntoPrimitive,
EnumIter,
EnumMessage,
Hash,
PartialOrd,
Ord,
)]
#[repr(i16)]
pub enum ThreadingModel {
#[strum(message = "")]
SingleThreaded = 0,
#[default]
#[strum(message = "")]
ApartmentThreaded = 1,
}
impl TryFrom<&str> for ThreadingModel {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(ThreadingModel::SingleThreaded),
"1" => Ok(ThreadingModel::ApartmentThreaded),
_ => Err(format!("Unknown ThreadingModel value: '{value}'")),
}
}
}