🛠️ Use File.separator to correctly separate paths

* Replaced "/" with "File.separator" to ensure correctness of the separation
This commit is contained in:
Acclorite 2025-01-16 10:43:40 +02:00
parent 181f1c94eb
commit 32cea59c7a
5 changed files with 23 additions and 18 deletions

View file

@ -9,6 +9,7 @@ import ua.acclorite.book_story.domain.reader.ReaderText
import ua.acclorite.book_story.presentation.core.util.clearAllMarkdown
import ua.acclorite.book_story.presentation.core.util.clearMarkdown
import ua.acclorite.book_story.presentation.core.util.containsVisibleText
import java.io.File
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import javax.inject.Inject
@ -72,11 +73,11 @@ class DocumentParser @Inject constructor(
select("img").forEach { element ->
val src = element.attr("src")
.trim()
.substringAfterLast("/")
.substringAfterLast(File.separator)
.lowercase()
.takeIf {
it.containsVisibleText() && imageEntries?.any { image ->
it == image.name.substringAfterLast('/').lowercase()
it == image.name.substringAfterLast(File.separator).lowercase()
} == true
} ?: return@forEach
@ -91,11 +92,11 @@ class DocumentParser @Inject constructor(
select("image").forEach { element ->
val src = element.attr("xlink:href")
.trim()
.substringAfterLast("/")
.substringAfterLast(File.separator)
.lowercase()
.takeIf {
it.containsVisibleText() && imageEntries?.any { image ->
it == image.name.substringAfterLast('/').lowercase()
it == image.name.substringAfterLast(File.separator).lowercase()
} == true
} ?: return@forEach
@ -125,7 +126,7 @@ class DocumentParser @Inject constructor(
val image = try {
val imageEntry = imageEntries?.find { image ->
src == image.name.substringAfterLast('/').lowercase()
src == image.name.substringAfterLast(File.separator).lowercase()
} ?: return@forEach
zipFile?.getImage(imageEntry)?.asImageBitmap()

View file

@ -226,7 +226,7 @@ class EpubTextParser @Inject constructor(
.let {
if (it == null) return@forEach
Uri.parse(it).path ?: it
}.substringAfterLast("/")
}.substringAfterLast(File.separator)
titleMap[source] = (titleMap[source] ?: emptyList()) + title
}
@ -245,7 +245,7 @@ class EpubTextParser @Inject constructor(
): String? {
if (chapterTitleMap.isNullOrEmpty()) return null
return chapterTitleMap
.getOrElse(chapterSource.substringAfterLast("/")) { null }
.getOrElse(chapterSource.substringAfterLast(File.separator)) { null }
?.joinToString(separator = " / ")
?.ifBlank { null }
?.trim()
@ -278,11 +278,13 @@ class EpubTextParser @Inject constructor(
document.select("spine > itemref").mapNotNull { itemRef ->
val spineId = itemRef.attr("idref")
val chapterSource = manifestItems[spineId]?.substringAfterLast('/')?.lowercase()
val chapterSource = manifestItems[spineId]
?.substringAfterLast(File.separator)
?.lowercase()
?: return@mapNotNull null
zipEntries.find { entry ->
entry.name.substringAfterLast('/').lowercase() == chapterSource
entry.name.substringAfterLast(File.separator).lowercase() == chapterSource
}
}.also { entries ->
if (entries.isEmpty()) return@let

View file

@ -234,7 +234,7 @@ class BookRepositoryImpl @Inject constructor(
if (book.image != null) {
try {
val fileToDelete = File(
"$coversDir/${book.image.substringAfterLast("/")}"
"$coversDir${File.separator}${book.image.substringAfterLast(File.separator)}"
)
if (fileToDelete.exists()) {
@ -288,7 +288,7 @@ class BookRepositoryImpl @Inject constructor(
if (book.image != null) {
try {
val fileToDelete = File(
"$coversDir/${book.image.substringAfterLast("/")}"
"$coversDir${File.separator}${book.image.substringAfterLast(File.separator)}"
)
if (fileToDelete.exists()) {

View file

@ -53,6 +53,10 @@ fun BookInfoDetailsBottomSheet(
else ""
}
val fileName = remember {
book.filePath.substringAfterLast(File.separatorChar)
}
ModalBottomSheet(
modifier = Modifier.fillMaxWidth(),
onDismissRequest = {
@ -67,11 +71,11 @@ fun BookInfoDetailsBottomSheet(
item {
BookInfoDetailsBottomSheetItem(
title = stringResource(id = R.string.file_name),
description = book.filePath.substringAfterLast("/").trim()
description = fileName
) {
copyToClipboard(
BookInfoEvent.OnCopyToClipboard(
text = book.filePath.substringAfterLast("/").trim(),
text = fileName,
context = context
)
)
@ -81,11 +85,11 @@ fun BookInfoDetailsBottomSheet(
item {
BookInfoDetailsBottomSheetItem(
title = stringResource(id = R.string.file_path),
description = book.filePath.trim()
description = book.filePath
) {
copyToClipboard(
BookInfoEvent.OnCopyToClipboard(
text = book.filePath.trim(),
text = book.filePath,
context = context
)
)

View file

@ -13,7 +13,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@ -46,9 +45,8 @@ fun BookInfoDetailsBottomSheetItem(
Spacer(modifier = Modifier.height(2.dp))
Text(
description,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}