From 451a1d9c5e7357d9ce3ace0b17fba8796a6fc1ea Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 2 May 2020 22:19:16 +0100 Subject: [PATCH] Use a single Resource::compressLibrary method for all writers Signed-off-by: Graham --- .../main/java/dev/openrs2/bundler/Bundler.kt | 31 ++++++++++++++----- .../main/java/dev/openrs2/bundler/Resource.kt | 28 ++++++----------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt index a23f06bc..a1e0fd1c 100644 --- a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt +++ b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt @@ -4,8 +4,11 @@ import com.github.michaelbull.logging.InlineLogger import dev.openrs2.asm.classpath.ClassPath import dev.openrs2.asm.classpath.Library import dev.openrs2.asm.io.JarLibraryReader +import dev.openrs2.asm.io.JarLibraryWriter +import dev.openrs2.asm.io.Js5LibraryWriter import dev.openrs2.asm.io.ManifestJarLibraryWriter import dev.openrs2.asm.io.Pack200LibraryReader +import dev.openrs2.asm.io.Pack200LibraryWriter import dev.openrs2.asm.io.SignedJarLibraryWriter import dev.openrs2.asm.transform.Transformer import dev.openrs2.bundler.transform.ResourceTransformer @@ -75,13 +78,27 @@ class Bundler @Inject constructor( // compress resources logger.info { "Compressing resources" } - val unpackerJar = Resource.compressJar("unpackclass.pack", "game_unpacker.dat", classPath, unpacker) - val clientPack = Resource.compressPack("runescape.pack200", "main_file_cache.dat0", classPath, client) - val clientJs5 = Resource.compressJs5("runescape.js5", "main_file_cache.dat1", classPath, client) - val glClientPack = Resource.compressPack("runescape_gl.pack200", "main_file_cache.dat3", glClassPath, glClient) - val glClientJs5 = Resource.compressJs5("runescape_gl.js5", "main_file_cache.dat4", glClassPath, glClient) - val glPack = Resource.compressPack("jaggl.pack200", "main_file_cache.dat5", glClassPath, gl) - val glJs5 = Resource.compressJs5("jaggl.js5", "main_file_cache.dat6", glClassPath, gl) + val unpackerJar = Resource.compressLibrary( + "unpackclass.pack", "game_unpacker.dat", classPath, unpacker, JarLibraryWriter() + ) + val clientPack = Resource.compressLibrary( + "runescape.pack200", "main_file_cache.dat0", classPath, client, Pack200LibraryWriter() + ) + val clientJs5 = Resource.compressLibrary( + "runescape.js5", "main_file_cache.dat1", classPath, client, Js5LibraryWriter() + ) + val glClientPack = Resource.compressLibrary( + "runescape_gl.pack200", "main_file_cache.dat3", glClassPath, glClient, Pack200LibraryWriter() + ) + val glClientJs5 = Resource.compressLibrary( + "runescape_gl.js5", "main_file_cache.dat4", glClassPath, glClient, Js5LibraryWriter() + ) + val glPack = Resource.compressLibrary( + "jaggl.pack200", "main_file_cache.dat5", glClassPath, gl, Pack200LibraryWriter() + ) + val glJs5 = Resource.compressLibrary( + "jaggl.js5", "main_file_cache.dat6", glClassPath, gl, Js5LibraryWriter() + ) val glNatives = Resource.compressGlNatives() val miscNatives = Resource.compressMiscNatives() diff --git a/bundler/src/main/java/dev/openrs2/bundler/Resource.kt b/bundler/src/main/java/dev/openrs2/bundler/Resource.kt index 515e087b..f469255e 100644 --- a/bundler/src/main/java/dev/openrs2/bundler/Resource.kt +++ b/bundler/src/main/java/dev/openrs2/bundler/Resource.kt @@ -3,9 +3,7 @@ package dev.openrs2.bundler import com.github.michaelbull.logging.InlineLogger import dev.openrs2.asm.classpath.ClassPath import dev.openrs2.asm.classpath.Library -import dev.openrs2.asm.io.JarLibraryWriter -import dev.openrs2.asm.io.Js5LibraryWriter -import dev.openrs2.asm.io.Pack200LibraryWriter +import dev.openrs2.asm.io.LibraryWriter import java.io.ByteArrayOutputStream import java.nio.file.Files import java.nio.file.Path @@ -68,23 +66,15 @@ class Resource( return Resource(source, destination, crc.value.toInt(), digest.digest(), uncompressed.size, content) } - fun compressJar(source: String, destination: String, classPath: ClassPath, library: Library): Resource { + fun compressLibrary( + source: String, + destination: String, + classPath: ClassPath, + library: Library, + writer: LibraryWriter + ): Resource { ByteArrayOutputStream().use { output -> - JarLibraryWriter().write(output, classPath, library) - return compress(source, destination, output.toByteArray()) - } - } - - fun compressPack(source: String, destination: String, classPath: ClassPath, library: Library): Resource { - ByteArrayOutputStream().use { output -> - Pack200LibraryWriter().write(output, classPath, library) - return compress(source, destination, output.toByteArray()) - } - } - - fun compressJs5(source: String, destination: String, classPath: ClassPath, library: Library): Resource { - ByteArrayOutputStream().use { output -> - Js5LibraryWriter().write(output, classPath, library) + writer.write(output, classPath, library) return compress(source, destination, output.toByteArray()) } }