Skip to content

Commit 8b950ad

Browse files
committed
Fix coop map folder structure
1 parent 31c6754 commit 8b950ad

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

apps/faf-legacy-deployment/scripts/CoopMapDeployer.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3939
private 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
*/
182182
private 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

apps/faf-legacy-deployment/scripts/Utils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ fun generateChecksums(
133133
* Extract checksums.md5 content from an existing ZIP file.
134134
* Returns null if the file doesn't exist or doesn't contain checksums.md5.
135135
*/
136-
fun extractChecksumsFromZip(zipPath: Path): String? {
136+
fun extractChecksumsFromZip(zipPath: Path, entryName: String = CHECKSUMS_FILENAME): String? {
137137
if (!Files.exists(zipPath)) return null
138138

139139
return try {
140140
ZipFile.builder().setPath(zipPath).get().use { zip ->
141-
val entry = zip.getEntry(CHECKSUMS_FILENAME) ?: return null
141+
val entry = zip.getEntry(entryName) ?: return null
142142
zip.getInputStream(entry).bufferedReader().readText()
143143
}
144144
} catch (e: Exception) {

0 commit comments

Comments
 (0)