From 2ac2ab82306e7a254f362fc4c9929b0909a6db04 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 14 Feb 2021 14:08:10 +0000 Subject: [PATCH] Add groups and total_uncompressed_length to master_index_archives This commit also adds support for populating the whirlpool column, and ensures version is set to 0 for the ORIGINAL master index format. Signed-off-by: Graham --- .../openrs2/archive/cache/CacheImporter.kt | 27 ++++++++++++++++--- .../org/openrs2/archive/V1__init.sql | 2 ++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt index 246c88d8..a23548f4 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt @@ -474,15 +474,36 @@ public class CacheImporter @Inject constructor( connection.prepareStatement( """ - INSERT INTO master_index_archives (master_index_id, archive_id, crc32, version) - VALUES (?, ?, ?, ?) + INSERT INTO master_index_archives ( + master_index_id, archive_id, crc32, version, whirlpool, groups, total_uncompressed_length + ) + VALUES (?, ?, ?, ?, ?, ?, ?) """.trimIndent() ).use { stmt -> for ((i, entry) in masterIndex.index.entries.withIndex()) { stmt.setInt(1, masterIndexId!!) stmt.setInt(2, i) stmt.setInt(3, entry.checksum) - stmt.setInt(4, entry.version) + + if (masterIndex.index.format >= MasterIndexFormat.VERSIONED) { + stmt.setInt(4, entry.version) + } else { + stmt.setInt(4, 0) + } + + if (masterIndex.index.format >= MasterIndexFormat.DIGESTS) { + stmt.setBytes(5, entry.digest ?: ByteArray(Whirlpool.DIGESTBYTES)) + } else { + stmt.setNull(5, Types.BINARY) + } + + if (masterIndex.index.format >= MasterIndexFormat.LENGTHS) { + stmt.setInt(6, entry.groups) + stmt.setInt(7, entry.totalUncompressedLength) + } else { + stmt.setNull(6, Types.INTEGER) + stmt.setNull(7, Types.INTEGER) + } stmt.addBatch() } diff --git a/archive/src/main/resources/org/openrs2/archive/V1__init.sql b/archive/src/main/resources/org/openrs2/archive/V1__init.sql index 1477ffcb..4954c868 100644 --- a/archive/src/main/resources/org/openrs2/archive/V1__init.sql +++ b/archive/src/main/resources/org/openrs2/archive/V1__init.sql @@ -117,6 +117,8 @@ CREATE TABLE master_index_archives ( crc32 INTEGER NOT NULL, whirlpool BYTEA NULL, version INTEGER NOT NULL, + groups INTEGER NULL, + total_uncompressed_length INTEGER NULL, PRIMARY KEY (master_index_id, archive_id) );