@@ -33,7 +33,7 @@ data class CoopMap(
3333 " ${folderName.lowercase()} .v${version.toString().padStart(4 , ' 0' )} .zip"
3434
3535 fun folderName (version : Int ) =
36- " ${folderName.lowercase() } .v${version.toString().padStart(4 , ' 0' )} "
36+ " ${folderName} .v${version.toString().padStart(4 , ' 0' )} "
3737}
3838
3939private val coopMaps = listOf (
@@ -139,7 +139,7 @@ private fun processCoopMap(
139139
140140 // Compare with checksums from existing ZIP
141141 val currentZip = Path .of(mapsDir, map.zipName(currentVersion))
142- val oldChecksums = extractChecksumsFromZip(currentZip)
142+ val oldChecksums = extractChecksumsFromZip(currentZip, " ${map.folderName(currentVersion)} / $CHECKSUMS_FILENAME " )
143143
144144 val changed = currentVersion == 0 || newChecksums != oldChecksums
145145
@@ -181,12 +181,15 @@ private fun generateChecksumsForMap(
181181 */
182182private fun getFileContent (file : Path , map : CoopMap , version : Int ): ByteArray {
183183 return if (file.isTextFile()) {
184- file.readText()
184+ var text = file.readText()
185185 .replace(
186186 " /maps/${map.folderName} /" ,
187187 " /maps/${map.folderName(version)} /" ,
188188 )
189- .toByteArray()
189+ if (file.toString().endsWith(" _scenario.lua" )) {
190+ text = text.replace(Regex (""" (map_version\s*=\s*)\d+""" ), " $1$version " )
191+ }
192+ text.toByteArray()
190193 } else {
191194 file.readBytes()
192195 }
@@ -202,22 +205,24 @@ private fun createZip(
202205 ZipArchiveOutputStream (out .toFile()).use { zip ->
203206 zip.setMethod(ZipArchiveEntry .DEFLATED )
204207
205- // Generate and write checksums.md5 as first entry
208+ // Write all files inside versioned subfolder
209+ val versionedFolder = map.folderName(version)
210+
211+ // Generate and write checksums.md5 as first entry inside subfolder
206212 val checksums = generateChecksumsForMap(map, version, files, base)
207213 val checksumBytes = checksums.toByteArray()
208- val checksumEntry = ZipArchiveEntry (CHECKSUMS_FILENAME ).apply {
214+ val checksumEntry = ZipArchiveEntry (" $versionedFolder / $ CHECKSUMS_FILENAME" ).apply {
209215 size = checksumBytes.size.toLong()
210216 }
211217 zip.putArchiveEntry(checksumEntry)
212218 zip.write(checksumBytes)
213219 zip.closeArchiveEntry()
214220
215- // Write all files at root level
216221 files.forEach { file ->
217222 val rel = base.relativize(file).toString().replace(" \\ " , " /" )
218223 val bytes = getFileContent(file, map, version)
219224
220- val entry = ZipArchiveEntry (rel).apply {
225+ val entry = ZipArchiveEntry (" $versionedFolder / $ rel" ).apply {
221226 size = bytes.size.toLong()
222227 }
223228
0 commit comments