This commit is contained in:
Aria Moradi 2021-03-30 17:21:41 +04:30
parent 50c2dbed5d
commit 77cf87c989
4 changed files with 11 additions and 13 deletions

View File

@ -6,13 +6,14 @@ plugins {
}
allprojects {
group = "xyz.nulldev.ts"
group = "ir.armor.tachidesk"
version = "1.0"
repositories {
jcenter()
mavenCentral()
maven("https://maven.google.com/")
maven("https://jitpack.io")
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://dl.bintray.com/inorichi/maven")

View File

@ -71,6 +71,12 @@ private fun dex2jar(dexFile: String, jarFile: String, fileNameWithoutType: Strin
}
}
fun loadExtension(jarPath: String, className: String): Any {
val classLoader = URLClassLoader(arrayOf<URL>(URL("file:$jarPath")))
val classToLoad = Class.forName(className, true, classLoader)
return classToLoad.getDeclaredConstructor().newInstance()
}
fun installExtension(pkgName: String): Int {
logger.debug("Installing $pkgName")
val extensionRecord = extensionTableAsDataClass().first { it.pkgName == pkgName }
@ -101,9 +107,7 @@ fun installExtension(pkgName: String): Int {
File(dexFilePath).delete()
// update sources of the extension
val child = URLClassLoader(arrayOf<URL>(URL("file:$jarFilePath")), this::class.java.classLoader)
val classToLoad = Class.forName(className, true, child)
val instance = classToLoad.newInstance()
val instance = loadExtension(jarFilePath,className)
val extensionId = transaction {
return@transaction ExtensionTable.select { ExtensionTable.name eq extensionRecord.name }.first()[ExtensionTable.id]

View File

@ -17,14 +17,13 @@ import mu.KotlinLogging
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import java.net.URL
import java.net.URLClassLoader
import java.util.concurrent.ConcurrentHashMap
private val logger = KotlinLogging.logger {}
private val sourceCache = ConcurrentHashMap<Long, HttpSource>()
fun getHttpSource(sourceId: Long): HttpSource {
val cachedResult: HttpSource? = sourceCache[sourceId]
if (cachedResult != null) {
@ -42,12 +41,7 @@ fun getHttpSource(sourceId: Long): HttpSource {
val jarName = apkName.substringBefore(".apk") + ".jar"
val jarPath = "${applicationDirs.extensionsRoot}/$jarName"
val extensionInstance =
{
val child = URLClassLoader(arrayOf<URL>(URL("file:$jarPath")), this::class.java.classLoader)
val classToLoad = Class.forName(className, true, child)
classToLoad.getDeclaredConstructor().newInstance()
}
val extensionInstance = loadExtension(jarPath,className)
if (sourceRecord[SourceTable.partOfFactorySource]) {
(extensionInstance as SourceFactory).createSources().forEach{

View File

@ -15,5 +15,4 @@ object SourceTable : IdTable<Long>() {
val lang = varchar("lang", 10)
val extension = reference("extension", ExtensionTable)
val partOfFactorySource = bool("part_of_factory_source").default(false)
val positionInFactorySource = integer("position_in_factory_source").nullable()
}