Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ dependencies {
api(libs.morphe.patcher)
implementation(libs.arsclib)
implementation(libs.morphe.library)
implementation(libs.jadb) {
exclude(group = "org.mockito")
}
implementation(libs.picocli)

// -- Bootstrap (Code Generation) ---------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ picocli = "4.7.7"
arsclib = "9b742c412d"
morphe-patcher = "1.15.1-dev.6"
morphe-library = "1.4.0"
jadb = "1.2.3"

# Compose Desktop
compose = "1.12.1"
Expand Down Expand Up @@ -53,7 +52,6 @@ junit-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref
picocli = { module = "info.picocli:picocli", version.ref = "picocli" }
morphe-patcher = { module = "app.morphe:morphe-patcher", version.ref = "morphe-patcher" }
morphe-library = { module = "app.morphe:morphe-library-jvm", version.ref = "morphe-library" }
jadb = { module = "app.morphe:jadb", version.ref = "jadb" }

# Ktor Client
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
Expand Down
54 changes: 0 additions & 54 deletions src/main/kotlin/app/morphe/desktop/command/CliHttpClient.kt

This file was deleted.

111 changes: 4 additions & 107 deletions src/main/kotlin/app/morphe/desktop/command/CommandUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,119 +5,16 @@

package app.morphe.desktop.command

import app.morphe.engine.patches.RemotePatchSourceFactory
import java.io.File
import picocli.CommandLine
import picocli.CommandLine.Model.CommandSpec
import java.io.File

internal fun checkFileExistsOrIsUrl(files: Set<File>, spec: CommandSpec) : Set<File> {
internal fun checkFileExistsOrIsUrl(files: Set<File>, spec: CommandSpec): Set<File> {
files.firstOrNull {
!it.exists() && !it.invariantSeparatorsPath.let { url ->
url.startsWith("http:/") || url.startsWith("https:/")
}
!it.exists() && RemotePatchSourceFactory.parse(it.invariantSeparatorsPath) == null
}?.let {
throw CommandLine.ParameterException(spec.commandLine(), "${it.name} can not be found")
}
return files
}

class OptionKeyConverter : CommandLine.ITypeConverter<String> {
override fun convert(value: String): String = value
}

class OptionValueConverter : CommandLine.ITypeConverter<Any?> {
override fun convert(value: String?): Any? {
value ?: return null

return when {
value.startsWith("[") && value.endsWith("]") -> {
val innerValue = value.substring(1, value.length - 1)

buildList {
var nestLevel = 0
var insideQuote = false
var escaped = false

val item = buildString {
for (char in innerValue) {
when (char) {
'\\' -> {
if (escaped || nestLevel != 0) {
append(char)
}

escaped = !escaped
}

'"', '\'' -> {
if (!escaped) {
insideQuote = !insideQuote
} else {
escaped = false
}

append(char)
}

'[' -> {
if (!insideQuote) {
nestLevel++
}

append(char)
}

']' -> {
if (!insideQuote) {
nestLevel--

if (nestLevel == -1) {
return value
}
}

append(char)
}

',' -> if (nestLevel == 0) {
if (insideQuote) {
append(char)
} else {
add(convert(toString()))
setLength(0)
}
} else {
append(char)
}

else -> append(char)
}
}
}

if (item.isNotEmpty()) {
add(convert(item))
}
}
}

value.startsWith("\"") && value.endsWith("\"") -> value.substring(1, value.length - 1)
value.startsWith("'") && value.endsWith("'") -> value.substring(1, value.length - 1)
value.endsWith("f") -> value.dropLast(1).toFloat()
value.endsWith("L") -> value.dropLast(1).toLong()
value.equals("true", ignoreCase = true) -> true
value.equals("false", ignoreCase = true) -> false
value.toIntOrNull() != null -> value.toInt()
value.toLongOrNull() != null -> value.toLong()
value.toDoubleOrNull() != null -> value.toDouble()
value.toFloatOrNull() != null -> value.toFloat()
value == "null" -> null
value == "int[]" -> emptyList<Int>()
value == "long[]" -> emptyList<Long>()
value == "double[]" -> emptyList<Double>()
value == "float[]" -> emptyList<Float>()
value == "boolean[]" -> emptyList<Boolean>()
value == "string[]" -> emptyList<String>()
else -> value
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

package app.morphe.desktop.command

import app.morphe.desktop.command.CliHttpClient
import app.morphe.engine.VersionMap
import app.morphe.engine.mostCommonCompatibleVersions
import app.morphe.engine.versionCodesFor
import app.morphe.patcher.patch.loadPatchesFromJar
import app.morphe.engine.patches.PatchBundleLoader
import app.morphe.engine.patches.PatchResolver
import app.morphe.engine.patches.SupportedAppCatalog
import app.morphe.engine.patches.VersionMap
import app.morphe.engine.patches.versionCodesFor
import java.io.File
import java.util.logging.Logger
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.Help.Visibility.ALWAYS
import picocli.CommandLine.Model.CommandSpec
import picocli.CommandLine.Option
import picocli.CommandLine.Spec
import java.io.File
import java.util.logging.Logger

@Command(
name = "list-versions",
Expand Down Expand Up @@ -73,10 +73,9 @@ internal class ListCompatibleVersions : Runnable {

override fun run() {
try {
patchesFiles = PatchFileResolver.resolve(
patchesFiles = PatchResolver.resolveCliFiles(
patchesFiles,
prerelease,
CliHttpClient.instance
)
} catch (e: IllegalArgumentException) {
throw CommandLine.ParameterException(
Expand All @@ -85,7 +84,7 @@ internal class ListCompatibleVersions : Runnable {
)
}

val patches = loadPatchesFromJar(patchesFiles)
val patches = PatchBundleLoader.loadFlat(patchesFiles)

fun getVersionCodesString(pkgName: String, versionName: String): String {
return patches.versionCodesFor(pkgName, versionName)?.let { codes ->
Expand All @@ -112,10 +111,11 @@ internal class ListCompatibleVersions : Runnable {
appendLine(versions.buildVersionsString(name).prependIndent("\t"))
}

patches.mostCommonCompatibleVersions(
packageNames,
countUnusedPatches,
includeExperimental,
SupportedAppCatalog.getCompatibilityMap(
packageNames = packageNames,
countUnusedPatches = countUnusedPatches,
includeExperimental = includeExperimental,
patches = patches,
).entries.joinToString("\n", transform = ::buildString).let(logger::info)
}
}
37 changes: 15 additions & 22 deletions src/main/kotlin/app/morphe/desktop/command/ListPatchesCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@

package app.morphe.desktop.command

import app.morphe.desktop.command.CliHttpClient
import app.morphe.engine.compatibleVersionsForDisplay
import app.morphe.engine.isCompatibleWith
import app.morphe.engine.versionCodesFor
import app.morphe.engine.patches.compatibleVersionsForDisplay
import app.morphe.engine.patches.isCompatibleWith
import app.morphe.engine.patches.versionCodesFor
import app.morphe.engine.patches.PatchResolver
import app.morphe.engine.patches.PatchBundleLoader
import app.morphe.patcher.patch.Option as PatchOption
import app.morphe.patcher.patch.Patch
import app.morphe.patcher.patch.loadPatchesFromJar
import java.io.File
import java.util.logging.Logger
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.Option
import picocli.CommandLine.Spec
import picocli.CommandLine.Model.CommandSpec
import picocli.CommandLine.Help.Visibility.ALWAYS
import java.io.File
import java.util.logging.Logger
import app.morphe.patcher.patch.Option as PatchOption

@Command(
name = "list-patches",
Expand Down Expand Up @@ -193,19 +193,10 @@ internal object ListPatchesCommand : Runnable {
}
}

fun Patch<*>.filterCompatiblePackages(name: String) =
isCompatibleWith(
packageName = name,
includeExperimental = includeExperimental,
includeUniversalPatches = withUniversalPatches,
)


try {
patchesFiles = PatchFileResolver.resolve(
patchesFiles = PatchResolver.resolveCliFiles(
patchesFiles,
prerelease,
CliHttpClient.instance
)
} catch (e: IllegalArgumentException) {
throw CommandLine.ParameterException(
Expand All @@ -214,12 +205,14 @@ internal object ListPatchesCommand : Runnable {
)
}

val patches = loadPatchesFromJar(patchesFiles).withIndex().toList()
val patches = PatchBundleLoader.loadFlat(patchesFiles).withIndex().toList()

val filtered = packageName?.let {
val filtered = packageName?.let { name ->
patches.filter { (_, patch) ->
patch.filterCompatiblePackages(
it
patch.isCompatibleWith(
packageName = name,
includeExperimental = includeExperimental,
includeUniversalPatches = withUniversalPatches,
)
}
} ?: patches
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/app/morphe/desktop/command/MainCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
package app.morphe.desktop.command

import app.morphe.desktop.command.utility.UtilityCommand
import app.morphe.engine.workspace.WorkspaceManager
import app.morphe.library.logging.Logger
import java.util.Properties
import kotlin.system.exitProcess
import org.jetbrains.annotations.VisibleForTesting
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.IVersionProvider
import java.util.Properties
import kotlin.system.exitProcess

fun desktopMain(args: Array<String>) {
Logger.setDefault()
runCatching { WorkspaceManager.reapStaleWorkspaces() }
val exitCode = CommandLine(MainCommand).execute(*args)
exitProcess(exitCode)
}
Expand Down
Loading
Loading