Skip to content

Commit

Permalink
fix(version download): 修复了因清华镜像源网址变化导致的下载失败
Browse files Browse the repository at this point in the history
  • Loading branch information
bic-potato committed May 15, 2022
1 parent d5e5bd4 commit da45cff
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/java_remote.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
);

Expand Down
27 changes: 26 additions & 1 deletion src/java_ver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
}
}
}
}
}
}
13 changes: 11 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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") {
Expand Down
8 changes: 8 additions & 0 deletions src/utils/ziputil.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();

Expand Down

0 comments on commit da45cff

Please sign in to comment.