1
0

Compare commits

...

4 Commits

2 changed files with 101 additions and 48 deletions

View File

@@ -282,15 +282,21 @@ impl Program {
// region: Program Internals
/// Internal used enum presenting a Program string resource.
type ProgramStr = lowlevel::LosseStrRefStr;
#[derive(Debug)]
struct ProgramStr {
inner: lowlevel::StrResVariant,
}
/// Internal used enum presenting a Program icon resource.
type ProgramIcon = lowlevel::LosseIconRefStr;
#[derive(Debug)]
struct ProgramIcon {
inner: lowlevel::IconResVariant,
}
/// Internal used enum presenting a Program behavior (command line setups).
#[derive(Debug)]
struct ProgramBehavior {
inner: String,
inner: win32::concept::CmdLine,
}
/// Internal used struct presenting a Program ProgId.

View File

@@ -85,7 +85,7 @@ impl TryFrom<View> for Scope {
// endregion
// region: Losse Structs
// region: Exposed Structs (Losse, Variant and others)
// region: Losse ProgId
@@ -129,43 +129,43 @@ impl From<concept::ProgId> for LosseProgId {
// endregion
// region: Losse Icon Reference String
// region: Icon Resource Variant
/// The enum representing a losse Icon Reference String.
///
///
/// In real usage, programmer can use Icon Reference String,
/// or a plain string pointing to a icon file as the icon setting value.
/// This enum is designed for handling this scenario.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum LosseIconRefStr {
pub enum IconResVariant {
Plain(String),
Strict(concept::IconRefStr),
RefStr(concept::IconRefStr),
}
impl LosseIconRefStr {
impl IconResVariant {
pub fn extract(&self, kind: concept::IconSizeKind) -> Result<concept::IconRc, Error> {
let rc = match self {
LosseIconRefStr::Plain(v) => concept::IconRc::with_ico_file(v.as_str(), kind)?,
LosseIconRefStr::Strict(v) => concept::IconRc::new(v.get_path(), v.get_index(), kind)?,
IconResVariant::Plain(v) => concept::IconRc::with_ico_file(v.as_str(), kind)?,
IconResVariant::RefStr(v) => concept::IconRc::new(v.get_path(), v.get_index(), kind)?,
};
Ok(rc)
}
}
impl Display for LosseIconRefStr {
impl Display for IconResVariant {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LosseIconRefStr::Plain(v) => v.fmt(f),
LosseIconRefStr::Strict(v) => v.fmt(f),
IconResVariant::Plain(v) => v.fmt(f),
IconResVariant::RefStr(v) => v.fmt(f),
}
}
}
impl From<&str> for LosseIconRefStr {
impl From<&str> for IconResVariant {
fn from(s: &str) -> Self {
// match it for standard IconRefStr first
if let Ok(v) = concept::IconRefStr::from_str(s) {
Self::Strict(v)
Self::RefStr(v)
} else {
// fallback with other
Self::Plain(s.to_string())
@@ -173,56 +173,56 @@ impl From<&str> for LosseIconRefStr {
}
}
impl From<concept::IconRefStr> for LosseIconRefStr {
impl From<concept::IconRefStr> for IconResVariant {
fn from(value: concept::IconRefStr) -> Self {
Self::Strict(value)
Self::RefStr(value)
}
}
// endregion
// region: Losse String Reference String
// region: String Resource Variant
/// The enum representing a losse String Reference String.
///
///
/// In real usage, programmer can use String Reference String,
/// or a plain string as the string setting value.
/// This enum is designed for handling this scenario.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum LosseStrRefStr {
pub enum StrResVariant {
Plain(String),
Strict(concept::StrRefStr),
RefStr(concept::StrRefStr),
}
impl LosseStrRefStr {
impl StrResVariant {
pub fn extract(&self) -> Result<String, Error> {
let rv = match self {
// For plain string, we just simply clone it.
LosseStrRefStr::Plain(v) => v.clone(),
StrResVariant::Plain(v) => v.clone(),
// For string reference string, we try to resolve it.
LosseStrRefStr::Strict(v) => {
StrResVariant::RefStr(v) => {
let rc = concept::StrRc::new(v.get_path(), v.get_index())?;
rc.into_string()
},
}
};
Ok(rv)
}
}
impl Display for LosseStrRefStr {
impl Display for StrResVariant {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LosseStrRefStr::Plain(v) => v.fmt(f),
LosseStrRefStr::Strict(v) => v.fmt(f),
StrResVariant::Plain(v) => v.fmt(f),
StrResVariant::RefStr(v) => v.fmt(f),
}
}
}
impl From<&str> for LosseStrRefStr {
impl From<&str> for StrResVariant {
fn from(s: &str) -> Self {
// match it for standard StrRefStr first
if let Ok(v) = concept::StrRefStr::from_str(s) {
Self::Strict(v)
Self::RefStr(v)
} else {
// fallback with other
Self::Plain(s.to_string())
@@ -230,9 +230,34 @@ impl From<&str> for LosseStrRefStr {
}
}
impl From<concept::StrRefStr> for LosseStrRefStr {
impl From<concept::StrRefStr> for StrResVariant {
fn from(value: concept::StrRefStr) -> Self {
Self::Strict(value)
Self::RefStr(value)
}
}
// endregion
// region: Shell Verb
/// The struct representing a shell verb pair.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ShellVerb {
verb: concept::Verb,
command: concept::CmdLine,
}
impl ShellVerb {
pub fn new(verb: concept::Verb, command: concept::CmdLine) -> Self {
Self { verb, command }
}
pub fn get_verb(&self) -> &concept::Verb {
&self.verb
}
pub fn get_command(&self) -> &concept::CmdLine {
&self.command
}
}
@@ -431,12 +456,18 @@ impl AppPathsKey {
const NAMEOF_PATH_TO_APPLICATION: &str = "";
pub fn get_path_to_application(&self, scope: Scope) -> Result<String, Error> {
///
///
/// This field point to the fully qualified path to the application.
pub fn get_default(&self, scope: Scope) -> Result<String, Error> {
let key = self.open_scope_for_getter(scope)?;
Ok(key.get_value(Self::NAMEOF_PATH_TO_APPLICATION)?)
}
pub fn set_path_to_application(&mut self, scope: Scope, value: &str) -> Result<(), Error> {
///
///
/// This field should be filled with fully qualified path to the application.
pub fn set_default(&mut self, scope: Scope, value: &str) -> Result<(), Error> {
let key = self.open_scope_for_setter(scope)?;
key.set_value(Self::NAMEOF_PATH_TO_APPLICATION, &value)?;
Ok(())
@@ -444,12 +475,20 @@ impl AppPathsKey {
const NAMEOF_APPLICATION_DIRECTORY: &str = "Path";
pub fn get_application_directory(&self, scope: Scope) -> Result<String, Error> {
///
///
/// This field point to the added path for PATH environment variable.
/// Usually it is the path to application directory.
pub fn get_path(&self, scope: Scope) -> Result<String, Error> {
let key = self.open_scope_for_getter(scope)?;
Ok(key.get_value(Self::NAMEOF_APPLICATION_DIRECTORY)?)
}
pub fn set_application_directory(&mut self, scope: Scope, value: &str) -> Result<(), Error> {
///
///
/// This field should be the added path for PATH environment variable.
/// Usually it is the path to application directory.
pub fn set_path(&mut self, scope: Scope, value: &str) -> Result<(), Error> {
let key = self.open_scope_for_setter(scope)?;
key.set_value(Self::NAMEOF_APPLICATION_DIRECTORY, &value)?;
Ok(())
@@ -568,35 +607,39 @@ impl ApplicationsKey {
// We temporarily use String and &str as the command line argument parameter.
// We may introduce a new complete Rust struct for replacing this arbitrary string.
pub fn get_shell_verb(&self, view: View) -> Result<(concept::Verb, String), Error> {
pub fn get_shell_verb(&self, view: View) -> Result<ShellVerb, Error> {
todo!()
}
pub fn set_shell_verb(
&mut self,
scope: Scope,
beh: (concept::Verb, &str),
) -> Result<(), Error> {
pub fn set_shell_verb(&mut self, scope: Scope, sv: &ShellVerb) -> Result<(), Error> {
todo!()
}
const NAMEOF_DEFAULT_ICON: &str = "DefaultIcon";
pub fn get_default_icon(&self, view: View) -> Result<Option<LosseIconRefStr>, Error> {
pub fn get_default_icon(&self, view: View) -> Result<Option<IconResVariant>, Error> {
todo!()
}
pub fn set_default_icon(&self, scope: Scope, icon: Option<&LosseIconRefStr>) -> Result<(), Error> {
pub fn set_default_icon(
&self,
scope: Scope,
icon: Option<&IconResVariant>,
) -> Result<(), Error> {
todo!()
}
const NAMEOF_FRIENDLY_APP_NAME: &str = "FriendlyAppName";
pub fn get_friendly_app_name(&self, view: View) -> Result<Option<LosseStrRefStr>, Error> {
pub fn get_friendly_app_name(&self, view: View) -> Result<Option<StrResVariant>, Error> {
todo!()
}
pub fn set_friendly_app_name(&self, scope: Scope, name: Option<&LosseStrRefStr>) -> Result<(), Error> {
pub fn set_friendly_app_name(
&self,
scope: Scope,
name: Option<&StrResVariant>,
) -> Result<(), Error> {
todo!()
}
@@ -606,7 +649,11 @@ impl ApplicationsKey {
todo!()
}
pub fn set_supported_types(&self, scope: Scope, tys: Option<&[concept::Ext]>) -> Result<(), Error> {
pub fn set_supported_types(
&self,
scope: Scope,
tys: Option<&[concept::Ext]>,
) -> Result<(), Error> {
todo!()
}