GET /version endpoint
This commit is contained in:
@ -3,6 +3,8 @@ package com.jaytux.simd.data
|
||||
import com.fleeksoft.ksoup.Ksoup
|
||||
import com.jaytux.simd.data.IntrinsicInstructions.xed
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.datetime.*
|
||||
import kotlinx.datetime.format.MonthNames
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
@ -16,12 +18,16 @@ import java.text.DateFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.prefs.Preferences
|
||||
import java.time.Instant
|
||||
|
||||
object Loader {
|
||||
private val cache = Preferences.userNodeForPackage(this::class.java)
|
||||
private val intelDateTimeFormat = SimpleDateFormat("MM/dd/yyyy")
|
||||
private val dateFormat = SimpleDateFormat("dd-MMMM-yyyy")
|
||||
private val intelDateTimeFormat = LocalDate.Format {
|
||||
monthNumber(); chars("/"); dayOfMonth(); chars("/"); year();
|
||||
}
|
||||
private val dateFormat = LocalDate.Format {
|
||||
dayOfMonth(); chars("-"); monthName(MonthNames.ENGLISH_FULL); chars("-"); year()
|
||||
}
|
||||
private val zero = LocalDate(1970, 1, 1)
|
||||
|
||||
data class XmlIntrinsic(val name: String, val tech: String, val retType: String, val retVar: String?,
|
||||
val args: List<Pair<String, String>>, val desc: String, val op: String?,
|
||||
@ -46,14 +52,14 @@ object Loader {
|
||||
}
|
||||
}
|
||||
|
||||
data class DatedVersion(val version: Version, val releaseDate: Date, val updateDate: Date) {
|
||||
data class DatedVersion(val version: Version, val releaseDate: LocalDate, val updateDate: LocalDate) {
|
||||
override fun toString(): String = "$version (remote released ${dateFormat.format(releaseDate)}; local updated ${dateFormat.format(updateDate)})"
|
||||
|
||||
companion object {
|
||||
fun fromPrefs(): DatedVersion {
|
||||
val v = cache.get("version", null)?.let { Version.fromString(it) } ?: Version(0, 0, 0)
|
||||
val r = cache.get("release", null)?.let { dateFormat.parse(it) } ?: Date.from(Instant.ofEpochMilli(0))
|
||||
val u = cache.get("update", null)?.let { dateFormat.parse(it) } ?: Date.from(Instant.ofEpochMilli(0))
|
||||
val r = cache.get("release", null)?.let { dateFormat.parse(it) } ?: zero
|
||||
val u = cache.get("update", null)?.let { dateFormat.parse(it) } ?: zero
|
||||
|
||||
return DatedVersion(v, r, u)
|
||||
}
|
||||
@ -100,14 +106,14 @@ object Loader {
|
||||
}
|
||||
|
||||
version to date
|
||||
} ?: Version(0, 0, 0) to Date()
|
||||
} ?: Version(0, 0, 0) to LocalDate.fromEpochDays(0) // dummy data
|
||||
|
||||
if(errors.isNotEmpty()) {
|
||||
errors.forEach { System.err.println(it) }
|
||||
throw Exception("XML file is (partially) invalid")
|
||||
}
|
||||
|
||||
val update = Date()
|
||||
val update = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date
|
||||
|
||||
xml.getElementsByTag("intrinsic").forEachIndexed { i, it ->
|
||||
val name = it.attribute("name")?.value
|
||||
|
Reference in New Issue
Block a user