mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-07-06 15:59:47 +03:00
Compare commits
7 commits
842856be28
...
0b2b3a9852
Author | SHA1 | Date | |
---|---|---|---|
|
0b2b3a9852 | ||
|
c65e20d77b | ||
|
e664c579a5 | ||
|
1e4e1c5837 | ||
|
b8f6857ef2 | ||
|
de844201b4 | ||
|
0e1691ee4c |
27 changed files with 327 additions and 84 deletions
|
@ -27,6 +27,7 @@
|
|||
import pro.gravit.utils.command.CommandHandler;
|
||||
import pro.gravit.utils.command.SubCommand;
|
||||
import pro.gravit.utils.helper.CommonHelper;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.JVMHelper;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
|
@ -226,8 +227,15 @@ public void reload(ReloadType type) throws Exception {
|
|||
if(!type.equals(ReloadType.NO_AUTH)) {
|
||||
nettyServerSocketHandler.nettyServer.service.forEachActiveChannels((channel, wsHandler) -> {
|
||||
Client client = wsHandler.getClient();
|
||||
if(client.auth != null) {
|
||||
var lock = client.writeLock();
|
||||
lock.lock();
|
||||
try {
|
||||
if (client.auth_id == null) {
|
||||
return;
|
||||
}
|
||||
client.auth = config.getAuthProviderPair(client.auth_id);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -298,6 +306,12 @@ public void checkCertificateExpired() {
|
|||
}
|
||||
}
|
||||
|
||||
public Path createTempDirectory(String name) throws IOException {
|
||||
var path = tmpDir.resolve(String.format("launchserver-%s-%s", name, SecurityHelper.randomStringToken()));
|
||||
Files.createDirectories(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
private LauncherBinary binary() {
|
||||
LaunchServerLauncherExeInit event = new LaunchServerLauncherExeInit(this, null);
|
||||
modulesManager.invokeEvent(event);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import pro.gravit.launchserver.modules.events.LaunchServerUpdatesSyncEvent;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -153,6 +153,14 @@ public void upload(String updateName, Map<String, Path> files, boolean deleteAft
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream upload(String updateName, String file) throws IOException {
|
||||
var path = resolveUpdateName(updateName);
|
||||
var target = path.resolve(file);
|
||||
IOHelper.createParentDirs(target);
|
||||
return new FileOutputStream(target.toFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Path> download(String updateName, List<String> files) {
|
||||
var path = resolveUpdateName(updateName);
|
||||
|
@ -163,6 +171,39 @@ public Map<String, Path> download(String updateName, List<String> files) {
|
|||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(String updateName, Map<String, Path> files) throws IOException {
|
||||
var path = resolveUpdateName(updateName);
|
||||
for(var e : files.entrySet()) {
|
||||
var source = path.resolve(e.getKey());
|
||||
var target = e.getValue();
|
||||
IOHelper.copy(source, target);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream download(String updateName, String path) throws IOException {
|
||||
return new FileInputStream(resolveUpdateName(updateName).resolve(path).toFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(Map<UpdateNameAndFile, UpdateNameAndFile> files) throws IOException {
|
||||
for(var e : files.entrySet()) {
|
||||
var source = resolveUpdateName(e.getKey().updateName()).resolve(e.getKey().path());
|
||||
var target = resolveUpdateName(e.getValue().updateName()).resolve(e.getValue().path());
|
||||
IOHelper.move(source, target);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy(Map<UpdateNameAndFile, UpdateNameAndFile> files) throws IOException {
|
||||
for(var e : files.entrySet()) {
|
||||
var source = resolveUpdateName(e.getKey().updateName()).resolve(e.getKey().path());
|
||||
var target = resolveUpdateName(e.getValue().updateName()).resolve(e.getValue().path());
|
||||
IOHelper.copy(source, target);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String updateName, List<String> files) throws IOException {
|
||||
var path = resolveUpdateName(updateName);
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
package pro.gravit.launchserver.auth.updates;
|
||||
|
||||
import pro.gravit.launcher.core.hasher.HashedDir;
|
||||
import pro.gravit.launcher.core.hasher.HashedEntry;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.utils.ProviderMap;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -38,7 +48,55 @@ public void sync() throws IOException {
|
|||
|
||||
public abstract void upload(String updateName, Map<String, Path> files, boolean deleteAfterUpload) throws IOException;
|
||||
|
||||
public abstract Map<String, Path> download(String updateName, List<String> files);
|
||||
public abstract OutputStream upload(String updateName, String file) throws IOException;
|
||||
|
||||
public void upload(String updateName, Path dir, boolean deleteAfterUpload) throws IOException {
|
||||
if(!Files.isDirectory(dir)) {
|
||||
throw new UnsupportedEncodingException(String.format("%s is not a directory", dir));
|
||||
}
|
||||
Map<String, Path> map = new HashMap<>();
|
||||
IOHelper.walk(dir, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
map.put(dir.relativize(file).toString(), file);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
}, true);
|
||||
upload(updateName, map, deleteAfterUpload);
|
||||
}
|
||||
|
||||
public abstract Map<String, Path> download(String updateName, List<String> files) throws IOException;
|
||||
|
||||
public abstract void download(String updateName, Map<String, Path> files) throws IOException;
|
||||
|
||||
public abstract InputStream download(String updateName, String path) throws IOException;
|
||||
|
||||
public abstract void move(Map<UpdateNameAndFile, UpdateNameAndFile> files) throws IOException;
|
||||
|
||||
public void move(String updateName, String newUpdateName) throws IOException {
|
||||
create(newUpdateName);
|
||||
var updatesDir = getUpdatesDir(updateName);
|
||||
Map<UpdateNameAndFile, UpdateNameAndFile> map = new HashMap<>();
|
||||
updatesDir.walk("/", (path, name, entry) -> {
|
||||
map.put(UpdateNameAndFile.of(updateName, path), UpdateNameAndFile.of(newUpdateName, path));
|
||||
return HashedDir.WalkAction.CONTINUE;
|
||||
});
|
||||
move(map);
|
||||
delete(updateName);
|
||||
}
|
||||
|
||||
public abstract void copy(Map<UpdateNameAndFile, UpdateNameAndFile> files) throws IOException;
|
||||
|
||||
public void copy(String updateName, String newUpdateName) throws IOException {
|
||||
create(newUpdateName);
|
||||
var updatesDir = getUpdatesDir(updateName);
|
||||
Map<UpdateNameAndFile, UpdateNameAndFile> map = new HashMap<>();
|
||||
updatesDir.walk("/", (path, name, entry) -> {
|
||||
map.put(UpdateNameAndFile.of(updateName, path), UpdateNameAndFile.of(newUpdateName, path));
|
||||
return HashedDir.WalkAction.CONTINUE;
|
||||
});
|
||||
copy(map);
|
||||
}
|
||||
|
||||
public abstract void delete(String updateName, List<String> files) throws IOException;
|
||||
|
||||
|
@ -49,4 +107,10 @@ public void sync() throws IOException {
|
|||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
public record UpdateNameAndFile(String updateName, String path) {
|
||||
public static UpdateNameAndFile of(String updateName, String path) {
|
||||
return new UpdateNameAndFile(updateName, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launcher.base.Launcher;
|
||||
import pro.gravit.launcher.base.Downloader;
|
||||
import pro.gravit.launcher.core.hasher.HashedDir;
|
||||
import pro.gravit.launchserver.HttpRequester;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
|
@ -44,7 +45,12 @@ public void invoke(String... args) throws Exception {
|
|||
String versionName = args[0];
|
||||
String dirName = IOHelper.verifyFileName(args.length > 1 ? args[1] : "assets");
|
||||
String type = args.length > 2 ? args[2] : "mojang";
|
||||
Path assetDir = server.updatesDir.resolve(dirName);
|
||||
Path assetDir = server.createTempDirectory("assets");
|
||||
var updatesDir = server.config.updatesProvider.getUpdatesDir(dirName);
|
||||
if(updatesDir == null) {
|
||||
updatesDir = new HashedDir();
|
||||
server.config.updatesProvider.create(dirName);
|
||||
}
|
||||
|
||||
// Create asset dir
|
||||
if (Files.notExists(assetDir)) {
|
||||
|
@ -91,15 +97,9 @@ public void invoke(String... args) throws Exception {
|
|||
hash = hash.substring(0, 2) + "/" + hash;
|
||||
var size = value.get("size").getAsLong();
|
||||
var path = "objects/" + hash;
|
||||
var target = assetDir.resolve(path);
|
||||
if (Files.exists(target)) {
|
||||
long fileSize = Files.size(target);
|
||||
if (fileSize != size) {
|
||||
logger.warn("File {} corrupted. Size {}, expected {}", target, size, fileSize);
|
||||
} else {
|
||||
if (updatesDir.tryFindRecursive(path).isFound()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
toDownload.add(new Downloader.SizedFile(hash, path, size));
|
||||
}
|
||||
logger.info("Download {} files", toDownload.size());
|
||||
|
@ -112,6 +112,8 @@ public void invoke(String... args) throws Exception {
|
|||
server.mirrorManager.downloadZip(assetDir, "assets/%s.zip", versionName);
|
||||
}
|
||||
|
||||
server.config.updatesProvider.upload(dirName, assetDir, true);
|
||||
|
||||
// Finished
|
||||
server.syncUpdatesDir(Collections.singleton(dirName));
|
||||
logger.info("Asset successfully downloaded: '{}'", dirName);
|
||||
|
|
|
@ -42,7 +42,8 @@ public void invoke(String... args) throws IOException, CommandException {
|
|||
//Version version = Version.byName(args[0]);
|
||||
String versionName = args[0];
|
||||
String dirName = IOHelper.verifyFileName(args[1] != null ? args[1] : args[0]);
|
||||
Path clientDir = server.updatesDir.resolve(dirName);
|
||||
Path clientDir = server.createTempDirectory("client");
|
||||
server.config.updatesProvider.create(dirName);
|
||||
|
||||
boolean isMirrorClientDownload = false;
|
||||
if (args.length > 2) {
|
||||
|
@ -97,6 +98,7 @@ public void invoke(String... args) throws IOException, CommandException {
|
|||
}
|
||||
}
|
||||
server.config.profileProvider.addProfile(clientProfile);
|
||||
server.config.updatesProvider.upload(dirName, clientDir, true);
|
||||
|
||||
// Finished
|
||||
server.syncProfilesDir();
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class IndexAssetCommand extends Command {
|
||||
public static final String INDEXES_DIR = "indexes";
|
||||
|
@ -54,24 +56,21 @@ public void invoke(String... args) throws Exception {
|
|||
String inputAssetDirName = IOHelper.verifyFileName(args[0]);
|
||||
String indexFileName = IOHelper.verifyFileName(args[1]);
|
||||
String outputAssetDirName = IOHelper.verifyFileName(args[2]);
|
||||
Path inputAssetDir = server.updatesDir.resolve(inputAssetDirName);
|
||||
Path outputAssetDir = server.updatesDir.resolve(outputAssetDirName);
|
||||
if (outputAssetDir.equals(inputAssetDir))
|
||||
throw new CommandException("Unindexed and indexed asset dirs can't be same");
|
||||
|
||||
// Create new asset dir
|
||||
logger.info("Creating indexed asset dir: '{}'", outputAssetDirName);
|
||||
Files.createDirectory(outputAssetDir);
|
||||
Path inputAssetDir = Path.of(inputAssetDirName);
|
||||
Map<String, Path> uploadMap = new HashMap<>();
|
||||
|
||||
// Index objects
|
||||
JsonObject objects = new JsonObject();
|
||||
logger.info("Indexing objects");
|
||||
IOHelper.walk(inputAssetDir, new IndexAssetVisitor(objects, inputAssetDir, outputAssetDir), false);
|
||||
IOHelper.walk(inputAssetDir, new IndexAssetVisitor(objects, inputAssetDir, uploadMap), false);
|
||||
server.config.updatesProvider.upload(outputAssetDirName, uploadMap, false);
|
||||
|
||||
// Write index file
|
||||
logger.info("Writing asset index file: '{}'", indexFileName);
|
||||
|
||||
try (BufferedWriter writer = IOHelper.newWriter(resolveIndexFile(outputAssetDir, indexFileName))) {
|
||||
var indexFile = resolveIndexFile(Path.of(""), indexFileName);
|
||||
|
||||
try (BufferedWriter writer = IOHelper.newWriter(server.config.updatesProvider.upload(outputAssetDirName, indexFile.toString()))) {
|
||||
JsonObject result = new JsonObject();
|
||||
result.add("objects", objects);
|
||||
writer.write(Launcher.gsonManager.gson.toJson(result));
|
||||
|
@ -95,12 +94,12 @@ public IndexObject(long size, String hash) {
|
|||
private final class IndexAssetVisitor extends SimpleFileVisitor<Path> {
|
||||
private final JsonObject objects;
|
||||
private final Path inputAssetDir;
|
||||
private final Path outputAssetDir;
|
||||
private final Map<String, Path> uploadMap;
|
||||
|
||||
private IndexAssetVisitor(JsonObject objects, Path inputAssetDir, Path outputAssetDir) {
|
||||
private IndexAssetVisitor(JsonObject objects, Path inputAssetDir, Map<String, Path> uploadMap) {
|
||||
this.objects = objects;
|
||||
this.inputAssetDir = inputAssetDir;
|
||||
this.outputAssetDir = outputAssetDir;
|
||||
this.uploadMap = uploadMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,7 +111,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
String digest = SecurityHelper.toHex(SecurityHelper.digest(DigestAlgorithm.SHA1, file));
|
||||
IndexObject obj = new IndexObject(attrs.size(), digest);
|
||||
objects.add(name, Launcher.gsonManager.gson.toJsonTree(obj));
|
||||
IOHelper.copy(file, resolveObjectFile(outputAssetDir, digest));
|
||||
uploadMap.put(resolveObjectFile(Path.of(""), digest).toString(), file);
|
||||
|
||||
// Continue visiting
|
||||
return super.visitFile(file, attrs);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import com.google.gson.JsonParser;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launcher.core.hasher.HashedDir;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.utils.command.CommandException;
|
||||
|
@ -14,6 +15,7 @@
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class UnindexAssetCommand extends Command {
|
||||
|
@ -39,10 +41,11 @@ public void invoke(String... args) throws Exception {
|
|||
String inputAssetDirName = IOHelper.verifyFileName(args[0]);
|
||||
String indexFileName = IOHelper.verifyFileName(args[1]);
|
||||
String outputAssetDirName = IOHelper.verifyFileName(args[2]);
|
||||
Path inputAssetDir = server.updatesDir.resolve(inputAssetDirName);
|
||||
Path outputAssetDir = server.updatesDir.resolve(outputAssetDirName);
|
||||
if (outputAssetDir.equals(inputAssetDir))
|
||||
throw new CommandException("Indexed and unindexed asset dirs can't be same");
|
||||
var updatesDir = server.config.updatesProvider.getUpdatesDir(inputAssetDirName);
|
||||
if(updatesDir == null) {
|
||||
server.config.updatesProvider.create(inputAssetDirName);
|
||||
}
|
||||
Path outputAssetDir = Path.of(outputAssetDirName);
|
||||
|
||||
// Create new asset dir
|
||||
logger.info("Creating unindexed asset dir: '{}'", outputAssetDirName);
|
||||
|
@ -51,7 +54,8 @@ public void invoke(String... args) throws Exception {
|
|||
// Read JSON file
|
||||
JsonObject objects;
|
||||
logger.info("Reading asset index file: '{}'", indexFileName);
|
||||
try (BufferedReader reader = IOHelper.newReader(IndexAssetCommand.resolveIndexFile(inputAssetDir, indexFileName))) {
|
||||
Path indexFilePath = IndexAssetCommand.resolveIndexFile(Path.of(""), indexFileName);
|
||||
try (BufferedReader reader = IOHelper.newReader(server.config.updatesProvider.download(inputAssetDirName, indexFilePath.toString()))) {
|
||||
objects = JsonParser.parseReader(reader).getAsJsonObject().get("objects").getAsJsonObject();
|
||||
}
|
||||
|
||||
|
@ -63,12 +67,12 @@ public void invoke(String... args) throws Exception {
|
|||
|
||||
// Copy hashed file to target
|
||||
String hash = member.getValue().getAsJsonObject().get("hash").getAsString();
|
||||
Path source = IndexAssetCommand.resolveObjectFile(inputAssetDir, hash);
|
||||
IOHelper.copy(source, outputAssetDir.resolve(name));
|
||||
Path source = IndexAssetCommand.resolveObjectFile(Path.of(""), hash);
|
||||
server.config.updatesProvider.download(inputAssetDirName, Map.of(source.toString(), outputAssetDir.resolve(name)));
|
||||
}
|
||||
|
||||
// Finished
|
||||
server.syncUpdatesDir(Collections.singleton(outputAssetDirName));
|
||||
logger.info("Asset successfully unindexed: '{}'", inputAssetDirName);
|
||||
logger.info("Asset successfully unindexed: '{}'", outputAssetDir.toAbsolutePath().toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,17 +48,7 @@ public void invoke(String... args) throws Exception {
|
|||
profile.getServers().getFirst().name = args[1];
|
||||
}
|
||||
logger.info("Copy {} to {}", profile.getDir(), args[1]);
|
||||
var src = server.updatesDir.resolve(profile.getDir());
|
||||
var dest = server.updatesDir.resolve(args[1]);
|
||||
try (Stream<Path> stream = Files.walk(src)) {
|
||||
stream.forEach(source -> {
|
||||
try {
|
||||
IOHelper.copy(source, dest.resolve(src.relativize(source)));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
server.config.updatesProvider.copy(profile.getDir(), args[1]);
|
||||
builder.setDir(args[1]);
|
||||
profile = builder.createClientProfile();
|
||||
server.config.profileProvider.addProfile(profile);
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.launchserver.helper.MakeProfileHelper;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class MakeProfileCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
|
@ -28,7 +30,7 @@ public String getUsageDescription() {
|
|||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 3);
|
||||
ClientProfile.Version version = parseClientVersion(args[1]);
|
||||
MakeProfileHelper.MakeProfileOption[] options = MakeProfileHelper.getMakeProfileOptionsFromDir(server.updatesDir.resolve(args[2]), version);
|
||||
MakeProfileHelper.MakeProfileOption[] options = MakeProfileHelper.getMakeProfileOptionsFromDir(Path.of(args[2]), version);
|
||||
for (MakeProfileHelper.MakeProfileOption option : options) {
|
||||
logger.info("Detected option {}", option);
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
import pro.gravit.launcher.base.modules.events.InitPhase;
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
public class LaunchServerCoreModule extends LauncherModule {
|
||||
public LaunchServerCoreModule() {
|
||||
super(new LauncherModuleInfo("LaunchServerCore", Version.getVersion()));
|
||||
super(new LauncherModuleInfoBuilder().setName("LaunchServerCore").setVersion(Version.getVersion()).createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,7 @@ public abstract class LauncherModule {
|
|||
private LauncherTrustManager.CheckClassResult checkResult;
|
||||
|
||||
protected LauncherModule() {
|
||||
moduleInfo = new LauncherModuleInfo("UnknownModule");
|
||||
moduleInfo = new LauncherModuleInfoBuilder().setName("UnknownModule").createLauncherModuleInfo();
|
||||
}
|
||||
|
||||
protected LauncherModule(LauncherModuleInfo info) {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package pro.gravit.launcher.base.modules;
|
||||
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
public class LauncherModuleInfoBuilder {
|
||||
private String name;
|
||||
private Version version;
|
||||
private String[] dependencies = new String[0];
|
||||
private int priority;
|
||||
private String[] providers = new String[0];
|
||||
|
||||
public LauncherModuleInfoBuilder setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LauncherModuleInfoBuilder setVersion(Version version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LauncherModuleInfoBuilder setDependencies(String[] dependencies) {
|
||||
this.dependencies = dependencies;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LauncherModuleInfoBuilder setPriority(int priority) {
|
||||
this.priority = priority;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LauncherModuleInfoBuilder setProviders(String[] providers) {
|
||||
this.providers = providers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LauncherModuleInfo createLauncherModuleInfo() {
|
||||
return new LauncherModuleInfo(name, version, priority, dependencies, providers);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package pro.gravit.launcher.base.modules;
|
||||
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SimpleModule extends LauncherModule {
|
||||
protected Consumer<SimpleModuleAccessor> consumer;
|
||||
|
||||
public SimpleModule(LauncherModuleInfo info, Consumer<SimpleModuleAccessor> consumer) {
|
||||
super(info);
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(LauncherInitContext initContext) {
|
||||
consumer.accept(new SimpleModuleAccessor(initContext));
|
||||
}
|
||||
|
||||
public static SimpleModule of(String name, Version version, Consumer<SimpleModuleAccessor> consumer) {
|
||||
return new SimpleModule(new LauncherModuleInfoBuilder()
|
||||
.setName(name)
|
||||
.setVersion(version)
|
||||
.createLauncherModuleInfo(), consumer);
|
||||
}
|
||||
|
||||
public class SimpleModuleAccessor {
|
||||
private final LauncherInitContext context;
|
||||
|
||||
public SimpleModuleAccessor(LauncherInitContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public final <T extends LauncherModule> T requireModule(Class<? extends T> clazz, Version minVersion) {
|
||||
return SimpleModule.this.requireModule(clazz, minVersion);
|
||||
}
|
||||
|
||||
public final void requireModule(String name, Version minVersion) {
|
||||
SimpleModule.this.requireModule(name, minVersion);
|
||||
}
|
||||
|
||||
public final LauncherModulesContext getModulesContext() {
|
||||
return SimpleModule.this.getContext();
|
||||
}
|
||||
|
||||
public LauncherInitContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public <T extends Event> boolean registerEvent(EventHandler<T> handle, Class<T> tClass) {
|
||||
return SimpleModule.this.registerEvent(handle, tClass);
|
||||
}
|
||||
|
||||
public final <T extends Event> void callEvent(T event) {
|
||||
SimpleModule.this.callEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,14 +2,12 @@
|
|||
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
public class Cyclic2DependModule extends LauncherModule {
|
||||
public Cyclic2DependModule() {
|
||||
super(new LauncherModuleInfo("cyclic2",
|
||||
new Version(1, 0, 0),
|
||||
2, new String[]{"cyclic1"}));
|
||||
super(new LauncherModuleInfoBuilder().setName("cyclic2").setVersion(new Version(1, 0, 0)).setPriority(2).setDependencies(new String[]{"cyclic1"}).createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,14 +2,12 @@
|
|||
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
public class CyclicDependModule extends LauncherModule {
|
||||
public CyclicDependModule() {
|
||||
super(new LauncherModuleInfo("cyclic1",
|
||||
new Version(1, 0, 0),
|
||||
2, new String[]{"cyclic2"}));
|
||||
super(new LauncherModuleInfoBuilder().setName("cyclic1").setVersion(new Version(1, 0, 0)).setPriority(2).setDependencies(new String[]{"cyclic2"}).createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,14 +3,12 @@
|
|||
import org.junit.jupiter.api.Assertions;
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
public class Depend1Module extends LauncherModule {
|
||||
public Depend1Module() {
|
||||
super(new LauncherModuleInfo("depend1", new Version(1, 0, 0),
|
||||
0,
|
||||
new String[]{"depend3", "internal", "virtual"}));
|
||||
super(new LauncherModuleInfoBuilder().setName("depend1").setVersion(new Version(1, 0, 0)).setPriority(0).setDependencies(new String[]{"depend3", "internal", "virtual"}).createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
import org.junit.jupiter.api.Assertions;
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
public class Depend2Module extends LauncherModule {
|
||||
public Depend2Module() {
|
||||
super(new LauncherModuleInfo("depend2"));
|
||||
super(new LauncherModuleInfoBuilder().setName("depend2").createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
|
||||
public class Depend3Module extends LauncherModule {
|
||||
public Depend3Module() {
|
||||
super(new LauncherModuleInfo("depend3"));
|
||||
super(new LauncherModuleInfoBuilder().setName("depend3").createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
|
||||
public class InternalModule extends LauncherModule {
|
||||
public InternalModule() {
|
||||
super(new LauncherModuleInfo("internal"));
|
||||
super(new LauncherModuleInfoBuilder().setName("internal").createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,15 +3,13 @@
|
|||
import org.junit.jupiter.api.Assertions;
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
public class MainModule extends LauncherModule {
|
||||
|
||||
public MainModule() {
|
||||
super(new LauncherModuleInfo("main",
|
||||
new Version(1, 0, 0),
|
||||
0, new String[]{"depend1", "depend2"}));
|
||||
super(new LauncherModuleInfoBuilder().setName("main").setVersion(new Version(1, 0, 0)).setPriority(0).setDependencies(new String[]{"depend1", "depend2"}).createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
public class ProvidedModule extends LauncherModule implements VirtualInterface {
|
||||
public ProvidedModule() {
|
||||
super(new LauncherModuleInfo("provided", new Version(1, 0, 0),
|
||||
0, new String[]{}, new String[]{"virtual"}));
|
||||
super(new LauncherModuleInfoBuilder().setName("provided").setVersion(new Version(1, 0, 0)).setPriority(0).setDependencies(new String[]{}).setProviders(new String[]{"virtual"}).createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package pro.gravit.launcher.impl;
|
||||
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
import pro.gravit.launcher.impl.event.CancelEvent;
|
||||
import pro.gravit.launcher.impl.event.NormalEvent;
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
|
||||
public class TestModule extends LauncherModule {
|
||||
|
||||
public TestModule() {
|
||||
super(new LauncherModuleInfo("testModule"));
|
||||
super(new LauncherModuleInfoBuilder().setName("testModule").createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
public class ClientLauncherCoreModule extends LauncherModule {
|
||||
public ClientLauncherCoreModule() {
|
||||
super(new LauncherModuleInfo("ClientLauncherCore", Version.getVersion()));
|
||||
super(new LauncherModuleInfoBuilder().setName("ClientLauncherCore").setVersion(Version.getVersion()).createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
import pro.gravit.launcher.base.modules.LauncherInitContext;
|
||||
import pro.gravit.launcher.base.modules.LauncherModule;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfo;
|
||||
import pro.gravit.launcher.base.modules.LauncherModuleInfoBuilder;
|
||||
import pro.gravit.utils.Version;
|
||||
|
||||
public class RuntimeLauncherCoreModule extends LauncherModule {
|
||||
public RuntimeLauncherCoreModule() {
|
||||
super(new LauncherModuleInfo("ClientLauncherCore", Version.getVersion()));
|
||||
super(new LauncherModuleInfoBuilder().setName("ClientLauncherCore").setVersion(Version.getVersion()).createLauncherModuleInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -95,6 +95,35 @@ public FindRecursiveResult findRecursive(String path) {
|
|||
return new FindRecursiveResult(current, entry, name);
|
||||
}
|
||||
|
||||
public FindRecursiveResult tryFindRecursive(String path) {
|
||||
StringTokenizer t = new StringTokenizer(path, "/");
|
||||
HashedDir current = this;
|
||||
HashedEntry entry = null;
|
||||
String name = null;
|
||||
while (t.hasMoreTokens()) {
|
||||
name = t.nextToken();
|
||||
HashedEntry e = current.map.get(name);
|
||||
if (e == null && !t.hasMoreTokens()) {
|
||||
break;
|
||||
}
|
||||
if (e == null) {
|
||||
return new FindRecursiveResult(current, entry, name);
|
||||
}
|
||||
if (e.getType() == Type.DIR) {
|
||||
if (!t.hasMoreTokens()) {
|
||||
entry = e;
|
||||
break;
|
||||
} else {
|
||||
current = ((HashedDir) e);
|
||||
}
|
||||
} else {
|
||||
entry = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new FindRecursiveResult(current, entry, name);
|
||||
}
|
||||
|
||||
public HashedEntry getEntry(String name) {
|
||||
return map.get(name);
|
||||
}
|
||||
|
@ -295,6 +324,10 @@ public FindRecursiveResult(HashedDir parent, HashedEntry entry, String name) {
|
|||
this.entry = entry;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isFound() {
|
||||
return entry != null;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Diff {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# Modification of the launcher sashok724's v3 from Gravit [](https://travis-ci.com/GravitLauncher/Launcher)
|
||||
# Modification of the launcher sashok724's v3 from Gravit
|
||||
[](https://travis-ci.com/GravitLauncher/Launcher)
|
||||
[](https://discord.gg/b9QG4ygY75)
|
||||
|
||||
* [Discord channel](https://discord.gg/b9QG4ygY75)
|
||||
|
||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit a18e0b7d7b6aff2b46c13d0290826cdb8e815dbe
|
||||
Subproject commit 38788df61f8efc5453fe9c05017b629648b5fe6f
|
Loading…
Reference in a new issue