diff --git a/.gitignore b/.gitignore deleted file mode 100644 index e655d3a..0000000 --- a/.gitignore +++ /dev/null @@ -1,210 +0,0 @@ - -# Created by https://www.gitignore.io/api/java,gradle,eclipse,intellij,forgegradle -# Edit at https://www.gitignore.io/?templates=java,gradle,eclipse,intellij,forgegradle - -### Eclipse ### -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - -# CDT- autotools -.autotools - -# Java annotation processor (APT) -.factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders -.recommenders/ - -# Annotation Processing -.apt_generated/ - -# Scala IDE specific (Scala & Java development for Eclipse) -.cache-main -.scala_dependencies -.worksheet - -### Eclipse Patch ### -# Eclipse Core -.project - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Annotation Processing -.apt_generated - -.sts4-cache/ - -### ForgeGradle ### -# Minecraft client/server files -run/ - -### Intellij ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -### Intellij Patch ### -# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 - -# *.iml -# modules.xml -# .idea/misc.xml -# *.ipr - -# Sonarlint plugin -.idea/**/sonarlint/ - -# SonarQube Plugin -.idea/**/sonarIssues.xml - -# Markdown Navigator plugin -.idea/**/markdown-navigator.xml -.idea/**/markdown-navigator/ - -### Java ### -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# 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* - -### Gradle ### -.gradle -build/ - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar - -# Cache of project -.gradletasknamecache - -# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 -# gradle/wrapper/gradle-wrapper.properties - -### Gradle Patch ### -**/build/ - -# End of https://www.gitignore.io/api/java,gradle,eclipse,intellij,forgegradle diff --git a/.gradle/6.1/executionHistory/executionHistory.bin b/.gradle/6.1/executionHistory/executionHistory.bin new file mode 100644 index 0000000..25c0344 Binary files /dev/null and b/.gradle/6.1/executionHistory/executionHistory.bin differ diff --git a/.gradle/6.1/executionHistory/executionHistory.lock b/.gradle/6.1/executionHistory/executionHistory.lock new file mode 100644 index 0000000..228a394 Binary files /dev/null and b/.gradle/6.1/executionHistory/executionHistory.lock differ diff --git a/.gradle/6.1/fileChanges/last-build.bin b/.gradle/6.1/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/6.1/fileChanges/last-build.bin differ diff --git a/.gradle/6.1/fileContent/fileContent.lock b/.gradle/6.1/fileContent/fileContent.lock new file mode 100644 index 0000000..ed8a793 Binary files /dev/null and b/.gradle/6.1/fileContent/fileContent.lock differ diff --git a/.gradle/6.1/fileHashes/fileHashes.bin b/.gradle/6.1/fileHashes/fileHashes.bin new file mode 100644 index 0000000..4a9371f Binary files /dev/null and b/.gradle/6.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/6.1/fileHashes/fileHashes.lock b/.gradle/6.1/fileHashes/fileHashes.lock new file mode 100644 index 0000000..8fb9020 Binary files /dev/null and b/.gradle/6.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/6.1/gc.properties b/.gradle/6.1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/6.1/javaCompile/classAnalysis.bin b/.gradle/6.1/javaCompile/classAnalysis.bin new file mode 100644 index 0000000..156885e Binary files /dev/null and b/.gradle/6.1/javaCompile/classAnalysis.bin differ diff --git a/.gradle/6.1/javaCompile/javaCompile.lock b/.gradle/6.1/javaCompile/javaCompile.lock new file mode 100644 index 0000000..5af65ab Binary files /dev/null and b/.gradle/6.1/javaCompile/javaCompile.lock differ diff --git a/.gradle/6.1/javaCompile/taskHistory.bin b/.gradle/6.1/javaCompile/taskHistory.bin new file mode 100644 index 0000000..26914fc Binary files /dev/null and b/.gradle/6.1/javaCompile/taskHistory.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000..e2a1c36 Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..f8a1693 --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Fri May 01 18:13:14 CEST 2020 +gradle.version=6.1 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000..1a066f3 Binary files /dev/null and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/checksums/checksums.lock b/.gradle/checksums/checksums.lock new file mode 100644 index 0000000..8982450 Binary files /dev/null and b/.gradle/checksums/checksums.lock differ diff --git a/.gradle/checksums/md5-checksums.bin b/.gradle/checksums/md5-checksums.bin new file mode 100644 index 0000000..915482b Binary files /dev/null and b/.gradle/checksums/md5-checksums.bin differ diff --git a/.gradle/checksums/sha1-checksums.bin b/.gradle/checksums/sha1-checksums.bin new file mode 100644 index 0000000..83e641b Binary files /dev/null and b/.gradle/checksums/sha1-checksums.bin differ diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/.name b/.idea/.name index 3b1429a..e2fedf1 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -ch.m4th1eu \ No newline at end of file +FlansUpdater \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..59b11d1 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 15a15b2..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..13a8247 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index bc8d0a3..32e560b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,13 @@ - + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 4451989..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 Mathieu B. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index 3d1358e..0000000 --- a/README.md +++ /dev/null @@ -1,9 +0,0 @@ -![logo](https://i.imgur.com/tms6CqT.png) - -# Flan's Mod Updater -Ce programme met lui-même à jour vos packs Flan's Mod de 1.7.10/1.8/etc. à 1.12.2. -*This program update himself your flan's mod packs from 1.7.10/1.8/etc. to 1.12.2.* - -## Documentation -- **Français** : https://m4th1eu.github.io/Flan-s-Mod-Updater/ -- **English** : *comming soon* diff --git a/_config.yml b/_config.yml deleted file mode 100644 index c419263..0000000 --- a/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-cayman \ No newline at end of file diff --git a/build.gradle b/build.gradle index bb11e6c..8ad5a0e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,47 +1,18 @@ -buildscript { - repositories { - maven { - url "https://plugins.gradle.org/m2/" - } - } - dependencies { - classpath "com.github.jengelman.gradle.plugins:shadow:4.0.4" - } -} - plugins { id 'java' } -apply plugin: "com.github.johnrengelman.shadow" -apply plugin: 'java' - -group 'flansupdater' -version '1.1' - -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - -compileJava.options.encoding = 'UTF-8' +group 'org.example' +version '1.0-SNAPSHOT' repositories { mavenCentral() } dependencies { - compile group: 'commons-io', name: 'commons-io', version: '2.4' - compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6' - compile group: 'net.lingala.zip4j', name: 'zip4j', version: '2.2.8' - implementation 'org.zeroturnaround:zt-zip:1.13' + compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.2' + compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.2' + compile group: 'commons-io', name: 'commons-io', version: '2.6' + implementation 'com.google.code.gson:gson:2.8.6' + implementation 'org.zeroturnaround:zt-zip:1.14' } - -jar { - baseName = 'flans-updater' - version = '0.1' - - manifest { - attributes( - 'Main-Class': 'ch.m4th1eu.flansupdater.Main' - ) - } -} \ No newline at end of file diff --git a/build/classes/java/main/ch/m4th1eu/flansupdater/ArmorUtils.class b/build/classes/java/main/ch/m4th1eu/flansupdater/ArmorUtils.class new file mode 100644 index 0000000..b1f74b9 Binary files /dev/null and b/build/classes/java/main/ch/m4th1eu/flansupdater/ArmorUtils.class differ diff --git a/build/classes/java/main/ch/m4th1eu/flansupdater/FileUtils.class b/build/classes/java/main/ch/m4th1eu/flansupdater/FileUtils.class new file mode 100644 index 0000000..b3e1e60 Binary files /dev/null and b/build/classes/java/main/ch/m4th1eu/flansupdater/FileUtils.class differ diff --git a/build/classes/java/main/ch/m4th1eu/flansupdater/Logger.class b/build/classes/java/main/ch/m4th1eu/flansupdater/Logger.class new file mode 100644 index 0000000..add4185 Binary files /dev/null and b/build/classes/java/main/ch/m4th1eu/flansupdater/Logger.class differ diff --git a/build/classes/java/main/ch/m4th1eu/flansupdater/Main.class b/build/classes/java/main/ch/m4th1eu/flansupdater/Main.class new file mode 100644 index 0000000..a70ee9a Binary files /dev/null and b/build/classes/java/main/ch/m4th1eu/flansupdater/Main.class differ diff --git a/build/classes/java/main/ch/m4th1eu/flansupdater/VehiclesUtils.class b/build/classes/java/main/ch/m4th1eu/flansupdater/VehiclesUtils.class new file mode 100644 index 0000000..7a97d81 Binary files /dev/null and b/build/classes/java/main/ch/m4th1eu/flansupdater/VehiclesUtils.class differ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 28861d2..f3d88b1 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e0a5c3b..07b3235 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Dec 31 11:42:11 CET 2019 +#Fri May 01 18:13:48 CEST 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index cccdd3d..2fe81a7 100644 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/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 @@ -28,7 +44,7 @@ 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="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -109,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# 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"` @@ -138,19 +154,19 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + 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" ;; + 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 @@ -159,14 +175,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +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" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f955316..9618d8d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@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 @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @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= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/settings.gradle b/settings.gradle index 79236af..f5945e3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ -rootProject.name = 'ch.m4th1eu' +rootProject.name = 'FlansUpdater' diff --git a/src/main/java/ch/m4th1eu/flansupdater/ArmorUtils.java b/src/main/java/ch/m4th1eu/flansupdater/ArmorUtils.java new file mode 100644 index 0000000..5a9ddab --- /dev/null +++ b/src/main/java/ch/m4th1eu/flansupdater/ArmorUtils.java @@ -0,0 +1,102 @@ +package ch.m4th1eu.flansupdater; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.stream.Stream; + +import static ch.m4th1eu.flansupdater.FileUtils.*; + +public class ArmorUtils { + + + /** + * Create the new armor's file from the old one. + * + * @param path old armor's file path + */ + public static void createNewArmorFile(Path path) { + //new armor file based on the newpack path and the current filename. + String NEWFILENAME = Main.ARMOR_NEWPATH + path.getFileName().toString().toLowerCase().replaceAll(" ", ""); + + //check if the newpack folder exists, if not we create it. + File armorsFolder = new File(Main.ARMOR_NEWPATH); + if (!armorsFolder.exists()) { + boolean isCreated = armorsFolder.mkdirs(); + if (isCreated) { + Logger.info("Successfully created new armors folder."); + } else { + Logger.error("Cannot create new armors folder!"); + } + } + + try { + FileWriter myWriter = new FileWriter(NEWFILENAME); + myWriter.write(processArmorFile(readFile(path.toFile()))); + myWriter.close(); + } catch (IOException e) { + Logger.error("An error occurred when creating armor's file : " + path.getFileName().toString().toLowerCase().replaceAll(" ", "")); + e.printStackTrace(); + } + } + + + /** + * Replace arguments to lowercase, replace space, etc... + * + * @param string the file content + */ + public static String processArmorFile(String string) { + //ShortName + String shortName = get("ShortName", string).toLowerCase().replaceAll(" ", "_"); + string = set("ShortName", shortName, string); + + //Texture + String texture = get("ArmourTexture", string).toLowerCase().replaceAll(" ", "_"); + string = set("ArmourTexture", texture, string); + + //Icon + String icon = get("Icon", string).toLowerCase().replaceAll(" ", "_"); + string = set("Icon", icon, string); + + //Add to lang array. + addLang(shortName, get("Name", string)); + + //Create json model file + FileUtils.createModels(shortName, icon); + + return string; + } + + public static void readAllArmorsFiles() { + try (Stream paths = Files.walk(Paths.get(Main.ARMOR_PATH))) { + paths.filter(Files::isRegularFile).forEach(ArmorUtils::createNewArmorFile); + Logger.info("Successfully generated new armors files and filled the lang file."); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void readAllArmorsTextures() { + try (Stream paths = Files.walk(Paths.get(Main.ARMOR_TEXTURES_PATH))) { + paths.filter(Files::isRegularFile).forEach(path -> { + Path newPath = Paths.get(Main.ARMOR_TEXTURES_NEWPATH + path.getFileName().toString().toLowerCase().replaceAll(" ", "")); + + try { + org.apache.commons.io.FileUtils.copyFile(path.toFile(), newPath.toFile(), false); + } catch (IOException e) { + Logger.error("Cannot rename/move armors textures file : " + path.getFileName()); + e.printStackTrace(); + } + }); + Logger.info("Successfully copied and renamed the armors textures files."); + + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/ch/m4th1eu/flansupdater/Controller.java b/src/main/java/ch/m4th1eu/flansupdater/Controller.java deleted file mode 100644 index c1228e8..0000000 --- a/src/main/java/ch/m4th1eu/flansupdater/Controller.java +++ /dev/null @@ -1,140 +0,0 @@ -package ch.m4th1eu.flansupdater; - -import javafx.application.Platform; -import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.TextField; -import javafx.scene.control.*; -import javafx.stage.FileChooser; -import net.lingala.zip4j.ZipFile; -import net.lingala.zip4j.exception.ZipException; - -import java.awt.*; -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Optional; - -import static ch.m4th1eu.flansupdater.Main.primaryStage; - - -public class Controller { - - - @FXML - TextField packname; - @FXML - Button bug; - @FXML - Button idea; - @FXML - Button convertir; - @FXML - Button selectpack; - - private File selectedFile; - - @FXML - private void initialize() { - registerHoverableButton(bug); - registerHoverableButton(idea); - registerHoverableButton(convertir); - registerHoverableButton(selectpack); - - registerLinkableButton(bug, "https://github.com/M4TH1EU/Flan-s-Mod-Updater/issues/new?assignees=&labels=&template=bug_report.md&title="); - registerLinkableButton(idea, "https://github.com/M4TH1EU/Flan-s-Mod-Updater/issues/new?assignees=&labels=&template=feature_request.md&title="); - - packname.setEditable(false); - convertir.setDisable(true); - - convertir.setOnAction(event -> { - - new Thread(() -> { - try { - Platform.runLater(() -> { - selectpack.setDisable(true); - convertir.setDisable(true); - packname.setDisable(true); - - convertir.setText("Extraction du pack..."); - }); - - new ZipFile(selectedFile).extractAll(selectedFile.getParent() + "\\dontTouch\\"); - } catch (ZipException e) { - e.printStackTrace(); - Platform.runLater(() -> convertir.setText("Erreur, extraction échouée !")); - } - - String[] args = new String[]{selectedFile.getParent() + "\\dontTouch", selectedFile.getName()}; - try { - Platform.runLater(() -> convertir.setText("Mise à jour...")); - Updater.main(args); - Platform.runLater(() -> convertir.setText("Terminé !")); - } catch (Exception e) { - Platform.runLater(() -> convertir.setText("Erreur, mise à jour échouée !")); - } - - Platform.runLater(() -> { - Alert alert = new Alert(Alert.AlertType.INFORMATION); - alert.setTitle("Information"); - alert.setHeaderText("Mise à jour terminée."); - alert.setContentText("La mise à jour du pack " + packname.getText() + " est terminée !" + "\nChemin : " + selectedFile.getParent()); - - alert.showAndWait(); - }); - - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - Platform.runLater(() -> { - packname.setText(""); - selectedFile = new File(""); - convertir.setText("Mettre à jour mon pack"); - convertir.setDisable(false); - packname.setDisable(false); - selectpack.setDisable(false); - }); - }).start(); - - - }); - - selectpack.setOnAction(event -> { - FileChooser fileChooser = new FileChooser(); - fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("ZIP Files", "*.zip")); - selectedFile = fileChooser.showOpenDialog(primaryStage); - - if (selectedFile != null) { - packname.setText(selectedFile.getName()); - } - convertir.setDisable(false); - }); - } - - public void registerHoverableButton(Button button) { - button.setOnMouseEntered(event -> { - button.setStyle("-fx-background-color: grey; " + - "-fx-border-color: grey;" + - "-fx-text-fill: white;"); - }); - - button.setOnMouseExited(event -> { - button.setStyle("-fx-background-color: transparent; " + - "-fx-border-color: grey;"); - }); - - } - - public void registerLinkableButton(Button button, String url) { - button.setOnAction(event -> { - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException | URISyntaxException e) { - e.printStackTrace(); - } - }); - } -} diff --git a/src/main/java/ch/m4th1eu/flansupdater/FileUtils.java b/src/main/java/ch/m4th1eu/flansupdater/FileUtils.java new file mode 100644 index 0000000..0d597ae --- /dev/null +++ b/src/main/java/ch/m4th1eu/flansupdater/FileUtils.java @@ -0,0 +1,224 @@ +package ch.m4th1eu.flansupdater; + + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Scanner; +import java.util.stream.Stream; + +public class FileUtils { + + public static final ArrayList langs = new ArrayList<>(); + + /** + * Get params from a file's path. + * + * @param argument argument's name + * @param url file's path + * @return argument's value + */ + public static String get(String argument, Path url) { + BufferedReader reader; + try { + reader = new BufferedReader(new FileReader(url.toString())); + String line = reader.readLine(); + while (line != null) { + if (line.startsWith(argument)) { + return line.replaceFirst(argument + " ", ""); + } + + // read next line + line = reader.readLine(); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + return "null"; + } + + /** + * Get params from a file's content + * + * @param argument argument's name + * @param content file's content + * @return argument's value + */ + public static String get(String argument, String content) { + Scanner scanner = new Scanner(content); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + + if (line.startsWith(argument)) { + return line.replaceFirst(argument + " ", ""); + } + } + scanner.close(); + + return "null"; + } + + /** + * Set params in a file's content + * + * @param argument argument's name + * @param content file's content + * @return argument's value + */ + public static String set(String argument, String value, String content) { + Scanner scanner = new Scanner(content); + StringBuilder stringBuilder = new StringBuilder(); + + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + + if (line.startsWith(argument)) { + line = argument + " " + value; + } + + stringBuilder.append(line).append("\n"); + } + scanner.close(); + + return stringBuilder.toString(); + } + + /** + * Read a file and convert it to string. + * + * @param file file to read + * @return file's content + */ + public static String readFile(File file) { + try { + StringBuilder fileData = new StringBuilder(); + BufferedReader reader = new BufferedReader( + new FileReader(file.toString())); + char[] buf = new char[1024]; + int numRead = 0; + while ((numRead = reader.read(buf)) != -1) { + String readData = String.valueOf(buf, 0, numRead); + fileData.append(readData); + } + reader.close(); + return fileData.toString(); + } catch (IOException e) { + e.printStackTrace(); + } + + return ""; + } + + public static void addLang(String shortName, String name) { + langs.add("item." + shortName + ".name=" + name); + } + + public static void writeLangs(ArrayList langs) { + try { + //check if the newpack folder exists, if not we create it. + File langsFolder = new File(Main.LANG_NEWPATH); + if (!langsFolder.exists()) { + boolean isCreated = langsFolder.mkdirs(); + if (isCreated) { + Logger.info("Successfully created new langs folder."); + } else { + Logger.error("Cannot create new langs folder!"); + } + } + + StringBuilder stringBuilder = new StringBuilder(); + langs.forEach(str -> stringBuilder.append(str).append("\n")); + + FileWriter myWriter = new FileWriter(Main.LANG_NEWPATH + "en_US.lang"); + myWriter.write(stringBuilder.toString()); + myWriter.close(); + Logger.info("Successfully generated the new lang file."); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void readAllIcons() { + try (Stream paths = Files.walk(Paths.get(Main.ICONS_PATH))) { + paths.filter(Files::isRegularFile).forEach(path -> { + Path newPath = Paths.get(Main.ICONS_NEWPATH + path.getFileName().toString().toLowerCase().replaceAll(" ", "")); + + try { + org.apache.commons.io.FileUtils.copyFile(path.toFile(), newPath.toFile(), false); + } catch (IOException e) { + Logger.error("Cannot rename/move icons file : " + path.getFileName()); + e.printStackTrace(); + } + }); + Logger.info("Successfully copied and renamed the icons files."); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void createModels(String shortName, String icon) { + //check if the models folder exists, if not we create it. + File modelsFolder = new File(Main.JSON_PATH); + if (!modelsFolder.exists()) { + boolean isCreated = modelsFolder.mkdirs(); + if (isCreated) { + Logger.info("Successfully created jsons folder."); + } else { + Logger.error("Cannot create -jsons folder!"); + } + } + + String jsonString = "{\"parent\":\"builtin/generated\",\"textures\":{\"layer0\":\"flansmod:items/your_item_texture\"},\"display\":{\"thirdperson_lefthand\":{\"rotation\":[0,90,-35],\"translation\":[0,1.25,-2.5],\"scale\":[0.8,0.8,0.8]},\"thirdperson_righthand\":{\"rotation\":[0,90,-35],\"translation\":[0,1.25,-2.5],\"scale\":[0.8,0.8,0.8]},\"firstperson_lefthand\":{\"rotation\":[0,-45,25],\"translation\":[0,4,2],\"scale\":[0.8,0.8,0.8]},\"firstperson_righthand\":{\"rotation\":[0,-45,25],\"translation\":[0,4,2],\"scale\":[0.8,0.8,0.8]}}}"; + jsonString = jsonString.replaceFirst("your_item_texture", icon); + + try { + FileWriter myWriter = new FileWriter(Main.JSON_PATH + shortName + ".json"); + myWriter.write(jsonString); + myWriter.close(); + } catch (IOException e) { + Logger.error("Cannot create the json model file for : " + shortName); + e.printStackTrace(); + } + } + + public static void copyModels() { + try { + org.apache.commons.io.FileUtils.copyDirectory(new File(Main.MODELS_PATH), new File(Main.MODELS_NEWPATH)); + Logger.info("Successfully copied the models directory."); + } catch (IOException e) { + Logger.error("Cannot copy models directory!"); + e.printStackTrace(); + } + } + + public static void createPackInfo() { + JsonObject jsonObject = new JsonObject(); + JsonObject pack = new JsonObject(); + pack.addProperty("pack_format", 1); + pack.addProperty("description", "Generated by Flans Updater."); + jsonObject.add("pack", pack); + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String jsonString = gson.toJson(jsonObject); + + try { + FileWriter myWriter = new FileWriter(Main.NEWPACK_PATH + "pack_info.mcmeta"); + myWriter.write(jsonString); + myWriter.close(); + Logger.info("Successfully created the pack_info file."); + } catch (IOException e) { + Logger.error("Cannot create the pack_info file!"); + e.printStackTrace(); + } + } + + +} diff --git a/src/main/java/ch/m4th1eu/flansupdater/Logger.java b/src/main/java/ch/m4th1eu/flansupdater/Logger.java new file mode 100644 index 0000000..c4d21a5 --- /dev/null +++ b/src/main/java/ch/m4th1eu/flansupdater/Logger.java @@ -0,0 +1,25 @@ +package ch.m4th1eu.flansupdater; + +public class Logger { + public static final String ANSI_RESET = "\u001B[0m"; + public static final String ANSI_RED = "\u001B[31m"; + public static final String ANSI_GREEN = "\u001B[32m"; + public static final String ANSI_YELLOW = "\u001B[33m"; + public static final String RED_BOLD = "\033[1;31m"; // RED + + public static void error(String message) { + System.out.println(ANSI_RED + "[ERROR] " + message + ANSI_RESET); + } + + public static void info(String message) { + System.out.println(ANSI_GREEN + "[INFO] " + message + ANSI_RESET); + } + + public static void warn(String message) { + System.out.println(ANSI_YELLOW + "[WARN] " + message + ANSI_RESET); + } + + public static void fatal(String message) { + System.out.println(RED_BOLD + "[FATAL] " + message + ANSI_RESET); + } +} diff --git a/src/main/java/ch/m4th1eu/flansupdater/Main.java b/src/main/java/ch/m4th1eu/flansupdater/Main.java index e391a4b..536894a 100644 --- a/src/main/java/ch/m4th1eu/flansupdater/Main.java +++ b/src/main/java/ch/m4th1eu/flansupdater/Main.java @@ -1,32 +1,51 @@ package ch.m4th1eu.flansupdater; -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.image.Image; -import javafx.stage.Stage; +import org.zeroturnaround.zip.ZipUtil; -import java.io.IOException; +import java.io.File; +import java.nio.file.Paths; -public class Main extends Application { - public static Stage primaryStage = null; +public class Main { + public static final String PACK_PATH = "C:\\Users\\Mathieu\\Downloads\\Altis Mine Pack\\"; + public static final String NEWPACK_PATH = "C:\\Users\\Mathieu\\Downloads\\Altis Mine Pack NEW\\"; + + public static final String VEHICLES_PATH = PACK_PATH + "vehicles\\"; + public static final String VEHICLES_NEWPATH = NEWPACK_PATH + "vehicles\\"; + + public static final String ARMOR_PATH = PACK_PATH + "armorFiles\\"; + public static final String ARMOR_NEWPATH = NEWPACK_PATH + "armorFiles\\"; + + public static final String ARMOR_TEXTURES_PATH = PACK_PATH + "assets\\flansmod\\armor\\"; + public static final String ARMOR_TEXTURES_NEWPATH = NEWPACK_PATH + "assets\\flansmod\\armor\\"; + + public static final String VEHICLESSKINS_PATH = PACK_PATH + "assets\\flansmod\\skins\\"; + public static final String VEHICLESSKINS_NEWPATH = NEWPACK_PATH + "assets\\flansmod\\skins\\"; + + public static final String JSON_PATH = NEWPACK_PATH + "assets\\flansmod\\models\\item\\"; + + public static final String LANG_NEWPATH = NEWPACK_PATH + "assets\\flansmod\\lang\\"; + + public static final String MODELS_PATH = PACK_PATH + "com\\"; + public static final String MODELS_NEWPATH = NEWPACK_PATH + "com\\"; + + public static final String ICONS_PATH = PACK_PATH + "assets\\flansmod\\textures\\items\\"; + public static final String ICONS_NEWPATH = NEWPACK_PATH + "assets\\flansmod\\textures\\items\\"; + + private static final Main INSTANCE = new Main(); public static void main(String[] args) { - launch(args); + FileUtils.copyModels(); + VehiclesUtils.readAllVehiclesFiles(); + VehiclesUtils.readAllVehiclesSkins(); + ArmorUtils.readAllArmorsFiles(); + ArmorUtils.readAllArmorsTextures(); + FileUtils.readAllIcons(); + FileUtils.createPackInfo(); + FileUtils.writeLangs(FileUtils.langs); + + ZipUtil.pack(new File(NEWPACK_PATH), new File(Paths.get(NEWPACK_PATH).getParent() + "\\" + Paths.get(NEWPACK_PATH).getFileName() + ".zip")); + Logger.info("Update complete."); } - @Override - public void start(Stage primaryStage) throws IOException { - - Parent root = FXMLLoader.load(Updater.class.getResource("/menu.fxml")); - - Main.primaryStage = primaryStage; - Main.primaryStage.setTitle("Flans Updater"); - Main.primaryStage.setResizable(false); - Main.primaryStage.setScene(new Scene(root, 625, 365)); - Main.primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("/icon.png"))); - Main.primaryStage.show(); - } } diff --git a/src/main/java/ch/m4th1eu/flansupdater/Updater.java b/src/main/java/ch/m4th1eu/flansupdater/Updater.java deleted file mode 100644 index 112abd3..0000000 --- a/src/main/java/ch/m4th1eu/flansupdater/Updater.java +++ /dev/null @@ -1,402 +0,0 @@ -/** - * @author Mathieu Broillet (M4TH1EU_#0001 (on discord)) - * @description This program update himself your flan's mod packs from 1.7.10/1.8/etc. to 1.12.2 - * @important This program is not meant to be very pretty or well coded. - * It just works, that's all we ask. - */ - -package ch.m4th1eu.flansupdater; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.zeroturnaround.zip.ZipUtil; - -import java.io.*; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.stream.Stream; - -public class Updater { - - private static String ICON_NAME = ""; - private static File MODEL_FILE = new File(""); - - private static String PATH = null; - private static String ZIP_FILE_NAME = null; - - public static void main(String[] args) throws Exception { - PATH = args[0]; - ZIP_FILE_NAME = args[1]; - - ArrayList files = new ArrayList<>(); - - try (Stream filePathStream = Files.walk(Paths.get(PATH))) { - filePathStream.forEach(filePath -> { - if (Files.isRegularFile(filePath)) { - files.add(filePath); - } - }); - } - - generateLangs(); - - //MCMETA - if (!new File(PATH + "\\pack_info.mcmeta").exists()) { - PrintWriter printWriter = new PrintWriter(new File(PATH + "\\pack_info.mcmeta")); - printWriter.println("{\n" + - " \"pack\": {\n" + - " \"pack_format\": 1,\n" + - " \"description\": \"Generated by Flans Updater.\"\n" + - " }\n" + - "}"); - printWriter.close(); - } - if (new File(PATH + "\\pack.mcmeta").exists()) { - new File(PATH + "\\pack.mcmeta").delete(); - } - - /* - Listen all files and check if they ends by ".txt". - */ - for (int i = 0; i < files.size(); i++) { - - /* armorFiles / models / lang / icons */ - if (files.get(i).getParent().toString().endsWith("armorFiles")) { - if (files.get(i).getFileName().toString().endsWith(".txt")) { - - //ARMOR FILES / ICONS(replaceNames) - renameFileToLowercase(files.get(i).toFile()); - replaceNames(Paths.get(files.get(i).toString().replaceAll(" ", "_").toLowerCase())); - - //MODELS - renameFileToLowercase(MODEL_FILE); - - if (hasModel(files.get(i))) { - replaceModelIcon(MODEL_FILE.toPath()); - } else { - createModelFile(MODEL_FILE.toPath()); - replaceModelIcon(MODEL_FILE.toPath()); - } - } - } - /* armors textures */ - if (files.get(i).getParent().toString().endsWith("armor")) { - - if (files.get(i).getFileName().toString().endsWith(".png")) { - renameFileToLowercase(files.get(i).toFile()); - } - } - - /* vehicles / models / lang / icons */ - if (files.get(i).getParent().toString().endsWith("vehicles")) { - if (files.get(i).getFileName().toString().endsWith(".txt")) { - - //VEHICLES FILES / ICONS(replaceNames) - renameFileToLowercase(files.get(i).toFile()); - replaceNames(Paths.get(files.get(i).toString().replaceAll(" ", "_").toLowerCase())); - - //MODELS - renameFileToLowercase(MODEL_FILE); - - if (hasModel(files.get(i))) { - replaceModelIcon(MODEL_FILE.toPath()); - } else { - createModelFile(MODEL_FILE.toPath()); - replaceModelIcon(MODEL_FILE.toPath()); - } - } - } - /* vehicles textures */ - if (files.get(i).getParent().toString().endsWith("skins")) { - if (files.get(i).getFileName().toString().endsWith(".png")) { - renameFileToLowercase(files.get(i).toFile()); - } - } - - /* items icons */ - if (files.get(i).getParent().toString().endsWith("items")) { - if (files.get(i).getFileName().toString().endsWith(".png")) { - renameFileToLowercase(files.get(i).toFile()); - } - } - } - - - boolean delete = new File(Paths.get(PATH).getParent() + "\\" + ZIP_FILE_NAME).delete(); - if (delete) { - System.out.println("Old zip deleted"); - } else { - System.out.println("Old zip not deleted (error)"); - } - - //Zip.main(new String[]{Paths.get(PATH).getParent() + "\\" + ZIP_FILE_NAME.replaceAll(".jar", "").replaceAll(".zip", "").replaceAll(".rar", "") + "_UPDATED.zip", PATH}); - ZipUtil.pack(new File(PATH), new File(Paths.get(PATH).getParent() + "\\" + ZIP_FILE_NAME.replaceAll(".jar", "").replaceAll(".zip", "").replaceAll(".rar", "") + "_UPDATED.zip")); - - System.gc(); - Thread.yield(); - FileUtils.deleteDirectory(new File(Paths.get(PATH).getParent() + "\\dontTouch\\")); - while (new File(Paths.get(PATH).getParent() + "\\dontTouch\\").exists()) { - System.gc(); - Thread.yield(); - FileUtils.deleteDirectory(new File(Paths.get(PATH).getParent() + "\\dontTouch\\")); - } - - - System.out.println("UPDATED SUCCESSFULLY"); - } - - - public static boolean hasModel(Path filePath) { - return new File(PATH + "\\assets\\flansmod\\models\\item\\" + filePath.getFileName().toString().replaceAll(".txt", ".json")).exists(); - } - - /** - * Read the file gave by @filePath and split all lines to find "ShortName" and "ArmourTexture" - * - * @param filePath - */ - public static void replaceNames(Path filePath) { - try { - // Open the file - FileInputStream fstream = new FileInputStream(String.valueOf(filePath)); - // Get the object of DataInputStream - DataInputStream in = new DataInputStream(fstream); - BufferedReader br = new BufferedReader(new InputStreamReader(in)); - String strLine; - - int i = 0; - //Read File Line By Line - while ((strLine = br.readLine()) != null) { - if (strLine.contains("ShortName")) { - String[] parts = strLine.split(" "); - String oldName = "ShortName " + parts[1]; - String newName = "ShortName " + parts[1].toLowerCase().replaceAll(" ", "_"); - System.out.println(oldName + " -> " + newName); - MODEL_FILE = new File(filePath.getParent().getParent() + "\\assets\\flansmod\\models\\item\\" + parts[1].toLowerCase().replaceAll(" ", "_") + ".json"); - modifyFile(String.valueOf(filePath), oldName, newName); - } - if (strLine.contains("ArmourTexture")) { - String[] parts = strLine.split(" "); - String oldName = "ArmourTexture " + parts[1]; - String newName = "ArmourTexture " + parts[1].toLowerCase(); - System.out.println(oldName + " -> " + newName); - modifyFile(String.valueOf(filePath), oldName, newName); - } - if (strLine.contains("Texture")) { - String[] parts = strLine.split(" "); - String oldName = "Texture " + parts[1]; - String newName = "Texture " + parts[1].toLowerCase().replaceAll(" ", "_"); - System.out.println(oldName + " -> " + newName); - - modifyFile(String.valueOf(filePath), oldName, newName); - } - if (strLine.contains("Icon")) { - String[] parts = strLine.split(" "); - String oldName = "Icon " + parts[1]; - String newName = "Icon " + parts[1].toLowerCase().replaceAll(" ", "_"); - System.out.println(oldName + " -> " + newName); - ICON_NAME = parts[1].toLowerCase().replaceAll(" ", "_"); - modifyFile(String.valueOf(filePath), oldName, newName); - } - i++; - } - - //Close the input stream - in.close(); - } catch (Exception e) {//Catch exception if any - System.err.println("Error: " + e.getMessage()); - } - } - - /** - * Read the file gave by @filePath and split all lines to find "ShortName" and "ArmourTexture" - * - * @param filePath - */ - public static void replaceModelIcon(Path filePath) { - - Gson gson = new Gson(); - JsonObject jsonObject = null; - try { - jsonObject = gson.fromJson(new FileReader(filePath.toFile()), JsonObject.class); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - - if (jsonObject != null) { - String oldIcon = jsonObject.getAsJsonObject("textures").get("layer0").getAsString(); - String newIcon = "flansmod:items/" + ICON_NAME; - System.out.println(oldIcon + " -> " + newIcon); - - modifyFile(String.valueOf(filePath), oldIcon, newIcon); - } else { - try { - createModelFile(MODEL_FILE.toPath()); - replaceModelIcon(filePath); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - /** - * Replace an old string by a new one in a file - * - * @param filePath - * @param oldString - * @param newString - */ - static void modifyFile(String filePath, String oldString, String newString) { - File fileToBeModified = new File(filePath); - String oldContent = ""; - BufferedReader reader = null; - FileWriter writer = null; - try { - reader = new BufferedReader(new FileReader(fileToBeModified)); - String line = reader.readLine(); - while (line != null) { - oldContent = oldContent + line + System.lineSeparator(); - line = reader.readLine(); - } - String newContent = oldContent.replaceAll(oldString, newString); - writer = new FileWriter(fileToBeModified); - writer.write(newContent); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - reader.close(); - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - /** - * Replace all uppercase to lowercase. - * - * @param file - */ - private static void renameFileToLowercase(File file) { - boolean rename = file.renameTo(new File(file.getPath().replaceAll(file.getName(), "") + file.getName().replaceAll(" ", "_").toLowerCase())); - if (!rename) { - for (int i = 0; i < 3; i++) { - file.renameTo(new File(file.getPath().replaceAll(file.getName(), "") + file.getName().replaceAll(" ", "_").toLowerCase())); - System.gc(); - Thread.yield(); - } - } - } - - /** - * Get the model.json tempalte and create new file with. - * - * @param filePath - * @throws Exception - */ - private static void createModelFile(Path filePath) throws Exception { - - InputStream in = Updater.class.getResourceAsStream("/model.json"); - - StringWriter writer = new StringWriter(); - IOUtils.copy(in, writer, Charset.forName("utf-8")); - String theString = writer.toString(); - - filePath.getParent().toFile().mkdirs(); - PrintWriter printWriter = new PrintWriter(filePath.toFile()); - printWriter.println(theString); - - System.out.println("Model " + filePath.toFile().getName() + "created."); - printWriter.close(); - } - - public static void createLangFile(Path filePath) throws Exception { - PrintWriter printWriter = new PrintWriter(filePath.toFile()); - printWriter.println(" "); - printWriter.close(); - } - - /** - * Lists all files and get their name & shortname to fill the lang file. - * - * @throws Exception - */ - public static void generateLangs() throws Exception { - File LANG_FILE = new File(PATH + "\\assets\\flansmod\\lang\\en_US.lang"); - - PrintWriter printWriter = new PrintWriter(LANG_FILE); - printWriter.println(""); - printWriter.close(); - - ArrayList files = new ArrayList<>(); - try (Stream filePathStream = Files.walk(Paths.get(PATH))) { - filePathStream.forEach(filePath -> { - if (Files.isRegularFile(filePath)) { - files.add(filePath); - } - }); - } - - /* - Listen all files and check if they ends by ".txt". - */ - for (int i = 0; i < files.size(); i++) { - if (!LANG_FILE.exists()) { - new File(LANG_FILE.getParent()).mkdirs(); - LANG_FILE.createNewFile(); - } - - - if (files.get(i).getParent().toString().endsWith("armorFiles") || files.get(i).getParent().toString().endsWith("vehicles")) { - if (files.get(i).getFileName().toString().endsWith(".txt")) { - try { - // Open the file - FileInputStream fstream = new FileInputStream(String.valueOf(files.get(i))); - // Get the object of DataInputStream - DataInputStream in = new DataInputStream(fstream); - BufferedReader br = new BufferedReader(new InputStreamReader(in)); - String strLine; - - - String id = ""; - String name = ""; - //Read File Line By Line - while ((strLine = br.readLine()) != null) { - if (strLine.startsWith("ShortName")) { - String[] parts = strLine.split(" "); - id = parts[1].toLowerCase(); - } - if (strLine.startsWith("Name")) { - name = strLine.replaceAll("Name", "").replaceFirst(" ", ""); - } - } - - InputStream inputStream = new FileInputStream(LANG_FILE); - - StringWriter writer = new StringWriter(); - IOUtils.copy(inputStream, writer, Charset.forName("utf-8")); - String theString = writer.toString(); - theString = theString + "item." + id + ".name=" + name; - System.out.println("New lang entry : " + theString); - - PrintWriter writer1 = new PrintWriter(LANG_FILE); - writer1.println(theString); - writer1.close(); - - - //Close the input stream - inputStream.close(); - } catch (Exception e) {//Catch exception if any - System.err.println("Error: " + e.getMessage()); - } - } - } - } - } -} diff --git a/src/main/java/ch/m4th1eu/flansupdater/VehiclesUtils.java b/src/main/java/ch/m4th1eu/flansupdater/VehiclesUtils.java new file mode 100644 index 0000000..e5b196d --- /dev/null +++ b/src/main/java/ch/m4th1eu/flansupdater/VehiclesUtils.java @@ -0,0 +1,101 @@ +package ch.m4th1eu.flansupdater; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.stream.Stream; + +import static ch.m4th1eu.flansupdater.FileUtils.*; + +public class VehiclesUtils { + + /** + * Create the new vehicle's file from the old one. + * + * @param path old vehicle's file path + */ + public static void createNewVehicleFile(Path path) { + //new vehicle file based on the newpack path and the current filename. + String NEWFILENAME = Main.VEHICLES_NEWPATH + path.getFileName().toString().toLowerCase().replaceAll(" ", ""); + + //check if the newpack folder exists, if not we create it. + File vehiclesFolder = new File(Main.VEHICLES_NEWPATH); + if (!vehiclesFolder.exists()) { + boolean isCreated = vehiclesFolder.mkdirs(); + if (isCreated) { + Logger.info("Successfully created new vehicles folder."); + } else { + Logger.error("Cannot create new vehicles folder!"); + } + } + + try { + FileWriter myWriter = new FileWriter(NEWFILENAME); + myWriter.write(processVehicleFile(readFile(path.toFile()))); + myWriter.close(); + } catch (IOException e) { + Logger.error("An error occurred when creating vehicle's file : " + path.getFileName().toString().toLowerCase().replaceAll(" ", "")); + e.printStackTrace(); + } + } + + + /** + * Replace arguments to lowercase, replace space, etc... + * + * @param string the file content + */ + public static String processVehicleFile(String string) { + //ShortName + String shortName = get("ShortName", string).toLowerCase().replaceAll(" ", "_"); + string = set("ShortName", shortName, string); + + //Texture + String texture = get("Texture", string).toLowerCase().replaceAll(" ", "_"); + string = set("Texture", texture, string); + + //Icon + String icon = get("Icon", string).toLowerCase().replaceAll(" ", "_"); + string = set("Icon", icon, string); + + //Add to lang array. + addLang(shortName, get("Name", string)); + + //Create json model file + FileUtils.createModels(shortName, icon); + + return string; + } + + public static void readAllVehiclesFiles() { + try (Stream paths = Files.walk(Paths.get(Main.VEHICLES_PATH))) { + paths.filter(Files::isRegularFile).forEach(VehiclesUtils::createNewVehicleFile); + Logger.info("Successfully generated new vehicles files and filled the new lang file."); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void readAllVehiclesSkins() { + try (Stream paths = Files.walk(Paths.get(Main.VEHICLESSKINS_PATH))) { + paths.filter(Files::isRegularFile).forEach(path -> { + Path newPath = Paths.get(Main.VEHICLESSKINS_NEWPATH + path.getFileName().toString().toLowerCase().replaceAll(" ", "")); + + try { + org.apache.commons.io.FileUtils.copyFile(path.toFile(), newPath.toFile(), false); + } catch (IOException e) { + Logger.error("Cannot rename/move skins file : " + path.getFileName()); + e.printStackTrace(); + } + }); + Logger.info("Successfully copied and renamed the skins files."); + + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/ch/m4th1eu/flansupdater/Zip.java b/src/main/java/ch/m4th1eu/flansupdater/Zip.java deleted file mode 100644 index 72e37fa..0000000 --- a/src/main/java/ch/m4th1eu/flansupdater/Zip.java +++ /dev/null @@ -1,107 +0,0 @@ -package ch.m4th1eu.flansupdater; - - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -public class Zip { - private static String OUTPUT_ZIP_FILE = "C:\\MyFile.zip"; - private static String SOURCE_FOLDER = "C:\\testzip"; - List fileList; - - Zip() { - fileList = new ArrayList(); - } - - public static void main(String[] args) { - OUTPUT_ZIP_FILE = args[0]; - SOURCE_FOLDER = args[1]; - - Zip appZip = new Zip(); - appZip.generateFileList(new File(SOURCE_FOLDER)); - appZip.zipIt(OUTPUT_ZIP_FILE); - } - - /** - * Zip it - * - * @param zipFile output ZIP file location - */ - public void zipIt(String zipFile) { - - byte[] buffer = new byte[1024]; - - try { - - FileOutputStream fos = new FileOutputStream(zipFile); - ZipOutputStream zos = new ZipOutputStream(fos); - - System.out.println("Output to Zip : " + zipFile); - - for (String file : this.fileList) { - - ZipEntry ze = new ZipEntry(file); - zos.putNextEntry(ze); - - FileInputStream in = - new FileInputStream(SOURCE_FOLDER + File.separator + file); - - int len; - while ((len = in.read(buffer)) > 0) { - zos.write(buffer, 0, len); - } - in.close(); - } - System.out.println("Files added"); - - zos.closeEntry(); - //remember close it - zos.close(); - fos.close(); - - System.out.println("Done"); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - /** - * Traverse a directory and get all files, - * and add the file into fileList - * - * @param node file or directory - */ - public void generateFileList(File node) { - - //add file only - if (node.isFile()) { - fileList.add(generateZipEntry(node.getAbsoluteFile().toString())); - } - - if (node.isDirectory()) { - String[] subNote = node.list(); - for (String filename : subNote) { - generateFileList(new File(node, filename)); - } - } - - } - - /** - * Format the file path for zip - * - * @param file file path - * @return Formatted file path - */ - private String generateZipEntry(String file) { - return file.substring(SOURCE_FOLDER.length() + 1); - } - - -} \ No newline at end of file diff --git a/src/main/resources/icon.png b/src/main/resources/icon.png deleted file mode 100644 index 2a6cc0b..0000000 Binary files a/src/main/resources/icon.png and /dev/null differ diff --git a/src/main/resources/logo_transparent.png b/src/main/resources/logo_transparent.png deleted file mode 100644 index f1c872c..0000000 Binary files a/src/main/resources/logo_transparent.png and /dev/null differ diff --git a/src/main/resources/logo_transparent_2.png b/src/main/resources/logo_transparent_2.png deleted file mode 100644 index 683aa6e..0000000 Binary files a/src/main/resources/logo_transparent_2.png and /dev/null differ diff --git a/src/main/resources/menu.fxml b/src/main/resources/menu.fxml deleted file mode 100644 index d4258e5..0000000 --- a/src/main/resources/menu.fxml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - -