mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-07-26 17:21:54 +03:00
[FEATURE] Implement ResourceLayer API
This commit is contained in:
parent
9844fc1abd
commit
9d3b3031cc
5 changed files with 61 additions and 3 deletions
|
@ -68,6 +68,7 @@ public class LauncherBackendImpl implements LauncherBackendAPI, TextureUploadExt
|
||||||
private volatile List<Java> availableJavas;
|
private volatile List<Java> availableJavas;
|
||||||
private volatile CompletableFuture<List<Java>> availableJavasFuture;
|
private volatile CompletableFuture<List<Java>> availableJavasFuture;
|
||||||
private volatile CompletableFuture<Void> processHardwareFuture;
|
private volatile CompletableFuture<Void> processHardwareFuture;
|
||||||
|
private volatile Path vfsRootPath;
|
||||||
private final Map<UUID, CompletableFuture<ServerPingInfo>> pingFutures = new ConcurrentHashMap<>();
|
private final Map<UUID, CompletableFuture<ServerPingInfo>> pingFutures = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -315,6 +316,14 @@ public boolean isTestMode() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLayer makeResourceLayer(List<Path> overlayList) {
|
||||||
|
if(vfsRootPath == null) {
|
||||||
|
vfsRootPath = initVfsDirectory();
|
||||||
|
}
|
||||||
|
return new ResourceLayerImpl(vfsRootPath, overlayList);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T extends Extension> T getExtension(Class<T> clazz) {
|
public <T extends Extension> T getExtension(Class<T> clazz) {
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package pro.gravit.launcher.runtime.backend;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.base.vfs.Vfs;
|
||||||
|
import pro.gravit.launcher.base.vfs.VfsDirectory;
|
||||||
|
import pro.gravit.launcher.base.vfs.directory.OverlayVfsDirectory;
|
||||||
|
import pro.gravit.launcher.core.backend.LauncherBackendAPI;
|
||||||
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class ResourceLayerImpl implements LauncherBackendAPI.ResourceLayer {
|
||||||
|
private final Path vfsPath;
|
||||||
|
|
||||||
|
public ResourceLayerImpl(Path basePath, List<Path> overlayList) {
|
||||||
|
if(overlayList == null || overlayList.isEmpty()) {
|
||||||
|
vfsPath = basePath;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<VfsDirectory> overlays = Stream.concat(overlayList.stream(), Stream.of(Path.of("")))
|
||||||
|
.map(basePath::resolve)
|
||||||
|
.map(x -> (VfsDirectory) Vfs.get().resolve(x))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toList();
|
||||||
|
OverlayVfsDirectory directory = new OverlayVfsDirectory(overlays);
|
||||||
|
String randomName = SecurityHelper.randomStringToken();
|
||||||
|
vfsPath = Path.of(randomName);
|
||||||
|
Vfs.get().put(vfsPath, directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URL getURL(Path path) throws IOException {
|
||||||
|
return Vfs.get().getURL(vfsPath.resolve(path));
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,10 +33,10 @@ public VfsEntry find(String name) {
|
||||||
@Override
|
@Override
|
||||||
public VfsEntry resolve(Path path) {
|
public VfsEntry resolve(Path path) {
|
||||||
if(path == null) {
|
if(path == null) {
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Path target = path.resolve(path);
|
Path target = this.path.resolve(path);
|
||||||
if(Files.exists(target)) {
|
if(Files.exists(target)) {
|
||||||
if(Files.isDirectory(target)) {
|
if(Files.isDirectory(target)) {
|
||||||
return new FileVfsDirectory(target);
|
return new FileVfsDirectory(target);
|
||||||
|
|
|
@ -19,7 +19,7 @@ public VfsEntry find(String name) {
|
||||||
@Override
|
@Override
|
||||||
public VfsEntry resolve(Path path) {
|
public VfsEntry resolve(Path path) {
|
||||||
if(path == null) {
|
if(path == null) {
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
VfsDirectory current = this;
|
VfsDirectory current = this;
|
||||||
|
@ -30,6 +30,9 @@ public VfsEntry resolve(Path path) {
|
||||||
if(entity instanceof SimpleVfsDirectory) {
|
if(entity instanceof SimpleVfsDirectory) {
|
||||||
current = newDir;
|
current = newDir;
|
||||||
} else {
|
} else {
|
||||||
|
if (i+1 >= path.getNameCount()) {
|
||||||
|
return newDir;
|
||||||
|
}
|
||||||
Path newPath = path.subpath(i+1, path.getNameCount());
|
Path newPath = path.subpath(i+1, path.getNameCount());
|
||||||
return newDir.resolve(newPath);
|
return newDir.resolve(newPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
import pro.gravit.launcher.core.api.model.UserPermissions;
|
import pro.gravit.launcher.core.api.model.UserPermissions;
|
||||||
import pro.gravit.launcher.core.backend.extensions.Extension;
|
import pro.gravit.launcher.core.backend.extensions.Extension;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -38,6 +40,7 @@ public interface LauncherBackendAPI {
|
||||||
String getUsername();
|
String getUsername();
|
||||||
SelfUser getSelfUser();
|
SelfUser getSelfUser();
|
||||||
boolean isTestMode();
|
boolean isTestMode();
|
||||||
|
ResourceLayer makeResourceLayer(List<Path> overlayList);
|
||||||
// Extensions
|
// Extensions
|
||||||
<T extends Extension> T getExtension(Class<T> clazz);
|
<T extends Extension> T getExtension(Class<T> clazz);
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
@ -173,4 +176,8 @@ interface ServerPingInfo {
|
||||||
int getOnline();
|
int getOnline();
|
||||||
List<String> getPlayerNames();
|
List<String> getPlayerNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ResourceLayer {
|
||||||
|
URL getURL(Path path) throws IOException;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue