Skip to content

Commit

Permalink
[Feature] Use libarchive.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai authored and Citrinae-Lime committed Sep 11, 2023
1 parent 4c631b0 commit 6d8d981
Show file tree
Hide file tree
Showing 21 changed files with 637 additions and 1,105 deletions.
12 changes: 2 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,11 @@ dependencies {
implementation 'me.zhanghai.android.appiconloader:appiconloader:1.5.0'
implementation 'me.zhanghai.android.fastscroll:library:1.3.0'
implementation 'me.zhanghai.android.foregroundcompat:library:1.0.2'
implementation 'me.zhanghai.android.libarchive:library:1.0.0'
implementation 'me.zhanghai.android.libselinux:library:2.1.0'
implementation 'me.zhanghai.android.retrofile:library:1.1.1'
implementation 'me.zhanghai.android.systemuihelper:library:1.0.0'
implementation 'net.sourceforge.streamsupport:android-retrostreams:1.7.4'
// Commons Compress 1.21 requires Android 8.0.
// See also https://issues.apache.org/jira/browse/COMPRESS-611
// Run `git revert fb1628e` if we ever created a fork that supports Android 5.0, or we raised
// minimum SDK version to Android 8.0.
//noinspection GradleDependency
implementation 'org.apache.commons:commons-compress:1.20'
// Optional dependency of Commons Compress for 7Z LZMA.
implementation 'org.tukaani:xz:1.9'
implementation 'org.apache.ftpserver:ftpserver-core:1.2.0'
// This is a dependency of org.apache.ftpserver:ftpserver-core but org.apache.mina:mina-core
// 2.1.3+ became incompatible before API 24 due to dependency on StandardSocketOptions
Expand All @@ -206,11 +199,10 @@ dependencies {
strictly '2.1.3'
}
}
// Also a dependency of jCIFS-NG and Junrar.
// Also a dependency of jCIFS-NG.
implementation 'org.slf4j:slf4j-android:1.7.36'

//#ifdef NONFREE
implementation 'com.github.junrar:junrar:7.5.4'
implementation platform('com.google.firebase:firebase-bom:32.2.3')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-crashlytics-ndk'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package me.zhanghai.android.files.file

import android.os.Build

val MimeType.isApk: Boolean
get() = this == MimeType.APK

Expand All @@ -20,24 +18,24 @@ private val supportedArchiveMimeTypes = mutableListOf(
"application/zip",
"application/vnd.android.package-archive",
"application/vnd.debian.binary-package",
"application/x-7z-compressed",
"application/x-bzip2",
"application/x-cab",
"application/x-compress",
"application/x-cpio",
"application/x-deb",
"application/x-debian-package",
"application/x-gtar",
"application/x-gtar-compressed",
"application/x-iso9660-image",
"application/x-java-archive",
"application/x-lha",
"application/x-lzma",
"application/x-redhat-package-manager",
"application/x-tar",
"application/x-ustar",
"application/x-xz"
)
.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
this += "application/x-7z-compressed"
}
}
.map { it.asMimeType() }.toSet()
).map { it.asMimeType() }.toSet()

val MimeType.isImage: Boolean
get() = icon == MimeTypeIcon.IMAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ class FileJobService : Service() {
fun archive(
sources: List<Path>,
archiveFile: Path,
archiveType: String,
compressorType: String?,
format: Int,
filter: Int,
password: String?,
context: Context
) {
startJob(ArchiveFileJob(sources, archiveFile, archiveType, compressorType), context)
startJob(ArchiveFileJob(sources, archiveFile, format, filter, password), context)
}

fun copy(sources: List<Path>, targetDirectory: Path, context: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,9 @@ private class ActionAllInfo(
class ArchiveFileJob(
private val sources: List<Path>,
private val archiveFile: Path,
private val archiveType: String,
private val compressorType: String?
private val format: Int,
private val filter: Int,
private val password: String?
) : FileJob() {
@Throws(IOException::class)
override fun run() {
Expand All @@ -594,16 +595,16 @@ class ArchiveFileJob(
var successful = false
try {
channel.use {
ArchiveWriter(archiveType, compressorType, channel).use { writer ->
ArchiveWriter(channel, format, filter, password).use { writer ->
val transferInfo = TransferInfo(scanInfo, archiveFile)
for (source in sources) {
val target = getTargetFileName(source)
archiveRecursively(source, writer, target, transferInfo)
throwIfInterrupted()
}
successful = true
}
}
successful = true
} finally {
if (!successful) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import me.zhanghai.android.files.util.args
import me.zhanghai.android.files.util.putArgs
import me.zhanghai.android.files.util.setTextWithSelection
import me.zhanghai.android.files.util.show
import org.apache.commons.compress.archivers.ArchiveStreamFactory
import org.apache.commons.compress.compressors.CompressorStreamFactory
import me.zhanghai.android.libarchive.Archive

class CreateArchiveDialogFragment : FileNameDialogFragment() {
private val args by args<Args>()
Expand Down Expand Up @@ -72,24 +71,13 @@ class CreateArchiveDialogFragment : FileNameDialogFragment() {
}

override fun onOk(name: String) {
val archiveType: String
val compressorType: String?
when (val typeId = binding.typeGroup.checkedRadioButtonId) {
R.id.zipRadio -> {
archiveType = ArchiveStreamFactory.ZIP
compressorType = null
}
R.id.tarXzRadio -> {
archiveType = ArchiveStreamFactory.TAR
compressorType = CompressorStreamFactory.XZ
}
R.id.sevenZRadio -> {
archiveType = ArchiveStreamFactory.SEVEN_Z
compressorType = null
}
val (format, filter) = when (val typeId = binding.typeGroup.checkedRadioButtonId) {
R.id.zipRadio -> Archive.FORMAT_ZIP to Archive.FILTER_NONE
R.id.tarXzRadio -> Archive.FORMAT_TAR to Archive.FILTER_XZ
R.id.sevenZRadio -> Archive.FORMAT_7ZIP to Archive.FILTER_NONE
else -> throw AssertionError(typeId)
}
listener.archive(args.files, name, archiveType, compressorType)
listener.archive(args.files, name, format, filter, null)
}

companion object {
Expand Down Expand Up @@ -120,6 +108,6 @@ class CreateArchiveDialogFragment : FileNameDialogFragment() {
}

interface Listener : FileNameDialogFragment.Listener {
fun archive(files: FileItemSet, name: String, archiveType: String, compressorType: String?)
fun archive(files: FileItemSet, name: String, format: Int, filter: Int, password: String?)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -911,12 +911,13 @@ class FileListFragment : Fragment(), BreadcrumbLayout.Listener, FileListAdapter.
override fun archive(
files: FileItemSet,
name: String,
archiveType: String,
compressorType: String?
format: Int,
filter: Int,
password: String?
) {
val archiveFile = viewModel.currentPath.resolve(name)
FileJobService.archive(
makePathListForJob(files), archiveFile, archiveType, compressorType, requireContext()
makePathListForJob(files), archiveFile, format, filter, password, requireContext()
)
viewModel.selectFiles(files, false)
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6d8d981

Please sign in to comment.