Compare commits

..

No commits in common. "9bff20cb1a0918d7789b281952624fed890fbab7" and "0da7ad6f1a15e8462d8270fc36ea9f135c3b8d29" have entirely different histories.

3 changed files with 20 additions and 14 deletions

View File

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

View File

@ -41,6 +41,7 @@ import tachiyomi.source.local.io.Format
import tachiyomi.source.local.io.LocalSourceFileSystem import tachiyomi.source.local.io.LocalSourceFileSystem
import tachiyomi.source.local.metadata.fillMetadata import tachiyomi.source.local.metadata.fillMetadata
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.io.File
import java.io.InputStream import java.io.InputStream
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
import kotlin.time.Duration.Companion.days import kotlin.time.Duration.Companion.days
@ -144,8 +145,8 @@ actual class LocalSource(
// Augment manga details based on metadata files // Augment manga details based on metadata files
try { try {
val mangaDir = fileSystem.getMangaDirectory(manga.url) ?: error("${manga.url} is not a valid directory") val mangaDir by lazy { fileSystem.getMangaDirectory(manga.url) }
val mangaDirFiles = mangaDir.listFiles().orEmpty() val mangaDirFiles = fileSystem.getFilesInMangaDirectory(manga.url)
val comicInfoFile = mangaDirFiles val comicInfoFile = mangaDirFiles
.firstOrNull { it.name == COMIC_INFO_FILE } .firstOrNull { it.name == COMIC_INFO_FILE }
@ -175,7 +176,7 @@ actual class LocalSource(
// Replace with ComicInfo.xml file // Replace with ComicInfo.xml file
val comicInfo = manga.getComicInfo() val comicInfo = manga.getComicInfo()
mangaDir mangaDir
.createFile(COMIC_INFO_FILE) ?.createFile(COMIC_INFO_FILE)
?.openOutputStream() ?.openOutputStream()
?.use { ?.use {
val comicInfoString = xml.encodeToString(ComicInfo.serializer(), comicInfo) val comicInfoString = xml.encodeToString(ComicInfo.serializer(), comicInfo)
@ -190,12 +191,14 @@ actual class LocalSource(
.filter(Archive::isSupported) .filter(Archive::isSupported)
.toList() .toList()
val copiedFile = copyComicInfoFileFromArchive(chapterArchives, mangaDir) val folderPath = mangaDir?.filePath
val copiedFile = copyComicInfoFileFromArchive(chapterArchives, folderPath)
if (copiedFile != null) { if (copiedFile != null) {
setMangaDetailsFromComicInfoFile(copiedFile.openInputStream(), manga) setMangaDetailsFromComicInfoFile(copiedFile.inputStream(), manga)
} else { } else {
// Avoid re-scanning // Avoid re-scanning
mangaDir.createFile(".noxml") mangaDir?.createFile(".noxml")
} }
} }
} }
@ -206,14 +209,14 @@ actual class LocalSource(
return@withIOContext manga return@withIOContext manga
} }
private fun copyComicInfoFileFromArchive(chapterArchives: List<UniFile>, folder: UniFile): UniFile? { private fun copyComicInfoFileFromArchive(chapterArchives: List<UniFile>, folderPath: String?): File? {
for (chapter in chapterArchives) { for (chapter in chapterArchives) {
when (Format.valueOf(chapter)) { when (Format.valueOf(chapter)) {
is Format.Zip -> { is Format.Zip -> {
ZipFile(chapter.openReadOnlyChannel(context)).use { zip: ZipFile -> ZipFile(chapter.openReadOnlyChannel(context)).use { zip: ZipFile ->
zip.getEntry(COMIC_INFO_FILE)?.let { comicInfoFile -> zip.getEntry(COMIC_INFO_FILE)?.let { comicInfoFile ->
zip.getInputStream(comicInfoFile).buffered().use { stream -> zip.getInputStream(comicInfoFile).buffered().use { stream ->
return copyComicInfoFile(stream, folder) return copyComicInfoFile(stream, folderPath)
} }
} }
} }
@ -222,7 +225,7 @@ actual class LocalSource(
JunrarArchive(chapter.openInputStream()).use { rar -> JunrarArchive(chapter.openInputStream()).use { rar ->
rar.fileHeaders.firstOrNull { it.fileName == COMIC_INFO_FILE }?.let { comicInfoFile -> rar.fileHeaders.firstOrNull { it.fileName == COMIC_INFO_FILE }?.let { comicInfoFile ->
rar.getInputStream(comicInfoFile).buffered().use { stream -> rar.getInputStream(comicInfoFile).buffered().use { stream ->
return copyComicInfoFile(stream, folder) return copyComicInfoFile(stream, folderPath)
} }
} }
} }
@ -233,9 +236,9 @@ actual class LocalSource(
return null return null
} }
private fun copyComicInfoFile(comicInfoFileStream: InputStream, folder: UniFile): UniFile? { private fun copyComicInfoFile(comicInfoFileStream: InputStream, folderPath: String?): File {
return folder.createFile(COMIC_INFO_FILE)?.apply { return File("$folderPath/$COMIC_INFO_FILE").apply {
openOutputStream().use { outputStream -> outputStream().use { outputStream ->
comicInfoFileStream.use { it.copyTo(outputStream) } comicInfoFileStream.use { it.copyTo(outputStream) }
} }
} }

View File

@ -22,6 +22,9 @@ actual class LocalSourceFileSystem(
} }
actual fun getFilesInMangaDirectory(name: String): List<UniFile> { actual fun getFilesInMangaDirectory(name: String): List<UniFile> {
return getMangaDirectory(name)?.listFiles().orEmpty().toList() return getBaseDirectory()
?.findFile(name, true)
?.takeIf { it.isDirectory }
?.listFiles().orEmpty().toList()
} }
} }