From e01183101f1922687dbc043bbd7ff5711689a30f Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 19 Sep 2023 18:15:42 +0900 Subject: [PATCH] quicksave to write modification time to the disk --- .../terrarum/TerrarumAppConfiguration.kt | 2 +- .../serialise/QuickSaveThread.kt | 2 + .../serialise/WorldSavingThread.kt | 2 + .../torvald/terrarum/savegame/DiskSkimmer.kt | 86 ------------------- 4 files changed, 5 insertions(+), 87 deletions(-) diff --git a/src/net/torvald/terrarum/TerrarumAppConfiguration.kt b/src/net/torvald/terrarum/TerrarumAppConfiguration.kt index d92817446..e9d8bf313 100644 --- a/src/net/torvald/terrarum/TerrarumAppConfiguration.kt +++ b/src/net/torvald/terrarum/TerrarumAppConfiguration.kt @@ -67,7 +67,7 @@ basegame // Commit counts up to the Release 0.3.1: 2278 // Commit counts up to the Release 0.3.2: 2732 - const val VERSION_TAG: String = "test004" + const val VERSION_TAG: String = "" ////////////////////////////////////////////////////////// // CONFIGURATION FOR TILE MAKER // diff --git a/src/net/torvald/terrarum/modulebasegame/serialise/QuickSaveThread.kt b/src/net/torvald/terrarum/modulebasegame/serialise/QuickSaveThread.kt index 125b674d2..455c9447e 100644 --- a/src/net/torvald/terrarum/modulebasegame/serialise/QuickSaveThread.kt +++ b/src/net/torvald/terrarum/modulebasegame/serialise/QuickSaveThread.kt @@ -151,6 +151,8 @@ class QuickSingleplayerWorldSavingThread( skimmer.setSaveMode(1 + 2 * isAuto.toInt()) skimmer.setSaveKind(VDSaveKind.WORLD_DATA) skimmer.setSaveOrigin(skimmer.getSaveOrigin() and 15) // remove flag "imported" if applicable + skimmer.setLastModifiedTime(time_t) + skimmer.setCreationTime(creation_t) printdbg(this, "Game saved with size of ${outFile.length()} bytes") diff --git a/src/net/torvald/terrarum/modulebasegame/serialise/WorldSavingThread.kt b/src/net/torvald/terrarum/modulebasegame/serialise/WorldSavingThread.kt index bf1924aaf..090aa711c 100644 --- a/src/net/torvald/terrarum/modulebasegame/serialise/WorldSavingThread.kt +++ b/src/net/torvald/terrarum/modulebasegame/serialise/WorldSavingThread.kt @@ -170,10 +170,12 @@ class WorldSavingThread( // Echo("Writing file to disk...") + disk.entries[0]!!.creationDate = creation_t disk.entries[0]!!.modificationDate = time_t // entry zero MUST NOT be used to get lastPlayDate, but we'll update it anyway // use entry -1 for that purpose! disk.capacity = 0 + VDUtil.dumpToRealMachine(disk, outFile) diff --git a/src/net/torvald/terrarum/savegame/DiskSkimmer.kt b/src/net/torvald/terrarum/savegame/DiskSkimmer.kt index 04f4f5386..57ec8fd0a 100644 --- a/src/net/torvald/terrarum/savegame/DiskSkimmer.kt +++ b/src/net/torvald/terrarum/savegame/DiskSkimmer.kt @@ -348,56 +348,6 @@ removefile: override fun getEntry(id: EntryID) = requestFile(id) override fun getFile(id: EntryID) = requestFile(id)?.contents as? EntryFile - /** - * Try to find a file with given path (which uses '/' as a separator). Is search is failed for whatever reason, - * `null` is returned. - * - * @param path A path to the file from the root, directory separated with '/' (and not '\') - * @return DiskEntry if the search was successful, `null` otherwise - */ - /*fun requestFile(path: String): DiskEntry? { - // fixme pretty much untested - - val path = path.split(dirDelim) - //debugPrintln(path) - - // bunch-of-io-access approach (for reading) - var traversedDir = 0L // entry ID - var dirFile: DiskEntry? = null - path.forEachIndexed { index, dirName -> - debugPrintln("[DiskSkimmer.requestFile] $index\t$dirName, traversedDir = $traversedDir") - - dirFile = requestFile(traversedDir) - if (dirFile == null) { - debugPrintln("[DiskSkimmer.requestFile] requestFile($traversedDir) came up null") - return null - } // outright null - if (dirFile!!.contents !is EntryDirectory && index < path.lastIndex) { // unexpectedly encountered non-directory - return null // because other than the last path, everything should be directory (think about it!) - } - //if (index == path.lastIndex) return dirFile // reached the end of the search strings - - // still got more paths behind to traverse - var dirGotcha = false - // loop for current dir contents - (dirFile!!.contents as EntryDirectory).forEach { - if (!dirGotcha) { // alternative impl of 'break' as it's not allowed - // get name of the file - val childDirFile = requestFile(it)!! - if (childDirFile.filename.toCanonicalString(charset) == dirName) { - //debugPrintln("[DiskSkimmer] found, $traversedDir -> $it") - dirGotcha = true - traversedDir = it - } - } - } - - if (!dirGotcha) return null // got null || directory empty || - } - - return requestFile(traversedDir) - }*/ - fun invalidateEntry(id: EntryID) { val fa = RandomAccessFile(diskFile, "rwd") entryToOffsetTable[id]?.let { @@ -418,21 +368,6 @@ removefile: fa.close() } - //private val modifiedDirectories = TreeSet() - - /*fun rewriteDirectories() { - modifiedDirectories.forEach { - invalidateEntry(it.entryID) - - val appendAt = fa.length() - fa.seek(appendAt) - - // append new file - entryToOffsetTable[it.entryID] = appendAt + 8 - it.serialize().forEach { fa.writeByte(it.toInt()) } - } - }*/ - fun setSaveMode(bits: Int) { val fa = RandomAccessFile(diskFile, "rwd") fa.seek(49L) @@ -585,28 +520,7 @@ removefile: } fun deleteEntry(id: EntryID) { - val fa = RandomAccessFile(diskFile, "rwd") - - - val entry = requestFile(id)!! -// val parentDir = requestFile(entry.parentEntryID)!! -// val parent = entry.parentEntryID - -// invalidateEntry(parent) invalidateEntry(id) - - // remove the entry -// val dirContent = (parentDir.contents as EntryDirectory) -// dirContent.remove(id) - - val appendAt = fa.length() - fa.seek(appendAt) - - // append modified directory -// entryToOffsetTable[id] = appendAt + 8 -// parentDir.serialize().forEach { fa.writeByte(it.toInt()) } - - fa.close() } fun appendEntries(entries: List) = entries.forEach { appendEntry(it) }