feat: finish manifest convertion
This commit is contained in:
@@ -62,14 +62,37 @@ impl Manifest {
|
|||||||
/// Error occurs when parsing manifest into schema.
|
/// Error occurs when parsing manifest into schema.
|
||||||
#[derive(Debug, TeError)]
|
#[derive(Debug, TeError)]
|
||||||
pub enum ParseSchemaError {
|
pub enum ParseSchemaError {
|
||||||
|
/// Error when operating with schema.
|
||||||
|
#[error("{0}")]
|
||||||
|
Schema(#[from] wfassoc::highlevel::SchemaError)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Manifest> for wfassoc::Schema {
|
impl TryFrom<Manifest> for wfassoc::Schema {
|
||||||
type Error = ParseSchemaError;
|
type Error = ParseSchemaError;
|
||||||
|
|
||||||
fn try_from(value: Manifest) -> std::result::Result<Self, Self::Error> {
|
fn try_from(value: Manifest) -> Result<Self, Self::Error> {
|
||||||
todo!()
|
let mut schema = wfassoc::Schema::new();
|
||||||
|
|
||||||
|
schema.set_identifier(&value.identifier);
|
||||||
|
schema.set_path(&value.path);
|
||||||
|
schema.set_clsid(&value.clsid);
|
||||||
|
schema.set_name(value.name.as_ref().map(|x| x.as_str()));
|
||||||
|
schema.set_icon(value.icon.as_ref().map(|x| x.as_str()));
|
||||||
|
schema.set_behavior(value.behavior.as_ref().map(|x| x.as_str()));
|
||||||
|
for (key, value) in value.strs {
|
||||||
|
schema.add_str(&key, &value)?;
|
||||||
|
}
|
||||||
|
for (key, value) in value.icons {
|
||||||
|
schema.add_icon(&key, &value)?;
|
||||||
|
}
|
||||||
|
for (key, value) in value.behaviors {
|
||||||
|
schema.add_behavior(&key, &value)?;
|
||||||
|
}
|
||||||
|
for (key, value) in value.exts {
|
||||||
|
schema.add_ext(&key, &value.name, &value.icon, &value.behavior)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(schema)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ pub use lowlevel::{Scope, View};
|
|||||||
|
|
||||||
/// Error occurs when operating with `Schema`.
|
/// Error occurs when operating with `Schema`.
|
||||||
#[derive(Debug, TeError)]
|
#[derive(Debug, TeError)]
|
||||||
pub enum SchemaError {}
|
pub enum SchemaError {
|
||||||
|
#[error("duplicate key: {0}")]
|
||||||
|
DuplicateKey(String),
|
||||||
|
}
|
||||||
|
|
||||||
/// Error occurs when trying converting `Schema` into `Program`.
|
/// Error occurs when trying converting `Schema` into `Program`.
|
||||||
#[derive(Debug, TeError)]
|
#[derive(Debug, TeError)]
|
||||||
@@ -40,14 +43,6 @@ pub struct Schema {
|
|||||||
exts: HashMap<String, SchemaExt>,
|
exts: HashMap<String, SchemaExt>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internal used struct as the Schema file extensions hashmap value type.
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct SchemaExt {
|
|
||||||
name: String,
|
|
||||||
icon: String,
|
|
||||||
behavior: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Schema {
|
impl Schema {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -64,24 +59,49 @@ impl Schema {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_identifier(&mut self, identifier: &str) -> Result<(), SchemaError> {
|
pub fn set_identifier(&mut self, identifier: &str) -> () {
|
||||||
todo!()
|
self.identifier = identifier.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_path(&mut self, exe_path: &str) -> Result<(), SchemaError> {
|
pub fn set_path(&mut self, exe_path: &str) -> () {
|
||||||
todo!()
|
self.path = exe_path.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_clsid(&mut self, clsid: &str) -> Result<(), SchemaError> {
|
pub fn set_clsid(&mut self, clsid: &str) -> () {
|
||||||
todo!()
|
self.clsid = clsid.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_name(&mut self, name: Option<&str>) -> () {
|
||||||
|
self.name = name.map(|n| n.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_icon(&mut self, icon: Option<&str>) -> () {
|
||||||
|
self.icon = icon.map(|i| i.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_behavior(&mut self, behavior: Option<&str>) -> () {
|
||||||
|
self.behavior = behavior.map(|b| b.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_str(&mut self, name: &str, value: &str) -> Result<(), SchemaError> {
|
||||||
|
match self.strs.insert(name.to_string(), value.to_string()) {
|
||||||
|
Some(_) => Err(SchemaError::DuplicateKey(name.to_string())),
|
||||||
|
None => Ok(()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_icon(&mut self, name: &str, value: &str) -> Result<(), SchemaError> {
|
pub fn add_icon(&mut self, name: &str, value: &str) -> Result<(), SchemaError> {
|
||||||
todo!()
|
match self.icons.insert(name.to_string(), value.to_string()) {
|
||||||
|
Some(_) => Err(SchemaError::DuplicateKey(name.to_string())),
|
||||||
|
None => Ok(()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_behavior(&mut self, name: &str, value: &str) -> Result<(), SchemaError> {
|
pub fn add_behavior(&mut self, name: &str, value: &str) -> Result<(), SchemaError> {
|
||||||
todo!()
|
match self.behaviors.insert(name.to_string(), value.to_string()) {
|
||||||
|
Some(_) => Err(SchemaError::DuplicateKey(name.to_string())),
|
||||||
|
None => Ok(()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_ext(
|
pub fn add_ext(
|
||||||
@@ -91,7 +111,13 @@ impl Schema {
|
|||||||
ext_icon: &str,
|
ext_icon: &str,
|
||||||
ext_behavior: &str,
|
ext_behavior: &str,
|
||||||
) -> Result<(), SchemaError> {
|
) -> Result<(), SchemaError> {
|
||||||
todo!()
|
match self.exts.insert(
|
||||||
|
ext.to_string(),
|
||||||
|
SchemaExt::new(ext_name, ext_icon, ext_behavior),
|
||||||
|
) {
|
||||||
|
Some(_) => Err(SchemaError::DuplicateKey(ext.to_string())),
|
||||||
|
None => Ok(()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_program(self) -> Result<Program, ParseProgramError> {
|
pub fn into_program(self) -> Result<Program, ParseProgramError> {
|
||||||
@@ -99,6 +125,24 @@ impl Schema {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Internal used struct as the Schema file extensions hashmap value type.
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct SchemaExt {
|
||||||
|
name: String,
|
||||||
|
icon: String,
|
||||||
|
behavior: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SchemaExt {
|
||||||
|
fn new(name: &str, icon: &str, behavior: &str) -> Self {
|
||||||
|
Self {
|
||||||
|
name: name.to_string(),
|
||||||
|
icon: icon.to_string(),
|
||||||
|
behavior: behavior.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Program is a complete and immutable program representer
|
/// Program is a complete and immutable program representer
|
||||||
pub struct Program {}
|
pub struct Program {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user