mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
savegames array itself is correctly sorted but the UI is not and lastmodified time is also not written
This commit is contained in:
@@ -677,10 +677,10 @@ fun AppUpdateListOfSavegames() {
|
|||||||
App.savegameWorlds.clear()
|
App.savegameWorlds.clear()
|
||||||
App.savegameWorldsName.clear()
|
App.savegameWorldsName.clear()
|
||||||
|
|
||||||
println("listing savegames...")
|
println("Listing saved worlds...")
|
||||||
|
|
||||||
// create list of worlds
|
// create list of worlds
|
||||||
(File(worldsDir).listFiles().filter { !it.isDirectory && !it.name.contains('.') }.mapNotNull { file ->
|
File(worldsDir).listFiles().filter { !it.isDirectory && !it.name.contains('.') }.mapNotNull { file ->
|
||||||
try {
|
try {
|
||||||
DiskSkimmer(file, Common.CHARSET, true)
|
DiskSkimmer(file, Common.CHARSET, true)
|
||||||
}
|
}
|
||||||
@@ -689,8 +689,8 @@ fun AppUpdateListOfSavegames() {
|
|||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}.sortedByDescending { it.getLastModifiedOfFirstFile() }).forEach {
|
}.sortedByDescending { it.getLastModifiedTime() }.forEachIndexed { index, it ->
|
||||||
println(it.diskFile.absolutePath)
|
println("${index+1}.\t${it.diskFile.absolutePath}")
|
||||||
it.rebuild() // disk skimmer was created without initialisation, so do it now
|
it.rebuild() // disk skimmer was created without initialisation, so do it now
|
||||||
|
|
||||||
// TODO write simple and dumb SAX parser for JSON
|
// TODO write simple and dumb SAX parser for JSON
|
||||||
@@ -702,8 +702,10 @@ fun AppUpdateListOfSavegames() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
println("Listing saved players...")
|
||||||
|
|
||||||
// create list of players
|
// create list of players
|
||||||
(File(playersDir).listFiles().filter { !it.isDirectory && !it.name.contains('.') }.mapNotNull { file ->
|
File(playersDir).listFiles().filter { !it.isDirectory && !it.name.contains('.') }.mapNotNull { file ->
|
||||||
try {
|
try {
|
||||||
DiskSkimmer(file, Common.CHARSET, true)
|
DiskSkimmer(file, Common.CHARSET, true)
|
||||||
}
|
}
|
||||||
@@ -712,8 +714,8 @@ fun AppUpdateListOfSavegames() {
|
|||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}.sortedByDescending { it.getLastModifiedOfFirstFile() }).forEach {
|
}.sortedByDescending { it.getLastModifiedTime() }.forEachIndexed { index, it ->
|
||||||
println(it.diskFile.absolutePath)
|
println("${index+1}.\t${it.diskFile.absolutePath}")
|
||||||
it.rebuild() // disk skimmer was created without initialisation, so do it now
|
it.rebuild() // disk skimmer was created without initialisation, so do it now
|
||||||
|
|
||||||
// TODO write simple and dumb SAX parser for JSON
|
// TODO write simple and dumb SAX parser for JSON
|
||||||
@@ -722,7 +724,6 @@ fun AppUpdateListOfSavegames() {
|
|||||||
val playerUUID = UUID.fromString(json.getString("uuid"))
|
val playerUUID = UUID.fromString(json.getString("uuid"))
|
||||||
App.savegamePlayers[playerUUID] = it
|
App.savegamePlayers[playerUUID] = it
|
||||||
App.savegamePlayersName[playerUUID] = it.getDiskName(Common.CHARSET)
|
App.savegamePlayersName[playerUUID] = it.getDiskName(Common.CHARSET)
|
||||||
// App.savegamePlayersName[playerUUID] = json.get("actorValue")?.get(AVKey.NAME)?.asString() ?: "NULL!"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -500,11 +500,14 @@ class UIItemPlayerCells(
|
|||||||
|
|
||||||
App.savegamePlayersName[playerUUID]?.let { if (it.isNotBlank()) playerName = it else "(name)" }
|
App.savegamePlayersName[playerUUID]?.let { if (it.isNotBlank()) playerName = it else "(name)" }
|
||||||
App.savegameWorldsName[worldUUID]?.let { if (it.isNotBlank()) worldName = it }
|
App.savegameWorldsName[worldUUID]?.let { if (it.isNotBlank()) worldName = it }
|
||||||
json["lastPlayTime"]?.asString()?.let {
|
/*json["lastPlayTime"]?.asString()?.let {
|
||||||
lastPlayTime = Instant.ofEpochSecond(it.toLong())
|
lastPlayTime = Instant.ofEpochSecond(it.toLong())
|
||||||
.atZone(TimeZone.getDefault().toZoneId())
|
.atZone(TimeZone.getDefault().toZoneId())
|
||||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
||||||
}
|
}*/
|
||||||
|
lastPlayTime = Instant.ofEpochSecond(skimmer.getLastModifiedTime())
|
||||||
|
.atZone(TimeZone.getDefault().toZoneId())
|
||||||
|
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
||||||
json["totalPlayTime"]?.asString()?.let {
|
json["totalPlayTime"]?.asString()?.let {
|
||||||
totalPlayTime = parseDuration(it.toLong())
|
totalPlayTime = parseDuration(it.toLong())
|
||||||
}
|
}
|
||||||
@@ -642,7 +645,7 @@ class UIItemWorldCells(
|
|||||||
|
|
||||||
if (metaFile != null) {
|
if (metaFile != null) {
|
||||||
val worldJson = JsonReader().parse(ByteArray64Reader(metaFile.bytes, Common.CHARSET))
|
val worldJson = JsonReader().parse(ByteArray64Reader(metaFile.bytes, Common.CHARSET))
|
||||||
val lastplay_t = worldJson["lastPlayTime"].asLong()
|
val lastplay_t = skimmer.getLastModifiedTime()//worldJson["lastPlayTime"].asLong()
|
||||||
val playtime_t = worldJson["totalPlayTime"].asLong()
|
val playtime_t = worldJson["totalPlayTime"].asLong()
|
||||||
lastPlayedTimestamp =
|
lastPlayedTimestamp =
|
||||||
Instant.ofEpochSecond(lastplay_t)
|
Instant.ofEpochSecond(lastplay_t)
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ removefile:
|
|||||||
val fis = FileInputStream(diskFile)
|
val fis = FileInputStream(diskFile)
|
||||||
var currentPosition = fis.skip(VirtualDisk.HEADER_SIZE) // skip disk header
|
var currentPosition = fis.skip(VirtualDisk.HEADER_SIZE) // skip disk header
|
||||||
|
|
||||||
println("[DiskSkimmer] loading the diskfile ${diskFile.canonicalPath}")
|
// println("[DiskSkimmer] loading the diskfile ${diskFile.canonicalPath}")
|
||||||
|
|
||||||
fun skipRead(bytes: Long) {
|
fun skipRead(bytes: Long) {
|
||||||
currentPosition += fis.skip(bytes)
|
currentPosition += fis.skip(bytes)
|
||||||
@@ -353,13 +353,44 @@ removefile:
|
|||||||
return bytes.toCanonicalString(charset)
|
return bytes.toCanonicalString(charset)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getLastModifiedOfFirstFile(): Long {
|
/**
|
||||||
|
* @return creation time of the root directory
|
||||||
|
*/
|
||||||
|
fun getCreationTime(): Long {
|
||||||
|
val bytes = ByteArray(6)
|
||||||
|
fa.seek(320L)
|
||||||
|
fa.read(bytes)
|
||||||
|
return bytes.toInt48()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return last modified time of the root directory
|
||||||
|
*/
|
||||||
|
fun getLastModifiedTime(): Long {
|
||||||
val bytes = ByteArray(6)
|
val bytes = ByteArray(6)
|
||||||
fa.seek(326L)
|
fa.seek(326L)
|
||||||
fa.read(bytes)
|
fa.read(bytes)
|
||||||
return bytes.toInt48()
|
return bytes.toInt48()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redefines creation time of the root directory
|
||||||
|
*/
|
||||||
|
fun setCreationTime(time_t: Long) {
|
||||||
|
val bytes = ByteArray(6)
|
||||||
|
fa.seek(320L)
|
||||||
|
fa.write(time_t.toInt48())
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redefines last modified time of the root directory
|
||||||
|
*/
|
||||||
|
fun setLastModifiedTime(time_t: Long) {
|
||||||
|
val bytes = ByteArray(6)
|
||||||
|
fa.seek(326L)
|
||||||
|
fa.write(time_t.toInt48())
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
// THESE ARE METHODS TO SUPPORT ON-LINE MODIFICATION //
|
// THESE ARE METHODS TO SUPPORT ON-LINE MODIFICATION //
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -148,9 +148,15 @@ class VirtualDisk(
|
|||||||
|
|
||||||
private fun serializeEntriesOnly(): ByteArray64 {
|
private fun serializeEntriesOnly(): ByteArray64 {
|
||||||
val buffer = ByteArray64()
|
val buffer = ByteArray64()
|
||||||
|
|
||||||
|
// make sure to write root directory first
|
||||||
|
entries[0L]!!.let { rootDir ->
|
||||||
|
rootDir.serialize().forEach { buffer.add(it) }
|
||||||
|
}
|
||||||
entries.forEach {
|
entries.forEach {
|
||||||
val serialised = it.value.serialize()
|
if (it.key != 0L) {
|
||||||
serialised.forEach { buffer.add(it) }
|
it.value.serialize().forEach { buffer.add(it) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer
|
return buffer
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ class WorldSavingThread(
|
|||||||
|
|
||||||
Echo("Writing file to disk...")
|
Echo("Writing file to disk...")
|
||||||
|
|
||||||
|
disk.entries[0]!!.creationDate = creation_t
|
||||||
disk.entries[0]!!.modificationDate = time_t
|
disk.entries[0]!!.modificationDate = time_t
|
||||||
// entry zero MUST NOT be used to get lastPlayDate, but we'll update it anyway
|
// entry zero MUST NOT be used to get lastPlayDate, but we'll update it anyway
|
||||||
// use entry -1 for that purpose!
|
// use entry -1 for that purpose!
|
||||||
|
|||||||
Reference in New Issue
Block a user