[FEATURE] Updates and profiles sync in new thread

This commit is contained in:
Gravita 2021-03-26 22:06:44 +07:00
parent 63891cd743
commit fc13442c89
3 changed files with 41 additions and 11 deletions

View file

@ -15,10 +15,7 @@
import pro.gravit.launchserver.launchermodules.LauncherModuleLoader;
import pro.gravit.launchserver.manangers.*;
import pro.gravit.launchserver.manangers.hook.AuthHookManager;
import pro.gravit.launchserver.modules.events.LaunchServerFullInitEvent;
import pro.gravit.launchserver.modules.events.LaunchServerInitPhase;
import pro.gravit.launchserver.modules.events.LaunchServerPostInitPhase;
import pro.gravit.launchserver.modules.events.NewLaunchServerInstanceEvent;
import pro.gravit.launchserver.modules.events.*;
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
import pro.gravit.launchserver.socket.handlers.NettyServerSocketHandler;
import pro.gravit.utils.command.Command;
@ -163,14 +160,23 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
LogHelper.debug("Init components successful");
}
// Sync updates dir
if (!IOHelper.isDir(updatesDir))
Files.createDirectory(updatesDir);
syncUpdatesDir(null);
CommonHelper.newThread("Profiles and updates sync", true, () -> {
try {
if (!IOHelper.isDir(updatesDir))
Files.createDirectory(updatesDir);
syncUpdatesDir(null);
modulesManager.invokeEvent(new LaunchServerUpdatesSyncEvent(this));
// Sync profiles dir
if (!IOHelper.isDir(profilesDir))
Files.createDirectory(profilesDir);
syncProfilesDir();
// Sync profiles dir
if (!IOHelper.isDir(profilesDir))
Files.createDirectory(profilesDir);
syncProfilesDir();
modulesManager.invokeEvent(new LaunchServerProfilesSyncEvent(this));
} catch (IOException e) {
LogHelper.error(e);
LogHelper.error("Updates/Profiles not synced");
}
});
launcherModuleLoader.init();
nettyServerSocketHandler = new NettyServerSocketHandler(this);
// post init modules

View file

@ -0,0 +1,12 @@
package pro.gravit.launchserver.modules.events;
import pro.gravit.launcher.modules.LauncherModule;
import pro.gravit.launchserver.LaunchServer;
public class LaunchServerProfilesSyncEvent extends LauncherModule.Event {
public final LaunchServer server;
public LaunchServerProfilesSyncEvent(LaunchServer server) {
this.server = server;
}
}

View file

@ -0,0 +1,12 @@
package pro.gravit.launchserver.modules.events;
import pro.gravit.launcher.modules.LauncherModule;
import pro.gravit.launchserver.LaunchServer;
public class LaunchServerUpdatesSyncEvent extends LauncherModule.Event {
public final LaunchServer server;
public LaunchServerUpdatesSyncEvent(LaunchServer server) {
this.server = server;
}
}