Iris/src/main/java/com/volmit/iris/util/ReactiveFolder.java
2021-07-14 02:34:13 -04:00

58 lines
1.6 KiB
Java

package com.volmit.iris.util;
import java.io.File;
public class ReactiveFolder {
private final File folder;
private final Consumer3<KList<File>, KList<File>, KList<File>> hotload;
private FolderWatcher fw;
public ReactiveFolder(File folder, Consumer3<KList<File>, KList<File>, KList<File>> hotload) {
this.folder = folder;
this.hotload = hotload;
this.fw = new FolderWatcher(folder);
fw.checkModified();
}
public void checkIgnore() {
fw = new FolderWatcher(folder);
}
public void check() {
boolean modified = false;
if (fw.checkModified()) {
for (File i : fw.getCreated()) {
if (i.getName().endsWith(".iob") || i.getName().endsWith(".json")) {
modified = true;
break;
}
}
if (!modified) {
for (File i : fw.getChanged()) {
if (i.getName().endsWith(".iob") || i.getName().endsWith(".json")) {
modified = true;
break;
}
}
}
if (!modified) {
for (File i : fw.getDeleted()) {
if (i.getName().endsWith(".iob") || i.getName().endsWith(".json")) {
modified = true;
break;
}
}
}
}
if (modified) {
hotload.accept(fw.getCreated(), fw.getChanged(), fw.getDeleted());
}
fw.checkModified();
}
}