Skip to content

Commit e17502c

Browse files
committed
allow unsafe injection of lua files
1 parent 9bbab58 commit e17502c

File tree

1 file changed

+41
-4
lines changed
  • de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests

1 file changed

+41
-4
lines changed

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@
4545
import java.nio.charset.StandardCharsets;
4646
import java.nio.file.Path;
4747
import java.nio.file.Paths;
48+
import java.nio.file.StandardOpenOption;
4849
import java.time.Duration;
49-
import java.util.List;
50-
import java.util.Objects;
51-
import java.util.Optional;
52-
import java.util.Set;
50+
import java.util.*;
5351
import java.util.concurrent.CompletableFuture;
5452
import java.util.concurrent.atomic.AtomicReference;
5553
import java.util.stream.Collectors;
@@ -477,6 +475,7 @@ protected void injectMapData(WurstGui gui, Optional<File> testMap, CompilationRe
477475
String mapScriptName;
478476
if (runArgs.isLua()) {
479477
mapScriptName = "war3map.lua";
478+
injectExternalLuaFiles(result.script);
480479
} else {
481480
mapScriptName = "war3map.j";
482481
}
@@ -490,4 +489,42 @@ protected void injectMapData(WurstGui gui, Optional<File> testMap, CompilationRe
490489
mpqEditor.insertFile(mapScriptName, result.script);
491490
}
492491
}
492+
493+
private void injectExternalLuaFiles(File script) {
494+
File luaDir;
495+
try {
496+
luaDir = new File(workspaceRoot.getFile(), "lua");
497+
} catch (FileNotFoundException e) {
498+
throw new RuntimeException("Cannot get build dir", e);
499+
}
500+
if (luaDir.exists()) {
501+
File[] children = luaDir.listFiles();
502+
if (children != null) {
503+
Arrays.stream(children).forEach(child -> {
504+
try {
505+
byte[] bytes = java.nio.file.Files.readAllBytes(child.toPath());
506+
if (child.getName().startsWith("pre_")) {
507+
byte[] existingBytes = java.nio.file.Files.readAllBytes(script.toPath());
508+
java.nio.file.Files.write(
509+
script.toPath(),
510+
bytes);
511+
java.nio.file.Files.write(
512+
script.toPath(),
513+
existingBytes,
514+
StandardOpenOption.APPEND);
515+
} else {
516+
java.nio.file.Files.write(
517+
script.toPath(),
518+
bytes,
519+
StandardOpenOption.APPEND);
520+
}
521+
} catch (IOException e) {
522+
throw new RuntimeException(e);
523+
}
524+
});
525+
}
526+
}
527+
}
528+
529+
493530
}

0 commit comments

Comments
 (0)