Skip to content

Commit

Permalink
fix: archive type (.zip instead of tar.gz) on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Jun 16, 2024
1 parent d61eb34 commit 71dfc5a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src-tauri/src/minecraft/java/distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ impl Default for JavaDistribution {
}

impl JavaDistribution {
pub fn get_url(&self, jre_version: &u32, os_name: &str, os_arch: &str) -> String {
pub fn get_url(
&self,
jre_version: &u32,
os_name: &str,
os_arch: &str,
archive_type: &str
) -> String {
match self {
JavaDistribution::Temurin => {
format!(
Expand All @@ -28,17 +34,17 @@ impl JavaDistribution {
}
JavaDistribution::GraalVM => {
format!(
"https://download.oracle.com/graalvm/{}/latest/graalvm-jdk-{}_{}-{}_bin.tar.gz",
jre_version, jre_version, os_name, os_arch
"https://download.oracle.com/graalvm/{}/latest/graalvm-jdk-{}_{}-{}_bin.{}",
jre_version, jre_version, os_name, os_arch, archive_type
)
}
JavaDistribution::OpenJDK => {
// use microsoft openjdk
// https://aka.ms/download-jdk/microsoft-jdk-21-linux-x64.tar.gz

format!(
"https://aka.ms/download-jdk/microsoft-jdk-{}_{}-{}.tar.gz",
jre_version, os_name, os_arch
"https://aka.ms/download-jdk/microsoft-jdk-{}_{}-{}.{}",
jre_version, os_name, os_arch, archive_type
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/minecraft/java/jre_downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ where
// OS details
let os_name = OS.get_graal_name()?;
let os_arch = ARCHITECTURE.get_simple_name()?;
let url = jre_distribution.get_url(jre_version, os_name, os_arch);
let archive_type = OS.get_archive_type()?;
let url = jre_distribution.get_url(jre_version, os_name, os_arch, archive_type);

// Download from JRE source and extract runtime files
fs::create_dir_all(&runtime_path).await?;
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/utils/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ impl OperatingSystem {
})
}

pub fn get_archive_type(&self) -> Result<&'static str> {
Ok(match self {
OperatingSystem::WINDOWS => "zip",
OperatingSystem::LINUX | OperatingSystem::OSX => "tar.gz",
_ => bail!("Invalid OS")
})
}

}

impl Display for OperatingSystem {
Expand Down

0 comments on commit 71dfc5a

Please sign in to comment.