get_all_uri_protocols/
lib.rs1
2#[derive(Debug)]
3pub struct UriProtocol {
4 pub protocol : String,
5 pub description : String,
6 pub command : String,
7}
8#[cfg(windows)]
9pub fn get_protocols() -> Result<Vec<UriProtocol>,String> {
10 use winreg::{enums::HKEY_CLASSES_ROOT, RegKey};
11
12 let hkey_cr = RegKey::predef(HKEY_CLASSES_ROOT);
13
14 let mut protocols = vec![];
15
16
17 for key_ in hkey_cr.enum_keys() {
18 if let Ok(key) = key_ {
19 let v = hkey_cr.open_subkey(&key).or(Err("unable to open key"))?;
20 if let Ok(proto) = v.get_value::<String,&str>("URL Protocol") {
21 if let Ok(default) = v.get_value::<String,&str>("") {
22 if let Ok(shell) = v.open_subkey("shell\\open\\command") {
23 if let Ok(command_to_run) = shell.get_value::<String,&str>("") {
24 if default.starts_with("URL:") {
25 let uri = &default[4..];
26 protocols.push(UriProtocol {
27 protocol : key.to_string(),
28 description : uri.to_string(),
29 command : command_to_run.to_string(),
30 });
31 }
33 }
34 }
35 }
36
37 }
38 }
39 }
40
41
42 Ok(protocols)
43}