Use a single Resource::compressLibrary method for all writers

Signed-off-by: Graham <gpe@openrs2.dev>
pull/105/head
Graham 4 years ago
parent daefa7f4ea
commit 451a1d9c5e
  1. 31
      bundler/src/main/java/dev/openrs2/bundler/Bundler.kt
  2. 28
      bundler/src/main/java/dev/openrs2/bundler/Resource.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()

@ -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())
}
}

Loading…
Cancel
Save