Initial commit

This commit is contained in:
Mathieu Broillet 2020-01-05 10:03:36 +01:00
parent 2c1164a440
commit 9d2435b2a6
21 changed files with 1222 additions and 36 deletions

210
.gitignore vendored Normal file
View File

@ -0,0 +1,210 @@
# 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

1
.idea/.name Normal file
View File

@ -0,0 +1 @@
ch.m4th1eu

4
.idea/encodings.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,37 +1,3 @@
## Welcome to GitHub Pages
## Flan's Mod Updater
You can use the [editor on GitHub](https://github.com/M4TH1EU/Flan-s-Mod-Updater/edit/master/README.md) to maintain and preview the content for your website in Markdown files.
Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files.
### Markdown
Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for
```markdown
Syntax highlighted code block
# Header 1
## Header 2
### Header 3
- Bulleted
- List
1. Numbered
2. List
**Bold** and _Italic_ and `Code` text
[Link](url) and ![Image](src)
```
For more details see [GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/).
### Jekyll Themes
Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/M4TH1EU/Flan-s-Mod-Updater/settings). The name of this theme is saved in the Jekyll `_config.yml` configuration file.
### Support or Contact
Having trouble with Pages? Check out our [documentation](https://help.github.com/categories/github-pages-basics/) or [contact support](https://github.com/contact) and well help you sort it out.
This program update himself your flan's mod packs from 1.7.10/1.8/etc. to 1.12.2.

41
build.gradle Normal file
View File

@ -0,0 +1,41 @@
plugins {
id 'java'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
group 'flansupdater'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'ch.m4th1eu.flansupdater.Main'
compileJava.options.encoding = 'UTF-8'
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'
testCompile "junit:junit:4.12"
}
jar {
baseName = 'flans-updater'
version = '0.1'
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes(
'Main-Class': 'ch.m4th1eu.flansupdater.Main'
)
}
}

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
#Tue Dec 31 11:42:11 CET 2019
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

172
gradlew vendored Normal file
View File

@ -0,0 +1,172 @@
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# 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" "$@"

84
gradlew.bat vendored Normal file
View File

@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem 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=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

2
settings.gradle Normal file
View File

@ -0,0 +1,2 @@
rootProject.name = 'ch.m4th1eu'

View File

@ -0,0 +1,130 @@
package ch.m4th1eu.flansupdater;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
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 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, "xyz");
registerLinkableButton(idea, "xyz");
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() + "\\");
} catch (ZipException e) {
e.printStackTrace();
Platform.runLater(() -> convertir.setText("Erreur, extraction échouée !"));
}
java.lang.String[] args = new java.lang.String[]{selectedFile.getParent()};
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 !"));
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Platform.runLater(() -> {
selectpack.setDisable(false);
selectpack.setText("");
selectedFile = new File("");
convertir.setText("Mettre à jour mon pack");
convertir.setDisable(false);
packname.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();
}
});
}
}

View File

@ -0,0 +1,32 @@
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 java.io.IOException;
public class Main extends Application {
public static Stage primaryStage = null;
public static void main(String[] args) {
launch(args);
}
@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();
}
}

View File

@ -0,0 +1,369 @@
/**
*
* @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.IOUtils;
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;
public static void main(String[] args) throws Exception {
PATH = args[0];
ArrayList<Path> files = new ArrayList<>();
try (Stream<Path> 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 M4TH1EU's 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());
}
}
}
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(" ", "_");
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();
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(" ", "_");
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(" ", "_");
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;
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);
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<Path> files = new ArrayList<>();
try (Stream<Path> 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")) {
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;
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());
}
}
}
}
}
}

View File

@ -0,0 +1,43 @@
package ch.m4th1eu.flansupdater;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class Zip {
public static void unzip(File file) throws IOException {
String fileZip = file.getPath();
File destDir = new File(file.getPath());
byte[] buffer = new byte[1024];
ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
File newFile = newFile(destDir, zipEntry);
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
}
public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
File destFile = new File(destinationDir, zipEntry.getName());
String destDirPath = destinationDir.getCanonicalPath();
String destFilePath = destFile.getCanonicalPath();
if (!destFilePath.startsWith(destDirPath + File.separator)) {
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
}
return destFile;
}
}

BIN
src/main/resources/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane style="-fx-background-color: #303030;" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.m4th1eu.flansupdater.Controller">
<Label layoutX="386.0" layoutY="357.0" text="Flans Updater - Developped by M4TH1EU_" textFill="WHITE">
<font>
<Font size="11.0" fx:id="x3" />
</font>
</Label>
<Button fx:id="bug" layoutX="182.0" layoutY="290.0" mnemonicParsing="false" prefHeight="30.0" prefWidth="126.0" style="-fx-background-color: transparent; -fx-border-color: white;" text="Signaler un bug" textFill="WHITE" />
<Button fx:id="idea" layoutX="333.0" layoutY="290.0" mnemonicParsing="false" prefHeight="30.0" prefWidth="126.0" style="-fx-background-color: transparent; -fx-border-color: white;" text="Une idée ?" textFill="WHITE" />
<Separator layoutY="347.0" prefHeight="16.0" prefWidth="640.0" />
<Button fx:id="convertir" layoutX="197.0" layoutY="179.0" mnemonicParsing="false" prefHeight="48.0" prefWidth="252.0" style="-fx-background-color: transparent; -fx-border-color: white; -fx-border-width: 2;" text="Mettre à jour mon pack" textFill="WHITE">
<font>
<Font size="20.0" />
</font>
</Button>
<Button fx:id="selectpack" layoutX="347.0" layoutY="130.0" mnemonicParsing="false" prefHeight="21.0" prefWidth="101.0" style="-fx-background-color: transparent; -fx-border-color: white;" text="Choisir un pack" textFill="WHITE" />
<TextField fx:id="packname" layoutX="196.0" layoutY="130.0" prefHeight="27.0" prefWidth="149.0" style="-fx-background-color: transparent; -fx-border-color: white; -fx-text-fill: white" />
<Label layoutX="197.0" layoutY="111.0" text="Nom du pack" textFill="WHITE" />
<ImageView fitHeight="135.0" fitWidth="437.0" layoutX="103.0" layoutY="-2.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@logo_transparent.png" />
</image>
</ImageView>
</AnchorPane>

View File

@ -0,0 +1,76 @@
{
"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.80,
0.80,
0.80
]
},
"thirdperson_righthand": {
"rotation": [
0,
90,
-35
],
"translation": [
0,
1.25,
-2.5
],
"scale": [
0.80,
0.80,
0.80
]
},
"firstperson_lefthand": {
"rotation": [
0,
-45,
25
],
"translation": [
0,
4,
2
],
"scale": [
0.80,
0.80,
0.80
]
},
"firstperson_righthand": {
"rotation": [
0,
-45,
25
],
"translation": [
0,
4,
2
],
"scale": [
0.80,
0.80,
0.80
]
}
}
}