diff --git a/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt b/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt index d9f107f..a607744 100644 --- a/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt +++ b/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt @@ -10,13 +10,18 @@ import kotlin.time.Duration.Companion.milliseconds object CurseforgeAPI : APIInterface() { override val ratelimit = Ratelimit(ModifoldArgs.args.curseforgeSpeed.milliseconds, true) - const val root = "https://cfproxy.fly.dev/v1" + const val root = "https://api.cfwidget.com" + + private val cache = mutableMapOf() + fun getProjectData(id: Int): CurseforgeProject? { - return try { - getWithoutAuth("$root/mods/$id").data - } catch (ignored: Exception) { - ignored.printStackTrace() - null + return cache.computeIfAbsent(id) { + try { + getWithoutAuth("$root/$id").data + } catch (ignored: Exception) { + ignored.printStackTrace() + null + } } } diff --git a/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt b/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt index e9748e2..f7c0dd1 100644 --- a/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt +++ b/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt @@ -69,6 +69,11 @@ class ModifoldArgsContainer(parser: ArgParser) { help = "Limits how many files to transfer (recent first), -1 (default) to disable/transfer all" ) { toInt() }.default(-1) + val noModrinth by parser.flagging( + "--no-modrinth", + help = "Disables all functionality related to modrinth" + ) + // // Required args // diff --git a/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/UI.kt b/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/UI.kt index 715e8df..2554953 100644 --- a/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/UI.kt +++ b/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/UI.kt @@ -12,4 +12,14 @@ fun userUnderstandsUsage(): Boolean { """.trimIndent() ) return KInquirer.promptConfirm("I understand this tool should only be used on my own projects") +} + +fun userUnderstandsUsageAlternative(): Boolean { + println( + """ + ONLY USE THIS TOOL ON PROJECTS YOU OWN + I built this for honest users who want to move off curseforge, and not for anyone else, as that has significant legal complications. + """.trimIndent() + ) + return KInquirer.promptConfirm("I understand this tool should only be used on my own projects") } \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 88ce8d4..3ca1b32 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,13 +3,13 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.7.20" + kotlin("jvm") version "1.8.10" id("com.github.johnrengelman.shadow") version "7.1.2" application } group = "com.github.p03w" -version = "2.2.3" +version = "2.2.4" repositories { mavenCentral() @@ -57,13 +57,15 @@ subprojects { implementation(it) } } +} + +allprojects { tasks.withType { kotlinOptions.jvmTarget = "9" } -} - -tasks.withType { - kotlinOptions.jvmTarget = "9" + tasks.withType { + targetCompatibility = "9" + } } application { diff --git a/src/main/kotlin/com/github/p03w/modifold/Main.kt b/src/main/kotlin/com/github/p03w/modifold/Main.kt index 17ce453..2494ec6 100644 --- a/src/main/kotlin/com/github/p03w/modifold/Main.kt +++ b/src/main/kotlin/com/github/p03w/modifold/Main.kt @@ -21,6 +21,12 @@ suspend fun main(args: Array) { } } + if (ModifoldArgs.args.noModrinth) { + noModrinthFlow() + AnsiConsole.systemUninstall() + return + } + if (!ModifoldArgs.args.donts.contains(DONT.MAP_CATEGORIES)) { checkForUnknownCategories(ModrinthAPI.getPossibleCategories().mapTo(mutableSetOf()) {it.name}) } diff --git a/src/main/kotlin/com/github/p03w/modifold/NoModrinthFlow.kt b/src/main/kotlin/com/github/p03w/modifold/NoModrinthFlow.kt new file mode 100644 index 0000000..4a4c242 --- /dev/null +++ b/src/main/kotlin/com/github/p03w/modifold/NoModrinthFlow.kt @@ -0,0 +1,36 @@ +package com.github.p03w.modifold + +import com.github.p03w.modifold.cli.ModifoldArgs +import com.github.p03w.modifold.cli.ModifoldArgsContainer.* +import com.github.p03w.modifold.cli.log +import com.github.p03w.modifold.cli.userUnderstandsUsageAlternative +import com.github.p03w.modifold.core.collectCurseforgeProjects +import com.github.p03w.modifold.core.getFilesToTransfer +import com.github.p03w.modifold.core.getInfoToSaveLocally +import com.github.p03w.modifold.core.transferProjectFiles +import kotlin.system.exitProcess + +fun noModrinthFlow() { + if (!ModifoldArgs.args.donts.contains(DONT.VERIFY_END_USER)) { + if (!userUnderstandsUsageAlternative()) { + println("Quiting") + exitProcess(1) + } + } + + val curseforgeProjects = collectCurseforgeProjects(ModifoldArgs.args.curseforgeIDs) + + if (curseforgeProjects.isEmpty()) { + error("No curseforge projects") + } + + log("Done getting projects") + + val toSave = getInfoToSaveLocally() + val toTransfer = getFilesToTransfer() + + log("Beginning file \"transfer\"") + transferProjectFiles(mutableMapOf(), toSave, toTransfer, true) + + log("Done!") +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/p03w/modifold/core/TransferProjectFiles.kt b/src/main/kotlin/com/github/p03w/modifold/core/TransferProjectFiles.kt index 613d0ec..e5780d6 100644 --- a/src/main/kotlin/com/github/p03w/modifold/core/TransferProjectFiles.kt +++ b/src/main/kotlin/com/github/p03w/modifold/core/TransferProjectFiles.kt @@ -15,7 +15,8 @@ import java.util.* fun transferProjectFiles( mapping: MutableMap, toSave: EnumSet, - toTransfer: FileSet + toTransfer: FileSet, + dummy: Boolean = false ) { fun File.make(): File { mkdirs() @@ -35,57 +36,80 @@ fun transferProjectFiles( } } - val modrinthProject = ModrinthAPI.getProjectInfo(mapping[project]!!.id) + if (!dummy) { + val modrinthProject = ModrinthAPI.getProjectInfo(mapping[project]!!.id) - // Save logo - if (toSave.contains(InformationToSave.IMAGES)) { - debug("Saving ${project.logo.url} as project_icon.png") - val localCopy = File("ModifoldSaved/${project.display()}/images/project_icon.png").make() - Files.copy(URL(project.logo.url).openStream(), localCopy.toPath(), StandardCopyOption.REPLACE_EXISTING) - } + // Save logo + if (toSave.contains(InformationToSave.IMAGES)) { + debug("Saving ${project.logo.url} as project_icon.png") + val localCopy = File("ModifoldSaved/${project.display()}/images/project_icon.png").make() + Files.copy(URL(project.logo.url).openStream(), localCopy.toPath(), StandardCopyOption.REPLACE_EXISTING) + } - // Transfer screenshots - project.screenshots.forEach nextAttach@{ - withSpinner("Transferring ${it.title} to gallery") { spinner -> - if (toSave.contains(InformationToSave.IMAGES)) { - debug("Saving ${it.url} as ${it.title}.${it.getExt()}") - val localCopy = File("ModifoldSaved/${project.display()}/images/${it.title}.${it.getExt()}").make() - Files.copy(URL(it.url).openStream(), localCopy.toPath(), StandardCopyOption.REPLACE_EXISTING) - } - try { - ModrinthAPI.addProjectImage(modrinthProject, it) - } catch (err: Throwable) { - log("Failed to add ${it.title} to gallery! ${err.localizedMessage}".error().toString()) - spinner.fail() + // Transfer screenshots + project.screenshots.forEach nextAttach@{ + withSpinner("Transferring ${it.title} to gallery") { spinner -> + if (toSave.contains(InformationToSave.IMAGES)) { + debug("Saving ${it.url} as ${it.title}.${it.getExt()}") + val localCopy = + File("ModifoldSaved/${project.display()}/images/${it.title}.${it.getExt()}").make() + Files.copy(URL(it.url).openStream(), localCopy.toPath(), StandardCopyOption.REPLACE_EXISTING) + } + try { + ModrinthAPI.addProjectImage(modrinthProject, it) + } catch (err: Throwable) { + log("Failed to add ${it.title} to gallery! ${err.localizedMessage}".error().toString()) + spinner.fail() + } } } - } + files.forEach { file -> + withSpinner("Transferring ${file.fileName}") { spinner -> + val buffered = CurseforgeAPI.getFileStream(file).buffered() - files.forEach { file -> - withSpinner("Transferring ${file.fileName}") { spinner -> - val buffered = CurseforgeAPI.getFileStream(file).buffered() + val stream = if (toSave.contains(InformationToSave.VERSIONS)) { + debug("Saving version to disk") + val localCopy = File("ModifoldSaved/${project.display()}/versions/${file.fileName}").make() + Files.copy(buffered, localCopy.toPath(), StandardCopyOption.REPLACE_EXISTING) + localCopy.inputStream().buffered() + } else { + buffered + } - val stream = if (toSave.contains(InformationToSave.VERSIONS)) { - debug("Saving version to disk") - val localCopy = File("ModifoldSaved/${project.display()}/versions/${file.fileName}").make() - Files.copy(buffered, localCopy.toPath(), StandardCopyOption.REPLACE_EXISTING) - localCopy.inputStream().buffered() - } else { buffered } + try { + ModrinthAPI.makeProjectVersion( + modrinthProject, + file, + stream, + project + ) + } catch (err: Throwable) { + log("Failed to upload ${file.fileName}! ${err.localizedMessage}".error().toString()) + spinner.fail() + } + } + } + println() + } else { + // Save logo + if (toSave.contains(InformationToSave.IMAGES)) { + debug("Saving ${project.logo.url} as project_icon.png") + val localCopy = File("ModifoldSaved/${project.display()}/images/project_icon.png").make() + Files.copy(URL(project.logo.url).openStream(), localCopy.toPath(), StandardCopyOption.REPLACE_EXISTING) + } - try { - ModrinthAPI.makeProjectVersion( - modrinthProject, - file, - stream, - project - ) - } catch (err: Throwable) { - log("Failed to upload ${file.fileName}! ${err.localizedMessage}".error().toString()) - spinner.fail() + // Transfer screenshots + if (toSave.contains(InformationToSave.IMAGES)) { + project.screenshots.forEach { + withSpinner("Saving gallery image ${it.title}") { spinner -> + debug("Saving ${it.url} as ${it.title}.${it.getExt()}") + val localCopy = + File("ModifoldSaved/${project.display()}/images/${it.title}.${it.getExt()}").make() + Files.copy(URL(it.url).openStream(), localCopy.toPath(), StandardCopyOption.REPLACE_EXISTING) + } } } } - println() } } diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt index 6b4d157..0476155 100644 --- a/src/main/resources/version.txt +++ b/src/main/resources/version.txt @@ -1 +1 @@ -2.2.3 \ No newline at end of file +2.2.4 \ No newline at end of file