Progress bar to indicate scanned mods

This commit is contained in:
Johannes Frohnmeyer 2022-01-02 18:37:31 +01:00
parent 66241d5631
commit 0040e7bd65
Signed by: Johannes
GPG Key ID: E76429612C2929F4
3 changed files with 21 additions and 2 deletions

View File

@ -34,7 +34,7 @@ public class HttpUtils {
public Request(Method method, String url) {
this.url = url.replace(" ", "%20");
try {
this.builder = HttpRequest.newBuilder().uri(new URI(this.url)).header("User-Agent", "Meteor Client");
this.builder = HttpRequest.newBuilder().uri(new URI(this.url)).header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
this.method = method;
} catch (URISyntaxException e) {
Inceptum.LOGGER.error("Could not create request", e);

View File

@ -17,6 +17,7 @@ import java.util.*;
public class ModsDirScanner implements Closeable {
private final Map<Path, IWModDescription> descriptions = new HashMap<>();
private final Set<Path> scannedPaths = new HashSet<>();
private final Thread th;
private final Path modsDir;
private final InstanceMeta instance;
@ -59,6 +60,11 @@ public class ModsDirScanner implements Closeable {
public void invalidate(Path path) {
descriptions.remove(path);
scannedPaths.remove(path);
}
public boolean hasScanned(Path path) {
return scannedPaths.contains(path);
}
private void scanTaskInternal() {
@ -73,6 +79,7 @@ public class ModsDirScanner implements Closeable {
if (disposed) return;
if (Files.isDirectory(mods)) {
descriptions.put(mods, new IWModDescription(mods));
scannedPaths.add(mods);
} else {
if (mods.toString().endsWith(".jar") || mods.toString().endsWith(".jar.disabled")) {
final var imod = new Object() {
@ -89,6 +96,7 @@ public class ModsDirScanner implements Closeable {
imod.md = Utils.loadObject(imod.i, ModDescription.class);
});
descriptions.put(imod.i, new IWModDescription(mods, Optional.of(imod.md), getFmj(mods, imod.md), Optional.of(imod.i)));
scannedPaths.add(mods);
}
else if (mods.toString().endsWith(".imod") || mods.toString().endsWith(".imod.disabled")) {
//TODO ensure this is not called while downloading a pack
@ -103,9 +111,11 @@ public class ModsDirScanner implements Closeable {
imod.md = Utils.loadObject(imod.i, ModDescription.class);
});
descriptions.put(imod.i, new IWModDescription(imod.i, Optional.of(imod.md), getFmj(modFile, imod.md), Optional.of(imod.i)));
scannedPaths.add(mods);
}
else {
descriptions.put(mods, new IWModDescription(mods));
scannedPaths.add(mods);
}
}
}

View File

@ -112,7 +112,11 @@ public class InstanceEditWindow extends Window {
try {
Set<ModsDirScanner.IWModDescription> modSet = mds.getMods();
boolean updatesFound = false;
float scannedPercentage = 0;
boolean hasUnScanned = false;
for (ModsDirScanner.IWModDescription mod : modSet) {
if (mds.hasScanned(mod.path())) scannedPercentage++;
else hasUnScanned = true;
if (mod.mod().isEmpty()) continue;
for (Optional<ModSource> value : mod.mod().get().sources.values()) {
if (value.isPresent()) {
@ -123,6 +127,8 @@ public class InstanceEditWindow extends Window {
break;
}
}
scannedPercentage /= modSet.size();
if (hasUnScanned) ImGui.progressBar(scannedPercentage);
if (updatesFound)
ImGui.checkbox("Updatable", filterUpdates);
else
@ -166,7 +172,7 @@ public class InstanceEditWindow extends Window {
ImGui.beginGroup();
if (selected == null) {
ImGui.text("Select a mod to view settings");
} else {
} else if (mds.hasScanned(selected)) {
ModsDirScanner.IWModDescription md = mds.get(selected);
ImGui.text(md.getName());
ImGui.separator();
@ -216,6 +222,9 @@ public class InstanceEditWindow extends Window {
}
}
}
else {
ImGui.text("This mod has not yet been scanned, please be patient");
}
ImGui.endGroup();
ImGui.endTabItem();
}