1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//! Safe wrapper for a individual `SearchDirectory` object (`ISearchDirectory`).
use crate::Error;
use crate::dispids::search_directory;
use rs_teststand_sys::{Dispatch, Value};
/// Safe wrapper for a individual `SearchDirectory` object (`ISearchDirectory`).
#[derive(Debug)]
pub struct SearchDirectory {
dispatch: Box<dyn Dispatch>,
}
impl SearchDirectory {
/// Creates a new `SearchDirectory` wrapper around a COM dispatch seam.
pub(crate) fn new(dispatch: Box<dyn Dispatch>) -> Self {
Self { dispatch }
}
/// Reads directory path (`VT_BSTR`).
///
/// # Errors
/// [`Error`] if the COM call fails or returns an unexpected type.
pub fn path(&self) -> Result<String, Error> {
Ok(self.dispatch.get(search_directory::PATH)?.into_string()?)
}
/// Reads directory type discriminant (`VT_I4`).
///
/// # Errors
/// [`Error`] if the COM call fails or returns an unexpected type.
pub fn dir_type(&self) -> Result<i32, Error> {
Ok(self.dispatch.get(search_directory::TYPE)?.as_i32()?)
}
/// Reads disabled state (`VT_BOOL`).
///
/// # Errors
/// [`Error`] if the COM call fails or returns an unexpected type.
pub fn disabled(&self) -> Result<bool, Error> {
Ok(self.dispatch.get(search_directory::DISABLED)?.as_bool()?)
}
/// Writes disabled state (`VT_BOOL`).
///
/// # Errors
/// [`Error`] if the COM call fails.
pub fn set_disabled(&self, value: bool) -> Result<(), Error> {
self.dispatch
.put(search_directory::DISABLED, Value::Bool(value))?;
Ok(())
}
/// Reads search subdirectories state (`VT_BOOL`).
///
/// # Errors
/// [`Error`] if the COM call fails or returns an unexpected type.
pub fn search_subdirectories(&self) -> Result<bool, Error> {
Ok(self
.dispatch
.get(search_directory::SEARCH_SUBDIRECTORIES)?
.as_bool()?)
}
/// Reads exclude hidden subdirectories state (`VT_BOOL`).
///
/// # Errors
/// [`Error`] if the COM call fails or returns an unexpected type.
pub fn exclude_hidden_subdirectories(&self) -> Result<bool, Error> {
Ok(self
.dispatch
.get(search_directory::EXCLUDE_HIDDEN_SUBDIRECTORIES)?
.as_bool()?)
}
/// Reads file extension restrictions (`VT_BSTR`).
///
/// # Errors
/// [`Error`] if the COM call fails or returns an unexpected type.
pub fn file_extension_restrictions(&self) -> Result<String, Error> {
Ok(self
.dispatch
.get(search_directory::FILE_EXTENSION_RESTRICTIONS)?
.into_string()?)
}
/// Reads exclude file extension state (`VT_BOOL`).
///
/// # Errors
/// [`Error`] if the COM call fails or returns an unexpected type.
pub fn exclude_file_extension(&self) -> Result<bool, Error> {
Ok(self
.dispatch
.get(search_directory::EXCLUDE_FILE_EXTENSION)?
.as_bool()?)
}
/// Writes the directory path (`VT_BSTR`).
///
/// # Errors
/// [`Error`] if the COM call fails.
pub fn set_path(&self, value: &str) -> Result<(), Error> {
self.dispatch
.put(search_directory::PATH, Value::Str(value.to_owned()))?;
Ok(())
}
/// Writes whether subdirectories are searched (`VT_BOOL`).
///
/// # Errors
/// [`Error`] if the COM call fails.
pub fn set_search_subdirectories(&self, value: bool) -> Result<(), Error> {
self.dispatch
.put(search_directory::SEARCH_SUBDIRECTORIES, Value::Bool(value))?;
Ok(())
}
/// Writes whether hidden subdirectories are skipped (`VT_BOOL`).
///
/// # Errors
/// [`Error`] if the COM call fails.
pub fn set_exclude_hidden_subdirectories(&self, value: bool) -> Result<(), Error> {
self.dispatch.put(
search_directory::EXCLUDE_HIDDEN_SUBDIRECTORIES,
Value::Bool(value),
)?;
Ok(())
}
/// Writes the file-extension restriction list (`VT_BSTR`).
///
/// The list is interpreted as an allow-list or a deny-list depending on
/// [`Self::exclude_file_extension`].
///
/// # Errors
/// [`Error`] if the COM call fails.
pub fn set_file_extension_restrictions(&self, value: &str) -> Result<(), Error> {
self.dispatch.put(
search_directory::FILE_EXTENSION_RESTRICTIONS,
Value::Str(value.to_owned()),
)?;
Ok(())
}
/// Writes whether the extension list excludes rather than includes
/// (`VT_BOOL`).
///
/// # Errors
/// [`Error`] if the COM call fails.
pub fn set_exclude_file_extension(&self, value: bool) -> Result<(), Error> {
self.dispatch
.put(search_directory::EXCLUDE_FILE_EXTENSION, Value::Bool(value))?;
Ok(())
}
}