├── .gitignore ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── com │ └── pistacium │ └── modcheck │ ├── ModCheck.java │ ├── ModCheckConstants.java │ ├── ModCheckFrameForm.form │ ├── ModCheckFrameForm.java │ ├── mod │ ├── MCVersion.java │ ├── ModFile.java │ ├── ModInfo.java │ ├── ModRule.java │ └── RuleIndicator.java │ └── util │ ├── Config.java │ ├── ModCheckStatus.java │ ├── ModCheckUtils.java │ └── SwingUtils.java └── resources └── end_crystal.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /.gradle/ 3 | /build/ 4 | /build/classes/java/main/ 5 | /out/ 6 | modcheck.json 7 | /.idea/ 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ModCheck 2 | ![ModCheck](https://cdn.7tv.app/emote/60eefb20119bd109472f7f4b/4x) 3 | 4 | Minecraft SpeedRun Mods Auto Installer/Updater 5 | 6 | original idea by [pistacium](https://github.com/pistacium/ModCheck) 7 | 8 | ![image](https://user-images.githubusercontent.com/25276450/172102912-455735a5-558f-4330-84c6-fad5bf9aa92b.png) 9 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | //file:noinspection GroovyAssignabilityCheck 2 | buildscript { 3 | repositories { 4 | gradlePluginPortal() 5 | } 6 | dependencies { 7 | classpath 'gradle.plugin.com.github.johnrengelman:shadow:7.1.2' 8 | } 9 | } 10 | 11 | plugins { 12 | id 'java' 13 | id 'com.github.johnrengelman.shadow' version '7.1.2' 14 | } 15 | 16 | apply plugin: 'com.github.johnrengelman.shadow' 17 | 18 | group 'com.redlimerl' 19 | version '1.0' 20 | repositories { 21 | mavenCentral() 22 | maven { 23 | url "https://repo.spongepowered.org/maven/" 24 | } 25 | maven { 26 | url "https://maven.fabricmc.net/" 27 | } 28 | } 29 | 30 | 31 | dependencies { 32 | implementation "net.fabricmc:fabric-loader:0.14.21" 33 | implementation 'com.google.code.gson:gson:2.9.0' 34 | implementation 'com.intellij:forms_rt:7.0.3' 35 | } 36 | 37 | test { 38 | useJUnitPlatform() 39 | } 40 | 41 | jar { 42 | finalizedBy shadowJar 43 | manifest { 44 | attributes 'Main-Class': "com.pistacium.modcheck.ModCheck" 45 | } 46 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedLime/ModCheck/d6e1b1fe58a8a0e8273469f8f5245cb781d39bd2/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MSYS* | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'ModCheck' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/ModCheck.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import com.google.gson.JsonElement; 6 | import com.google.gson.JsonParser; 7 | import com.pistacium.modcheck.mod.MCVersion; 8 | import com.pistacium.modcheck.mod.ModInfo; 9 | import com.pistacium.modcheck.util.ModCheckStatus; 10 | import com.pistacium.modcheck.util.ModCheckUtils; 11 | 12 | import javax.swing.*; 13 | import java.awt.*; 14 | import java.awt.datatransfer.Clipboard; 15 | import java.awt.datatransfer.StringSelection; 16 | import java.io.PrintWriter; 17 | import java.io.StringWriter; 18 | import java.util.ArrayList; 19 | import java.util.Objects; 20 | import java.util.concurrent.ExecutorService; 21 | import java.util.concurrent.Executors; 22 | 23 | public class ModCheck { 24 | 25 | public static void setStatus(ModCheckStatus status) { 26 | FRAME_INSTANCE.getProgressBar().setString(status.getDescription()); 27 | } 28 | 29 | public static final Gson GSON = new GsonBuilder().serializeNulls().create(); 30 | public static final ExecutorService THREAD_EXECUTOR = Executors.newSingleThreadExecutor(); 31 | 32 | public static ModCheckFrameForm FRAME_INSTANCE; 33 | 34 | public static final ArrayList AVAILABLE_VERSIONS = new ArrayList<>(); 35 | 36 | public static final ArrayList AVAILABLE_MODS = new ArrayList<>(); 37 | 38 | public static void main(String[] args) { 39 | THREAD_EXECUTOR.submit(() -> { 40 | try { 41 | FRAME_INSTANCE = new ModCheckFrameForm(); 42 | 43 | // Get available versions 44 | setStatus(ModCheckStatus.LOADING_AVAILABLE_VERSIONS); 45 | JsonElement availableElement = JsonParser.parseString(Objects.requireNonNull(ModCheckUtils.getUrlRequest("https://redlime.github.io/MCSRMods/meta/v4/mc_versions.json"))); 46 | FRAME_INSTANCE.getProgressBar().setValue(30); 47 | for (JsonElement jsonElement : availableElement.getAsJsonArray()) { 48 | AVAILABLE_VERSIONS.add(GSON.fromJson(jsonElement, MCVersion.class)); 49 | } 50 | 51 | // Get mod list 52 | setStatus(ModCheckStatus.LOADING_MOD_LIST); 53 | JsonElement modElement = JsonParser.parseString(Objects.requireNonNull(ModCheckUtils.getUrlRequest("https://redlime.github.io/MCSRMods/meta/v4/files.json"))); 54 | FRAME_INSTANCE.getProgressBar().setValue(60); 55 | 56 | setStatus(ModCheckStatus.LOADING_MOD_RESOURCE); 57 | int count = 0, maxCount = modElement.getAsJsonArray().size(); 58 | for (JsonElement jsonElement : modElement.getAsJsonArray()) { 59 | try { 60 | FRAME_INSTANCE.getProgressBar().setString("Loading information of "+jsonElement.getAsJsonObject().get("name")); 61 | ModInfo modInfo = GSON.fromJson(jsonElement, ModInfo.class); 62 | if (Objects.equals(modInfo.getType(), "fabric_mod")) AVAILABLE_MODS.add(modInfo); 63 | } catch (Throwable e) { 64 | StringWriter sw = new StringWriter(); 65 | PrintWriter pw = new PrintWriter(sw); 66 | e.printStackTrace(pw); 67 | System.out.println("Failed to init " + jsonElement.getAsJsonObject().get("name").getAsString() + "!\r\n" + sw); 68 | } finally { 69 | FRAME_INSTANCE.getProgressBar().setValue((int) (60 + (((++count * 1f) / maxCount) * 40))); 70 | } 71 | } 72 | FRAME_INSTANCE.getProgressBar().setValue(100); 73 | setStatus(ModCheckStatus.IDLE); 74 | FRAME_INSTANCE.updateVersionList(); 75 | } catch (Throwable e) { 76 | StringWriter sw = new StringWriter(); 77 | PrintWriter pw = new PrintWriter(sw); 78 | e.printStackTrace(pw); 79 | int result = JOptionPane.showOptionDialog(null, sw.toString(), "Error exception!", 80 | JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, 81 | new String[] { "Copy to clipboard a logs", "Cancel" }, "Copy to clipboard a logs"); 82 | if (result == 0) { 83 | StringSelection selection = new StringSelection(sw.toString()); 84 | Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 85 | clipboard.setContents(selection, selection); 86 | } 87 | 88 | System.exit(0); 89 | } 90 | }); 91 | //System.out.println(new Gson().toJson(ModCheckUtils.getFabricJsonFileInJar(new File("D:/MultiMC/instances/1.16-1/.minecraft/mods/SpeedRunIGT-10.0+1.16.1.jar")))); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/ModCheckConstants.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck; 2 | 3 | public class ModCheckConstants { 4 | 5 | public static final String APPLICATION_VERSION = "1.0"; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/ModCheckFrameForm.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/ModCheckFrameForm.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck; 2 | 3 | import com.google.gson.JsonObject; 4 | import com.google.gson.JsonParser; 5 | import com.pistacium.modcheck.mod.*; 6 | import com.pistacium.modcheck.util.Config; 7 | import com.pistacium.modcheck.util.ModCheckStatus; 8 | import com.pistacium.modcheck.util.ModCheckUtils; 9 | import com.pistacium.modcheck.util.SwingUtils; 10 | import net.fabricmc.loader.api.Version; 11 | import net.fabricmc.loader.impl.util.version.VersionParser; 12 | 13 | import javax.swing.*; 14 | import javax.swing.border.EmptyBorder; 15 | import javax.swing.plaf.FontUIResource; 16 | import javax.swing.plaf.basic.BasicComboBoxEditor; 17 | import java.awt.*; 18 | import java.io.File; 19 | import java.net.URI; 20 | import java.net.URL; 21 | import java.nio.file.Path; 22 | import java.util.*; 23 | 24 | @SuppressWarnings("ResultOfMethodCallIgnored") 25 | public class ModCheckFrameForm extends JFrame { 26 | 27 | private static final FontUIResource font = new FontUIResource("SansSerif", Font.BOLD, 15); 28 | private JProgressBar progressBar; 29 | private JButton downloadButton; 30 | private JCheckBox deleteAllJarCheckbox; 31 | private JButton selectInstancePathsButton; 32 | private JComboBox mcVersionCombo; 33 | private JRadioButton randomSeedRadioButton; 34 | private JRadioButton setSeedRadioButton; 35 | private JRadioButton windowsRadioButton; 36 | private JRadioButton macRadioButton; 37 | private JRadioButton linuxRadioButton; 38 | private JCheckBox accessibilityCheckBox; 39 | private JScrollPane modListScroll; 40 | private JPanel mainPanel; 41 | private JLabel selectedDirLabel; 42 | private JButton deselectAllButton; 43 | private JButton selectAllRecommendsButton; 44 | private JPanel modListPanel; 45 | private JScrollBar scrollBar1; 46 | 47 | 48 | private File[] selectDirs = null; 49 | private final HashMap modCheckBoxes = new HashMap<>(); 50 | private String currentOS = ModCheckUtils.getCurrentOS(); 51 | 52 | ModCheckFrameForm() throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException { 53 | setContentPane(mainPanel); 54 | setTitle("ModCheck v" + ModCheckConstants.APPLICATION_VERSION + " by RedLime"); 55 | setSize(1100, 700); 56 | setVisible(true); 57 | setLocationRelativeTo(null); 58 | setDefaultCloseOperation(EXIT_ON_CLOSE); 59 | Enumeration keys = UIManager.getLookAndFeelDefaults().keys(); 60 | while (keys.hasMoreElements()) { 61 | Object key = keys.nextElement(); 62 | Object value = UIManager.get(key); 63 | if (value instanceof FontUIResource) 64 | UIManager.put(key, font); 65 | } 66 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 67 | 68 | URL resource = getClass().getClassLoader().getResource("end_crystal.png"); 69 | if (resource != null) setIconImage(new ImageIcon(resource).getImage()); 70 | 71 | initMenuBar(); 72 | 73 | selectInstancePathsButton.addActionListener(e -> { 74 | Config instanceDir = ModCheckUtils.readConfig(); 75 | JFileChooser pathSelector = instanceDir == null ? new JFileChooser() : new JFileChooser(instanceDir.getDir()); 76 | pathSelector.setMultiSelectionEnabled(true); 77 | pathSelector.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 78 | pathSelector.setDialogType(JFileChooser.CUSTOM_DIALOG); 79 | pathSelector.setDialogTitle("Select Instance Paths"); 80 | JComboBox jComboBox = SwingUtils.getDescendantsOfType(JComboBox.class, pathSelector).get(0); 81 | jComboBox.setEditable(true); 82 | jComboBox.setEditor(new BasicComboBoxEditor.UIResource() { 83 | @Override 84 | public Object getItem() { 85 | try { 86 | return new File((String) super.getItem()); 87 | } catch (Exception e) { 88 | return super.getItem(); 89 | } 90 | } 91 | }); 92 | 93 | int showDialog = pathSelector.showDialog(this, "Select"); 94 | File[] files = pathSelector.getSelectedFiles(); 95 | if (pathSelector.getSelectedFiles() != null && showDialog == JFileChooser.APPROVE_OPTION) { 96 | selectDirs = files; 97 | String parentDir = ""; 98 | StringBuilder stringBuilder = new StringBuilder(); 99 | for (File selectDir : selectDirs) { 100 | stringBuilder.append(parentDir.isEmpty() ? selectDir.getPath() : selectDir.getPath().replace(parentDir, "")).append(", "); 101 | parentDir = selectDir.getParent(); 102 | } 103 | selectedDirLabel.setText("Selected Instances :
" + stringBuilder.substring(0, stringBuilder.length() - (stringBuilder.length() != 0 ? 2 : 0)) + ""); 104 | } 105 | ModCheckUtils.writeConfig(files[0].getParentFile()); 106 | }); 107 | 108 | progressBar.setString("Idle..."); 109 | downloadButton.addActionListener(e -> { 110 | if (selectDirs == null || selectDirs.length < 1) return; 111 | 112 | downloadButton.setEnabled(false); 113 | Stack modsFileStack = new Stack<>(); 114 | 115 | int ignoreInstance = -1; 116 | 117 | for (File instanceDir : selectDirs) { 118 | Path instancePath = instanceDir.toPath(); 119 | File dotMinecraft = instancePath.resolve(".minecraft").toFile(); 120 | if (dotMinecraft.isDirectory()) { 121 | instancePath = instancePath.resolve(".minecraft"); 122 | } 123 | 124 | Path modsPath = instancePath.resolve("mods"); 125 | File modsDir = modsPath.toFile(); 126 | if (!modsDir.isDirectory()) { 127 | int result = ignoreInstance != -1 ? ignoreInstance : JOptionPane.showConfirmDialog(this, "You have selected a directory but not a minecraft instance directory.\nAre you sure you want to download in this directory?", "Wrong instance directory", JOptionPane.OK_CANCEL_OPTION); 128 | 129 | System.out.println(result); 130 | if (result != 0) { 131 | downloadButton.setEnabled(true); 132 | return; 133 | } else { 134 | ignoreInstance = result; 135 | modsFileStack.push(instanceDir); 136 | } 137 | } else { 138 | modsFileStack.push(modsDir); 139 | } 140 | } 141 | 142 | if (mcVersionCombo.getSelectedItem() == null) { 143 | JOptionPane.showMessageDialog(this, "Error: selected item is null"); 144 | downloadButton.setEnabled(true); 145 | return; 146 | } 147 | 148 | ArrayList targetMods = new ArrayList<>(); 149 | int maxCount = 0; 150 | for (Map.Entry modEntry : modCheckBoxes.entrySet()) { 151 | if (modEntry.getValue().isSelected() && modEntry.getValue().isEnabled()) { 152 | System.out.println("Selected " + modEntry.getKey().getName()); 153 | targetMods.add(modEntry.getKey()); 154 | maxCount++; 155 | } 156 | } 157 | MCVersion mcVersion = (MCVersion) mcVersionCombo.getSelectedItem(); 158 | 159 | for (File instanceDir : modsFileStack) { 160 | File[] modFiles = instanceDir.listFiles(); 161 | if (modFiles == null) return; 162 | for (File file : modFiles) { 163 | if (file.getName().endsWith(".jar")) { 164 | if (deleteAllJarCheckbox.isSelected()) { 165 | file.delete(); 166 | } else { 167 | String modFileName = file.getName().split("-")[0].split("\\+")[0]; 168 | for (ModInfo targetMod : targetMods) { 169 | String targetModFileName = targetMod.getFileFromVersion(mcVersion, this.getRuleIndicator()).getName(); 170 | if (targetModFileName.startsWith(modFileName)) { 171 | file.delete(); 172 | } 173 | } 174 | } 175 | } 176 | } 177 | } 178 | 179 | this.progressBar.setValue(0); 180 | ModCheck.setStatus(ModCheckStatus.DOWNLOADING_MOD_FILE); 181 | 182 | int finalMaxCount = maxCount; 183 | ModCheck.THREAD_EXECUTOR.submit(() -> { 184 | int count = 0; 185 | ArrayList failedMods = new ArrayList<>(); 186 | for (ModInfo targetMod : targetMods) { 187 | this.progressBar.setString("Downloading '" + targetMod.getName() + "'"); 188 | System.out.println("Downloading " + targetMod.getName()); 189 | Stack downloadFiles = new Stack<>(); 190 | downloadFiles.addAll(modsFileStack); 191 | if (!targetMod.downloadFile(mcVersion, this.getRuleIndicator(), downloadFiles)) { 192 | System.out.println("Failed to downloading " + targetMod.getName()); 193 | failedMods.add(targetMod); 194 | } 195 | this.progressBar.setValue((int) ((++count / (finalMaxCount * 1f)) * 100)); 196 | } 197 | this.progressBar.setValue(100); 198 | ModCheck.setStatus(ModCheckStatus.IDLE); 199 | 200 | System.out.println("Downloading mods complete"); 201 | 202 | if (failedMods.size() > 0) { 203 | StringBuilder failedModString = new StringBuilder(); 204 | for (ModInfo failedMod : failedMods) { 205 | failedModString.append(failedMod.getName()).append(", "); 206 | } 207 | JOptionPane.showMessageDialog(this, "Failed to download " + failedModString.substring(0, failedModString.length() - 2) + ".", "Please try again", JOptionPane.ERROR_MESSAGE); 208 | } else { 209 | JOptionPane.showMessageDialog(this, "All selected mods have been downloaded!"); 210 | } 211 | downloadButton.setEnabled(true); 212 | }); 213 | }); 214 | downloadButton.setEnabled(false); 215 | 216 | mcVersionCombo.addActionListener(e -> updateModList()); 217 | 218 | selectAllRecommendsButton.addActionListener(e -> { 219 | for (Map.Entry entry : modCheckBoxes.entrySet()) { 220 | if (!entry.getKey().isRecommended() 221 | || entry.getKey().getIncompatible().stream().anyMatch(incompatible -> 222 | modCheckBoxes.entrySet().stream().anyMatch(entry2 -> 223 | entry2.getKey().getName().equals(incompatible) && entry2.getValue().isSelected())) 224 | ) continue; 225 | 226 | if (entry.getValue().isEnabled()) { 227 | entry.getValue().setSelected(true); 228 | } 229 | } 230 | JOptionPane.showMessageDialog(this, "Some mods that have warnings (like noPeaceful)
or incompatible with other mods (like Starlight and Phosphor) aren't automatically selected.
You have to select them yourself.", "WARNING!", JOptionPane.WARNING_MESSAGE); 231 | }); 232 | 233 | deselectAllButton.addActionListener(e -> { 234 | for (JCheckBox cb : modCheckBoxes.values()) { 235 | cb.setSelected(false); 236 | cb.setEnabled(true); 237 | } 238 | }); 239 | 240 | windowsRadioButton.addActionListener(e -> { 241 | currentOS = "windows"; 242 | updateModList(); 243 | }); 244 | if (currentOS.equals("windows")) windowsRadioButton.setSelected(true); 245 | macRadioButton.addActionListener(e -> { 246 | currentOS = "osx"; 247 | updateModList(); 248 | }); 249 | if (currentOS.equals("osx")) macRadioButton.setSelected(true); 250 | linuxRadioButton.addActionListener(e -> { 251 | currentOS = "linux"; 252 | updateModList(); 253 | }); 254 | if (currentOS.equals("linux")) linuxRadioButton.setSelected(true); 255 | 256 | randomSeedRadioButton.addActionListener(e -> updateModList()); 257 | setSeedRadioButton.addActionListener(e -> updateModList()); 258 | accessibilityCheckBox.addActionListener(e -> { 259 | if (accessibilityCheckBox.isSelected()) { 260 | String message = "You may utilize these mods ONLY if you tell the MCSR Team about a medical condition that makes them necessary in advance."; 261 | int result = JOptionPane.showConfirmDialog(this, message, "THIS OPTION IS NOT FOR ALL!", JOptionPane.OK_CANCEL_OPTION); 262 | if (result == 0) { 263 | updateModList(); 264 | } else { 265 | accessibilityCheckBox.setSelected(false); 266 | } 267 | } else { 268 | updateModList(); 269 | } 270 | }); 271 | } 272 | 273 | 274 | public void initMenuBar() { 275 | JMenuBar menuBar = new JMenuBar(); 276 | 277 | JMenu source = new JMenu("Info"); 278 | 279 | JMenuItem githubSource = new JMenuItem("GitHub..."); 280 | githubSource.addActionListener(e -> { 281 | try { 282 | Desktop.getDesktop().browse(new URI("https://github.com/RedLime/ModCheck")); 283 | } catch (Exception ignored) { 284 | } 285 | }); 286 | source.add(githubSource); 287 | 288 | JMenuItem donateSource = new JMenuItem("Support"); 289 | donateSource.addActionListener(e -> { 290 | try { 291 | Desktop.getDesktop().browse(new URI("https://ko-fi.com/redlimerl")); 292 | } catch (Exception ignored) { 293 | } 294 | }); 295 | source.add(donateSource); 296 | 297 | JMenuItem checkChangeLogSource = new JMenuItem("Changelog"); 298 | checkChangeLogSource.addActionListener(e -> { 299 | try { 300 | Desktop.getDesktop().browse(new URI("https://github.com/RedLime/ModCheck/releases/tag/" + ModCheckConstants.APPLICATION_VERSION)); 301 | } catch (Exception ignored) { 302 | } 303 | }); 304 | source.add(checkChangeLogSource); 305 | 306 | JMenuItem updateCheckSource = new JMenuItem("Check for updates"); 307 | updateCheckSource.addActionListener(e -> { 308 | try { 309 | JsonObject jsonObject = JsonParser.parseString(ModCheckUtils.getUrlRequest("https://api.github.com/repos/RedLime/ModCheck/releases/latest")).getAsJsonObject(); 310 | if (VersionParser.parseSemantic(jsonObject.get("tag_name").getAsString()).compareTo((Version) VersionParser.parseSemantic(ModCheckConstants.APPLICATION_VERSION)) > 0) { 311 | int result = JOptionPane.showOptionDialog(null, "Found new ModCheck update!

Current Version : " + ModCheckConstants.APPLICATION_VERSION + "
Updated Version : " + jsonObject.get("tag_name").getAsString() + "", "Update Checker", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, new String[]{"Download", "Cancel"}, "Download"); 312 | if (result == 0) { 313 | Desktop.getDesktop().browse(new URI("https://github.com/RedLime/ModCheck/releases/latest")); 314 | } 315 | } else { 316 | JOptionPane.showMessageDialog(this, "You are using the latest version!"); 317 | } 318 | } catch (Exception ignored) { 319 | } 320 | }); 321 | source.add(updateCheckSource); 322 | 323 | menuBar.add(source); 324 | 325 | this.setJMenuBar(menuBar); 326 | } 327 | 328 | public void updateVersionList() { 329 | mcVersionCombo.removeAllItems(); 330 | for (MCVersion availableVersion : ModCheck.AVAILABLE_VERSIONS) { 331 | mcVersionCombo.addItem(availableVersion); 332 | } 333 | mcVersionCombo.setSelectedItem(ModCheck.AVAILABLE_VERSIONS.get(0)); 334 | updateModList(); 335 | } 336 | 337 | public void updateModList() { 338 | modListPanel.removeAll(); 339 | modListPanel.setLayout(new BoxLayout(modListPanel, BoxLayout.Y_AXIS)); 340 | modCheckBoxes.clear(); 341 | 342 | if (mcVersionCombo.getSelectedItem() == null) return; 343 | 344 | MCVersion mcVersion = (MCVersion) mcVersionCombo.getSelectedItem(); 345 | 346 | modFor: 347 | for (ModInfo modInfo : ModCheck.AVAILABLE_MODS) { 348 | ModFile modFile = modInfo.getFileFromVersion(mcVersion, this.getRuleIndicator()); 349 | if (modFile != null) { 350 | if (modFile.getRules() != null) { 351 | for (ModRule rule : modFile.getRules()) { 352 | boolean allowed = rule.getAction().equals("allow"); 353 | for (Map.Entry entry : rule.getProperties().entrySet()) { 354 | if (entry.getKey().equals("category") && !(entry.getValue().equals("rsg") == randomSeedRadioButton.isSelected() == allowed)) 355 | continue modFor; 356 | if (entry.getKey().equals("condition") && !(entry.getValue().equals("medical_issue") == accessibilityCheckBox.isSelected() == allowed)) 357 | continue modFor; 358 | if (entry.getKey().equals("os") && !(entry.getValue().equals(currentOS) == allowed)) 359 | continue modFor; 360 | } 361 | } 362 | } 363 | 364 | JPanel modPanel = new JPanel(); 365 | modPanel.setLayout(new BoxLayout(modPanel, BoxLayout.Y_AXIS)); 366 | 367 | String versionName = modFile.getVersion(); 368 | JCheckBox checkBox = new JCheckBox(modInfo.getName() + " (v" + (versionName.substring(versionName.startsWith("v") ? 1 : 0)) + ")"); 369 | checkBox.addChangeListener(i -> { 370 | modCheckBoxes.entrySet().stream() 371 | .filter(entry -> entry.getKey().getIncompatible().contains(modInfo.getName()) || modInfo.getIncompatible().contains(entry.getKey().getName())) 372 | .forEach(entry -> entry.getValue().setEnabled(modCheckBoxes.entrySet().stream() 373 | .noneMatch(entry2 -> (entry.getKey().getIncompatible().contains(entry2.getKey().getName()) || entry2.getKey().getIncompatible().contains(entry.getKey().getName())) && entry2.getValue().isSelected()))); 374 | }); 375 | 376 | int line = modInfo.getDescription().split("\n").length; 377 | JLabel description = new JLabel("" + modInfo.getDescription().replaceAll("\n", "
").replaceAll("", "") + ""); 378 | description.setMaximumSize(new Dimension(800, 60 * line)); 379 | description.setBorder(new EmptyBorder(0, 15, 0, 0)); 380 | Font f = description.getFont(); 381 | description.setFont(f.deriveFont(f.getStyle() & ~Font.BOLD)); 382 | 383 | modPanel.add(checkBox); 384 | modPanel.add(description); 385 | modPanel.setMaximumSize(new Dimension(950, 60 * line)); 386 | modPanel.setBorder(new EmptyBorder(0, 10, 10, 0)); 387 | 388 | modListPanel.add(modPanel); 389 | modCheckBoxes.put(modInfo, checkBox); 390 | } 391 | } 392 | modListPanel.updateUI(); 393 | modListScroll.updateUI(); 394 | downloadButton.setEnabled(true); 395 | } 396 | 397 | public JProgressBar getProgressBar() { 398 | return progressBar; 399 | } 400 | 401 | private RuleIndicator getRuleIndicator() { 402 | String runType = randomSeedRadioButton.isSelected() ? "rsg" : "ssg"; 403 | return new RuleIndicator(currentOS, runType, accessibilityCheckBox.isSelected()); 404 | } 405 | 406 | } 407 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/mod/MCVersion.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck.mod; 2 | 3 | public class MCVersion { 4 | private String name; 5 | private String value; 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | 11 | public String getValue() { 12 | return value; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return this.getName(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/mod/ModFile.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck.mod; 2 | 3 | import java.util.List; 4 | 5 | public class ModFile { 6 | private String version; 7 | private List game_versions; 8 | private String name; 9 | private String url; 10 | private String page; 11 | private String sha1; 12 | private int size; 13 | private List rules; 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public List getRules() { 20 | return rules; 21 | } 22 | 23 | public int getSize() { 24 | return size; 25 | } 26 | 27 | public String getPage() { 28 | return page; 29 | } 30 | 31 | public List getGameVersions() { 32 | return game_versions; 33 | } 34 | 35 | public String getSha1() { 36 | return sha1; 37 | } 38 | 39 | public String getUrl() { 40 | return url; 41 | } 42 | 43 | public String getVersion() { 44 | return version; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/mod/ModInfo.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck.mod; 2 | 3 | import net.fabricmc.loader.api.VersionParsingException; 4 | import net.fabricmc.loader.api.metadata.version.VersionPredicate; 5 | import net.fabricmc.loader.impl.util.version.VersionParser; 6 | import net.fabricmc.loader.impl.util.version.VersionPredicateParser; 7 | 8 | import java.io.File; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | import java.net.URL; 12 | import java.net.URLConnection; 13 | import java.nio.channels.Channels; 14 | import java.nio.channels.ReadableByteChannel; 15 | import java.nio.file.Files; 16 | import java.nio.file.Path; 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | import java.util.Stack; 20 | 21 | public class ModInfo { 22 | private String name; 23 | private String description; 24 | private String type; 25 | private boolean recommended; 26 | private List files; 27 | private List incompatible; 28 | 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public String getDescription() { 35 | return description; 36 | } 37 | 38 | public String getType() { 39 | return type; 40 | } 41 | 42 | public boolean isRecommended() { 43 | return recommended; 44 | } 45 | 46 | public List getFiles() { 47 | return files; 48 | } 49 | 50 | public List getIncompatible() { 51 | return incompatible == null ? new ArrayList<>() : incompatible; 52 | } 53 | 54 | public ModFile getFileFromVersion(MCVersion mcVersion, RuleIndicator ruleIndicator) { 55 | try { 56 | for (ModFile file : this.getFiles()) { 57 | if (!ruleIndicator.checkWithRules(file.getRules())) continue; 58 | for (String gameVersion : file.getGameVersions()) { 59 | VersionPredicate versionPredicate = VersionPredicateParser.parse(gameVersion); 60 | if (versionPredicate.test(VersionParser.parseSemantic(mcVersion.getValue()))) return file; 61 | } 62 | } 63 | } catch (VersionParsingException e) { 64 | throw new RuntimeException(e); 65 | } 66 | return null; 67 | } 68 | 69 | public boolean downloadFile(MCVersion mcVersion, RuleIndicator ruleIndicator, Stack downloadFiles) { 70 | ModFile modFile = this.getFileFromVersion(mcVersion, ruleIndicator); 71 | 72 | try { 73 | if (downloadFiles.size() < 1) return false; 74 | URL url = new URL(modFile.getUrl()); 75 | 76 | URLConnection con = url.openConnection(); 77 | con.setRequestProperty("User-Agent", "ModCheck-Client"); 78 | 79 | File download = downloadFiles.pop().toPath().resolve(modFile.getName()).toFile(); 80 | 81 | ReadableByteChannel rbc = Channels.newChannel(con.getInputStream()); 82 | try (FileOutputStream fos = new FileOutputStream(download)) { 83 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 84 | } 85 | System.out.println("Downloaded "+modFile.getName()+" in "+download.getPath()); 86 | 87 | while (downloadFiles.size() > 0) { 88 | Path copyPath = downloadFiles.pop().toPath().resolve(modFile.getName()); 89 | Files.copy(download.toPath(), copyPath); 90 | System.out.println("Copied to " + copyPath); 91 | } 92 | return true; 93 | } catch (IOException e) { 94 | e.printStackTrace(); 95 | return false; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/mod/ModRule.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck.mod; 2 | 3 | import java.util.Map; 4 | 5 | public class ModRule { 6 | private String action; 7 | private Map properties; 8 | 9 | public String getAction() { 10 | return action; 11 | } 12 | 13 | public Map getProperties() { 14 | return properties; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/mod/RuleIndicator.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck.mod; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class RuleIndicator { 7 | 8 | private final String osName; 9 | private final String category; 10 | private final boolean medicalIssue; 11 | 12 | public RuleIndicator(String osName, String category, boolean medicalIssue) { 13 | this.osName = osName; 14 | this.category = category; 15 | this.medicalIssue = medicalIssue; 16 | } 17 | 18 | public boolean checkWithRules(List ruleList) { 19 | if (ruleList == null) return true; 20 | for (ModRule modRule : ruleList) { 21 | boolean allowed = modRule.getAction().equals("allow"); 22 | for (Map.Entry entry : modRule.getProperties().entrySet()) { 23 | if (entry.getKey().equals("category") && entry.getValue().equals(category) != allowed) return false; 24 | if (entry.getKey().equals("os") && entry.getValue().equals(osName) != allowed) return false; 25 | if (entry.getKey().equals("condition") && entry.getValue().equals("medical_issue") && medicalIssue != allowed) return false; 26 | } 27 | } 28 | return true; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/util/Config.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck.util; 2 | 3 | import java.io.File; 4 | 5 | public class Config { 6 | final String filepath; 7 | 8 | public Config(String filepath) { 9 | this.filepath = filepath; 10 | } 11 | 12 | public File getDir() { 13 | return new File(filepath); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/util/ModCheckStatus.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck.util; 2 | 3 | public enum ModCheckStatus { 4 | 5 | IDLE(""), 6 | 7 | LOADING_AVAILABLE_VERSIONS("Loading available versions info"), 8 | 9 | LOADING_MOD_LIST("Loading mod list"), 10 | 11 | LOADING_MOD_RESOURCE("Loading mod's resource"), 12 | 13 | GETTING_INSTALLED_MODS("Getting installed mods info"), 14 | 15 | DOWNLOADING_MOD_FILE("Downloading file"); 16 | 17 | private final String description; 18 | 19 | ModCheckStatus(String s) { 20 | this.description = s; 21 | } 22 | 23 | public String getDescription() { 24 | return description; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/util/ModCheckUtils.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck.util; 2 | 3 | import com.google.gson.FieldNamingPolicy; 4 | import com.google.gson.Gson; 5 | import com.google.gson.GsonBuilder; 6 | 7 | import java.io.*; 8 | import java.net.HttpURLConnection; 9 | import java.net.URL; 10 | import java.nio.charset.StandardCharsets; 11 | import java.util.HashMap; 12 | 13 | public class ModCheckUtils { 14 | private static final HashMap urlReqCache = new HashMap<>(); 15 | 16 | public static String getUrlRequest(String url) throws IllegalAccessException { 17 | if (urlReqCache.containsKey(url)) { 18 | return urlReqCache.get(url); 19 | } 20 | try { 21 | URL obj = new URL(url); 22 | HttpURLConnection conn = (HttpURLConnection) obj.openConnection(); 23 | conn.setConnectTimeout(10000); 24 | conn.setReadTimeout(10000); 25 | 26 | BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); 27 | 28 | String inputLine; 29 | StringBuilder response = new StringBuilder(); 30 | 31 | while ((inputLine = in.readLine()) != null) { 32 | response.append(inputLine); 33 | } 34 | in.close(); 35 | 36 | urlReqCache.put(url, response.toString()); 37 | return response.toString(); 38 | } catch (Exception e) { 39 | e.printStackTrace(); 40 | } 41 | throw new IllegalAccessException("Couldn't loading url request data! check your internet status"); 42 | } 43 | 44 | public static Config readConfig() { 45 | Gson gson = new Gson(); 46 | File file = new File("modcheck.json"); 47 | if (!file.exists()) { 48 | return null; 49 | } 50 | BufferedReader br = null; 51 | try { 52 | br = new BufferedReader(new FileReader(file)); 53 | } catch (FileNotFoundException e) { 54 | e.printStackTrace(); 55 | } 56 | assert br != null; 57 | return gson.fromJson(br, Config.class); 58 | } 59 | 60 | public static void writeConfig(File dir) { 61 | File file = new File("modcheck.json"); 62 | Config config = new Config(dir.getPath()); 63 | try (Writer writer = new FileWriter(file)) { 64 | Gson gson = new GsonBuilder() 65 | .setPrettyPrinting() 66 | .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) 67 | .create(); 68 | gson.toJson(config, writer); 69 | } catch (IOException e) { 70 | throw new RuntimeException(e); 71 | } 72 | } 73 | 74 | public static String getCurrentOS() { 75 | String osName = System.getProperty("os.name").toLowerCase(); 76 | if (osName.contains("win")) return "windows"; 77 | if (osName.contains("mac")) return "osx"; 78 | if (osName.contains("nix") || osName.contains("nux") || osName.contains("aix")) { 79 | return "linux"; 80 | } 81 | return "unknown"; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/pistacium/modcheck/util/SwingUtils.java: -------------------------------------------------------------------------------- 1 | package com.pistacium.modcheck.util; 2 | /* 3 | * @(#)SwingUtils.java 1.02 11/15/08 4 | * 5 | */ 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * A collection of utility methods for Swing. 14 | * 15 | * @author Darryl Burke 16 | */ 17 | public final class SwingUtils { 18 | 19 | private SwingUtils() { 20 | throw new Error("SwingUtils is just a container for static methods"); 21 | } 22 | 23 | public static List getDescendantsOfType( 24 | Class clazz, Container container) { 25 | return getDescendantsOfType(clazz, container, true); 26 | } 27 | 28 | 29 | public static List getDescendantsOfType( 30 | Class clazz, Container container, boolean nested) { 31 | List tList = new ArrayList<>(); 32 | for (Component component : container.getComponents()) { 33 | if (clazz.isAssignableFrom(component.getClass())) { 34 | tList.add(clazz.cast(component)); 35 | } 36 | if (nested || !clazz.isAssignableFrom(component.getClass())) { 37 | tList.addAll(SwingUtils.getDescendantsOfType(clazz, 38 | (Container) component, nested)); 39 | } 40 | } 41 | return tList; 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/resources/end_crystal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RedLime/ModCheck/d6e1b1fe58a8a0e8273469f8f5245cb781d39bd2/src/main/resources/end_crystal.png --------------------------------------------------------------------------------