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 {
id 'java'
}
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
group 'flansupdater'
version '1.0-SNAPSHOT'
version '1.1'
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'ch.m4th1eu.flansupdater.Main'
compileJava.options.encoding = 'UTF-8'
repositories {
@ -22,17 +32,13 @@ 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"
implementation 'org.zeroturnaround:zt-zip:1.13'
}
jar {
baseName = 'flans-updater'
version = '0.1'
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes(
'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.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;
@ -13,6 +14,7 @@ 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;
@ -40,8 +42,8 @@ public class Controller {
registerHoverableButton(convertir);
registerHoverableButton(selectpack);
registerLinkableButton(bug, "xyz");
registerLinkableButton(idea, "xyz");
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);
@ -58,34 +60,42 @@ public class Controller {
convertir.setText("Extraction du pack...");
});
new ZipFile(selectedFile).extractAll(selectedFile.getParent() + "\\");
new ZipFile(selectedFile).extractAll(selectedFile.getParent() + "\\dontTouch\\");
} catch (ZipException e) {
e.printStackTrace();
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 {
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(() -> {
selectpack.setDisable(false);
selectpack.setText("");
packname.setText("");
selectedFile = new File("");
convertir.setText("Mettre à jour mon pack");
convertir.setDisable(false);
packname.setDisable(false);
selectpack.setDisable(false);
});
}).start();

View File

@ -1,8 +1,6 @@
/**
*
* @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.
*/
@ -11,7 +9,9 @@ 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;
@ -27,9 +27,11 @@ public class Updater {
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<Path> files = new ArrayList<>();
@ -49,7 +51,7 @@ public class Updater {
printWriter.println("{\n" +
" \"pack\": {\n" +
" \"pack_format\": 1,\n" +
" \"description\": \"Generated by M4TH1EU's Flans Updater.\"\n" +
" \"description\": \"Generated by Flans Updater.\"\n" +
" }\n" +
"}");
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");
}
public static boolean hasModel(Path filePath) {
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 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);
}
@ -159,18 +184,22 @@ public class Updater {
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);
}
@ -202,6 +231,7 @@ public class Updater {
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 {
@ -281,6 +311,8 @@ public class Updater {
filePath.getParent().toFile().mkdirs();
PrintWriter printWriter = new PrintWriter(filePath.toFile());
printWriter.println(theString);
System.out.println("Model " + filePath.toFile().getName() + "created.");
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")) {
try {
// Open the file
@ -351,6 +383,7 @@ public class Updater {
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);

View File

@ -1,43 +1,107 @@
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.ZipInputStream;
import java.util.zip.ZipOutputStream;
public class Zip {
public static void unzip(File file) throws IOException {
String fileZip = file.getPath();
File destDir = new File(file.getPath());
private static String OUTPUT_ZIP_FILE = "C:\\MyFile.zip";
private static String SOURCE_FOLDER = "C:\\testzip";
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];
ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
File newFile = newFile(destDir, zipEntry);
FileOutputStream fos = new FileOutputStream(newFile);
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 = zis.read(buffer)) > 0) {
fos.write(buffer, 0, 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();
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();
String destFilePath = destFile.getCanonicalPath();
if (!destFilePath.startsWith(destDirPath + File.separator)) {
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
//add file only
if (node.isFile()) {
fileList.add(generateZipEntry(node.getAbsoluteFile().toString()));
}
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