mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-02-05 16:44:47 +08:00
Replace .pack.gz with .pack.xz
This commit is contained in:
parent
ace830bced
commit
2b8843ca19
@ -6,10 +6,12 @@ import java.security.spec.PKCS8EncodedKeySpec
|
||||
import java.util.jar.JarFile
|
||||
import java.util.jar.JarOutputStream
|
||||
import java.util.jar.Pack200
|
||||
import java.util.zip.GZIPOutputStream
|
||||
import java.util.zip.ZipFile
|
||||
import java.nio.file.Files
|
||||
|
||||
import org.tukaani.xz.LZMA2Options
|
||||
import org.tukaani.xz.XZOutputStream
|
||||
|
||||
def buildnumber = System.getenv("BUILD_NUMBER") ?: "SNAPSHOT"
|
||||
def versionroot = System.getenv("VERSION_ROOT") ?: "3.1"
|
||||
version = versionroot + '.' + buildnumber
|
||||
@ -87,9 +89,9 @@ def createExecutable(String suffix, String header) {
|
||||
createChecksum(output)
|
||||
}
|
||||
|
||||
task makePackGz(dependsOn: jar) doLast {
|
||||
def outputPath = new File(jar.archivePath.parentFile, jar.archivePath.name[0..-4] + "pack.gz")
|
||||
new GZIPOutputStream(outputPath.newOutputStream()).withCloseable { out ->
|
||||
task makePackXz(dependsOn: jar) doLast {
|
||||
def outputPath = new File(jar.archivePath.parentFile, jar.archivePath.name[0..-4] + "pack.xz")
|
||||
new XZOutputStream(outputPath.newOutputStream(), new LZMA2Options(9)).withCloseable { out ->
|
||||
new JarFile(jar.archivePath).withCloseable { jarFile -> packer.pack(jarFile, out) }
|
||||
}
|
||||
|
||||
@ -101,5 +103,5 @@ task makeExecutables(dependsOn: jar) doLast {
|
||||
createExecutable("exe", "src/main/resources/assets/HMCLauncher.exe")
|
||||
}
|
||||
|
||||
build.dependsOn makePackGz
|
||||
build.dependsOn makePackXz
|
||||
build.dependsOn makeExecutables
|
||||
|
@ -30,10 +30,10 @@ import java.util.jar.JarFile;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.jar.Pack200;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.jackhuang.hmcl.Launcher;
|
||||
import org.jackhuang.hmcl.task.FileDownloadTask;
|
||||
import org.tukaani.xz.XZInputStream;
|
||||
|
||||
/**
|
||||
* A class used to manage the local HMCL repository.
|
||||
@ -89,10 +89,10 @@ final class LocalRepository {
|
||||
writeToStorage(downloaded, false);
|
||||
break;
|
||||
|
||||
case PACK_GZ:
|
||||
case PACK_XZ:
|
||||
Path unpacked = Files.createTempFile("hmcl-update-unpack-", null);
|
||||
try {
|
||||
try (InputStream in = new GZIPInputStream(Files.newInputStream(downloaded));
|
||||
try (InputStream in = new XZInputStream(Files.newInputStream(downloaded));
|
||||
JarOutputStream out = new JarOutputStream(Files.newOutputStream(unpacked))) {
|
||||
Pack200.newUnpacker().unpack(in, out);
|
||||
}
|
||||
|
@ -36,10 +36,10 @@ public class RemoteVersion {
|
||||
String version = Optional.ofNullable(response.get("version")).map(JsonElement::getAsString).orElseThrow(() -> new IOException("version is missing"));
|
||||
String jarUrl = Optional.ofNullable(response.get("jar")).map(JsonElement::getAsString).orElse(null);
|
||||
String jarHash = Optional.ofNullable(response.get("jarsha1")).map(JsonElement::getAsString).orElse(null);
|
||||
String packUrl = Optional.ofNullable(response.get("pack")).map(JsonElement::getAsString).orElse(null);
|
||||
String packHash = Optional.ofNullable(response.get("packsha1")).map(JsonElement::getAsString).orElse(null);
|
||||
if (packUrl != null && packHash != null) {
|
||||
return new RemoteVersion(version, packUrl, Type.PACK_GZ, new IntegrityCheck("SHA-1", packHash));
|
||||
String packXZUrl = Optional.ofNullable(response.get("packxz")).map(JsonElement::getAsString).orElse(null);
|
||||
String packXZHash = Optional.ofNullable(response.get("packxzsha1")).map(JsonElement::getAsString).orElse(null);
|
||||
if (packXZUrl != null && packXZHash != null) {
|
||||
return new RemoteVersion(version, packXZUrl, Type.PACK_XZ, new IntegrityCheck("SHA-1", packXZHash));
|
||||
} else if (jarUrl != null && jarHash != null) {
|
||||
return new RemoteVersion(version, jarUrl, Type.JAR, new IntegrityCheck("SHA-1", jarHash));
|
||||
} else {
|
||||
@ -84,7 +84,7 @@ public class RemoteVersion {
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
PACK_GZ,
|
||||
PACK_XZ,
|
||||
JAR
|
||||
}
|
||||
}
|
||||
|
10
build.gradle
10
build.gradle
@ -19,6 +19,16 @@
|
||||
group 'org.jackhuang'
|
||||
version '3.0'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'org.tukaani:xz:1.8'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
subprojects {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'idea'
|
||||
|
Loading…
Reference in New Issue
Block a user