new load wip

This commit is contained in:
minjaesong
2021-10-11 17:46:46 +09:00
parent 198237dee2
commit ef603ec5d5
26 changed files with 250 additions and 285 deletions

View File

@@ -1,9 +1,7 @@
package net.torvald.terrarum.tvda
import net.torvald.terrarum.serialise.Common
import java.io.*
import java.nio.charset.Charset
import java.nio.file.NoSuchFileException
import java.util.*
import java.util.logging.Level
import kotlin.experimental.and
@@ -344,7 +342,7 @@ removefile:
return fa.read()
}
fun getDiskName(charset: Charset): String {
override fun getDiskName(charset: Charset): String {
val bytes = ByteArray(268)
fa.seek(10L)
fa.read(bytes, 0, 32)

View File

@@ -1,9 +1,12 @@
package net.torvald.terrarum.tvda
import java.nio.charset.Charset
/**
* Created by minjaesong on 2021-10-07.
*/
interface SimpleFileSystem {
fun getEntry(id: EntryID): DiskEntry?
fun getFile(id: EntryID): EntryFile?
fun getDiskName(charset: Charset): String
}

View File

@@ -56,7 +56,7 @@ object VDUtil {
throw RuntimeException("Invalid Virtual Disk file!")
val diskSize = inbytes.sliceArray64(4L..9L).toInt48Big()
val diskName = inbytes.sliceArray64(10L..10L + 31)
val diskName = inbytes.sliceArray(10..10 + 31) + inbytes.sliceArray(10+32+22..10+32+22+235)
val diskCRC = inbytes.sliceArray64(10L + 32..10L + 32 + 3).toIntBig() // to check with completed vdisk
val diskSpecVersion = inbytes[10L + 32 + 4]
val footers = inbytes.sliceArray64(10L+32+6..10L+32+21)
@@ -64,7 +64,7 @@ object VDUtil {
if (diskSpecVersion != specversion)
throw RuntimeException("Unsupported disk format version: current internal version is $specversion; the file's version is $diskSpecVersion")
val vdisk = VirtualDisk(diskSize, diskName.toByteArray())
val vdisk = VirtualDisk(diskSize, diskName)
vdisk.__internalSetFooter__(footers)

View File

@@ -133,7 +133,7 @@ class VirtualDisk(
var saveMode: Int
set(value) { extraInfoBytes[1] = value.toByte() }
get() = extraInfoBytes[1].toUint()
fun getDiskNameString(charset: Charset) = diskName.toCanonicalString(charset)
override fun getDiskName(charset: Charset) = diskName.toCanonicalString(charset)
val root: DiskEntry
get() = entries[0]!!
@@ -207,7 +207,7 @@ class VirtualDisk(
}
override fun equals(other: Any?) = if (other == null) false else this.hashCode() == other.hashCode()
override fun toString() = "VirtualDisk(name: ${getDiskNameString(Charsets.UTF_8)}, capacity: $capacity bytes, crc: ${hashCode().toHex()})"
override fun toString() = "VirtualDisk(name: ${getDiskName(Charsets.UTF_8)}, capacity: $capacity bytes, crc: ${hashCode().toHex()})"
companion object {
val HEADER_SIZE = 300L // according to the spec