1
0

feat: upgrade wfassoc_exec

This commit is contained in:
2025-12-30 23:21:01 +08:00
parent 7a03d38f68
commit 27ab6721de
13 changed files with 331 additions and 182 deletions

View File

@@ -1,30 +1,90 @@
use serde::Deserialize;
use std::collections::HashMap;
use std::path::Path;
use thiserror::Error as TeError;
use toml;
/// Error occurs in this module.
#[derive(Debug, TeError)]
#[error("{0}")]
pub enum Error {
/// Io error
Io(#[from] std::io::Error),
/// Toml deserialization error
Toml(#[from] toml::de::Error),
}
pub type Result<T> = std::result::Result<T, Error>;
/// Result type used in this module.
type Result<T> = std::result::Result<T, Error>;
// 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 config: RawManifest = toml::from_str(&contents)?;
Ok(config)
}
}
// endregion
// region: Checked Manifest
/// 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 {
pub(crate) identifier: String,
pub(crate) path: String,
pub(crate) clsid: String,
pub(crate) manners: HashMap<String, String>,
pub(crate) exts: HashMap<String, String>,
}
impl Manifest {
pub fn from_file(path: &str) -> Result<Manifest> {
let contents = std::fs::read_to_string(path)?;
let config: Manifest = toml::from_str(&contents)?;
Ok(config)
}
}
}
pub struct ManifestExt {
}
impl ManifestExt {
}
// endregion