diff --git a/src/java_remote.rs b/src/java_remote.rs index c2565c9..22ac3d9 100644 --- a/src/java_remote.rs +++ b/src/java_remote.rs @@ -1,3 +1,10 @@ +/* + * @Author: ZuoXichen + * @Date: 2022-01-30 11:56:36 + * @LastEditTime: 2022-05-12 23:49:20 + * @LastEditors: ZuoXichen + * @Description: + */ use crate::java_ver; use download_rs::async_download::Download; use json; @@ -45,7 +52,7 @@ pub async fn get_remote(version: &str) { if !version_store.contains(&version_name, "Eclipse Adoptium") { // println!("{}", file_name); let download_url = format!( - "https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/{}/jdk/{}/windows/{}", + "https://mirrors.tuna.tsinghua.edu.cn/Adoptium/{}/jdk/{}/windows/{}", version, arch, file_name ); diff --git a/src/java_ver.rs b/src/java_ver.rs index 332a550..64ea14a 100644 --- a/src/java_ver.rs +++ b/src/java_ver.rs @@ -10,7 +10,7 @@ use std::path::Path; use std::path::PathBuf; use toml; use crate::utils::release_utils::ReleaseParser; - +use std::process::Command; #[derive(Serialize, Deserialize)] pub struct Java { @@ -158,6 +158,7 @@ pub fn version_record(java_config: JavaNew) { } pub fn enable_version(implementor: &str, version: &str) { + println!("enable global"); let store: StoreNew = read_version(); if let Some(lists) = store.java_version { for element in lists { @@ -205,3 +206,27 @@ pub fn read_local(path: &str) { } } +pub fn enable_temp(implementor: &str, version: &str) { + let store: StoreNew = read_version(); + if let Some(lists) = store.java_version { + for element in lists { + if version == element.full_version && implementor == element.implementor { + let mut path = PathBuf::new(); + path.push(&element.path); + let str_path:String = path.to_str().unwrap().to_owned(); + str_path.replace("\\", "/"); + let result = std::process::Command::new("cmd").arg(format!("/K set path={str_path};%path%")).output(); + match result { + Ok(_) => { + let green = Style::new().green(); + println!("{}, JDK VERSION:{}", green.apply_to("Enable SUCCESS"), version) + } + Err(e) => { + let red = Style::new().red(); + println!("{}, {}", red.apply_to("Enable FAILED"), e.to_string()); + } + } + } + } + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 8137ca5..9fdded3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,8 +27,12 @@ async fn main() { .subcommand( clap::App::new("enable") .about("enable one jdk version globally") - .args(&[clap::Arg::new("implementor").takes_value(true).short('i'), clap::Arg::new("JDK version").takes_value(true).short('v')]) - .override_usage("jdkman.exe -i [IMPLEMENTOR] -v [JDK_VERSION]"), + .args(&[clap::Arg::new("implementor").takes_value(true).short('i'), + clap::Arg::new("version").takes_value(true).short('v'), + // clap::Arg::new("global").short('g').long("global").takes_value(false).help("enable jdk globally").default_missing_value("true") + ]) + + .override_usage("jdkman.exe enable -i [IMPLEMENTOR] -v [JDK_VERSION]"), ) .subcommand( clap::App::new("disable") @@ -82,6 +86,11 @@ async fn main() { let implementors = String::from(implementor); let imple = implementors.replace("\"", ""); java_ver::enable_version(&imple, version); + // if let Some(_) = e.value_of("global"){ + // java_ver::enable_version(&imple, version); + // } else { + // java_ver::enable_temp(&imple, version); + // } } } } else if let Some(_) = matches.subcommand_matches("disable") { diff --git a/src/utils/ziputil.rs b/src/utils/ziputil.rs index 32357e7..a62ffb5 100644 --- a/src/utils/ziputil.rs +++ b/src/utils/ziputil.rs @@ -1,3 +1,10 @@ +/* + * @Author: ZuoXichen + * @Date: 2022-02-11 18:02:31 + * @LastEditTime: 2022-05-12 23:43:47 + * @LastEditors: ZuoXichen + * @Description: + */ use std; use std::path::Path; use std::path::PathBuf; @@ -7,6 +14,7 @@ use indicatif::ProgressBar; use console::Term; pub fn extract(files: &Path, current_location: &PathBuf) { + println!("{}", files.to_str().unwrap()); let file = std::fs::File::open(files).unwrap();