mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
quicksave to write modification time to the disk
This commit is contained in:
@@ -67,7 +67,7 @@ basegame
|
|||||||
// Commit counts up to the Release 0.3.1: 2278
|
// Commit counts up to the Release 0.3.1: 2278
|
||||||
// Commit counts up to the Release 0.3.2: 2732
|
// 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 //
|
// CONFIGURATION FOR TILE MAKER //
|
||||||
|
|||||||
@@ -151,6 +151,8 @@ class QuickSingleplayerWorldSavingThread(
|
|||||||
skimmer.setSaveMode(1 + 2 * isAuto.toInt())
|
skimmer.setSaveMode(1 + 2 * isAuto.toInt())
|
||||||
skimmer.setSaveKind(VDSaveKind.WORLD_DATA)
|
skimmer.setSaveKind(VDSaveKind.WORLD_DATA)
|
||||||
skimmer.setSaveOrigin(skimmer.getSaveOrigin() and 15) // remove flag "imported" if applicable
|
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")
|
printdbg(this, "Game saved with size of ${outFile.length()} bytes")
|
||||||
|
|
||||||
|
|||||||
@@ -170,10 +170,12 @@ 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!
|
||||||
disk.capacity = 0
|
disk.capacity = 0
|
||||||
|
|
||||||
VDUtil.dumpToRealMachine(disk, outFile)
|
VDUtil.dumpToRealMachine(disk, outFile)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -348,56 +348,6 @@ removefile:
|
|||||||
override fun getEntry(id: EntryID) = requestFile(id)
|
override fun getEntry(id: EntryID) = requestFile(id)
|
||||||
override fun getFile(id: EntryID) = requestFile(id)?.contents as? EntryFile
|
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) {
|
fun invalidateEntry(id: EntryID) {
|
||||||
val fa = RandomAccessFile(diskFile, "rwd")
|
val fa = RandomAccessFile(diskFile, "rwd")
|
||||||
entryToOffsetTable[id]?.let {
|
entryToOffsetTable[id]?.let {
|
||||||
@@ -418,21 +368,6 @@ removefile:
|
|||||||
fa.close()
|
fa.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
//private val modifiedDirectories = TreeSet<DiskEntry>()
|
|
||||||
|
|
||||||
/*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) {
|
fun setSaveMode(bits: Int) {
|
||||||
val fa = RandomAccessFile(diskFile, "rwd")
|
val fa = RandomAccessFile(diskFile, "rwd")
|
||||||
fa.seek(49L)
|
fa.seek(49L)
|
||||||
@@ -585,28 +520,7 @@ removefile:
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun deleteEntry(id: EntryID) {
|
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)
|
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<DiskEntry>) = entries.forEach { appendEntry(it) }
|
fun appendEntries(entries: List<DiskEntry>) = entries.forEach { appendEntry(it) }
|
||||||
|
|||||||
Reference in New Issue
Block a user