From 08a95e01db91933f6fa8caf3518815852aba4b44 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Sun, 16 Oct 2022 16:34:39 +0300 Subject: [PATCH] use cfg_if --- Cargo.lock | 1 + Cargo.toml | 1 + src/sdk.rs | 36 +++++++++++++++++++----------------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f06761..08dd374 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -577,6 +577,7 @@ dependencies = [ name = "geode" version = "1.1.0" dependencies = [ + "cfg-if", "clap", "colored", "dirs", diff --git a/Cargo.toml b/Cargo.toml index 150213e..9b97cb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ walkdir = "2" zip = "0.5.13" semver = "1.0.14" reqwest = { version = "0.11.12", features = ["json", "blocking"] } +cfg-if = "1.0.0" [target.'cfg(windows)'.dependencies] winreg = "0.7.0" diff --git a/src/sdk.rs b/src/sdk.rs index 7c6d43c..a8e8f60 100644 --- a/src/sdk.rs +++ b/src/sdk.rs @@ -174,26 +174,28 @@ fn install(config: &mut Config, path: PathBuf) { update_submodules_recurse(&repo).nice_unwrap("Unable to update submodules!"); // set GEODE_SDK environment variable - if cfg!(windows) { - let hklm = RegKey::predef(winreg::enums::HKEY_CURRENT_USER); - if let Err(_) = hklm - .create_subkey("Environment") - .map(|(env, _)| env.set_value("GEODE_SDK", &path.to_str().unwrap().to_string())) - { - warn!( - "Unable to set the GEODE_SDK enviroment variable to {}, \ - you will have to set it manually! (You may be missing Admin priviledges)", + cfg_if::cfg_if!( + if #[cfg(windows)] { + let hklm = RegKey::predef(winreg::enums::HKEY_CURRENT_USER); + if let Err(_) = hklm + .create_subkey("Environment") + .map(|(env, _)| env.set_value("GEODE_SDK", &path.to_str().unwrap().to_string())) + { + warn!( + "Unable to set the GEODE_SDK enviroment variable to {}, \ + you will have to set it manually! (You may be missing Admin priviledges)", + path.to_str().unwrap() + ); + } else { + info!("Set GEODE_SDK environment variable automatically"); + } + } else { + info!( + "Please set the GEODE_SDK enviroment variable to {}", path.to_str().unwrap() ); - } else { - info!("Set GEODE_SDK environment variable automatically"); } - } else { - info!( - "Please set the GEODE_SDK enviroment variable to {}", - path.to_str().unwrap() - ); - } + ); switch_to_tag(config, &repo);