From da45cff0016463ce02f61876195f2c4fba51dd5a Mon Sep 17 00:00:00 2001 From: bic-potato Date: Sun, 15 May 2022 17:37:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(version=20download):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=86=E5=9B=A0=E6=B8=85=E5=8D=8E=E9=95=9C=E5=83=8F=E6=BA=90?= =?UTF-8?q?=E7=BD=91=E5=9D=80=E5=8F=98=E5=8C=96=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java_remote.rs | 9 ++++++++- src/java_ver.rs | 27 ++++++++++++++++++++++++++- src/main.rs | 13 +++++++++++-- src/utils/ziputil.rs | 8 ++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) 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();