mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-07-07 00:09:46 +03:00
Compare commits
6 commits
183d0fc9df
...
324de7226d
Author | SHA1 | Date | |
---|---|---|---|
|
324de7226d | ||
|
37546e8a5a | ||
|
110c2a089e | ||
|
6013f75091 | ||
|
04ecbfc14b | ||
|
68e2230d34 |
26 changed files with 713 additions and 4 deletions
|
@ -79,8 +79,26 @@ public void delete(UncompletedProfile profile) {
|
|||
|
||||
@Override
|
||||
public Set<UncompletedProfile> getProfiles(Client client) {
|
||||
if(client == null) {
|
||||
return new HashSet<>(profilesMap.values());
|
||||
}
|
||||
if(!client.isAuth) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
Set<UncompletedProfile> profiles = new HashSet<>();
|
||||
for(var p : profilesMap.entrySet()) {
|
||||
var uuid = p.getKey();
|
||||
var profile = p.getValue();
|
||||
if(profile.getProfile() != null && profile.getProfile().isLimited()) {
|
||||
if(client.isAuth && client.permissions != null && client.permissions.hasPerm(String.format("launchserver.profile.%s.show", uuid))) {
|
||||
profiles.add(profile);
|
||||
}
|
||||
} else {
|
||||
profiles.add(profile);
|
||||
}
|
||||
}
|
||||
return profiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletedProfile pushUpdate(UncompletedProfile profile, String tag, ClientProfile clientProfile, List<ProfileAction> assetActions, List<ProfileAction> clientActions, List<UpdateFlag> flags) throws IOException {
|
||||
|
|
|
@ -170,6 +170,8 @@ public static LauncherEngine newInstance(boolean clientInstance, Class<? extends
|
|||
}
|
||||
|
||||
public void start(String... args) throws Throwable {
|
||||
var config = Launcher.getConfig();
|
||||
config.apply();
|
||||
//Launcher.modulesManager = new ClientModuleManager(this);
|
||||
ClientPreGuiPhase event = new ClientPreGuiPhase(null);
|
||||
LauncherEngine.modulesManager.invokeEvent(event);
|
||||
|
@ -178,7 +180,7 @@ public void start(String... args) throws Throwable {
|
|||
runtimeProvider.init(clientInstance);
|
||||
//runtimeProvider.preLoad();
|
||||
if (!Request.isAvailable()) {
|
||||
String address = Launcher.getConfig().address;
|
||||
String address = config.address;
|
||||
LogHelper.debug("Start async connection to %s", address);
|
||||
RequestService service;
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package pro.gravit.launcher.runtime.backend;
|
||||
|
||||
import pro.gravit.launcher.base.Launcher;
|
||||
import pro.gravit.launcher.base.vfs.Vfs;
|
||||
import pro.gravit.launcher.base.vfs.VfsFile;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.CipherInputStream;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class EncryptedVfsFile extends VfsFile {
|
||||
private VfsFile parent;
|
||||
private final String alg;
|
||||
private final SecretKeySpec sKeySpec;
|
||||
private final IvParameterSpec iKeySpec;
|
||||
|
||||
public EncryptedVfsFile(VfsFile parent) {
|
||||
this.parent = parent;
|
||||
this.alg = "AES/CBC/PKCS5Padding";
|
||||
try {
|
||||
byte[] compat = SecurityHelper.getAESKey(Launcher.getConfig().runtimeEncryptKey.getBytes(StandardCharsets.UTF_8));
|
||||
sKeySpec = new SecretKeySpec(compat, "AES");
|
||||
iKeySpec = new IvParameterSpec("8u3d90ikr7o67lsq".getBytes());
|
||||
} catch (Exception e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
Cipher cipher;
|
||||
try {
|
||||
cipher = Cipher.getInstance(alg);
|
||||
cipher.init(Cipher.DECRYPT_MODE, sKeySpec, iKeySpec);
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException |
|
||||
InvalidAlgorithmParameterException e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
return new BufferedInputStream(new CipherInputStream(parent.getInputStream(), cipher));
|
||||
}
|
||||
}
|
|
@ -1,7 +1,12 @@
|
|||
package pro.gravit.launcher.runtime.backend;
|
||||
|
||||
import pro.gravit.launcher.base.ClientPermissions;
|
||||
import pro.gravit.launcher.base.Launcher;
|
||||
import pro.gravit.launcher.base.profiles.ClientProfile;
|
||||
import pro.gravit.launcher.base.vfs.Vfs;
|
||||
import pro.gravit.launcher.base.vfs.directory.FileVfsDirectory;
|
||||
import pro.gravit.launcher.base.vfs.file.CachedVfsFile;
|
||||
import pro.gravit.launcher.base.vfs.file.UrlVfsFile;
|
||||
import pro.gravit.launcher.core.api.LauncherAPIHolder;
|
||||
import pro.gravit.launcher.core.api.features.*;
|
||||
import pro.gravit.launcher.core.api.method.AuthMethod;
|
||||
|
@ -22,12 +27,15 @@
|
|||
import pro.gravit.launcher.runtime.managers.SettingsManager;
|
||||
import pro.gravit.launcher.runtime.utils.HWIDProvider;
|
||||
import pro.gravit.launcher.runtime.utils.LauncherUpdater;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.JavaHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
@ -370,4 +378,34 @@ public CompletableFuture<Void> processHardware() {
|
|||
return CompletableFuture.failedFuture(new UnsupportedOperationException());
|
||||
});
|
||||
}
|
||||
|
||||
public Path initVfsDirectory() {
|
||||
Path defaultPath = Path.of("runtime");
|
||||
if(isTestMode()) {
|
||||
Vfs.get().put(defaultPath, new FileVfsDirectory(defaultPath));
|
||||
} else {
|
||||
var encryptKey = Launcher.getConfig().runtimeEncryptKey;
|
||||
if(encryptKey == null) {
|
||||
for(var e : Launcher.getConfig().runtime.entrySet()) {
|
||||
var realPath = e.getKey();
|
||||
var encodedName = "runtime/" + realPath;
|
||||
try {
|
||||
Vfs.get().put(defaultPath.resolve(realPath), new UrlVfsFile(IOHelper.getResourceURL(encodedName)));
|
||||
} catch (NoSuchFileException ignored) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(var e : Launcher.getConfig().runtime.entrySet()) {
|
||||
var realPath = e.getKey();
|
||||
var hash = e.getValue();
|
||||
var encodedName = "runtime/" + SecurityHelper.toHex(hash);
|
||||
try {
|
||||
Vfs.get().put(defaultPath.resolve(realPath), new CachedVfsFile(new EncryptedVfsFile(new UrlVfsFile(IOHelper.getResourceURL(encodedName)))));
|
||||
} catch (NoSuchFileException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return defaultPath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ public static void initialize() throws Exception {
|
|||
config.unlockSecret = DebugProperties.UNLOCK_SECRET;
|
||||
Launcher.setConfig(config);
|
||||
Launcher.applyLauncherEnv(DebugProperties.ENV);
|
||||
config.apply();
|
||||
LauncherEngine.modulesManager = new RuntimeModuleManager();
|
||||
LauncherEngine.modulesManager.loadModule(new RuntimeLauncherCoreModule());
|
||||
for (String moduleClassName : DebugProperties.MODULE_CLASSES) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package pro.gravit.launcher.base;
|
||||
|
||||
import pro.gravit.launcher.core.BuildInParams;
|
||||
import pro.gravit.launcher.core.LauncherInject;
|
||||
import pro.gravit.launcher.core.LauncherInjectionConstructor;
|
||||
import pro.gravit.launcher.core.LauncherTrustManager;
|
||||
|
@ -8,6 +9,7 @@
|
|||
import pro.gravit.launcher.core.serialize.HInput;
|
||||
import pro.gravit.launcher.core.serialize.HOutput;
|
||||
import pro.gravit.launcher.core.serialize.stream.StreamObject;
|
||||
import pro.gravit.utils.Version;
|
||||
import pro.gravit.utils.helper.JVMHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
@ -122,6 +124,12 @@ public LauncherConfig(String address, Map<String, byte[]> runtime, String projec
|
|||
runtimeEncryptKey = null;
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
Version version = Version.getVersion();
|
||||
BuildInParams.setVersion(new Version(version.major, version.minor, version.patch, (int) buildNumber));
|
||||
BuildInParams.setProjectName(projectName);
|
||||
}
|
||||
|
||||
public static void initModules(LauncherModulesManager modulesManager) {
|
||||
if(JVMHelper.JVM_VERSION >= 17) {
|
||||
modulesClasses.addAll(ModernModulesClass.modulesClasses);
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
package pro.gravit.launcher.base.vfs;
|
||||
|
||||
|
||||
import pro.gravit.launcher.base.vfs.directory.SimpleVfsDirectory;
|
||||
import pro.gravit.launcher.base.vfs.protocol.vfs.VfsURLStreamHandlerProvider;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Vfs {
|
||||
private final VfsDirectory directory;
|
||||
private static final Map<String, Vfs> map = new HashMap<>();
|
||||
private static final Vfs defaultImpl = new Vfs();
|
||||
static {
|
||||
URL.setURLStreamHandlerFactory(new VfsURLStreamHandlerProvider());
|
||||
register("", defaultImpl);
|
||||
}
|
||||
|
||||
public Vfs() {
|
||||
directory = new SimpleVfsDirectory();
|
||||
}
|
||||
|
||||
public Vfs(VfsDirectory directory) {
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
public VfsEntry resolve(Path path) {
|
||||
return directory.resolve(path);
|
||||
}
|
||||
|
||||
public void put(Path path, VfsEntry entry) {
|
||||
VfsEntry parent = resolve(path.getParent());
|
||||
if(parent instanceof SimpleVfsDirectory dir) {
|
||||
dir.put(path.getFileName().toString(), entry);
|
||||
} else {
|
||||
throw new VfsException(String.format("%s not support add new files", path.getParent()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void register(String name, Vfs vfs) {
|
||||
map.put(name, vfs);
|
||||
}
|
||||
|
||||
public static Vfs getByName(String name) {
|
||||
if(name == null) {
|
||||
return defaultImpl;
|
||||
}
|
||||
return map.get(name);
|
||||
}
|
||||
|
||||
public static Vfs get() {
|
||||
return defaultImpl;
|
||||
}
|
||||
|
||||
public InputStream getInputStream(Path path) throws IOException {
|
||||
VfsEntry entry = directory.resolve(path);
|
||||
if (entry == null) throw new FileNotFoundException(String.format("File %s not found", path));
|
||||
if(entry instanceof VfsFile file) {
|
||||
return file.getInputStream();
|
||||
}
|
||||
throw new VfsException(String.format("%s is a directory", path.getParent()));
|
||||
}
|
||||
|
||||
public URL getURL(String path) throws IOException {
|
||||
return getURL(Paths.get(path));
|
||||
}
|
||||
|
||||
public URL getURL(Path name) throws IOException {
|
||||
try (InputStream stream = defaultImpl.getInputStream(name)) {
|
||||
return new URI("vfs", null, "/"+name, null).toURL();
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
throw new FileNotFoundException(name.toString());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package pro.gravit.launcher.base.vfs;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class VfsDirectory extends VfsEntry {
|
||||
public abstract VfsEntry find(String name);
|
||||
public abstract VfsEntry resolve(Path path);
|
||||
public abstract Stream<String> getFiles();
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package pro.gravit.launcher.base.vfs;
|
||||
|
||||
public class VfsEntry {
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package pro.gravit.launcher.base.vfs;
|
||||
|
||||
public class VfsException extends RuntimeException {
|
||||
public VfsException() {
|
||||
}
|
||||
|
||||
public VfsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public VfsException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public VfsException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public VfsException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package pro.gravit.launcher.base.vfs;
|
||||
|
||||
|
||||
import pro.gravit.launcher.base.vfs.protocol.vfs.VfsURLConnection;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public abstract class VfsFile extends VfsEntry {
|
||||
public URLConnection openConnection(URL url) {
|
||||
return new VfsURLConnection(url, this);
|
||||
}
|
||||
public abstract InputStream getInputStream();
|
||||
|
||||
public byte[] readAll() throws IOException {
|
||||
try(var input = getInputStream()) {
|
||||
try(var output = new ByteArrayOutputStream()) {
|
||||
input.transferTo(output);
|
||||
return output.toByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package pro.gravit.launcher.base.vfs.directory;
|
||||
|
||||
|
||||
import pro.gravit.launcher.base.vfs.VfsDirectory;
|
||||
import pro.gravit.launcher.base.vfs.VfsEntry;
|
||||
import pro.gravit.launcher.base.vfs.VfsException;
|
||||
import pro.gravit.launcher.base.vfs.file.FileVfsFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class FileVfsDirectory extends VfsDirectory {
|
||||
private final Path path;
|
||||
|
||||
public FileVfsDirectory(Path path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VfsEntry find(String name) {
|
||||
Path target = path.resolve(name);
|
||||
if(Files.exists(target)) {
|
||||
if(Files.isDirectory(target)) {
|
||||
return new FileVfsDirectory(target);
|
||||
}
|
||||
return new FileVfsFile(target);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VfsEntry resolve(Path path) {
|
||||
if(path == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Path target = path.resolve(path);
|
||||
if(Files.exists(target)) {
|
||||
if(Files.isDirectory(target)) {
|
||||
return new FileVfsDirectory(target);
|
||||
}
|
||||
return new FileVfsFile(target);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Override
|
||||
public Stream<String> getFiles() {
|
||||
try {
|
||||
return Files.list(path).map(Path::getFileName).map(Path::toString);
|
||||
} catch (IOException e) {
|
||||
throw new VfsException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package pro.gravit.launcher.base.vfs.directory;
|
||||
|
||||
import pro.gravit.launcher.base.vfs.VfsDirectory;
|
||||
import pro.gravit.launcher.base.vfs.VfsEntry;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class OverlayVfsDirectory extends VfsDirectory {
|
||||
private final List<VfsDirectory> list;
|
||||
|
||||
public OverlayVfsDirectory(List<VfsDirectory> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VfsEntry find(String name) {
|
||||
for(var e : list) {
|
||||
var result = e.find(name);
|
||||
if(result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VfsEntry resolve(Path path) {
|
||||
for(var e : list) {
|
||||
var result = e.resolve(path);
|
||||
if(result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getFiles() {
|
||||
Stream<String> stream = Stream.empty();
|
||||
for(var e : list) {
|
||||
var result = e.getFiles();
|
||||
if(result != null) {
|
||||
stream = Stream.concat(stream, result);
|
||||
}
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package pro.gravit.launcher.base.vfs.directory;
|
||||
|
||||
|
||||
import pro.gravit.launcher.base.vfs.VfsDirectory;
|
||||
import pro.gravit.launcher.base.vfs.VfsEntry;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SimpleVfsDirectory extends VfsDirectory {
|
||||
private final Map<String, VfsEntry> map = new HashMap<>();
|
||||
@Override
|
||||
public VfsEntry find(String name) {
|
||||
return map.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VfsEntry resolve(Path path) {
|
||||
if(path == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
VfsDirectory current = this;
|
||||
for(int i=0;i<path.getNameCount();++i) {
|
||||
String s = path.getName(i).toString();
|
||||
VfsEntry entity = current.find(s);
|
||||
if(entity instanceof VfsDirectory newDir) {
|
||||
if(entity instanceof SimpleVfsDirectory) {
|
||||
current = newDir;
|
||||
} else {
|
||||
Path newPath = path.subpath(i+1, path.getNameCount());
|
||||
return newDir.resolve(newPath);
|
||||
}
|
||||
} else {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public VfsEntry remove(String name) {
|
||||
return map.remove(name);
|
||||
}
|
||||
|
||||
public void put(String name, VfsEntry entry) {
|
||||
map.put(name, entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getFiles() {
|
||||
return map.keySet().stream();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package pro.gravit.launcher.base.vfs.file;
|
||||
|
||||
|
||||
import pro.gravit.launcher.base.vfs.VfsFile;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class BytesVfsFile extends VfsFile {
|
||||
private final byte[] bytes;
|
||||
|
||||
public BytesVfsFile(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
return new ByteArrayInputStream(bytes);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package pro.gravit.launcher.base.vfs.file;
|
||||
|
||||
import pro.gravit.launcher.base.vfs.VfsFile;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ref.SoftReference;
|
||||
|
||||
public class CachedVfsFile extends VfsFile {
|
||||
private final VfsFile delegate;
|
||||
private volatile SoftReference<byte[]> cache;
|
||||
|
||||
public CachedVfsFile(VfsFile delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
private synchronized InputStream tryCache() {
|
||||
try {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
try(InputStream input = delegate.getInputStream()) {
|
||||
input.transferTo(output);
|
||||
}
|
||||
byte[] bytes = output.toByteArray();
|
||||
cache = new SoftReference<>(bytes);
|
||||
return new ByteArrayInputStream(bytes);
|
||||
} catch (OutOfMemoryError | IOException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
var cachedBytes = cache == null ? null : cache.get();
|
||||
if(cachedBytes != null) {
|
||||
return new ByteArrayInputStream(cachedBytes);
|
||||
}
|
||||
var cached = tryCache();
|
||||
if(cached != null) {
|
||||
return cached;
|
||||
}
|
||||
return delegate.getInputStream();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package pro.gravit.launcher.base.vfs.file;
|
||||
|
||||
|
||||
import pro.gravit.launcher.base.vfs.VfsFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class DelegateVfsFile extends VfsFile {
|
||||
private final VfsFile vfsFile;
|
||||
|
||||
public DelegateVfsFile(VfsFile vfsFile) {
|
||||
this.vfsFile = vfsFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URLConnection openConnection(URL url) {
|
||||
return vfsFile.openConnection(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
return vfsFile.getInputStream();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package pro.gravit.launcher.base.vfs.file;
|
||||
|
||||
|
||||
import pro.gravit.launcher.base.vfs.VfsException;
|
||||
import pro.gravit.launcher.base.vfs.VfsFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class FileVfsFile extends VfsFile {
|
||||
private final File file;
|
||||
|
||||
public FileVfsFile(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public FileVfsFile(Path path) {
|
||||
this.file = path.toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URLConnection openConnection(URL url) {
|
||||
try {
|
||||
return file.toURI().toURL().openConnection();
|
||||
} catch (IOException e) {
|
||||
throw new VfsException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new VfsException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package pro.gravit.launcher.base.vfs.file;
|
||||
|
||||
|
||||
import pro.gravit.launcher.base.vfs.VfsFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class InputStreamVfsFile extends VfsFile {
|
||||
private final Supplier<InputStream> streamSupplier;
|
||||
|
||||
public InputStreamVfsFile(Supplier<InputStream> streamSupplier) {
|
||||
this.streamSupplier = streamSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
return streamSupplier.get();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package pro.gravit.launcher.base.vfs.file;
|
||||
|
||||
|
||||
import pro.gravit.launcher.base.vfs.VfsException;
|
||||
import pro.gravit.launcher.base.vfs.VfsFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class UrlVfsFile extends VfsFile {
|
||||
private final URL internalUrl;
|
||||
|
||||
public UrlVfsFile(URL internalUrl) {
|
||||
this.internalUrl = internalUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URLConnection openConnection(URL url) {
|
||||
try {
|
||||
return internalUrl.openConnection();
|
||||
} catch (IOException e) {
|
||||
throw new VfsException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
try {
|
||||
return openConnection(internalUrl).getInputStream();
|
||||
} catch (IOException e) {
|
||||
throw new VfsException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package pro.gravit.launcher.base.vfs.protocol.vfs;
|
||||
|
||||
|
||||
import pro.gravit.launcher.base.vfs.Vfs;
|
||||
import pro.gravit.launcher.base.vfs.VfsFile;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLStreamHandler;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class Handler extends URLStreamHandler {
|
||||
@Override
|
||||
protected URLConnection openConnection(URL url) throws IOException {
|
||||
Vfs enFS = Vfs.getByName(url.getHost());
|
||||
String realPath = URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8);
|
||||
var fileEntry = enFS.resolve(Paths.get(realPath));
|
||||
if(fileEntry == null) throw new FileNotFoundException(url.toString());
|
||||
if(fileEntry instanceof VfsFile file) {
|
||||
return file.openConnection(url);
|
||||
}
|
||||
throw new UnsupportedOperationException(String.format("%s not supported openConnection()", url));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package pro.gravit.launcher.base.vfs.protocol.vfs;
|
||||
|
||||
|
||||
import pro.gravit.launcher.base.vfs.VfsFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class VfsURLConnection extends URLConnection {
|
||||
private final VfsFile fileEntry;
|
||||
public VfsURLConnection(URL url, VfsFile fileEntry) {
|
||||
super(url);
|
||||
this.fileEntry = fileEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect() throws IOException {
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return fileEntry.getInputStream();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package pro.gravit.launcher.base.vfs.protocol.vfs;
|
||||
|
||||
import java.net.URLStreamHandler;
|
||||
import java.net.spi.URLStreamHandlerProvider;
|
||||
|
||||
public class VfsURLStreamHandlerProvider extends URLStreamHandlerProvider {
|
||||
@Override
|
||||
public URLStreamHandler createURLStreamHandler(String s) {
|
||||
if (s.equals("vfs")) {
|
||||
return new Handler();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -119,12 +119,14 @@ private static void realMain(String[] args) throws Throwable {
|
|||
// Verify ClientLauncher sign and classpath
|
||||
LogHelper.debug("Verifying ClientLauncher sign and classpath");
|
||||
// Start client with WatchService monitoring
|
||||
var config = Launcher.getConfig();
|
||||
config.apply();
|
||||
RequestService service;
|
||||
if (params.offlineMode) {
|
||||
service = ClientLauncherMethods.initOffline(modulesManager, params);
|
||||
Request.setRequestService(service);
|
||||
} else {
|
||||
service = StdWebSocketService.initWebSockets(Launcher.getConfig().address).get();
|
||||
service = StdWebSocketService.initWebSockets(config.address).get();
|
||||
Request.setRequestService(service);
|
||||
LogHelper.debug("Restore sessions");
|
||||
Request.restore(false, false, true);
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package pro.gravit.launcher.core;
|
||||
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
public class BuildInParams {
|
||||
private static volatile Version version;
|
||||
private static volatile String projectName;
|
||||
|
||||
public static Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public static void setVersion(Version version) {
|
||||
BuildInParams.version = version;
|
||||
}
|
||||
|
||||
public static String getProjectName() {
|
||||
return projectName;
|
||||
}
|
||||
|
||||
public static void setProjectName(String projectName) {
|
||||
BuildInParams.projectName = projectName;
|
||||
}
|
||||
}
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit acab14e403bb12649883017b14f2cf66cb1f4e68
|
||||
Subproject commit 53103486065ff7dde30e480d2b24f6afb2decddb
|
Loading…
Reference in a new issue