diff --git a/cache/src/main/kotlin/org/openrs2/cache/DiskStoreZipWriter.kt b/cache/src/main/kotlin/org/openrs2/cache/DiskStoreZipWriter.kt index 47cb5961..30cb4b8f 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/DiskStoreZipWriter.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/DiskStoreZipWriter.kt @@ -30,10 +30,12 @@ public class DiskStoreZipWriter( private val prefix: String = "cache/", level: Int = Deflater.BEST_COMPRESSION, timestamp: Instant = Instant.EPOCH, - private val alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT + private val alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT, + legacy: Boolean = false ) : Store { private data class IndexEntry(val len: Int, val block: Int) + private val archiveOffset = if (legacy) 1 else 0 private val timestamp = FileTime.from(timestamp) private val indexes = arrayOfNulls>(Store.MAX_ARCHIVE + 1) private val zeroBlock = ByteArray(DiskStore.BLOCK_SIZE) @@ -45,7 +47,13 @@ public class DiskStoreZipWriter( out.putNextEntry(createZipEntry("")) - out.putNextEntry(createZipEntry("main_file_cache.dat2")) + val dataFile = if (legacy) { + "main_file_cache.dat" + } else { + "main_file_cache.dat2" + } + + out.putNextEntry(createZipEntry(dataFile)) out.write(zeroBlock) } @@ -136,7 +144,7 @@ public class DiskStoreZipWriter( tempBuf.writeMedium(0) } - tempBuf.writeByte(archive) + tempBuf.writeByte(archive + archiveOffset) tempBuf.readBytes(out, tempBuf.readableBytes()) // write data diff --git a/cache/src/test/kotlin/org/openrs2/cache/DiskStoreZipWriterTest.kt b/cache/src/test/kotlin/org/openrs2/cache/DiskStoreZipWriterTest.kt index a970b83e..55f44e15 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/DiskStoreZipWriterTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/DiskStoreZipWriterTest.kt @@ -89,14 +89,13 @@ class DiskStoreZipWriterTest { } } - @Test - fun testWrite() { + private fun testWrite(expected: String, legacy: Boolean) { Jimfs.newFileSystem(Configuration.forCurrentPlatform()).use { fs -> val actual = fs.rootDirectories.first().resolve("zip") Files.createDirectories(actual) Files.newOutputStream(actual.resolve("cache.zip")).use { out -> - DiskStoreZipWriter(ZipOutputStream(out)).use { store -> + DiskStoreZipWriter(ZipOutputStream(out), legacy = legacy).use { store -> store.create(0) copiedBuffer("OpenRS2").use { buf -> @@ -113,10 +112,20 @@ class DiskStoreZipWriterTest { } } - assertTrue(ROOT.recursiveEquals(actual)) + assertTrue(ROOT.resolve(expected).recursiveEquals(actual)) } } + @Test + fun testWrite() { + testWrite("cache", legacy = false) + } + + @Test + fun testWriteLegacy() { + testWrite("cache-legacy", legacy = true) + } + private companion object { private val ROOT = Path.of(DiskStoreZipWriterTest::class.java.getResource("disk-store-zip").toURI()) } diff --git a/cache/src/test/resources/org/openrs2/cache/disk-store-zip/cache-legacy/cache.zip b/cache/src/test/resources/org/openrs2/cache/disk-store-zip/cache-legacy/cache.zip new file mode 100644 index 00000000..9a547276 Binary files /dev/null and b/cache/src/test/resources/org/openrs2/cache/disk-store-zip/cache-legacy/cache.zip differ diff --git a/cache/src/test/resources/org/openrs2/cache/disk-store-zip/cache.zip b/cache/src/test/resources/org/openrs2/cache/disk-store-zip/cache/cache.zip similarity index 100% rename from cache/src/test/resources/org/openrs2/cache/disk-store-zip/cache.zip rename to cache/src/test/resources/org/openrs2/cache/disk-store-zip/cache/cache.zip