|
|
@ -15,7 +15,8 @@ import kotlin.math.min |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A [Store] implementation compatible with the native `main_file_cache.dat2` |
|
|
|
* A [Store] implementation compatible with the native `main_file_cache.dat2` |
|
|
|
* and `main_file_cache.idx*` format used by the client. |
|
|
|
* (or `main_file_cache.dat`) and `main_file_cache.idx*` format used by the |
|
|
|
|
|
|
|
* client. |
|
|
|
* |
|
|
|
* |
|
|
|
* It supports opening existing caches with a `main_file_cache.dat2m` file for |
|
|
|
* It supports opening existing caches with a `main_file_cache.dat2m` file for |
|
|
|
* compatibility purposes. It does not support creating new caches with a |
|
|
|
* compatibility purposes. It does not support creating new caches with a |
|
|
@ -484,6 +485,10 @@ public class DiskStore private constructor( |
|
|
|
return root.resolve("main_file_cache.dat2") |
|
|
|
return root.resolve("main_file_cache.dat2") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal fun legacyDataPath(root: Path): Path { |
|
|
|
|
|
|
|
return root.resolve("main_file_cache.dat") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun musicDataPath(root: Path): Path { |
|
|
|
private fun musicDataPath(root: Path): Path { |
|
|
|
return root.resolve("main_file_cache.dat2m") |
|
|
|
return root.resolve("main_file_cache.dat2m") |
|
|
|
} |
|
|
|
} |
|
|
@ -493,15 +498,23 @@ public class DiskStore private constructor( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store { |
|
|
|
public fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store { |
|
|
|
|
|
|
|
val js5DataPath = dataPath(root) |
|
|
|
|
|
|
|
val legacyDataPath = legacyDataPath(root) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val dataPath = if (Files.exists(js5DataPath)) { |
|
|
|
|
|
|
|
js5DataPath |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
legacyDataPath |
|
|
|
|
|
|
|
} |
|
|
|
val data = BufferedFileChannel( |
|
|
|
val data = BufferedFileChannel( |
|
|
|
FileChannel.open(dataPath(root), READ, WRITE), |
|
|
|
FileChannel.open(dataPath, READ, WRITE), |
|
|
|
DATA_BUFFER_SIZE, |
|
|
|
DATA_BUFFER_SIZE, |
|
|
|
DATA_BUFFER_SIZE, |
|
|
|
DATA_BUFFER_SIZE, |
|
|
|
alloc |
|
|
|
alloc |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
val path = musicDataPath(root) |
|
|
|
val musicDataPath = musicDataPath(root) |
|
|
|
val musicData = if (Files.exists(path)) { |
|
|
|
val musicData = if (Files.exists(musicDataPath)) { |
|
|
|
BufferedFileChannel( |
|
|
|
BufferedFileChannel( |
|
|
|
FileChannel.open(musicDataPath(root), READ, WRITE), |
|
|
|
FileChannel.open(musicDataPath(root), READ, WRITE), |
|
|
|
DATA_BUFFER_SIZE, |
|
|
|
DATA_BUFFER_SIZE, |
|
|
@ -529,11 +542,20 @@ public class DiskStore private constructor( |
|
|
|
return DiskStore(root, data, musicData, archives, alloc) |
|
|
|
return DiskStore(root, data, musicData, archives, alloc) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public fun create(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store { |
|
|
|
public fun create( |
|
|
|
|
|
|
|
root: Path, |
|
|
|
|
|
|
|
alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT, |
|
|
|
|
|
|
|
legacyDataPath: Boolean = false |
|
|
|
|
|
|
|
): Store { |
|
|
|
Files.createDirectories(root) |
|
|
|
Files.createDirectories(root) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val dataPath = if (legacyDataPath) { |
|
|
|
|
|
|
|
legacyDataPath(root) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
dataPath(root) |
|
|
|
|
|
|
|
} |
|
|
|
val data = BufferedFileChannel( |
|
|
|
val data = BufferedFileChannel( |
|
|
|
FileChannel.open(dataPath(root), CREATE, READ, WRITE), |
|
|
|
FileChannel.open(dataPath, CREATE, READ, WRITE), |
|
|
|
DATA_BUFFER_SIZE, |
|
|
|
DATA_BUFFER_SIZE, |
|
|
|
DATA_BUFFER_SIZE, |
|
|
|
DATA_BUFFER_SIZE, |
|
|
|
alloc |
|
|
|
alloc |
|
|
|