diff --git a/.gitignore b/.gitignore index 92c6fd0..d79290a 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ sp-relay/out sp-relay/test sp-relay/.idea sp-relay/src/main/java/META-INF +zip-generator/zip-generator.iml +zip-generator/out +zip-generator/src/main/java/META-INF diff --git a/stable-download/stable-download.zip b/stable-download/stable-download.zip index 88de0cc..eb2f22e 100644 Binary files a/stable-download/stable-download.zip and b/stable-download/stable-download.zip differ diff --git a/stable-download/stable-download_repl.zip b/stable-download/stable-download_repl.zip index 88de0cc..3263f00 100644 Binary files a/stable-download/stable-download_repl.zip and b/stable-download/stable-download_repl.zip differ diff --git a/zip-generator/run.bat b/zip-generator/run.bat new file mode 100644 index 0000000..b7e3c7d --- /dev/null +++ b/zip-generator/run.bat @@ -0,0 +1,5 @@ +@echo off +title zip-generator +cd .. +java -jar zip-generator/zipGenerator.jar +pause \ No newline at end of file diff --git a/zip-generator/run_path.bat b/zip-generator/run_path.bat new file mode 100644 index 0000000..09582e5 --- /dev/null +++ b/zip-generator/run_path.bat @@ -0,0 +1,19 @@ +@echo off +setlocal enabledelayedexpansion +title zip-generator +cd .. +echo enter the path to your java 11 installation (or leave blank to assume it is the default): +SET /P "JAVA11PATH=" +if "!JAVA11PATH!" neq "" ( + set "JAVA11PATH=!JAVA11PATH:\=/!" + if "!JAVA11PATH:~-1!" neq "/" ( + set "JAVA11PATH=!JAVA11PATH!/" + ) + if "!JAVA11PATH:~-5!" neq "/bin/" ( + set "JAVA11PATH=!JAVA11PATH!bin/" + ) +) +echo Using java at: "!JAVA11PATH!java" +"!JAVA11PATH!java" -jar zip-generator/zipGenerator.jar +endlocal +pause \ No newline at end of file diff --git a/zip-generator/run_unix.sh b/zip-generator/run_unix.sh new file mode 100644 index 0000000..435b70b --- /dev/null +++ b/zip-generator/run_unix.sh @@ -0,0 +1,2 @@ +#!/bin/sh +java -jar zip-generator/zipGenerator.jar \ No newline at end of file diff --git a/zip-generator/src/main/java/net/lax1dude/eaglercraft/zip_generator/ZipGenerator.java b/zip-generator/src/main/java/net/lax1dude/eaglercraft/zip_generator/ZipGenerator.java index 1804c02..fd1017b 100644 --- a/zip-generator/src/main/java/net/lax1dude/eaglercraft/zip_generator/ZipGenerator.java +++ b/zip-generator/src/main/java/net/lax1dude/eaglercraft/zip_generator/ZipGenerator.java @@ -96,35 +96,73 @@ public class ZipGenerator { zOut.close(); System.out.println("Writing 'stable-download/stable-download_repl.zip'"); - - FileUtils.copyFile(new File("stable-download/stable-download.zip"), new File("stable-download/stable-download_repl.zip")); + + ZipOutputStream zOutRepl = new ZipOutputStream(new FileOutputStream(new File("stable-download/stable-download_repl.zip"))); + zOutRepl.setLevel(9); + + zipFolder(zOutRepl, "web", new File("stable-download/web"), true); + zipFolder(zOutRepl, "java", new File("stable-download/java")); + + zOutRepl.close(); } - + private static void zipFolder(ZipOutputStream zOut, String pfx, File file) throws IOException { - zipFolder0(zOut, file.getAbsolutePath().replace('\\', '/'), pfx, file); + zipFolder(zOut, pfx, file, false); } - + + private static void zipFolder(ZipOutputStream zOut, String pfx, File file, boolean repl) throws IOException { + zipFolder0(zOut, file.getAbsolutePath().replace('\\', '/'), pfx, file, repl); + } + private static void zipFolder0(ZipOutputStream zOut, String pfx, String writePfx, File file) throws IOException { + zipFolder0(zOut, pfx, writePfx, file, false); + } + + private static void zipFolder0(ZipOutputStream zOut, String pfx, String writePfx, File file, boolean repl) throws IOException { + byte[] replCache = new byte[0]; + if(writePfx.length() > 0 && !writePfx.endsWith("/")) { + writePfx = writePfx + "/"; + } for(File f : file.listFiles()) { if(f.isDirectory()) { - zipFolder0(zOut, pfx, writePfx, f); + zipFolder0(zOut, pfx, writePfx, f); // do not apply repl boolean to subdirs, as it only happens for this one top level directory in the web folder }else if(f.isFile()) { String path = f.getAbsolutePath().replace('\\', '/').replace(pfx, ""); if(path.startsWith("/")) { path = path.substring(1); } - if(writePfx.length() > 0 && !writePfx.endsWith("/")) { - writePfx = writePfx + "/"; + if (repl && (f.getName().equals("classes.js") || f.getName().equals("eagswebrtc.js"))) { + if (replCache.length == 0) { + replCache = FileUtils.readFileToByteArray(f); + } else { + System.out.println("Concatenating 'eagswebrtc.js' onto 'classes.js'"); + byte[] newFile = FileUtils.readFileToByteArray(f); + byte[] replCacheCache = replCache; + replCache = new byte[replCache.length + 2 + newFile.length]; + System.arraycopy(replCacheCache, 0, replCache, 0, replCacheCache.length); + System.arraycopy(newFile, 0, replCache, replCacheCache.length + 2, newFile.length); + // add line breaks between them + replCache[replCacheCache.length] = 10; + replCache[replCacheCache.length + 1] = 10; + } + } else { + zipFile(zOut, writePfx + path, f); } - zipFile(zOut, writePfx + path, f); } } + if (repl) { + zipFile(zOut, writePfx + "classes.js", replCache); + } } - + private static void zipFile(ZipOutputStream zOut, String name, File file) throws IOException { + zipFile(zOut, name, FileUtils.readFileToByteArray(file)); + } + + private static void zipFile(ZipOutputStream zOut, String name, byte[] data) throws IOException { zOut.putNextEntry(new ZipEntry(name)); - IOUtils.write(FileUtils.readFileToByteArray(file), zOut); + IOUtils.write(data, zOut); } } diff --git a/zip-generator/zipGenerator.jar b/zip-generator/zipGenerator.jar index b8bdd32..c92ae83 100644 Binary files a/zip-generator/zipGenerator.jar and b/zip-generator/zipGenerator.jar differ