commit 3ce74af20d637c7d9ba69020a2e130d2afded562 Author: 筱傑 <840465812@qq.com> Date: Sun Oct 17 23:43:52 2021 +0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3542e01 --- /dev/null +++ b/.gitignore @@ -0,0 +1,121 @@ +# User-specific stuff +.idea/ + +*.iml +*.ipr +*.iws + +# IntelliJ +out/ +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Cache of project +.gradletasknamecache + +**/build/ + +# Common working directory +run/ + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Local Test Launch point +src/test/kotlin/RunTerminal.kt diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..14e4fd9 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + val kotlinVersion = "1.5.10" + kotlin("jvm") version kotlinVersion + kotlin("plugin.serialization") version kotlinVersion + + id("net.mamoe.mirai-console") version "2.7.0" +} + +group = "me.jie65535" +version = "0.1.0" + +repositories { + maven("https://maven.aliyun.com/repository/public") + mavenCentral() +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..29e08e8 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7454180 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..69a9715 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..744e882 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MSYS* | MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..babf9cc --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "mirai-console-jcf-plugin" \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/CurseClient.kt b/src/main/kotlin/me/jie65535/jcf/CurseClient.kt new file mode 100644 index 0000000..8cc41c5 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/CurseClient.kt @@ -0,0 +1,225 @@ +package me.jie65535.jcf + +import io.ktor.client.* +import io.ktor.client.engine.okhttp.* +import io.ktor.client.features.* +import io.ktor.client.request.* +import io.ktor.http.* +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json +import me.jie65535.jcf.model.addon.* +import me.jie65535.jcf.model.addon.file.* +import me.jie65535.jcf.model.addon.request.* +import me.jie65535.jcf.model.category.* +import me.jie65535.jcf.model.fingerprint.* +import me.jie65535.jcf.model.fingerprint.request.* +import me.jie65535.jcf.model.game.* +import me.jie65535.jcf.model.minecraft.* +import me.jie65535.jcf.model.minecraft.modloader.* +import me.jie65535.jcf.util.Date +import me.jie65535.jcf.util.internal.DateSerializer + +@OptIn(ExperimentalSerializationApi::class) +class CurseClient { + private val json = Json { + isLenient = true + ignoreUnknownKeys = true + serializersModule + } + private val http = HttpClient(OkHttp) { + install(HttpTimeout) { + this.requestTimeoutMillis = 30_0000 + this.connectTimeoutMillis = 30_0000 + this.socketTimeoutMillis = 30_0000 + } + defaultRequest { + url.protocol = URLProtocol.HTTPS + url.host = "addons-ecs.forgesvc.net" + header("accept", "*/*") + } + } + + suspend fun getGames(supportsAddons: Boolean = false): List { + return json.decodeFromString( + http.get("api/v2/game") { + parameter("supportsAddons", supportsAddons.toString()) + } + ) + } + + suspend fun getGame(gameId: Int): Game { + return json.decodeFromString(http.get("api/v2/game/$gameId")) + } + + suspend fun getGameDatabaseTimestamp(): Date { + return json.decodeFromString(http.get("api/v2/game/timestamp")) + } + + suspend fun getAddon(projectId: Int): Addon { + return json.decodeFromString(http.get("api/v2/addon/$projectId")) + } + + suspend fun getAddons(projectIds: Collection): List { + return json.decodeFromString( + http.post("api/v2/addon") { + contentType(ContentType.Application.Json) + body = projectIds + } + ) + } + + suspend fun getAddons(vararg projectIds: Int): List = getAddons(projectIds.toList()) + + suspend fun getAddonDescription(projectId: Int): String { + return json.decodeFromString(http.get("api/v2/addon/$projectId/description")) + } + + suspend fun getAddonFiles(projectId: Int): List { + return json.decodeFromString(http.get("api/v2/addon/$projectId/files")) + } + + suspend fun getAddonFiles(keys: Collection): Map> { + return json.decodeFromString( + http.post("api/v2/addon/files") { + contentType(ContentType.Application.Json) + body = keys + } + ) + } + + suspend fun getAddonFiles(vararg keys: Int): Map> = getAddonFiles(keys.toList()) + + suspend fun getAddonFileDownloadUrl(projectId: Int, fileId: Int): String { + return json.decodeFromString(http.get("api/v2/addon/$projectId/file/$fileId/download-url")) + } + + suspend fun getAddonFile(projectId: Int, fileId: Int): AddonFile { + return json.decodeFromString(http.get("api/v2/addon/$projectId/file/$fileId")) + } + + suspend fun searchAddons( + gameId: Int, + sectionId: Int = -1, + categoryId: Int = -1, + sort: AddonSortMethod = AddonSortMethod.FEATURED, + sortDescending: Boolean = true, + gameVersion: String? = null, + index: Int = 0, + pageSize: Int = 1000, + searchFilter: String? = null + ): List { + return json.decodeFromString( + http.get("api/v2/addon/search") { + parameter("gameId", gameId) + parameter("sectionId", sectionId) + parameter("categoryId", categoryId) + parameter("gameVersion", gameVersion) + parameter("index", index) + parameter("pageSize", pageSize) + parameter("searchFilter", searchFilter) + parameter("sort", sort) + parameter("sortDescending", sortDescending) + } + ) + } + + suspend fun getFeaturedAddons( + gameId: Int, + featuredCount: Int = 6, + popularCount: Int = 14, + updatedCount: Int = 14, + excludedAddons: Collection = listOf() + ): Map> { + return json.decodeFromString( + http.post("api/v2/addon/featured") { + contentType(ContentType.Application.Json) + body = FeaturedAddonsRequest(gameId, featuredCount, popularCount, updatedCount, excludedAddons) + } + ) + } + + suspend fun getFeaturedAddons( + gameId: Int, + featuredCount: Int = 6, + popularCount: Int = 14, + updatedCount: Int = 14, + vararg excludedAddons: Int + ): Map> = getFeaturedAddons(gameId, featuredCount, popularCount, updatedCount, excludedAddons.toList()) + + suspend fun getCategory(categoryId: Int): Category { + return json.decodeFromString(http.get("api/v2/category/$categoryId")) + } + + suspend fun getCategory(slug: String): List { + return json.decodeFromString( + http.get("api/v2/category") { + parameter("slug", slug) + } + ) + } + + suspend fun getCategorySection(sectionId: Int): List { + return json.decodeFromString(http.get("api/v2/category/section/$sectionId")) + } + + suspend fun getCategories(): List { + return json.decodeFromString(http.get("api/v2/category")) + } + + suspend fun getCategoryDatabaseTimestamp(): Date { + return json.decodeFromString(http.get("api/v2/category/timestamp")) + } + + suspend fun getFingerprintMatches(fingerprints: Collection): FingerprintMatchResult { + return json.decodeFromString( + http.post("api/v2/fingerprint") { + contentType(ContentType.Application.Json) + body = fingerprints + } + ) + } + + suspend fun getFingerprintMatches(vararg fingerprints: Long): FingerprintMatchResult = getFingerprintMatches(fingerprints.toList()) + + suspend fun getFuzzyFingerprintMatches(gameId: Int, fingerprints: List): List { + return json.decodeFromString( + http.post("api/v2/fingerprint/fuzzy") { + contentType(ContentType.Application.Json) + body = FuzzyMatchesRequest(gameId, fingerprints) + } + ) + } + + suspend fun getModloader(key: String): ModloaderVersion { + return json.decodeFromString(http.get("api/v2/minecraft/modloader/$key")) + } + + suspend fun getModloaders(): List { + return json.decodeFromString(http.get("api/v2/minecraft/modloader")) + } + + suspend fun getModloaders(gameVersion: String): List { + return json.decodeFromString( + http.get("api/v2/minecraft/modloader") { + parameter("version", gameVersion) + } + ) + } + + suspend fun getModloadersDatabaseTimestamp(): Date { + return json.decodeFromString(http.get("api/v2/minecraft/modloader/timestamp")) + } + + suspend fun getMinecraftVersions(): List { + return json.decodeFromString(http.get("api/v2/minecraft/version")) + } + + suspend fun getMinecraftVersion(gameVersion: String): MinecraftVersion { + return json.decodeFromString(http.get("api/v2/minecraft/version/$gameVersion")) + } + + suspend fun getMinecraftVersionsDatabaseTimestamp(): Date { + return json.decodeFromString(http.get("api/v2/minecraft/version/timestamp")) + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/JCurseforge.kt b/src/main/kotlin/me/jie65535/jcf/JCurseforge.kt new file mode 100644 index 0000000..99ee390 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/JCurseforge.kt @@ -0,0 +1,27 @@ +package me.jie65535.jcf + +import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register +import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregister +import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription +import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin +import net.mamoe.mirai.utils.info + +object JCurseforge : KotlinPlugin( + JvmPluginDescription( + id = "me.jie65535.jcf", + name = "J Curseforge Util", + version = "0.1.0", + ) { + author("jie65535") + info("""Curseforge Util""") + } +) { + override fun onEnable() { + logger.info { "Plugin loaded" } + JcfCommand.register() + } + + override fun onDisable() { + JcfCommand.unregister() + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/JcfCommand.kt b/src/main/kotlin/me/jie65535/jcf/JcfCommand.kt new file mode 100644 index 0000000..d953790 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/JcfCommand.kt @@ -0,0 +1,18 @@ +package me.jie65535.jcf + +import net.mamoe.mirai.console.command.CommandSender +import net.mamoe.mirai.console.command.CompositeCommand + +object JcfCommand : CompositeCommand( + JCurseforge, "jcf", + description = "Curseforge Util" +) { + private val curse = CurseClient() + + @SubCommand + @Description("帮助") + suspend fun CommandSender.help() { + sendMessage(usage) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/Addon.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/Addon.kt new file mode 100644 index 0000000..ecfd19a --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/Addon.kt @@ -0,0 +1,52 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import me.jie65535.jcf.model.addon.file.AddonFile +import me.jie65535.jcf.model.addon.file.AddonFileLatestForGameVersion +import me.jie65535.jcf.model.category.CategorySection +import me.jie65535.jcf.util.Date +import me.jie65535.jcf.util.internal.DateSerializer + +@Serializable +data class Addon( + val id: Int, + val name: String, + val authors: List, + val attachments: List, + val websiteUrl: String, + val gameId: Int, + val summary: String, + val defaultFileId: Int, + val downloadCount: Double, + val latestFiles: List, + val categories: List, + val status: AddonStatus, + val primaryCategoryId: Int, + val categorySection: CategorySection, + val slug: String, + val gameVersionLatestFiles: List, + val isFeatured: Boolean, + val popularityScore: Double, + val gamePopularityRank: Int, + val primaryLanguage: String, + val gameSlug: String, + val gameName: String, + val portalName: String, + @Serializable(with = DateSerializer::class) + val dateModified: Date, + @Serializable(with = DateSerializer::class) + val dateCreated: Date, + @Serializable(with = DateSerializer::class) + val dateReleased: Date, + val isAvailable: Boolean, + @SerialName("isExperiemental") + val isExperimental: Boolean +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/AddonAttachment.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonAttachment.kt new file mode 100644 index 0000000..9606ec9 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonAttachment.kt @@ -0,0 +1,22 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + +import kotlinx.serialization.Serializable + +@Serializable +data class AddonAttachment( + val id: Int, + val projectId: Int, + val description: String, + val isDefault: Boolean, + val thumbnailUrl: String, + val title: String, + val url: String, + val status: AddonAttachmentStatus +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/AddonAttachmentStatus.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonAttachmentStatus.kt new file mode 100644 index 0000000..2a0e5e6 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonAttachmentStatus.kt @@ -0,0 +1,24 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + + +@Serializable(with = AddonAttachmentStatus.Ser::class) +enum class AddonAttachmentStatus { + NORMAL, + DELETED, + UPLOADING, + BANNED, + PENDING_MODERATION; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.addon.AttachmentStatus", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/AddonAuthor.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonAuthor.kt new file mode 100644 index 0000000..32ec933 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonAuthor.kt @@ -0,0 +1,22 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + +import kotlinx.serialization.Serializable + +@Serializable +data class AddonAuthor( + val name: String, + val url: String, + val projectId: Int, + val id: Int, + val projectTitleId: Int?, + val projectTitleTitle: String?, + val userId: Int, + val twitchId: Int? +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/AddonCategory.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonCategory.kt new file mode 100644 index 0000000..4f3ea12 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonCategory.kt @@ -0,0 +1,23 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + +import kotlinx.serialization.Serializable + +@Serializable +data class AddonCategory( + val categoryId: Int, + val name: String, + val url: String, + val avatarUrl: String?, + val parentId: Int?, + val rootId: Int?, + val projectId: Int, + val avatarId: Int?, + val gameId: Int +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/AddonPackageType.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonPackageType.kt new file mode 100644 index 0000000..9f510cb --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonPackageType.kt @@ -0,0 +1,24 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = AddonPackageType.Ser::class) +enum class AddonPackageType { + FOLDER, + CTOC, + SINGLE_FILE, + CMOD2, + MOD_PACK, + MOD; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.addon.AddonPackageType", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/AddonRepositoryMatch.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonRepositoryMatch.kt new file mode 100644 index 0000000..c7b3c86 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonRepositoryMatch.kt @@ -0,0 +1,17 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.model.addon.file.AddonFile + +@Serializable +data class AddonRepositoryMatch( + val id: Int, + val latestFiles: List +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/AddonRestrictFileAccess.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonRestrictFileAccess.kt new file mode 100644 index 0000000..eff9052 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonRestrictFileAccess.kt @@ -0,0 +1,21 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = AddonRestrictFileAccess.Ser::class) +enum class AddonRestrictFileAccess { + NONE, + ALPHA, + ALPHA_AND_BETA; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.addon.AddonRestrictFileAccess", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/AddonSortMethod.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonSortMethod.kt new file mode 100644 index 0000000..8631c2f --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonSortMethod.kt @@ -0,0 +1,20 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + + +enum class AddonSortMethod { + FEATURED, + POPULARITY, + LAST_UPDATED, + NAME, + AUTHOR, + TOTAL_DOWNLOADS, + CATEGORY, + GAME_VERSION +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/AddonStatus.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonStatus.kt new file mode 100644 index 0000000..1cd52dc --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/AddonStatus.kt @@ -0,0 +1,28 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = AddonStatus.Ser::class) +enum class AddonStatus { + NEW, + CHANGES_REQUIRED, + UNDER_SOFT_REVIEW, + APPROVED, + REJECTED, + CHANGES_MADE, + INACTIVE, + ABANDONED, + DELETED, + UNDER_REVIEW; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.addon.AddonStatus", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/FeaturedAddonType.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/FeaturedAddonType.kt new file mode 100644 index 0000000..4db1fcf --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/FeaturedAddonType.kt @@ -0,0 +1,21 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +enum class FeaturedAddonType { + @SerialName("Featured") + FEATURED, + @SerialName("Popular") + POPULAR, + @SerialName("RecentlyUpdated") + RECENTLY_UPDATED; +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/SortableGameVersion.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/SortableGameVersion.kt new file mode 100644 index 0000000..7978fc6 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/SortableGameVersion.kt @@ -0,0 +1,21 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.Date +import me.jie65535.jcf.util.internal.DateSerializer + +@Serializable +data class SortableGameVersion( + val gameVersionPadded: String, + val gameVersion: String, + @Serializable(with = DateSerializer::class) + val gameVersionReleaseDate: Date, + val gameVersionName: String +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFile.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFile.kt new file mode 100644 index 0000000..8d16c88 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFile.kt @@ -0,0 +1,60 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon.file + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.model.addon.AddonPackageType +import me.jie65535.jcf.model.addon.AddonRestrictFileAccess +import me.jie65535.jcf.model.addon.AddonStatus +import me.jie65535.jcf.model.addon.SortableGameVersion +import me.jie65535.jcf.util.Date +import me.jie65535.jcf.util.internal.DateSerializer + +@Serializable +data class AddonFile( + val id: Int, + val displayName: String, + val fileName: String, + @Serializable(with = DateSerializer::class) + val fileDate: Date, + val fileLength: Long, + val releaseType: AddonFileReleaseType, + val fileStatus: AddonFileStatus, + val downloadUrl: String, + val isAlternate: Boolean, + val alternateFileId: Int, + val dependencies: List, + val isAvailable: Boolean, + val modules: List, + val packageFingerprint: Long, + val gameVersion: List, + val sortableGameVersion: List? = null, + val installMetadata: String?, + val changelog: String? = null, + val hasInstallScript: Boolean, + val isCompatibleWithClient: Boolean? = null, + val categorySectionPackageType: AddonPackageType? = null, + val restrictProjectFileAccess: AddonRestrictFileAccess? = null, + val projectStatus: AddonStatus? = null, + val renderCacheId: Int? = null, + val fileLegacyMappingId: Int? = null, + val projectId: Int? = null, + val parentProjectFileId: Int? = null, + val parentFileLegacyMappingId: Int? = null, + val fileTypeId: Int? = null, + val exposeAsAlternative: Boolean? = null, + val packageFingerprintId: Int? = null, + @Serializable(with = DateSerializer::class) + val gameVersionDateReleased: Date?, + val gameVersionMappingId: Int? = null, + val gameVersionId: Int? = null, + val gameId: Int? = null, + val isServerPack: Boolean = false, + val serverPackFileId: Int?, + val gameVersionFlavor: String? +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileDependency.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileDependency.kt new file mode 100644 index 0000000..e5b1751 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileDependency.kt @@ -0,0 +1,18 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon.file + +import kotlinx.serialization.Serializable + +@Serializable +data class AddonFileDependency( + val id: Int? = null, + val addonId: Int, + val type: AddonFileRelationType, + val fileId: Int? = null +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileFingerprintType.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileFingerprintType.kt new file mode 100644 index 0000000..391c18a --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileFingerprintType.kt @@ -0,0 +1,23 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon.file + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = AddonFileFingerprintType.Ser::class) +enum class AddonFileFingerprintType { + PACKAGE, + MODULE, + MAIN_MODULE, + FILE, + REFERRENCED_FILE; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.addon.file.AddonFileFingerprintType", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileLatestForGameVersion.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileLatestForGameVersion.kt new file mode 100644 index 0000000..14b2d3b --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileLatestForGameVersion.kt @@ -0,0 +1,19 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon.file + +import kotlinx.serialization.Serializable + +@Serializable +data class AddonFileLatestForGameVersion( + val gameVersion: String, + val projectFileId: Int, + val projectFileName: String, + val fileType: AddonFileReleaseType, + val gameVersionFlavor: String? +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileModule.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileModule.kt new file mode 100644 index 0000000..5a2f650 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileModule.kt @@ -0,0 +1,19 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon.file + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class AddonFileModule( + @SerialName("foldername") + val folderName: String, + val fingerprint: Long, + val type: AddonFileFingerprintType? = null +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileRelationType.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileRelationType.kt new file mode 100644 index 0000000..ef0cdc2 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileRelationType.kt @@ -0,0 +1,24 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon.file + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = AddonFileRelationType.Ser::class) +enum class AddonFileRelationType { + EMBEDDED_LIBRARY, + OPTIONAL_DEPENDENCY, + REQUIRED_DEPENDENCY, + TOOL, + INCOMPATIBLE, + INCLUDE; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.addon.file.AddonFileRelationType", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileReleaseType.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileReleaseType.kt new file mode 100644 index 0000000..672f61c --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileReleaseType.kt @@ -0,0 +1,21 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon.file + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = AddonFileReleaseType.Ser::class) +enum class AddonFileReleaseType { + RELEASE, + BETA, + ALPHA; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.addon.file.AddonFileReleaseType", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileStatus.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileStatus.kt new file mode 100644 index 0000000..7f5e5a8 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/file/AddonFileStatus.kt @@ -0,0 +1,33 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.addon.file + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = AddonFileStatus.Ser::class) +enum class AddonFileStatus { + PROCESSING, + CHANGES_REQUIRED, + UNDER_REVIEW, + APPROVED, + REJECTED, + MALWARE_DETECTED, + DELETED, + ARCHIVED, + TESTING, + RELEASED, + READY_FOR_REVIEW, + DEPRECATED, + BAKING, + AWAITING_FOR_PUBLISHING, + FAILED_PUBLISHING; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.addon.file.AddonFileStatus", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/addon/request/FeaturedAddonsRequest.kt b/src/main/kotlin/me/jie65535/jcf/model/addon/request/FeaturedAddonsRequest.kt new file mode 100644 index 0000000..3d5d2d9 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/addon/request/FeaturedAddonsRequest.kt @@ -0,0 +1,18 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ +package me.jie65535.jcf.model.addon.request + +import kotlinx.serialization.Serializable + +@Serializable +data class FeaturedAddonsRequest( + val gameId: Int, + val featuredCount: Int, + val popularCount: Int, + val updatedCount: Int, + val excludedAddons: Collection +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/category/Category.kt b/src/main/kotlin/me/jie65535/jcf/model/category/Category.kt new file mode 100644 index 0000000..6bb3523 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/category/Category.kt @@ -0,0 +1,25 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.category + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.Date +import me.jie65535.jcf.util.internal.DateSerializer + +@Serializable +data class Category( + val id: Int, + val name: String, + val slug: String, + val avatarUrl: String?, + @Serializable(with = DateSerializer::class) + val dateModified: Date, + val parentGameCategoryId: Int?, + val rootGameCategoryId: Int?, + val gameId: Int +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/category/CategorySection.kt b/src/main/kotlin/me/jie65535/jcf/model/category/CategorySection.kt new file mode 100644 index 0000000..ea71732 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/category/CategorySection.kt @@ -0,0 +1,23 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.category + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.model.addon.AddonPackageType + +@Serializable +data class CategorySection( + val extraIncludePattern: String?, + val gameCategoryId: Int, + val gameId: Int, + val id: Int, + val initialInclusionPattern: String, + val name: String, + val packageType: AddonPackageType, + val path: String +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FingerprintMatch.kt b/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FingerprintMatch.kt new file mode 100644 index 0000000..d594d6a --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FingerprintMatch.kt @@ -0,0 +1,18 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.fingerprint + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.model.addon.file.AddonFile + +@Serializable +data class FingerprintMatch( + val id: Int, + val file: AddonFile, + val latestFiles: List +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FingerprintMatchResult.kt b/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FingerprintMatchResult.kt new file mode 100644 index 0000000..600bf81 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FingerprintMatchResult.kt @@ -0,0 +1,21 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.fingerprint + +import kotlinx.serialization.Serializable + +@Serializable +data class FingerprintMatchResult( + val isCacheBuilt: Boolean, + val exactMatches: List, + val exactFingerprints: List, + val partialMatches: List, + val partialMatchFingerprints: Map>, + val installedFingerprints: List, + val unmatchedFingerprints: List +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FolderFingerprint.kt b/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FolderFingerprint.kt new file mode 100644 index 0000000..8950f12 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FolderFingerprint.kt @@ -0,0 +1,18 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.fingerprint + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class FolderFingerprint( + @SerialName("foldername") + val folderName: String, + val fingerprints: List +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FuzzyFingerprintMatch.kt b/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FuzzyFingerprintMatch.kt new file mode 100644 index 0000000..cb08808 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/fingerprint/FuzzyFingerprintMatch.kt @@ -0,0 +1,19 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.fingerprint + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.model.addon.file.AddonFile + +@Serializable +data class FuzzyFingerprintMatch( + val id: Int, + val file: AddonFile, + val latestFiles: List, + val fingerprints: List +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/fingerprint/request/FuzzyMatchesRequest.kt b/src/main/kotlin/me/jie65535/jcf/model/fingerprint/request/FuzzyMatchesRequest.kt new file mode 100644 index 0000000..0832a35 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/fingerprint/request/FuzzyMatchesRequest.kt @@ -0,0 +1,17 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.fingerprint.request + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.model.fingerprint.FolderFingerprint + +@Serializable +data class FuzzyMatchesRequest( + val gameId: Int, + val fingerprints: List +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/game/Game.kt b/src/main/kotlin/me/jie65535/jcf/model/game/Game.kt new file mode 100644 index 0000000..e34be44 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/game/Game.kt @@ -0,0 +1,41 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.game + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.model.category.CategorySection +import me.jie65535.jcf.util.Date +import me.jie65535.jcf.util.internal.DateSerializer + +@Serializable +data class Game( + val id: Int, + val name: String, + val slug: String, + @Serializable(with = DateSerializer::class) + val dateModified: Date, + val gameFiles: List, + val gameDetectionHints: List, + val fileParsingRules: List, + val categorySections: List, + val maxFreeStorage: Long, + val maxPremiumStorage: Long, + val maxFileSize: Long, + val addonSettingsFolderFilter: String?, + val addonSettingsStartingFolder: String?, + val addonSettingsFileFilter: String?, + val addonSettingsFileRemovalFilter: String?, + val supportsAddons: Boolean, + val supportsPartnerAddons: Boolean, + @Serializable(with = SupportedClientConfiguration.Ser::class) + val supportedClientConfiguration: Set, + val supportsNotifications: Boolean, + val profilerAddonId: Int, + val twitchGameId: Int, + val clientGameSettingsId: Int +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/game/GameDetectionHint.kt b/src/main/kotlin/me/jie65535/jcf/model/game/GameDetectionHint.kt new file mode 100644 index 0000000..ef7b284 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/game/GameDetectionHint.kt @@ -0,0 +1,21 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.game + +import kotlinx.serialization.Serializable + +@Serializable +data class GameDetectionHint( + val id: Int, + val hintType: GameDetectionHintType, + val hintPath: String, + val hintKey: String?, + @Serializable(with = GameDetectionHintOption.Ser::class) + val hintOptions: Set, + val gameId: Int +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/game/GameDetectionHintOption.kt b/src/main/kotlin/me/jie65535/jcf/model/game/GameDetectionHintOption.kt new file mode 100644 index 0000000..9b12174 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/game/GameDetectionHintOption.kt @@ -0,0 +1,19 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.game + +import me.jie65535.jcf.util.internal.FlagSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +enum class GameDetectionHintOption { + NONE, + INCLUDE_SUB_FOLDERS, + FOLDER_ONLY; + + internal object Ser : FlagSerializer("$MODEL_PACKAGE.game.GameDetectionHintOption", NONE to 0x1, INCLUDE_SUB_FOLDERS to 0x2, FOLDER_ONLY to 0x4) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/game/GameDetectionHintType.kt b/src/main/kotlin/me/jie65535/jcf/model/game/GameDetectionHintType.kt new file mode 100644 index 0000000..0f3b641 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/game/GameDetectionHintType.kt @@ -0,0 +1,21 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + + +package me.jie65535.jcf.model.game + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = GameDetectionHintType.Ser::class) +enum class GameDetectionHintType { + REGISTRY, + FILE_PATH; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.game.GameDetectionHintType", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/game/GameFile.kt b/src/main/kotlin/me/jie65535/jcf/model/game/GameFile.kt new file mode 100644 index 0000000..8227241 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/game/GameFile.kt @@ -0,0 +1,20 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.game + +import kotlinx.serialization.Serializable + +@Serializable +data class GameFile( + val id: Int, + val gameId: Int, + val isRequired: Boolean, + val fileName: String, + val fileType: GameFileType, + val platformType: GamePlatformType +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/game/GameFileParsingRule.kt b/src/main/kotlin/me/jie65535/jcf/model/game/GameFileParsingRule.kt new file mode 100644 index 0000000..0ade2fb --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/game/GameFileParsingRule.kt @@ -0,0 +1,19 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.game + +import kotlinx.serialization.Serializable + +@Serializable +data class GameFileParsingRule( + val commentStripPattern: String, + val fileExtension: String, + val inclusionPattern: String, + val gameId: Int, + val id: Int +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/game/GameFileType.kt b/src/main/kotlin/me/jie65535/jcf/model/game/GameFileType.kt new file mode 100644 index 0000000..b4c3c70 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/game/GameFileType.kt @@ -0,0 +1,22 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.game + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = GameFileType.Ser::class) +enum class GameFileType { + GENERIC, + GAME, + LAUNCHER, + PROFILER_LOCK_CHECK; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.game.GameFileType", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/game/GamePlatformType.kt b/src/main/kotlin/me/jie65535/jcf/model/game/GamePlatformType.kt new file mode 100644 index 0000000..467ef61 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/game/GamePlatformType.kt @@ -0,0 +1,23 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.game + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = GamePlatformType.Ser::class) +enum class GamePlatformType { + GENERIC, + WINDOWS_32, + WINDOWS_64, + WINDOWS, + OSX; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.game.GamePlatformType", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/game/SupportedClientConfiguration.kt b/src/main/kotlin/me/jie65535/jcf/model/game/SupportedClientConfiguration.kt new file mode 100644 index 0000000..80ad84d --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/game/SupportedClientConfiguration.kt @@ -0,0 +1,19 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.game + +import me.jie65535.jcf.util.internal.FlagSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +enum class SupportedClientConfiguration { + DEBUG, + BETA, + RELEASE; + + internal object Ser : FlagSerializer("$MODEL_PACKAGE.game.SupportedClientConfiguration", DEBUG to 0x1, BETA to 0x2, RELEASE to 0x4) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/minecraft/MinecraftVersion.kt b/src/main/kotlin/me/jie65535/jcf/model/minecraft/MinecraftVersion.kt new file mode 100644 index 0000000..f8a3223 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/minecraft/MinecraftVersion.kt @@ -0,0 +1,27 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.minecraft + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.Date +import me.jie65535.jcf.util.internal.DateSerializer + +@Serializable +data class MinecraftVersion( + val id: Int, + val gameVersionId: Int, + val versionString: String, + val jarDownloadUrl: String, + val jsonDownloadUrl: String, + val approved: Boolean, + @Serializable(with = DateSerializer::class) + val dateModified: Date, + val gameVersionTypeId: Int, + val gameVersionStatus: MinecraftVersionStatus, + val gameVersionTypeStatus: MinecraftVersionTypeStatus +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/minecraft/MinecraftVersionStatus.kt b/src/main/kotlin/me/jie65535/jcf/model/minecraft/MinecraftVersionStatus.kt new file mode 100644 index 0000000..a910ad4 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/minecraft/MinecraftVersionStatus.kt @@ -0,0 +1,21 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.minecraft + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = MinecraftVersionStatus.Ser::class) +enum class MinecraftVersionStatus { + APPROVED, + DELETED, + NEW; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.game.MinecraftVersionStatus", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/minecraft/MinecraftVersionTypeStatus.kt b/src/main/kotlin/me/jie65535/jcf/model/minecraft/MinecraftVersionTypeStatus.kt new file mode 100644 index 0000000..7db0e27 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/minecraft/MinecraftVersionTypeStatus.kt @@ -0,0 +1,20 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.minecraft + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = MinecraftVersionTypeStatus.Ser::class) +enum class MinecraftVersionTypeStatus { + NORMAL, + DELETED; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.game.MinecraftVersionTypeStatus", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderIndex.kt b/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderIndex.kt new file mode 100644 index 0000000..d8b5c73 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderIndex.kt @@ -0,0 +1,22 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.minecraft.modloader + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.Date +import me.jie65535.jcf.util.internal.DateSerializer + +@Serializable +data class ModloaderIndex( + val name: String, + val gameVersion: String, + val latest: Boolean, + val recommended: Boolean, + @Serializable(with = DateSerializer::class) + val dateModified: Date +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderInstallMethod.kt b/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderInstallMethod.kt new file mode 100644 index 0000000..668b8c0 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderInstallMethod.kt @@ -0,0 +1,22 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.minecraft.modloader + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = ModloaderInstallMethod.Ser::class) +enum class ModloaderInstallMethod { + ANY, + FORGE, + CAULDRON, + LITE_LOADER; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.game.ModloaderInstallMethod", values()) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderType.kt b/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderType.kt new file mode 100644 index 0000000..0450fbd --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderType.kt @@ -0,0 +1,22 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.minecraft.modloader + +import kotlinx.serialization.Serializable +import me.jie65535.jcf.util.internal.EnumIntSerializer +import me.jie65535.jcf.util.internal.MODEL_PACKAGE + +@Serializable(with = ModloaderType.Ser::class) +enum class ModloaderType { + ANY, + FORGE, + CAULDRON, + LITE_LOADER; + + internal object Ser : EnumIntSerializer("$MODEL_PACKAGE.game.ModloaderType", values(), 0) +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderVersion.kt b/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderVersion.kt new file mode 100644 index 0000000..7359b0f --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/model/minecraft/modloader/ModloaderVersion.kt @@ -0,0 +1,48 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.model.minecraft.modloader + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import me.jie65535.jcf.model.minecraft.MinecraftVersionStatus +import me.jie65535.jcf.model.minecraft.MinecraftVersionTypeStatus +import me.jie65535.jcf.util.Date +import me.jie65535.jcf.util.internal.DateSerializer + +@Serializable +data class ModloaderVersion( + val id: Int, + val gameVersionId: Int, + val minecraftGameVersionId: Int, + val forgeVersion: String, + val name: String, + val type: ModloaderType, + val downloadUrl: String, + @SerialName("filename") + val fileName: String, + val installMethod: ModloaderInstallMethod, + val latest: Boolean, + val recommended: Boolean, + val approved: Boolean, + @Serializable(with = DateSerializer::class) + val dateModified: Date, + val mavenVersionString: String, + val versionJson: String, + val librariesInstallLocation: String, + val minecraftVersion: String, + val additionalFilesJson: String, + val modLoaderGameVersionId: Int, + val modLoaderGameVersionTypeId: Int, + val modLoaderGameVersionStatus: MinecraftVersionStatus, + val modLoaderGameVersionTypeStatus: MinecraftVersionTypeStatus, + val mcGameVersionId: Int, + val mcGameVersionTypeId: Int, + val mcGameVersionStatus: MinecraftVersionStatus, + val mcGameVersionTypeStatus: MinecraftVersionTypeStatus, + val installProfileJson: String +) \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/util/Date.kt b/src/main/kotlin/me/jie65535/jcf/util/Date.kt new file mode 100644 index 0000000..040f193 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/util/Date.kt @@ -0,0 +1,5 @@ +package me.jie65535.jcf.util + +import java.time.OffsetDateTime + +typealias Date = OffsetDateTime \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/util/internal/DateSerializer.kt b/src/main/kotlin/me/jie65535/jcf/util/internal/DateSerializer.kt new file mode 100644 index 0000000..f657ab5 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/util/internal/DateSerializer.kt @@ -0,0 +1,26 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.util.internal + +import kotlinx.serialization.* +import kotlinx.serialization.descriptors.* +import kotlinx.serialization.encoding.* +import me.jie65535.jcf.util.Date +import java.time.OffsetDateTime + +internal object DateSerializer : KSerializer { + override val descriptor = PrimitiveSerialDescriptor("Date", PrimitiveKind.STRING) + + override fun deserialize(decoder: Decoder): Date { + return OffsetDateTime.parse(decoder.decodeString()) + } + + override fun serialize(encoder: Encoder, value: Date) { + encoder.encodeString(value.toString()) + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/util/internal/EnumIntSerializer.kt b/src/main/kotlin/me/jie65535/jcf/util/internal/EnumIntSerializer.kt new file mode 100644 index 0000000..8f8bfa3 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/util/internal/EnumIntSerializer.kt @@ -0,0 +1,25 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.util.internal + +import kotlinx.serialization.* +import kotlinx.serialization.descriptors.* +import kotlinx.serialization.encoding.* + +internal open class EnumIntSerializer(private val serialName: String, private val values: Array, private val startFrom: Int = 1) : KSerializer { + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(serialName, PrimitiveKind.INT) + + override fun deserialize(decoder: Decoder): T { + val value = decoder.decodeInt() + return values[value - startFrom] ?: throw NoSuchElementException("Can't find $serialName with key $value") + } + + override fun serialize(encoder: Encoder, value: T) { + encoder.encodeInt(values.indexOf(value) + startFrom) + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/util/internal/FlagSerializer.kt b/src/main/kotlin/me/jie65535/jcf/util/internal/FlagSerializer.kt new file mode 100644 index 0000000..4cc0959 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/util/internal/FlagSerializer.kt @@ -0,0 +1,36 @@ +/* + * Copyright © 2020, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package me.jie65535.jcf.util.internal + +import kotlinx.serialization.* +import kotlinx.serialization.descriptors.* +import kotlinx.serialization.encoding.* + +internal open class FlagSerializer>(serialName: String, private val map: Map) : KSerializer> { + constructor(serialName: String, vararg pairs: Pair) : this(serialName, mapOf(*pairs)) + + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(serialName, PrimitiveKind.INT) + + override fun serialize(encoder: Encoder, value: Set) { + var bits = 0 + for(flag in value) { + bits = bits or (map[flag] ?: error("")) + } + encoder.encodeInt(bits) + } + + override fun deserialize(decoder: Decoder): Set { + val set = mutableSetOf() + val bits = decoder.decodeInt() + for((flag, shift) in map) { + if(bits and shift == shift) + set += flag + } + return set + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jcf/util/internal/PackageNames.kt b/src/main/kotlin/me/jie65535/jcf/util/internal/PackageNames.kt new file mode 100644 index 0000000..97afd57 --- /dev/null +++ b/src/main/kotlin/me/jie65535/jcf/util/internal/PackageNames.kt @@ -0,0 +1,3 @@ +package me.jie65535.jcf.util.internal + +internal const val MODEL_PACKAGE = "me.jie65535.jcf.model" \ No newline at end of file diff --git a/src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin b/src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin new file mode 100644 index 0000000..8de3fbb --- /dev/null +++ b/src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin @@ -0,0 +1 @@ +me.jie65535.jcf.JCurseforge \ No newline at end of file