Release 1.0 and 1.1

This commit is contained in:
Mathieu Broillet 2020-01-05 13:09:53 +01:00
parent 9d2435b2a6
commit ef26b6ecd4
8 changed files with 195 additions and 45 deletions

View File

@ -1,17 +1,27 @@
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.github.jengelman.gradle.plugins:shadow:4.0.4"
}
}
plugins { plugins {
id 'java' id 'java'
} }
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
group 'flansupdater' group 'flansupdater'
version '1.0-SNAPSHOT' version '1.1'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8
mainClassName = 'ch.m4th1eu.flansupdater.Main'
compileJava.options.encoding = 'UTF-8' compileJava.options.encoding = 'UTF-8'
repositories { repositories {
@ -22,17 +32,13 @@ dependencies {
compile group: 'commons-io', name: 'commons-io', version: '2.4' compile group: 'commons-io', name: 'commons-io', version: '2.4'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6' compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile group: 'net.lingala.zip4j', name: 'zip4j', version: '2.2.8' compile group: 'net.lingala.zip4j', name: 'zip4j', version: '2.2.8'
testCompile "junit:junit:4.12" implementation 'org.zeroturnaround:zt-zip:1.13'
} }
jar { jar {
baseName = 'flans-updater' baseName = 'flans-updater'
version = '0.1' version = '0.1'
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest { manifest {
attributes( attributes(
'Main-Class': 'ch.m4th1eu.flansupdater.Main' 'Main-Class': 'ch.m4th1eu.flansupdater.Main'

37
docs/README.md Normal file
View File

@ -0,0 +1,37 @@
## Welcome to GitHub Pages
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.

View File

@ -4,6 +4,7 @@ import javafx.application.Platform;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.exception.ZipException;
@ -13,6 +14,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Optional;
import static ch.m4th1eu.flansupdater.Main.primaryStage; import static ch.m4th1eu.flansupdater.Main.primaryStage;
@ -40,8 +42,8 @@ public class Controller {
registerHoverableButton(convertir); registerHoverableButton(convertir);
registerHoverableButton(selectpack); registerHoverableButton(selectpack);
registerLinkableButton(bug, "xyz"); registerLinkableButton(bug, "https://github.com/M4TH1EU/Flan-s-Mod-Updater/issues/new?assignees=&labels=&template=bug_report.md&title=");
registerLinkableButton(idea, "xyz"); registerLinkableButton(idea, "https://github.com/M4TH1EU/Flan-s-Mod-Updater/issues/new?assignees=&labels=&template=feature_request.md&title=");
packname.setEditable(false); packname.setEditable(false);
convertir.setDisable(true); convertir.setDisable(true);
@ -58,34 +60,42 @@ public class Controller {
convertir.setText("Extraction du pack..."); convertir.setText("Extraction du pack...");
}); });
new ZipFile(selectedFile).extractAll(selectedFile.getParent() + "\\"); new ZipFile(selectedFile).extractAll(selectedFile.getParent() + "\\dontTouch\\");
} catch (ZipException e) { } catch (ZipException e) {
e.printStackTrace(); e.printStackTrace();
Platform.runLater(() -> convertir.setText("Erreur, extraction échouée !")); Platform.runLater(() -> convertir.setText("Erreur, extraction échouée !"));
} }
java.lang.String[] args = new java.lang.String[]{selectedFile.getParent()}; String[] args = new String[]{selectedFile.getParent() + "\\dontTouch", selectedFile.getName()};
try { try {
Platform.runLater(() -> convertir.setText("Mise à jour...")); Platform.runLater(() -> convertir.setText("Mise à jour..."));
Updater.main(args); Updater.main(args);
Platform.runLater(() -> convertir.setText("Terminé !")); Platform.runLater(() -> convertir.setText("Terminé !"));
} catch (Exception e) { } catch (Exception e) {
Platform.runLater(() -> convertir.setText("Erreur, mise à jour échoué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 { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
Platform.runLater(() -> { Platform.runLater(() -> {
selectpack.setDisable(false); packname.setText("");
selectpack.setText("");
selectedFile = new File(""); selectedFile = new File("");
convertir.setText("Mettre à jour mon pack"); convertir.setText("Mettre à jour mon pack");
convertir.setDisable(false); convertir.setDisable(false);
packname.setDisable(false); packname.setDisable(false);
selectpack.setDisable(false);
}); });
}).start(); }).start();

View File

@ -1,8 +1,6 @@
/** /**
*
* @author Mathieu Broillet (M4TH1EU_#0001 (on discord)) * @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 * @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. * @important This program is not meant to be very pretty or well coded.
* It just works, that's all we ask. * It just works, that's all we ask.
*/ */
@ -11,7 +9,9 @@ package ch.m4th1eu.flansupdater;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.zeroturnaround.zip.ZipUtil;
import java.io.*; import java.io.*;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -27,9 +27,11 @@ public class Updater {
private static File MODEL_FILE = new File(""); private static File MODEL_FILE = new File("");
private static String PATH = null; private static String PATH = null;
private static String ZIP_FILE_NAME = null;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
PATH = args[0]; PATH = args[0];
ZIP_FILE_NAME = args[1];
ArrayList<Path> files = new ArrayList<>(); ArrayList<Path> files = new ArrayList<>();
@ -49,7 +51,7 @@ public class Updater {
printWriter.println("{\n" + printWriter.println("{\n" +
" \"pack\": {\n" + " \"pack\": {\n" +
" \"pack_format\": 1,\n" + " \"pack_format\": 1,\n" +
" \"description\": \"Generated by M4TH1EU's Flans Updater.\"\n" + " \"description\": \"Generated by Flans Updater.\"\n" +
" }\n" + " }\n" +
"}"); "}");
printWriter.close(); printWriter.close();
@ -124,9 +126,31 @@ public class Updater {
} }
} }
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"); System.out.println("UPDATED SUCCESSFULLY");
} }
public static boolean hasModel(Path filePath) { public static boolean hasModel(Path filePath) {
return new File(PATH + "\\assets\\flansmod\\models\\item\\" + filePath.getFileName().toString().replaceAll(".txt", ".json")).exists(); return new File(PATH + "\\assets\\flansmod\\models\\item\\" + filePath.getFileName().toString().replaceAll(".txt", ".json")).exists();
} }
@ -152,6 +176,7 @@ public class Updater {
String[] parts = strLine.split(" "); String[] parts = strLine.split(" ");
String oldName = "ShortName " + parts[1]; String oldName = "ShortName " + parts[1];
String newName = "ShortName " + parts[1].toLowerCase().replaceAll(" ", "_"); 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"); MODEL_FILE = new File(filePath.getParent().getParent() + "\\assets\\flansmod\\models\\item\\" + parts[1].toLowerCase().replaceAll(" ", "_") + ".json");
modifyFile(String.valueOf(filePath), oldName, newName); modifyFile(String.valueOf(filePath), oldName, newName);
} }
@ -159,18 +184,22 @@ public class Updater {
String[] parts = strLine.split(" "); String[] parts = strLine.split(" ");
String oldName = "ArmourTexture " + parts[1]; String oldName = "ArmourTexture " + parts[1];
String newName = "ArmourTexture " + parts[1].toLowerCase(); String newName = "ArmourTexture " + parts[1].toLowerCase();
System.out.println(oldName + " -> " + newName);
modifyFile(String.valueOf(filePath), oldName, newName); modifyFile(String.valueOf(filePath), oldName, newName);
} }
if (strLine.contains("Texture")) { if (strLine.contains("Texture")) {
String[] parts = strLine.split(" "); String[] parts = strLine.split(" ");
String oldName = "Texture " + parts[1]; String oldName = "Texture " + parts[1];
String newName = "Texture " + parts[1].toLowerCase().replaceAll(" ", "_"); String newName = "Texture " + parts[1].toLowerCase().replaceAll(" ", "_");
System.out.println(oldName + " -> " + newName);
modifyFile(String.valueOf(filePath), oldName, newName); modifyFile(String.valueOf(filePath), oldName, newName);
} }
if (strLine.contains("Icon")) { if (strLine.contains("Icon")) {
String[] parts = strLine.split(" "); String[] parts = strLine.split(" ");
String oldName = "Icon " + parts[1]; String oldName = "Icon " + parts[1];
String newName = "Icon " + parts[1].toLowerCase().replaceAll(" ", "_"); String newName = "Icon " + parts[1].toLowerCase().replaceAll(" ", "_");
System.out.println(oldName + " -> " + newName);
ICON_NAME = parts[1].toLowerCase().replaceAll(" ", "_"); ICON_NAME = parts[1].toLowerCase().replaceAll(" ", "_");
modifyFile(String.valueOf(filePath), oldName, newName); modifyFile(String.valueOf(filePath), oldName, newName);
} }
@ -202,6 +231,7 @@ public class Updater {
if (jsonObject != null) { if (jsonObject != null) {
String oldIcon = jsonObject.getAsJsonObject("textures").get("layer0").getAsString(); String oldIcon = jsonObject.getAsJsonObject("textures").get("layer0").getAsString();
String newIcon = "flansmod:items/" + ICON_NAME; String newIcon = "flansmod:items/" + ICON_NAME;
System.out.println(oldIcon + " -> " + newIcon);
modifyFile(String.valueOf(filePath), oldIcon, newIcon); modifyFile(String.valueOf(filePath), oldIcon, newIcon);
} else { } else {
@ -281,6 +311,8 @@ public class Updater {
filePath.getParent().toFile().mkdirs(); filePath.getParent().toFile().mkdirs();
PrintWriter printWriter = new PrintWriter(filePath.toFile()); PrintWriter printWriter = new PrintWriter(filePath.toFile());
printWriter.println(theString); printWriter.println(theString);
System.out.println("Model " + filePath.toFile().getName() + "created.");
printWriter.close(); printWriter.close();
} }
@ -321,7 +353,7 @@ public class Updater {
} }
if (files.get(i).getParent().toString().endsWith("armorFiles")) { if (files.get(i).getParent().toString().endsWith("armorFiles") || files.get(i).getParent().toString().endsWith("vehicles")) {
if (files.get(i).getFileName().toString().endsWith(".txt")) { if (files.get(i).getFileName().toString().endsWith(".txt")) {
try { try {
// Open the file // Open the file
@ -351,6 +383,7 @@ public class Updater {
IOUtils.copy(inputStream, writer, Charset.forName("utf-8")); IOUtils.copy(inputStream, writer, Charset.forName("utf-8"));
String theString = writer.toString(); String theString = writer.toString();
theString = theString + "item." + id + ".name=" + name; theString = theString + "item." + id + ".name=" + name;
System.out.println("New lang entry : " + theString);
PrintWriter writer1 = new PrintWriter(LANG_FILE); PrintWriter writer1 = new PrintWriter(LANG_FILE);
writer1.println(theString); writer1.println(theString);

View File

@ -1,43 +1,107 @@
package ch.m4th1eu.flansupdater; package ch.m4th1eu.flansupdater;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream;
public class Zip { public class Zip {
public static void unzip(File file) throws IOException { private static String OUTPUT_ZIP_FILE = "C:\\MyFile.zip";
String fileZip = file.getPath(); private static String SOURCE_FOLDER = "C:\\testzip";
File destDir = new File(file.getPath()); List<String> fileList;
Zip() {
fileList = new ArrayList<String>();
}
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]; byte[] buffer = new byte[1024];
ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
ZipEntry zipEntry = zis.getNextEntry(); try {
while (zipEntry != null) {
File newFile = newFile(destDir, zipEntry); FileOutputStream fos = new FileOutputStream(zipFile);
FileOutputStream fos = new FileOutputStream(newFile); 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; int len;
while ((len = zis.read(buffer)) > 0) { while ((len = in.read(buffer)) > 0) {
fos.write(buffer, 0, len); zos.write(buffer, 0, len);
} }
in.close();
}
System.out.println("Files added");
zos.closeEntry();
//remember close it
zos.close();
fos.close(); fos.close();
zipEntry = zis.getNextEntry();
System.out.println("Done");
} catch (IOException ex) {
ex.printStackTrace();
} }
zis.closeEntry();
zis.close();
} }
public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { /**
File destFile = new File(destinationDir, zipEntry.getName()); * Traverse a directory and get all files,
* and add the file into fileList
*
* @param node file or directory
*/
public void generateFileList(File node) {
String destDirPath = destinationDir.getCanonicalPath(); //add file only
String destFilePath = destFile.getCanonicalPath(); if (node.isFile()) {
fileList.add(generateZipEntry(node.getAbsoluteFile().toString()));
if (!destFilePath.startsWith(destDirPath + File.separator)) {
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
} }
return destFile; 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);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB