win_ctx/
path.rs

1use super::ActivationType;
2
3/// Exposed for testing purposes only.
4pub const CTX_MENU_PATH: &str = "Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}";
5
6/// Exposed for testing purposes only.
7pub fn get_base_path(entry_type: &ActivationType) -> String {
8    match entry_type {
9        ActivationType::File(ext) => ext.to_string(),
10        ActivationType::Folder => "Directory".to_string(),
11        ActivationType::Background => "Directory\\Background".to_string(),
12    }
13}
14
15/// Exposed for testing purposes only.
16pub fn get_full_path<N: AsRef<str>>(entry_type: &ActivationType, name_path: &[N]) -> String {
17    let mut path = get_base_path(entry_type);
18
19    if name_path.is_empty() {
20        path.push_str("\\shell");
21    }
22
23    for entry_name in name_path.iter().map(|x| x.as_ref()) {
24        path = format!("{path}\\shell\\{entry_name}");
25    }
26
27    path
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn empty_name_path() {
36        let path = get_full_path(&ActivationType::Folder, &Vec::<&str>::new());
37        assert_eq!(path, "Directory\\shell");
38    }
39
40    #[test]
41    fn filled_name_path() {
42        let path = get_full_path(&ActivationType::Folder, &["1", "2", "3"]);
43        assert_eq!(path, "Directory\\shell\\1\\shell\\2\\shell\\3");
44    }
45}