|
|
|
@ -7,7 +7,6 @@ import android.provider.DocumentsContract |
|
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
|
import io.legado.app.model.NoStackTraceException |
|
|
|
|
import splitties.init.appCtx |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.io.File |
|
|
|
|
import java.nio.charset.Charset |
|
|
|
|
import java.util.* |
|
|
|
@ -95,6 +94,7 @@ object DocumentUtils { |
|
|
|
|
} ?: throw NoStackTraceException("打开文件失败\n${uri}") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Throws(Exception::class) |
|
|
|
|
fun listFiles(uri: Uri, regex: Regex? = null): ArrayList<DocItem> { |
|
|
|
|
val docList = arrayListOf<DocItem>() |
|
|
|
|
var cursor: Cursor? = null |
|
|
|
@ -133,33 +133,30 @@ object DocumentUtils { |
|
|
|
|
} while (cursor.moveToNext()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
Timber.e(e) |
|
|
|
|
} finally { |
|
|
|
|
cursor?.close() |
|
|
|
|
} |
|
|
|
|
return docList |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Throws(Exception::class) |
|
|
|
|
fun listFiles(path: String, regex: Regex? = null): ArrayList<DocItem> { |
|
|
|
|
val docItems = arrayListOf<DocItem>() |
|
|
|
|
kotlin.runCatching { |
|
|
|
|
val file = File(path) |
|
|
|
|
file.listFiles { pathName -> |
|
|
|
|
regex?.let { |
|
|
|
|
pathName.name.matches(it) |
|
|
|
|
} ?: true |
|
|
|
|
}?.forEach { |
|
|
|
|
docItems.add( |
|
|
|
|
DocItem( |
|
|
|
|
it.name, |
|
|
|
|
it.extension, |
|
|
|
|
it.length(), |
|
|
|
|
Date(it.lastModified()), |
|
|
|
|
Uri.parse(it.absolutePath) |
|
|
|
|
) |
|
|
|
|
val file = File(path) |
|
|
|
|
file.listFiles { pathName -> |
|
|
|
|
regex?.let { |
|
|
|
|
pathName.name.matches(it) |
|
|
|
|
} ?: true |
|
|
|
|
}?.forEach { |
|
|
|
|
docItems.add( |
|
|
|
|
DocItem( |
|
|
|
|
it.name, |
|
|
|
|
it.extension, |
|
|
|
|
it.length(), |
|
|
|
|
Date(it.lastModified()), |
|
|
|
|
Uri.parse(it.absolutePath) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
return docItems |
|
|
|
|
} |
|
|
|
|