mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] ModulesConfigManager
This commit is contained in:
parent
fa531a7b55
commit
68540a1c44
11 changed files with 99 additions and 8 deletions
|
@ -189,6 +189,14 @@ public void verify() {
|
|||
{
|
||||
throw new NullPointerException("TextureProvider must not be null");
|
||||
}
|
||||
if(permissionsHandler == null)
|
||||
{
|
||||
throw new NullPointerException("PermissionsHandler must not be null");
|
||||
}
|
||||
if(env == null)
|
||||
{
|
||||
throw new NullPointerException("Env must not be null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,17 +3,20 @@
|
|||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ru.gravit.launcher.modules.SimpleModuleManager;
|
||||
import ru.gravit.launcher.managers.ModulesConfigManager;
|
||||
import ru.gravit.launcher.managers.SimpleModuleManager;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.modules.CoreModule;
|
||||
import ru.gravit.launchserver.modules.LaunchServerModuleContext;
|
||||
import ru.gravit.utils.PublicURLClassLoader;
|
||||
|
||||
public class ModulesManager extends SimpleModuleManager {
|
||||
public ModulesConfigManager configManager;
|
||||
public ModulesManager(LaunchServer lsrv) {
|
||||
modules = new ArrayList<>(1);
|
||||
configManager = new ModulesConfigManager(lsrv.dir.resolve("config"));
|
||||
classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
|
||||
context = new LaunchServerModuleContext(lsrv, classloader);
|
||||
context = new LaunchServerModuleContext(lsrv, classloader, configManager);
|
||||
registerCoreModule();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package ru.gravit.launchserver.modules;
|
||||
|
||||
import ru.gravit.launcher.managers.ModulesConfigManager;
|
||||
import ru.gravit.launcher.modules.ModuleContext;
|
||||
import ru.gravit.launcher.modules.ModulesConfigManagerInterface;
|
||||
import ru.gravit.launcher.modules.ModulesManagerInterface;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.utils.PublicURLClassLoader;
|
||||
|
@ -8,10 +10,12 @@
|
|||
public class LaunchServerModuleContext implements ModuleContext {
|
||||
public final LaunchServer launchServer;
|
||||
public final PublicURLClassLoader classloader;
|
||||
public final ModulesConfigManager modulesConfigManager;
|
||||
|
||||
public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader) {
|
||||
public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader, ModulesConfigManager modulesConfigManager) {
|
||||
launchServer = server;
|
||||
this.classloader = classloader;
|
||||
this.modulesConfigManager = modulesConfigManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,4 +27,9 @@ public Type getType() {
|
|||
public ModulesManagerInterface getModulesManager() {
|
||||
return launchServer.modulesManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModulesConfigManagerInterface getModulesConfigManager() {
|
||||
return modulesConfigManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import ru.gravit.launcher.Launcher;
|
||||
import ru.gravit.launcher.LauncherEngine;
|
||||
import ru.gravit.launcher.modules.ModuleContext;
|
||||
import ru.gravit.launcher.modules.ModulesConfigManagerInterface;
|
||||
import ru.gravit.launcher.modules.ModulesManagerInterface;
|
||||
|
||||
public class ClientModuleContext implements ModuleContext {
|
||||
|
@ -21,4 +22,9 @@ public Type getType() {
|
|||
public ModulesManagerInterface getModulesManager() {
|
||||
return Launcher.modulesManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModulesConfigManagerInterface getModulesConfigManager() {
|
||||
return null; // ClientModuleContext не поддерживает modulesConfigManager
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package ru.gravit.launcher.client;
|
||||
|
||||
import ru.gravit.launcher.LauncherEngine;
|
||||
import ru.gravit.launcher.modules.SimpleModuleManager;
|
||||
import ru.gravit.launcher.managers.SimpleModuleManager;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
package ru.gravit.launcher.server;
|
||||
|
||||
import ru.gravit.launcher.modules.SimpleModuleManager;
|
||||
import ru.gravit.launcher.managers.ModulesConfigManager;
|
||||
import ru.gravit.launcher.managers.SimpleModuleManager;
|
||||
import ru.gravit.utils.PublicURLClassLoader;
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ModulesManager extends SimpleModuleManager {
|
||||
public ModulesConfigManager modulesConfigManager;
|
||||
public ModulesManager(ServerWrapper wrapper) {
|
||||
modules = new ArrayList<>();
|
||||
modulesConfigManager = new ModulesConfigManager(Paths.get("modules-config"));
|
||||
classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
|
||||
context = new ServerModuleContext(wrapper, classloader);
|
||||
context = new ServerModuleContext(wrapper, classloader, modulesConfigManager);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
package ru.gravit.launcher.server;
|
||||
|
||||
import ru.gravit.launcher.Launcher;
|
||||
import ru.gravit.launcher.managers.ModulesConfigManager;
|
||||
import ru.gravit.launcher.modules.ModuleContext;
|
||||
import ru.gravit.launcher.modules.ModulesConfigManagerInterface;
|
||||
import ru.gravit.launcher.modules.ModulesManagerInterface;
|
||||
import ru.gravit.utils.PublicURLClassLoader;
|
||||
|
||||
public class ServerModuleContext implements ModuleContext {
|
||||
public final PublicURLClassLoader classLoader;
|
||||
public final ServerWrapper wrapper;
|
||||
public final ModulesConfigManager modulesConfigManager;
|
||||
|
||||
public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader) {
|
||||
public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader, ModulesConfigManager modulesConfigManager) {
|
||||
this.classLoader = classLoader;
|
||||
this.wrapper = wrapper;
|
||||
this.modulesConfigManager = modulesConfigManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,4 +27,9 @@ public Type getType() {
|
|||
public ModulesManagerInterface getModulesManager() {
|
||||
return Launcher.modulesManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModulesConfigManagerInterface getModulesConfigManager() {
|
||||
return modulesConfigManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package ru.gravit.launcher.managers;
|
||||
|
||||
import ru.gravit.launcher.modules.ModulesConfigManagerInterface;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ModulesConfigManager implements ModulesConfigManagerInterface {
|
||||
public Path configDir;
|
||||
|
||||
public ModulesConfigManager(Path configDir) {
|
||||
this.configDir = configDir;
|
||||
}
|
||||
|
||||
public Path getModuleConfig(String moduleName)
|
||||
{
|
||||
if(!IOHelper.isDir(configDir)) {
|
||||
try {
|
||||
Files.createDirectories(configDir);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
return configDir.resolve(moduleName.concat("Config.json"));
|
||||
}
|
||||
public Path getModuleConfigDir(String moduleName)
|
||||
{
|
||||
if(!IOHelper.isDir(configDir)) {
|
||||
try {
|
||||
Files.createDirectories(configDir);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
return configDir.resolve(moduleName);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
package ru.gravit.launcher.modules;
|
||||
package ru.gravit.launcher.managers;
|
||||
|
||||
import ru.gravit.launcher.modules.Module;
|
||||
import ru.gravit.launcher.modules.ModuleContext;
|
||||
import ru.gravit.launcher.modules.ModulesManagerInterface;
|
||||
import ru.gravit.utils.PublicURLClassLoader;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
|
@ -8,4 +8,5 @@ enum Type {
|
|||
Type getType();
|
||||
|
||||
ModulesManagerInterface getModulesManager();
|
||||
ModulesConfigManagerInterface getModulesConfigManager();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package ru.gravit.launcher.modules;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface ModulesConfigManagerInterface {
|
||||
Path getModuleConfig(String moduleName);
|
||||
Path getModuleConfigDir(String moduleName);
|
||||
}
|
Loading…
Reference in a new issue