mirror of
https://github.com/lax1dude/eagler-binary-tools.git
synced 2024-11-21 17:06:04 -08:00
Better directory support for EBP encoder/decoder
This commit is contained in:
parent
5dd00ca113
commit
4fc0a8d63f
|
@ -3,8 +3,10 @@ package net.lax1dude.eaglercraft.bintools;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
@ -36,27 +38,14 @@ public class EBPFileDecoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void _main(String[] args) throws IOException {
|
public static void _main(String[] args) throws IOException {
|
||||||
if(args.length == 1) {
|
if(args.length > 1 && args.length < 4 && args[0].equals("-r")) {
|
||||||
File input = new File(args[0]);
|
File input = new File(args[1]);
|
||||||
if(!input.isDirectory()) {
|
if(!input.isDirectory()) {
|
||||||
System.err.println("Error: Not a directory: " + input.getAbsolutePath());
|
System.err.println("Error: Not a directory: " + input.getAbsolutePath());
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File[] f = input.listFiles();
|
convertDir(input, args.length == 3 ? new File(args[2]) : input);
|
||||||
for(int i = 0; i < f.length; ++i) {
|
|
||||||
String name = f[i].getAbsolutePath();
|
|
||||||
if(!name.toLowerCase().endsWith(".ebp")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
File ff = new File(name.substring(0, name.length() - 3) + "png");
|
|
||||||
System.out.println(f[i].getName());
|
|
||||||
BufferedImage img;
|
|
||||||
try(InputStream is = new FileInputStream(f[i])) {
|
|
||||||
img = read(is);
|
|
||||||
}
|
|
||||||
ImageIO.write(img, "PNG", ff);
|
|
||||||
}
|
|
||||||
}else if(args.length == 2) {
|
}else if(args.length == 2) {
|
||||||
System.out.println("Reading input file...");
|
System.out.println("Reading input file...");
|
||||||
BufferedImage img;
|
BufferedImage img;
|
||||||
|
@ -68,7 +57,31 @@ public class EBPFileDecoder {
|
||||||
ImageIO.write(img, "PNG", output);
|
ImageIO.write(img, "PNG", output);
|
||||||
}else {
|
}else {
|
||||||
System.out.println("Usage: ebp-decode <input file> <output file>");
|
System.out.println("Usage: ebp-decode <input file> <output file>");
|
||||||
System.out.println(" ebp-decode <directory>");
|
System.out.println(" ebp-decode -r <directory> [output directory]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void convertDir(File inputDir, File outputDir) throws IOException {
|
||||||
|
if(!outputDir.isDirectory() && !outputDir.mkdirs()) {
|
||||||
|
throw new IOException("Could not create directory: " + outputDir.getAbsolutePath());
|
||||||
|
}
|
||||||
|
File[] f = inputDir.listFiles();
|
||||||
|
for(int i = 0; i < f.length; ++i) {
|
||||||
|
String name = f[i].getName();
|
||||||
|
if(f[i].isDirectory()) {
|
||||||
|
convertDir(f[i], new File(outputDir, name));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!name.toLowerCase().endsWith(".ebp")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
File ff = new File(outputDir, name.substring(0, name.length() - 3) + "png");
|
||||||
|
System.out.println(f[i].getAbsolutePath());
|
||||||
|
BufferedImage img;
|
||||||
|
try(InputStream is = new FileInputStream(f[i])) {
|
||||||
|
img = read(is);
|
||||||
|
}
|
||||||
|
ImageIO.write(img, "PNG", ff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,25 +40,14 @@ public class EBPFileEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void _main(String[] args) throws IOException {
|
public static void _main(String[] args) throws IOException {
|
||||||
if(args.length == 1) {
|
if(args.length > 1 && args.length < 4 && args[0].equals("-r")) {
|
||||||
File input = new File(args[0]);
|
File input = new File(args[1]);
|
||||||
if(!input.isDirectory()) {
|
if(!input.isDirectory()) {
|
||||||
System.err.println("Error: Not a directory: " + input.getAbsolutePath());
|
System.err.println("Error: Not a directory: " + input.getAbsolutePath());
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File[] f = input.listFiles();
|
convertDir(input, args.length == 3 ? new File(args[2]) : input);
|
||||||
for(int i = 0; i < f.length; ++i) {
|
|
||||||
String name = f[i].getAbsolutePath();
|
|
||||||
if(!name.toLowerCase().endsWith(".png")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
File ff = new File(name.substring(0, name.length() - 3) + "ebp");
|
|
||||||
System.out.println(f[i].getName());
|
|
||||||
try(OutputStream os = new FileOutputStream(ff)) {
|
|
||||||
write(ImageIO.read(f[i]), os);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else if(args.length == 2) {
|
}else if(args.length == 2) {
|
||||||
System.out.println("Reading input file...");
|
System.out.println("Reading input file...");
|
||||||
BufferedImage img = ImageIO.read(new File(args[0]));
|
BufferedImage img = ImageIO.read(new File(args[0]));
|
||||||
|
@ -69,7 +58,29 @@ public class EBPFileEncoder {
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
System.out.println("Usage: ebp-encode <input file> <output file>");
|
System.out.println("Usage: ebp-encode <input file> <output file>");
|
||||||
System.out.println(" ebp-encode <directory>");
|
System.out.println(" ebp-encode -r <directory> [output directory]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void convertDir(File inputDir, File outputDir) throws IOException {
|
||||||
|
if(!outputDir.isDirectory() && !outputDir.mkdirs()) {
|
||||||
|
throw new IOException("Could not create directory: " + outputDir.getAbsolutePath());
|
||||||
|
}
|
||||||
|
File[] f = inputDir.listFiles();
|
||||||
|
for(int i = 0; i < f.length; ++i) {
|
||||||
|
String name = f[i].getName();
|
||||||
|
if(f[i].isDirectory()) {
|
||||||
|
convertDir(f[i], new File(outputDir, name));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!name.toLowerCase().endsWith(".png")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
File ff = new File(outputDir, name.substring(0, name.length() - 3) + "ebp");
|
||||||
|
System.out.println(f[i].getAbsolutePath());
|
||||||
|
try(OutputStream os = new FileOutputStream(ff)) {
|
||||||
|
write(ImageIO.read(f[i]), os);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user