-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-14270] Use rust to access windows registry (#11413)
- Loading branch information
1 parent
f6755da
commit 2e6ed4a
Showing
12 changed files
with
113 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use anyhow::{bail, Result}; | ||
|
||
pub fn create_key(_key: &str, _subkey: &str, _value: &str) -> Result<()> { | ||
bail!("Not implemented") | ||
} | ||
|
||
pub fn delete_key(_key: &str, _subkey: &str) -> Result<()> { | ||
bail!("Not implemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#[cfg_attr(target_os = "windows", path = "windows.rs")] | ||
#[cfg_attr(not(target_os = "windows"), path = "dummy.rs")] | ||
mod internal; | ||
pub use internal::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use anyhow::{bail, Result}; | ||
|
||
fn convert_key(key: &str) -> Result<&'static windows_registry::Key> { | ||
Ok(match key.to_uppercase().as_str() { | ||
"HKEY_CURRENT_USER" | "HKCU" => windows_registry::CURRENT_USER, | ||
"HKEY_LOCAL_MACHINE" | "HKLM" => windows_registry::LOCAL_MACHINE, | ||
"HKEY_CLASSES_ROOT" | "HKCR" => windows_registry::CLASSES_ROOT, | ||
_ => bail!("Invalid key"), | ||
}) | ||
} | ||
|
||
pub fn create_key(key: &str, subkey: &str, value: &str) -> Result<()> { | ||
let key = convert_key(key)?; | ||
|
||
let subkey = key.create(subkey)?; | ||
|
||
const DEFAULT: &str = ""; | ||
subkey.set_string(DEFAULT, value)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn delete_key(key: &str, subkey: &str) -> Result<()> { | ||
let key = convert_key(key)?; | ||
|
||
key.remove_tree(subkey)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.