in app/services/PremiereVersionConverter.scala [119:154]
def tweakProjectVersionStreaming(targetFile:Path, backupFile:Path, currentVersion:Int, newVersion:PremiereVersionTranslation) = {
def canFindAttribute(attribs:List[akka.stream.alpakka.xml.Attribute], key:String): Option[String] = {
attribs.find(_.name == key).map(_.value)
}
logger.warn("in tweakProjectVersionStreaming")
FileIO.fromPath(backupFile)
.via(Compression.gunzip())
.via(XmlParsing.parser)
.map({
case elem@StartElement("Project", attributesList, prefix, namespace, namespaceCtx)=>
logger.debug(s"Found projectNode with attributes $attributesList")
canFindAttribute(attributesList, "Version") match {
case Some(oldVersion)=>
if(oldVersion!=currentVersion.toString) {
logger.warn(s"${targetFile.toString}: Expected current version of $currentVersion but got $oldVersion")
}
logger.info(s"Changing version from $oldVersion to ${newVersion.internalVersionNumber} in ${targetFile.toString}")
val newAttributes = attributesList.filter(_.name!="Version") :+ Attribute("Version", newVersion.internalVersionNumber.toString)
elem.copy(attributesList=newAttributes)
case None=>
elem
}
case other@_ => other
})
.via(XmlWriting.writer(StandardCharsets.UTF_8))
.via(Compression.gzip)
.toMat(FileIO.toPath(targetFile))(Keep.right)
.run()
.flatMap(result=>{
logger.info(s"Output to ${targetFile.toString} completed. Wrote ${result.count} bytes")
Future.fromTry(result.status)
})
.flatMap(_=>Future.fromTry(RunXmlLint.runXmlLint(targetFile.toAbsolutePath.toString)))
}