mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-01-30 14:39:56 +08:00
Apache common-compress
This commit is contained in:
parent
cc2c186e7f
commit
e70226afba
@ -17,6 +17,7 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.download.forge
|
||||
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile
|
||||
import org.jackhuang.hmcl.download.DefaultDependencyManager
|
||||
import org.jackhuang.hmcl.download.RemoteVersion
|
||||
import org.jackhuang.hmcl.download.game.GameLibrariesTask
|
||||
@ -30,7 +31,6 @@ import org.jackhuang.hmcl.task.then
|
||||
import org.jackhuang.hmcl.util.*
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
class ForgeInstallTask(private val dependencyManager: DefaultDependencyManager,
|
||||
private val gameVersion: String,
|
||||
|
@ -19,12 +19,12 @@ package org.jackhuang.hmcl.mod
|
||||
|
||||
import com.google.gson.JsonParseException
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile
|
||||
import org.jackhuang.hmcl.util.GSON
|
||||
import org.jackhuang.hmcl.util.parseParams
|
||||
import org.jackhuang.hmcl.util.readFullyAsString
|
||||
import org.jackhuang.hmcl.util.typeOf
|
||||
import java.io.File
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
class ForgeModMetadata @JvmOverloads internal constructor(
|
||||
@SerializedName("modid")
|
||||
|
@ -18,17 +18,16 @@
|
||||
package org.jackhuang.hmcl.mod
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile
|
||||
import org.jackhuang.hmcl.download.DefaultDependencyManager
|
||||
import org.jackhuang.hmcl.download.game.VersionJSONSaveTask
|
||||
import org.jackhuang.hmcl.game.Library
|
||||
import org.jackhuang.hmcl.game.Version
|
||||
import org.jackhuang.hmcl.task.Task
|
||||
import org.jackhuang.hmcl.util.*
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
class InstancePatch @JvmOverloads constructor(
|
||||
val name: String = "",
|
||||
@ -221,7 +220,7 @@ class MMCModpackInstallTask(private val dependencyManager: DefaultDependencyMana
|
||||
unzipSubDirectory(zipFile, run, "minecraft/", false)
|
||||
|
||||
ZipFile(zipFile).use { zip ->
|
||||
for (entry in zip.entries()) {
|
||||
for (entry in zip.entries) {
|
||||
// ensure that this entry is in folder 'patches' and is a json file.
|
||||
if (!entry.isDirectory && entry.name.startsWith("patches/") && entry.name.endsWith(".json")) {
|
||||
val patch = GSON.fromJson<InstancePatch>(zip.getInputStream(entry).readFullyAsString())!!
|
||||
|
@ -17,12 +17,12 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.util
|
||||
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipFile
|
||||
import java.util.zip.ZipInputStream
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
/**
|
||||
* Compress the given directory to a zip file.
|
||||
@ -35,7 +35,7 @@ import java.util.zip.ZipOutputStream
|
||||
@JvmOverloads
|
||||
@Throws(IOException::class)
|
||||
fun zip(src: File, destZip: File, pathNameCallback: ((String, Boolean) -> String?)? = null) {
|
||||
ZipOutputStream(destZip.outputStream()).use { zos ->
|
||||
ZipArchiveOutputStream(destZip.outputStream()).use { zos ->
|
||||
val basePath: String
|
||||
if (src.isDirectory)
|
||||
basePath = src.path
|
||||
@ -43,7 +43,7 @@ fun zip(src: File, destZip: File, pathNameCallback: ((String, Boolean) -> String
|
||||
//直接压缩单个文件时,取父目录
|
||||
basePath = src.parent
|
||||
zipFile(src, basePath, zos, pathNameCallback)
|
||||
zos.closeEntry()
|
||||
zos.closeArchiveEntry()
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ fun zip(src: File, destZip: File, pathNameCallback: ((String, Boolean) -> String
|
||||
@Throws(IOException::class)
|
||||
private fun zipFile(src: File,
|
||||
basePath: String,
|
||||
zos: ZipOutputStream,
|
||||
zos: ZipArchiveOutputStream,
|
||||
pathNameCallback: ((String, Boolean) -> String?)?) {
|
||||
val files: Array<File>
|
||||
if (src.isDirectory)
|
||||
@ -75,7 +75,7 @@ private fun zipFile(src: File,
|
||||
pathName = pathNameCallback.invoke(pathName, true)
|
||||
if (pathName == null)
|
||||
continue
|
||||
zos.putNextEntry(ZipEntry(pathName))
|
||||
zos.putArchiveEntry(ZipArchiveEntry(pathName))
|
||||
zipFile(file, basePath, zos, pathNameCallback)
|
||||
} else {
|
||||
pathName = file.path.substring(basePath.length + 1)
|
||||
@ -84,7 +84,7 @@ private fun zipFile(src: File,
|
||||
if (pathName == null)
|
||||
continue
|
||||
file.inputStream().use { inputStream ->
|
||||
zos.putNextEntry(ZipEntry(pathName))
|
||||
zos.putArchiveEntry(ZipArchiveEntry(pathName))
|
||||
inputStream.copyTo(zos, buf)
|
||||
}
|
||||
}
|
||||
@ -102,17 +102,13 @@ private fun zipFile(src: File,
|
||||
fun unzip(zip: File, dest: File, callback: ((String) -> Boolean)? = null, ignoreExistsFile: Boolean = true) {
|
||||
val buf = ByteArray(1024)
|
||||
dest.mkdirs()
|
||||
ZipInputStream(zip.inputStream()).use { zipFile ->
|
||||
ZipArchiveInputStream(zip.inputStream()).use { zipFile ->
|
||||
if (zip.exists()) {
|
||||
var gbkPath: String
|
||||
var strtemp: String
|
||||
val strPath = dest.absolutePath
|
||||
var zipEnt: ZipEntry?
|
||||
while (true) {
|
||||
zipEnt = zipFile.nextEntry
|
||||
if (zipEnt == null)
|
||||
break
|
||||
gbkPath = zipEnt.name
|
||||
val zipEnt = zipFile.nextEntry ?: break
|
||||
var strtemp: String
|
||||
var gbkPath = zipEnt.name
|
||||
if (callback != null)
|
||||
if (!callback.invoke(gbkPath))
|
||||
continue
|
||||
@ -126,7 +122,7 @@ fun unzip(zip: File, dest: File, callback: ((String) -> Boolean)? = null, ignore
|
||||
strtemp = strPath + File.separator + gbkPath
|
||||
//建目录
|
||||
val strsubdir = gbkPath
|
||||
for (i in 0..strsubdir.length - 1)
|
||||
for (i in 0 until strsubdir.length)
|
||||
if (strsubdir.substring(i, i + 1).equals("/", ignoreCase = true)) {
|
||||
val temp = strPath + File.separator + strsubdir.substring(0, i)
|
||||
val subdir = File(temp)
|
||||
@ -157,16 +153,13 @@ fun unzip(zip: File, dest: File, callback: ((String) -> Boolean)? = null, ignore
|
||||
fun unzipSubDirectory(zip: File, dest: File, subDirectory: String, ignoreExistentFile: Boolean = true) {
|
||||
val buf = ByteArray(1024)
|
||||
dest.mkdirs()
|
||||
ZipInputStream(zip.inputStream()).use { zipFile ->
|
||||
ZipArchiveInputStream(zip.inputStream()).use { zipFile ->
|
||||
if (zip.exists()) {
|
||||
var gbkPath: String
|
||||
var strtemp: String
|
||||
val strPath = dest.absolutePath
|
||||
var zipEnt: ZipEntry?
|
||||
while (true) {
|
||||
zipEnt = zipFile.nextEntry
|
||||
if (zipEnt == null)
|
||||
break
|
||||
val zipEnt = zipFile.nextEntry ?: break
|
||||
var strtemp: String
|
||||
var gbkPath: String
|
||||
gbkPath = zipEnt.name
|
||||
if (!gbkPath.startsWith(subDirectory))
|
||||
continue
|
||||
|
@ -60,6 +60,7 @@ allprojects {
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
|
||||
compile "com.google.code.gson:gson:2.8.1"
|
||||
compile "org.apache.commons:commons-compress:1.8.1"
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user