diff --git a/wfassoc_cdylib/src/lib.rs b/wfassoc_cdylib/src/lib.rs index a1a8cec..5046c90 100644 --- a/wfassoc_cdylib/src/lib.rs +++ b/wfassoc_cdylib/src/lib.rs @@ -4,6 +4,7 @@ use thiserror::Error as TeError; mod last_error; mod string_cache; +mod wrapper; // region: Error diff --git a/wfassoc_cdylib/src/wrapper.rs b/wfassoc_cdylib/src/wrapper.rs new file mode 100644 index 0000000..d7dca53 --- /dev/null +++ b/wfassoc_cdylib/src/wrapper.rs @@ -0,0 +1,83 @@ +use std::collections::HashMap; + +use thiserror::Error as TeError; + +/// Error occurs in this module. +#[derive(Debug, TeError)] +pub enum Error {} + +/// Result type used in this module. +type Result = std::result::Result; + +/// Schema is the sketchpad of complete Program. +/// +/// We will create a Schema first, fill some properties, add file extensions, +/// then convert it into immutable Program for following using. +#[derive(Debug)] +pub struct Schema { + identifier: String, + path: String, + clsid: String, + icons: HashMap, + behaviors: HashMap, + exts: HashMap, +} + +/// Internal used struct as the Schema file extensions hashmap value type. +#[derive(Debug)] +struct SchemaExt { + name: String, + icon: String, + behavior: String, +} + +impl Schema { + pub fn new() -> Self { + Self { + identifier: String::new(), + path: String::new(), + clsid: String::new(), + icons: HashMap::new(), + behaviors: HashMap::new(), + exts: HashMap::new(), + } + } + + pub fn set_identifier(&mut self, identifier: &str) -> Result<()> {} + + pub fn set_path(&mut self, exe_path: &str) -> Result<()> {} + + pub fn set_clsid(&mut self, clsid: &str) -> Result<()> {} + + pub fn add_icon(&mut self, name: &str, value: &str) -> Result<()> {} + + pub fn add_behavior(&mut self, name: &str, value: &str) -> Result<()> {} + + pub fn add_ext( + &mut self, + ext: &str, + ext_name: &str, + ext_icon: &str, + ext_behavior: &str, + ) -> Result<()> { + } + + pub fn into_program(self) -> Result { + Program::new(self) + } +} + +/// Program is a complete and immutable program representer +pub struct Program {} + +impl TryFrom for Program { + type Error = Error; + + fn try_from(value: Schema) -> std::result::Result { + Self::new(value) + } +} + +impl Program { + pub fn new(schema: Schema) -> Result {} +} diff --git a/wfassoc_exec/src/cli.rs b/wfassoc_exec/src/cli.rs index 53afacf..8765df7 100644 --- a/wfassoc_exec/src/cli.rs +++ b/wfassoc_exec/src/cli.rs @@ -112,5 +112,5 @@ pub struct RequestExtCommand { /// This is the mechanism of clap crate. pub fn parse() -> Request { let cli = Cli::parse(); - + todo!() } diff --git a/wfassoc_exec/src/manifest.rs b/wfassoc_exec/src/manifest.rs index 1d2eb44..e896a3d 100644 --- a/wfassoc_exec/src/manifest.rs +++ b/wfassoc_exec/src/manifest.rs @@ -6,11 +6,12 @@ use toml; /// Error occurs in this module. #[derive(Debug, TeError)] -#[error("{0}")] pub enum Error { /// Io error + #[error("IO error when reading manifest file")] Io(#[from] std::io::Error), /// Toml deserialization error + #[error("given TOML manifest file has bad format")] Toml(#[from] toml::de::Error), } diff --git a/wfassoc_exec/src/runner.rs b/wfassoc_exec/src/runner.rs index e69de29..1c2f70c 100644 --- a/wfassoc_exec/src/runner.rs +++ b/wfassoc_exec/src/runner.rs @@ -0,0 +1,45 @@ +use crate::cli::Request; +use thiserror::Error as TeError; + +/// Error occurs in this module. +#[derive(Debug, TeError)] +#[error("{0}")] +pub enum Error { + +} + +/// Result type used in this module. +type Result = std::result::Result; + +// region: Respective Runners + +fn run_register() -> Result<()> { + todo!() +} + +fn run_unregister() -> Result<()> { + todo!() +} + +fn run_status() -> Result<()> { + todo!() +} + +fn run_ext_link() -> Result<()> { + todo!() +} + +fn run_ext_unlink() -> Result<()> { + todo!() +} + +fn run_ext_list() -> Result<()> { + todo!() +} + + +// endregion + +pub fn run(request: Request) -> Result<()> { + todo!() +}