commit 06/10/2025
This commit is contained in:
@@ -2,11 +2,13 @@ package codes
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import content.Language
|
||||
import content.ScheduleDay
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.tinylog.Logger
|
||||
import oshi.SystemInfo
|
||||
import oshi.hardware.CentralProcessor
|
||||
import oshi.hardware.GlobalMemory
|
||||
@@ -22,8 +24,18 @@ import kotlin.io.path.name
|
||||
class Somecodes {
|
||||
companion object {
|
||||
val current_directory : String = System.getProperty("user.dir")
|
||||
val Soundbank_directory : Path = Path.of(current_directory,"Soundbank")
|
||||
val Soundbank_Languages_directory : List<Path> = listOf(
|
||||
Soundbank_directory.resolve(Language.INDONESIA.name),
|
||||
Soundbank_directory.resolve(Language.LOCAL.name),
|
||||
Soundbank_directory.resolve(Language.ENGLISH.name),
|
||||
Soundbank_directory.resolve(Language.CHINESE.name),
|
||||
Soundbank_directory.resolve(Language.JAPANESE.name),
|
||||
Soundbank_directory.resolve(Language.ARABIC.name)
|
||||
)
|
||||
val SoundbankResult_directory : Path = Path.of(current_directory,"SoundbankResult")
|
||||
val PagingResult_directory : Path = Path.of(current_directory,"PagingResult")
|
||||
|
||||
val si = SystemInfo()
|
||||
val processor: CentralProcessor = si.hardware.processor
|
||||
val memory : GlobalMemory = si.hardware.memory
|
||||
@@ -42,6 +54,39 @@ class Somecodes {
|
||||
// regex for getting ann_id from Message, which is the number inside []
|
||||
private val ann_id_regex = Regex("\\[(\\d+)]")
|
||||
|
||||
fun ExtractFilesFromClassPath(resourcePath: String, outputDir: Path) {
|
||||
try {
|
||||
val resource = Somecodes::class.java.getResource(resourcePath)
|
||||
if (resource != null) {
|
||||
val uri = resource.toURI()
|
||||
val path = if (uri.scheme == "jar") {
|
||||
val fileSystem = java.nio.file.FileSystems.newFileSystem(uri, emptyMap<String, Any>())
|
||||
fileSystem.getPath(resourcePath)
|
||||
} else {
|
||||
Path.of(uri)
|
||||
}
|
||||
|
||||
Files.walk(path).use { stream ->
|
||||
stream.forEach { sourcePath ->
|
||||
if (Files.isRegularFile(sourcePath)) {
|
||||
val fn = sourcePath.fileName
|
||||
val targetPath = outputDir.resolve(fn)
|
||||
if (Files.isRegularFile(targetPath) && Files.size(targetPath) > 0) {
|
||||
Logger.info { "File $targetPath already exists, skipping extraction." }
|
||||
return@forEach
|
||||
}
|
||||
Files.copy(sourcePath, targetPath)
|
||||
Logger.info { "Extracted ${sourcePath.name} to $targetPath" }
|
||||
return@forEach
|
||||
}
|
||||
}
|
||||
}
|
||||
} else Logger.error { "Resource $resource not found" }
|
||||
} catch (e: Exception) {
|
||||
Logger.error { "Exception while extracting $resourcePath, Message = ${e.message}"}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is a valid number.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user