|
@@ -5,7 +5,11 @@ import java.io.File;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.lang.reflect.Array;
|
|
|
import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
+import java.nio.file.attribute.FileAttribute;
|
|
|
+import java.nio.file.attribute.PosixFilePermission;
|
|
|
+import java.nio.file.attribute.PosixFilePermissions;
|
|
|
import java.time.ZonedDateTime;
|
|
|
import java.util.List;
|
|
|
import java.util.ArrayList;
|
|
@@ -24,6 +28,9 @@ import me.hammerle.snuviscript.config.SnuviConfig;
|
|
|
import me.hammerle.snuviscript.inputprovider.Variable;
|
|
|
|
|
|
public class FunctionRegistry {
|
|
|
+ public static final FileAttribute<Set<PosixFilePermission>> FILE_ACCESS =
|
|
|
+ PosixFilePermissions.asFileAttribute(
|
|
|
+ PosixFilePermissions.fromString("rwxrwxrwx"));
|
|
|
private static final HashMap<String, Object> GLOBAL_VARS = new HashMap<>();
|
|
|
private static final HashMap<String, NamedFunction> FUNCTIONS = new HashMap<>();
|
|
|
|
|
@@ -354,16 +361,16 @@ public class FunctionRegistry {
|
|
|
(sc, in) -> Files.readAllLines(((File) in[0].get(sc)).toPath()));
|
|
|
registerConsumer("file.write", (sc, in) -> {
|
|
|
File f = (File) in[0].get(sc);
|
|
|
- if(f.getParentFile() != null) {
|
|
|
- f.getParentFile().mkdirs();
|
|
|
- }
|
|
|
+ Path p = Paths.get(f.toURI());
|
|
|
if(!f.exists()) {
|
|
|
- f.createNewFile();
|
|
|
+ Files.createFile(p, FILE_ACCESS);
|
|
|
}
|
|
|
- Files.write(
|
|
|
- Paths.get(f.toURI()), ((List<Object>) in[1].get(sc)).stream()
|
|
|
- .map(o -> String.valueOf(o)).collect(Collectors.toList()),
|
|
|
- StandardCharsets.UTF_8);
|
|
|
+ Files.write(p, ((List<Object>) in[1].get(sc)).stream().map(o -> String.valueOf(o))
|
|
|
+ .collect(Collectors.toList()), StandardCharsets.UTF_8);
|
|
|
+ });
|
|
|
+ registerConsumer("file.createfolder", (sc, in) -> {
|
|
|
+ File f = (File) in[0].get(sc);
|
|
|
+ Files.createDirectory(Paths.get(f.toURI()), FILE_ACCESS);
|
|
|
});
|
|
|
registerFunction("config.new",
|
|
|
(sc, in) -> new SnuviConfig(in[0].getString(sc), in[1].getString(sc)));
|