feat: update wfassoc-exec
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -763,6 +763,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"toml 0.9.8",
|
"toml 0.9.8",
|
||||||
|
"wfassoc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ license = "SPDX:MIT"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
#wfassoc = { path="../wfassoc" }
|
wfassoc = { path="../wfassoc" }
|
||||||
clap = { version="4.5.48", features=["derive"]}
|
clap = { version="4.5.48", features=["derive"]}
|
||||||
serde = { version = "1.0.228", features=["derive"]}
|
serde = { version = "1.0.228", features=["derive"]}
|
||||||
toml = "0.9.8"
|
toml = "0.9.8"
|
||||||
|
|||||||
@@ -11,21 +11,24 @@ use thiserror::Error as TeError;
|
|||||||
enum Error {
|
enum Error {
|
||||||
/// Error when parsing manifest TOML file.
|
/// Error when parsing manifest TOML file.
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
Manifest(#[from] manifest::Error),
|
ParseManifest(#[from] manifest::ParseManifestError),
|
||||||
|
/// Error when parsing manifest into schema.
|
||||||
|
#[error("{0}")]
|
||||||
|
ParseSchema(#[from] manifest::ParseSchemaError),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Result type used in this executable.
|
/// Result type used in this executable.
|
||||||
type Result<T> = std::result::Result<T, Error>;
|
type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
fn runner() -> Result<()> {
|
fn runner() -> Result<()> {
|
||||||
let raw_mf = manifest::RawManifest::from_file(Path::new(r#"D:\Repo\wfassoc\example\ppic.toml"#))?;
|
let mf = manifest::Manifest::from_file(Path::new(r#"D:\Repo\wfassoc\example\manifest\ppic.toml"#))?;
|
||||||
//let mf = raw_mf.to_checked()?;
|
//let mf = raw_mf.to_checked()?;
|
||||||
println!("{:?}", raw_mf);
|
println!("{:?}", mf);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = cli::parse();
|
//let cli = cli::parse();
|
||||||
|
|
||||||
runner().unwrap_or_else(|e| {
|
runner().unwrap_or_else(|e| {
|
||||||
eprintln!("Runtime error: {}.", e);
|
eprintln!("Runtime error: {}.", e);
|
||||||
|
|||||||
@@ -3,10 +3,45 @@ use std::collections::HashMap;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use thiserror::Error as TeError;
|
use thiserror::Error as TeError;
|
||||||
use toml;
|
use toml;
|
||||||
|
use wfassoc;
|
||||||
|
|
||||||
/// Error occurs in this module.
|
// region: Manifest
|
||||||
|
|
||||||
|
/// Raw user input manifest.
|
||||||
|
///
|
||||||
|
/// This manifest is the raw input of user.
|
||||||
|
/// Some fields may not be checked due to user invalid input.
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct Manifest {
|
||||||
|
identifier: String,
|
||||||
|
path: String,
|
||||||
|
clsid: String,
|
||||||
|
|
||||||
|
name: Option<String>,
|
||||||
|
icon: Option<String>,
|
||||||
|
behavior: Option<String>,
|
||||||
|
|
||||||
|
strs: HashMap<String, String>,
|
||||||
|
icons: HashMap<String, String>,
|
||||||
|
behaviors: HashMap<String, String>,
|
||||||
|
exts: HashMap<String, ManifestExt>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The sub-type in raw user input manifest.
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct ManifestExt {
|
||||||
|
name: String,
|
||||||
|
icon: String,
|
||||||
|
behavior: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region: Manifest Operation
|
||||||
|
|
||||||
|
/// Error occurs when parsing manifest TOML file.
|
||||||
#[derive(Debug, TeError)]
|
#[derive(Debug, TeError)]
|
||||||
pub enum Error {
|
pub enum ParseManifestError {
|
||||||
/// Io error
|
/// Io error
|
||||||
#[error("IO error when reading manifest file")]
|
#[error("IO error when reading manifest file")]
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
@@ -15,77 +50,27 @@ pub enum Error {
|
|||||||
Toml(#[from] toml::de::Error),
|
Toml(#[from] toml::de::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Result type used in this module.
|
impl Manifest {
|
||||||
type Result<T> = std::result::Result<T, Error>;
|
/// Read user manifest.
|
||||||
|
pub fn from_file(path: &Path) -> Result<Manifest, ParseManifestError> {
|
||||||
// region: Raw Manifest
|
|
||||||
|
|
||||||
/// Raw user input manifest.
|
|
||||||
///
|
|
||||||
/// This manifest is the raw input of user.
|
|
||||||
/// Some fields may not be checked due to user invalid input.
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct RawManifest {
|
|
||||||
identifier: String,
|
|
||||||
path: String,
|
|
||||||
clsid: String,
|
|
||||||
icons: HashMap<String, String>,
|
|
||||||
behaviors: HashMap<String, String>,
|
|
||||||
exts: HashMap<String, RawManifestExt>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RawManifest {
|
|
||||||
pub fn into_checked(&self) -> Result<Manifest> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The sub-type in raw user input manifest.
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct RawManifestExt {
|
|
||||||
name: String,
|
|
||||||
icon: String,
|
|
||||||
behavior: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RawManifestExt {
|
|
||||||
pub fn into_checked(&self) -> Result<ManifestExt> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RawManifest {
|
|
||||||
/// Read raw user manifest.
|
|
||||||
pub fn from_file(path: &Path) -> Result<RawManifest> {
|
|
||||||
let contents = std::fs::read_to_string(path)?;
|
let contents = std::fs::read_to_string(path)?;
|
||||||
let config: RawManifest = toml::from_str(&contents)?;
|
let config: Manifest = toml::from_str(&contents)?;
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
/// Error occurs when parsing manifest into schema.
|
||||||
|
#[derive(Debug, TeError)]
|
||||||
// region: Checked Manifest
|
pub enum ParseSchemaError {
|
||||||
|
|
||||||
/// Converted user input manifest.
|
|
||||||
///
|
|
||||||
/// This manifest struct is prepared for final use.
|
|
||||||
/// All fields loacted in this struct is checked and ready to be used.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Manifest {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Manifest {
|
impl TryFrom<Manifest> for wfassoc::Schema {
|
||||||
|
type Error = ParseSchemaError;
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ManifestExt {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ManifestExt {
|
|
||||||
|
|
||||||
|
fn try_from(value: Manifest) -> std::result::Result<Self, Self::Error> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|||||||
@@ -6,12 +6,17 @@ pub use lowlevel::{Scope, View};
|
|||||||
|
|
||||||
// region: Error Type
|
// region: Error Type
|
||||||
|
|
||||||
/// Error occurs in this module.
|
/// Error occurs when operating with `Schema`.
|
||||||
#[derive(Debug, TeError)]
|
#[derive(Debug, TeError)]
|
||||||
pub enum Error {}
|
pub enum SchemaError {}
|
||||||
|
|
||||||
/// Result type used in this module.
|
/// Error occurs when trying converting `Schema` into `Program`.
|
||||||
type Result<T> = std::result::Result<T, Error>;
|
#[derive(Debug, TeError)]
|
||||||
|
pub enum ParseProgramError {}
|
||||||
|
|
||||||
|
/// Error occurs when operating with `Program`.
|
||||||
|
#[derive(Debug, TeError)]
|
||||||
|
pub enum ProgramError {}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
@@ -24,6 +29,12 @@ pub struct Schema {
|
|||||||
identifier: String,
|
identifier: String,
|
||||||
path: String,
|
path: String,
|
||||||
clsid: String,
|
clsid: String,
|
||||||
|
|
||||||
|
name: Option<String>,
|
||||||
|
icon: Option<String>,
|
||||||
|
behavior: Option<String>,
|
||||||
|
|
||||||
|
strs: HashMap<String, String>,
|
||||||
icons: HashMap<String, String>,
|
icons: HashMap<String, String>,
|
||||||
behaviors: HashMap<String, String>,
|
behaviors: HashMap<String, String>,
|
||||||
exts: HashMap<String, SchemaExt>,
|
exts: HashMap<String, SchemaExt>,
|
||||||
@@ -43,29 +54,33 @@ impl Schema {
|
|||||||
identifier: String::new(),
|
identifier: String::new(),
|
||||||
path: String::new(),
|
path: String::new(),
|
||||||
clsid: String::new(),
|
clsid: String::new(),
|
||||||
|
name: None,
|
||||||
|
icon: None,
|
||||||
|
behavior: None,
|
||||||
|
strs: HashMap::new(),
|
||||||
icons: HashMap::new(),
|
icons: HashMap::new(),
|
||||||
behaviors: HashMap::new(),
|
behaviors: HashMap::new(),
|
||||||
exts: HashMap::new(),
|
exts: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_identifier(&mut self, identifier: &str) -> Result<()> {
|
pub fn set_identifier(&mut self, identifier: &str) -> Result<(), SchemaError> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_path(&mut self, exe_path: &str) -> Result<()> {
|
pub fn set_path(&mut self, exe_path: &str) -> Result<(), SchemaError> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_clsid(&mut self, clsid: &str) -> Result<()> {
|
pub fn set_clsid(&mut self, clsid: &str) -> Result<(), SchemaError> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_icon(&mut self, name: &str, value: &str) -> Result<()> {
|
pub fn add_icon(&mut self, name: &str, value: &str) -> Result<(), SchemaError> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_behavior(&mut self, name: &str, value: &str) -> Result<()> {
|
pub fn add_behavior(&mut self, name: &str, value: &str) -> Result<(), SchemaError> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,11 +90,11 @@ impl Schema {
|
|||||||
ext_name: &str,
|
ext_name: &str,
|
||||||
ext_icon: &str,
|
ext_icon: &str,
|
||||||
ext_behavior: &str,
|
ext_behavior: &str,
|
||||||
) -> Result<()> {
|
) -> Result<(), SchemaError> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_program(self) -> Result<Program> {
|
pub fn into_program(self) -> Result<Program, ParseProgramError> {
|
||||||
Program::new(self)
|
Program::new(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +103,7 @@ impl Schema {
|
|||||||
pub struct Program {}
|
pub struct Program {}
|
||||||
|
|
||||||
impl TryFrom<Schema> for Program {
|
impl TryFrom<Schema> for Program {
|
||||||
type Error = Error;
|
type Error = ParseProgramError;
|
||||||
|
|
||||||
fn try_from(value: Schema) -> std::result::Result<Self, Self::Error> {
|
fn try_from(value: Schema) -> std::result::Result<Self, Self::Error> {
|
||||||
Self::new(value)
|
Self::new(value)
|
||||||
@@ -96,7 +111,7 @@ impl TryFrom<Schema> for Program {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Program {
|
impl Program {
|
||||||
pub fn new(schema: Schema) -> Result<Self> {
|
pub fn new(schema: Schema) -> Result<Self, ParseProgramError> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user