Fix save image filename for external archives
This commit is contained in:
1 parent
bbe8fd6b8f
commit
d9c7daebea
2 files changed
+20
-1
No files matched your search
@@ -32,6 +32,7 @@ import com.hippo.ehviewer.jni.providePassword
|
||||
import com.hippo.ehviewer.jni.releaseByteBuffer
|
||||
import com.hippo.ehviewer.util.FileUtils
|
||||
import com.hippo.ehviewer.util.detectAds
|
||||
import com.hippo.ehviewer.util.displayName
|
||||
import com.hippo.files.openFileDescriptor
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import java.nio.ByteBuffer
|
||||
@@ -75,7 +76,7 @@ suspend fun <T> useArchivePageLoader(
|
||||
private val mutex = NamedMutex<Int>()
|
||||
private val semaphore = Semaphore(4)
|
||||
|
||||
override val title by lazy { FileUtils.getNameFromFilename(file.name)!! }
|
||||
override val title by lazy { FileUtils.getNameFromFilename(file.displayName)!! }
|
||||
|
||||
override fun getImageExtension(index: Int) = getExtension(index)
|
||||
|
||||
|
||||
@@ -4,7 +4,10 @@ import android.content.ContentResolver
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import android.provider.DocumentsContract
|
||||
import androidx.core.provider.DocumentsContractCompat
|
||||
import arrow.core.Either
|
||||
import com.hippo.files.openFileDescriptor
|
||||
import com.hippo.files.toUri
|
||||
import okio.Path
|
||||
import splitties.init.appCtx
|
||||
|
||||
@@ -37,4 +40,19 @@ val Uri.displayPath: String?
|
||||
return toString()
|
||||
}
|
||||
|
||||
val Path.displayName: String
|
||||
get() {
|
||||
val uri = toUri()
|
||||
// The Path is constructed by us if the URI is a tree URI, so we don't need to query
|
||||
if (uri.scheme != ContentResolver.SCHEME_FILE && !DocumentsContractCompat.isTreeUri(uri)) {
|
||||
Either.catch {
|
||||
val proj = arrayOf(DocumentsContract.Document.COLUMN_DISPLAY_NAME)
|
||||
appCtx.contentResolver.query(uri, proj, null, null, null)?.use { c ->
|
||||
if (c.moveToNext()) return c.getString(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
fun Path.sha1() = openFileDescriptor("r").use { com.hippo.ehviewer.jni.sha1(it.fd) }
|
||||
Reference in new issue
Block a user