1
0
mirror of https://github.com/fumiama/copymanga.git synced 2026-06-27 14:20:30 +08:00
修复
1. 配置导入导出
This commit is contained in:
源文雨
2025-06-13 23:00:05 +09:00
parent 74c0b165ed
commit e53db6762f
2 changed files with 27 additions and 19 deletions

View File

@@ -12,8 +12,8 @@ android {
minSdkVersion 23 minSdkVersion 23
//noinspection OldTargetApi //noinspection OldTargetApi
targetSdkVersion 34 targetSdkVersion 34
versionCode 79 versionCode 80
versionName '2.5.6' versionName '2.5.7'
resourceConfigurations += ['zh', 'zh-rCN'] resourceConfigurations += ['zh', 'zh-rCN']
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@@ -11,35 +11,35 @@ object Base16384 {
fun encode(input: ByteArray): String { fun encode(input: ByteArray): String {
val sb = StringBuilder() val sb = StringBuilder()
var buffer = 0 var buffer = 0
var bitCount = 0 var bLen = 0
for (b in input) { for (b in input) {
buffer = (buffer shl 8) or (b.toInt() and 0xFF) buffer = (buffer shl 8) or (b.toInt() and 0xFF)
bitCount += 8 bLen += 8
while (bitCount >= 14) { while (bLen >= 14) {
bitCount -= 14 bLen -= 14
val index = (buffer shr bitCount) and (BASE - 1) val index = (buffer shr bLen) and (BASE - 1)
sb.append(Char(FIRST_CHAR + index)) sb.append(Char(FIRST_CHAR + index))
buffer = buffer and ((1 shl bitCount) - 1) buffer = buffer and ((1 shl bLen) - 1)
} }
} }
if (bitCount in 1..6) { if (bLen > 0) {
buffer = (buffer shl (14 - bitCount)) buffer = (buffer shl (14 - bLen))
val index = buffer and (BASE - 1) val index = buffer and (BASE - 1)
sb.append(Char(FIRST_CHAR + index)) sb.append(Char(FIRST_CHAR + index))
val padIndex = PAD_START + bitCount val padIndex = PAD_START + (input.size%7)
sb.append(Char(padIndex)) sb.append(Char(padIndex))
} }
Log.d("MyB14", "encode bitCount $bitCount, len ${input.size}, data: ${Base64.encode(input, Base64.DEFAULT).decodeToString()}") Log.d("MyB14", "encode offset ${input.size%7}, len ${input.size}, data: ${Base64.encode(input, Base64.DEFAULT).decodeToString()}")
return sb.toString() return sb.toString()
} }
fun decode(input: String): ByteArray { fun decode(input: String): ByteArray {
val bits = mutableListOf<Boolean>() val bits = mutableListOf<Boolean>()
var tailBits = 0 var offset = 0
for (c in input) { for (c in input) {
when (val code = c.code) { when (val code = c.code) {
in FIRST_CHAR until FIRST_CHAR + BASE -> { in FIRST_CHAR until FIRST_CHAR + BASE -> {
@@ -49,17 +49,25 @@ object Base16384 {
} }
} }
in (PAD_START + 1)..(PAD_START + 6) -> { in (PAD_START + 1)..(PAD_START + 6) -> {
tailBits = code - PAD_START offset = code - PAD_START
break break
} }
else -> throw IllegalArgumentException("Invalid base16384 char: $c") else -> throw IllegalArgumentException("Invalid base16384 char: $c")
} }
} }
val totalBits = bits.size - (14 - tailBits) val dLen = input.toByteArray(Charsets.UTF_16BE).size
val byteCount = totalBits / 8 val outLen = when (offset) {
val out = ByteArray(byteCount) 0 -> dLen
for (i in 0 until byteCount) { 1 -> dLen - 4
2, 3 -> dLen - 6
4, 5 -> dLen - 8
6 -> dLen - 10
else -> dLen
}/8*7 + offset
val out = ByteArray(outLen)
for (i in 0 until outLen) {
var byteVal = 0 var byteVal = 0
for (j in 0 until 8) { for (j in 0 until 8) {
if (bits[i * 8 + j]) byteVal = byteVal or (1 shl (7 - j)) if (bits[i * 8 + j]) byteVal = byteVal or (1 shl (7 - j))
@@ -67,7 +75,7 @@ object Base16384 {
out[i] = byteVal.toByte() out[i] = byteVal.toByte()
} }
Log.d("MyB14", "decode totalBits $totalBits, tailBits $tailBits, len ${out.size}, data: ${Base64.encode(out, Base64.DEFAULT).decodeToString()}") Log.d("MyB14", "decode offset $offset, len ${out.size}, data: ${Base64.encode(out, Base64.DEFAULT).decodeToString()}")
return out return out
} }
} }