mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-07-01 12:57:24 +00:00
initial: 基本完成的首个版本, 还需要调整一下.
暂时按照当初的计划实现了一个可用版本出来, 发布与否晚些再确定.
This commit is contained in:
55
scalabot-app/src/main/kotlin/util/Utils.kt
Normal file
55
scalabot-app/src/main/kotlin/util/Utils.kt
Normal file
@ -0,0 +1,55 @@
|
||||
package net.lamgc.scalabot.util
|
||||
|
||||
import org.eclipse.aether.artifact.Artifact
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
import java.io.FilenameFilter
|
||||
|
||||
internal fun ByteArray.toHaxString(): String = ByteUtils.bytesToHexString(this)
|
||||
|
||||
internal fun Artifact.equalsArtifact(that: Artifact): Boolean =
|
||||
this.groupId.equals(that.groupId) &&
|
||||
this.artifactId.equals(that.artifactId) &&
|
||||
this.version.equals(that.version) &&
|
||||
this.baseVersion.equals(that.baseVersion) &&
|
||||
this.isSnapshot == that.isSnapshot &&
|
||||
this.classifier.equals(that.classifier) &&
|
||||
this.extension.equals(that.extension) &&
|
||||
(if (this.file == null) that.file == null else this.file.equals(that.file)) &&
|
||||
this.properties.equals(that.properties)
|
||||
|
||||
internal fun File.deepListFiles(
|
||||
addSelf: Boolean = false,
|
||||
onlyFile: Boolean = false,
|
||||
fileFilter: FileFilter? = null,
|
||||
filenameFilter: FilenameFilter? = null
|
||||
): Array<File>? {
|
||||
val files = if (fileFilter != null) {
|
||||
this.listFiles(fileFilter)
|
||||
} else if (filenameFilter != null) {
|
||||
this.listFiles(filenameFilter)
|
||||
} else {
|
||||
this.listFiles()
|
||||
}
|
||||
|
||||
if (files == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
val result = if (addSelf) mutableSetOf(this) else mutableSetOf()
|
||||
for (file in files) {
|
||||
if (file.isFile) {
|
||||
result.add(file)
|
||||
} else {
|
||||
if (!onlyFile) {
|
||||
result.add(file)
|
||||
}
|
||||
val subFiles = file.deepListFiles(false, onlyFile, fileFilter, filenameFilter)
|
||||
if (subFiles != null) {
|
||||
result.addAll(subFiles)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toTypedArray()
|
||||
}
|
||||
|
Reference in New Issue
Block a user