diff --git a/Cargo.lock b/Cargo.lock index 11ea53fd..ed82d9ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3463,6 +3463,7 @@ version = "0.1.3" dependencies = [ "dirs", "log", + "windows-registry", ] [[package]] @@ -5098,6 +5099,16 @@ dependencies = [ "windows-targets 0.52.4", ] +[[package]] +name = "windows-registry" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e885d2dff8cad07e7451b78eac1ff62f958825c4598d6ddf87e7d2661980c1c" +dependencies = [ + "windows-result", + "windows-targets 0.52.4", +] + [[package]] name = "windows-result" version = "0.1.0" diff --git a/support/utils/Cargo.toml b/support/utils/Cargo.toml index ef183f66..215a1169 100644 --- a/support/utils/Cargo.toml +++ b/support/utils/Cargo.toml @@ -16,6 +16,8 @@ repository.workspace = true dirs.workspace = true log = { workspace = true, optional = true } +[target.'cfg(target_os = "windows")'.dependencies.windows-registry] +version = "0.1.0" [features] default = ["log", "cargo-message"] diff --git a/support/utils/src/toolchain/sdk.rs b/support/utils/src/toolchain/sdk.rs index f593623e..ce1a9d2e 100644 --- a/support/utils/src/toolchain/sdk.rs +++ b/support/utils/src/toolchain/sdk.rs @@ -60,6 +60,9 @@ impl Sdk { #[cfg(unix)] let res = res.or_else(|_| try_with(Self::try_xdg_unix_path)); + #[cfg(windows)] + let res = res.or_else(|_| try_with(Self::try_windows_registry)); + res.or_else(|_| try_with(Self::try_from_default_path)) } @@ -85,6 +88,13 @@ impl Sdk { } } + #[cfg(windows)] + pub fn try_windows_registry() -> Result { + let key: String = windows_registry::CURRENT_USER.open(r#"Software\\PlaydateSDK"#)? + .get_string("")?; + return Self::try_new_exact(key); + } + /// Create new `Sdk` with default env var pub fn try_from_default_env() -> Result { let sdk = std::env::var_os(SDK_ENV_VAR).map(PathBuf::from)