Combine classes.js and eagswebrtc.js for replits & add some helper batch files

This commit is contained in:
ayunami2000 2022-08-26 11:20:40 -04:00
parent 32d063bfa7
commit eb0c7cb961
8 changed files with 78 additions and 11 deletions

3
.gitignore vendored
View File

@ -31,3 +31,6 @@ sp-relay/out
sp-relay/test sp-relay/test
sp-relay/.idea sp-relay/.idea
sp-relay/src/main/java/META-INF sp-relay/src/main/java/META-INF
zip-generator/zip-generator.iml
zip-generator/out
zip-generator/src/main/java/META-INF

Binary file not shown.

5
zip-generator/run.bat Normal file
View File

@ -0,0 +1,5 @@
@echo off
title zip-generator
cd ..
java -jar zip-generator/zipGenerator.jar
pause

View File

@ -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

View File

@ -0,0 +1,2 @@
#!/bin/sh
java -jar zip-generator/zipGenerator.jar

View File

@ -97,34 +97,72 @@ public class ZipGenerator {
System.out.println("Writing 'stable-download/stable-download_repl.zip'"); 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 { 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 { 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()) { for(File f : file.listFiles()) {
if(f.isDirectory()) { 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()) { }else if(f.isFile()) {
String path = f.getAbsolutePath().replace('\\', '/').replace(pfx, ""); String path = f.getAbsolutePath().replace('\\', '/').replace(pfx, "");
if(path.startsWith("/")) { if(path.startsWith("/")) {
path = path.substring(1); path = path.substring(1);
} }
if(writePfx.length() > 0 && !writePfx.endsWith("/")) { if (repl && (f.getName().equals("classes.js") || f.getName().equals("eagswebrtc.js"))) {
writePfx = writePfx + "/"; 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 { 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)); zOut.putNextEntry(new ZipEntry(name));
IOUtils.write(FileUtils.readFileToByteArray(file), zOut); IOUtils.write(data, zOut);
} }
} }

Binary file not shown.