@@ -340,12 +340,15 @@ class Patcher(
340340 }
341341
342342 private fun Path.commonPath (other : Path ): Path {
343- val a = this . toAbsolutePath().normalize()
343+ val a = toAbsolutePath().normalize()
344344 val b = other.toAbsolutePath().normalize()
345- val min = minOf(a.nameCount, b.nameCount)
346- var i = 0
347- while (i < min && a.getName(i) == b.getName(i)) i++
348- return if (i == 0 ) a.root else a.root.resolve(a.subpath(0 , i))
345+
346+ val commonCount = (0 until minOf(a.nameCount, b.nameCount))
347+ .takeWhile { a.getName(it) == b.getName(it) }
348+ .count()
349+
350+ return if (commonCount == 0 ) a.root
351+ else a.root.resolve(a.subpath(0 , commonCount))
349352 }
350353
351354 private fun zipPreserveStructure (sources : List <Path >, outputFile : Path , base : Path ) {
@@ -354,33 +357,34 @@ class Patcher(
354357 for (src in sources) {
355358 if (! Files .exists(src)) {
356359 // skip
360+ log.warn(" Could not find path {}" , src)
357361 continue
358362 }
359363 if (Files .isDirectory(src)) {
360364 Files .walk(src).use { stream ->
361- stream.filter { Files .isRegularFile(it) }.forEach { file ->
362- val arcname = base.relativize(file).toString().replace(" \\ " , " /" )
363- val entry = ZipEntry (arcname)
364- // fix timestamp for determinism (not strictly necessary)
365- entry.time = 315532800000L // 1980-01-01 00:00:00 UTC in ms
366- zos.putNextEntry(entry)
367- Files .newInputStream(file).use { inp -> inp.copyTo(zos) }
368- zos.closeEntry()
369- }
365+ stream
366+ .filter { Files .isRegularFile(it) }
367+ .forEach { zos.pushNormalizedFile(base, it) }
370368 }
371369 } else {
372- val arcname = base.relativize(src).toString().replace(" \\ " , " /" )
373- val entry = ZipEntry (arcname)
374- // earliest timestamp allowed in zip file
375- entry.time = 315532800000L
376- zos.putNextEntry(entry)
377- Files .newInputStream(src).use { inp -> inp.copyTo(zos) }
378- zos.closeEntry()
370+ zos.pushNormalizedFile(base, src)
379371 }
380372 }
381373 }
382374 }
383375
376+ private fun ZipOutputStream.pushNormalizedFile (base : Path , path : Path ) {
377+ require(Files .isRegularFile(path)) { " Path $path is not a regular file" }
378+
379+ val archiveName = base.relativize(path).toString().replace(" \\ " , " /" )
380+ val entry = ZipEntry (archiveName)
381+ // fix timestamp for determinism (not strictly necessary)
382+ entry.time = 315532800000L
383+ this .putNextEntry(entry)
384+ Files .newInputStream(path).use { inp -> inp.copyTo(this ) }
385+ this .closeEntry()
386+ }
387+
384388}
385389
386390fun main () {
@@ -445,11 +449,10 @@ fun main() {
445449 Patcher .PatchFile (19 , " E05_VO.v%d.nx2" , null ),
446450 Patcher .PatchFile (20 , " E06_VO.v%d.nx2" , null ),
447451 Patcher .PatchFile (21 , " Prothyon16_VO.v%d.nx2" , null ),
448- Patcher .PatchFile (22 , " A03_VO.v%d.nx2" , null ),
449- Patcher .PatchFile (23 , " A03_VO.v%d.nx2" , null ),
450- Patcher .PatchFile (24 , " A03_VO.v%d.nx2" , null ),
451- Patcher .PatchFile (25 , " A03_VO.v%d.nx2" , null ),
452- // … add the rest
452+ Patcher .PatchFile (22 , " TCR_VO.v%d.nx2" , null ),
453+ Patcher .PatchFile (23 , " SCCA_Briefings.v%d.nx2" , null ),
454+ Patcher .PatchFile (24 , " SCCA_FMV.v%d.nx2" , null ),
455+ Patcher .PatchFile (25 , " FAF_Coop_Operation_Tight_Spot_VO.v%d.nx2" , null ),
453456 )
454457
455458 FafDatabase (
0 commit comments