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 { allprojects {
group = "xyz.nulldev.ts" group = "ir.armor.tachidesk"
version = "1.0" version = "1.0"
repositories { repositories {
jcenter() jcenter()
mavenCentral() mavenCentral()
maven("https://maven.google.com/")
maven("https://jitpack.io") maven("https://jitpack.io")
maven("https://oss.sonatype.org/content/repositories/snapshots/") maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://dl.bintray.com/inorichi/maven") 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 { fun installExtension(pkgName: String): Int {
logger.debug("Installing $pkgName") logger.debug("Installing $pkgName")
val extensionRecord = extensionTableAsDataClass().first { it.pkgName == pkgName } val extensionRecord = extensionTableAsDataClass().first { it.pkgName == pkgName }
@ -101,9 +107,7 @@ fun installExtension(pkgName: String): Int {
File(dexFilePath).delete() File(dexFilePath).delete()
// update sources of the extension // update sources of the extension
val child = URLClassLoader(arrayOf<URL>(URL("file:$jarFilePath")), this::class.java.classLoader) val instance = loadExtension(jarFilePath,className)
val classToLoad = Class.forName(className, true, child)
val instance = classToLoad.newInstance()
val extensionId = transaction { val extensionId = transaction {
return@transaction ExtensionTable.select { ExtensionTable.name eq extensionRecord.name }.first()[ExtensionTable.id] 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.select
import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
import java.net.URL
import java.net.URLClassLoader
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
private val logger = KotlinLogging.logger {} private val logger = KotlinLogging.logger {}
private val sourceCache = ConcurrentHashMap<Long, HttpSource>() private val sourceCache = ConcurrentHashMap<Long, HttpSource>()
fun getHttpSource(sourceId: Long): HttpSource { fun getHttpSource(sourceId: Long): HttpSource {
val cachedResult: HttpSource? = sourceCache[sourceId] val cachedResult: HttpSource? = sourceCache[sourceId]
if (cachedResult != null) { if (cachedResult != null) {
@ -42,12 +41,7 @@ fun getHttpSource(sourceId: Long): HttpSource {
val jarName = apkName.substringBefore(".apk") + ".jar" val jarName = apkName.substringBefore(".apk") + ".jar"
val jarPath = "${applicationDirs.extensionsRoot}/$jarName" val jarPath = "${applicationDirs.extensionsRoot}/$jarName"
val extensionInstance = val extensionInstance = loadExtension(jarPath,className)
{
val child = URLClassLoader(arrayOf<URL>(URL("file:$jarPath")), this::class.java.classLoader)
val classToLoad = Class.forName(className, true, child)
classToLoad.getDeclaredConstructor().newInstance()
}
if (sourceRecord[SourceTable.partOfFactorySource]) { if (sourceRecord[SourceTable.partOfFactorySource]) {
(extensionInstance as SourceFactory).createSources().forEach{ (extensionInstance as SourceFactory).createSources().forEach{

View File

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