diff --git a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java index 5c45135d..b812b3c5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java +++ b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java @@ -8,37 +8,10 @@ import java.util.*; public class NewLauncherSettings { - @LauncherAPI - public String login; - @LauncherAPI - public String auth; - @LauncherAPI - public byte[] rsaPassword; - @LauncherAPI - public int profile; - @LauncherAPI - public transient Path updatesDir; - @LauncherAPI - public String updatesDirPath; - @LauncherAPI - public boolean autoEnter; - @LauncherAPI - public boolean debug; - @LauncherAPI - public boolean fullScreen; - @LauncherAPI - public boolean offline; - @LauncherAPI - public int ram; - - @LauncherAPI - public byte[] lastDigest; - @LauncherAPI - public List lastProfiles = new LinkedList<>(); @LauncherAPI public Map userSettings = new HashMap<>(); @LauncherAPI - public boolean featureStore; + public List features = new ArrayList<>(); @LauncherAPI public String consoleUnlockKey; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java index 62c1e1e5..c66a7ee1 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java @@ -22,60 +22,58 @@ public class LauncherUpdateController { public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException { if (e.zip && e.fullDownload) return; - if (SettingsManager.settings.featureStore) { - LogHelper.info("Enabled HStore feature. Find"); - AtomicReference lastEn = new AtomicReference<>(null); - //ArrayList removed = new ArrayList<>(); - diff.mismatch.walk(File.separator, (path, name, entry) -> { - if (entry.getType() == HashedEntry.Type.DIR) { - Files.createDirectories(request.getDir().resolve(path)); - return HashedDir.WalkAction.CONTINUE; - } - HashedFile file = (HashedFile) entry; - //Первый экспериментальный способ - честно обходим все возможные Store - Path ret = null; - if (lastEn.get() == null) { - for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { - ret = tryFind(en, file); - if (ret != null) { - lastEn.set(en); - break; - } - } - } else { - ret = tryFind(lastEn.get(), file); - } - if (ret == null) { - for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { - ret = tryFind(en, file); - if (ret != null) { - lastEn.set(en); - break; - } - } - } - if (ret != null) { - //Еще раз проверим корректность хеша - //Возможно эта проверка избыточна - //if(file.isSame(ret, true)) - { - Path source = request.getDir().resolve(path); - if (LogHelper.isDebugEnabled()) { - LogHelper.debug("Copy file %s to %s", ret.toAbsolutePath().toString(), source.toAbsolutePath().toString()); - } - //Let's go! - Files.deleteIfExists(source); - Files.copy(ret, source); - try (InputStream input = IOHelper.newInput(ret)) { - IOHelper.transfer(input, source); - } - entry.flag = true; - //removed.add(path.replace('\\', '/')); - } - } + LogHelper.info("Enabled HStore feature. Find"); + AtomicReference lastEn = new AtomicReference<>(null); + //ArrayList removed = new ArrayList<>(); + diff.mismatch.walk(File.separator, (path, name, entry) -> { + if (entry.getType() == HashedEntry.Type.DIR) { + Files.createDirectories(request.getDir().resolve(path)); return HashedDir.WalkAction.CONTINUE; - }); - } + } + HashedFile file = (HashedFile) entry; + //Первый экспериментальный способ - честно обходим все возможные Store + Path ret = null; + if (lastEn.get() == null) { + for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { + ret = tryFind(en, file); + if (ret != null) { + lastEn.set(en); + break; + } + } + } else { + ret = tryFind(lastEn.get(), file); + } + if (ret == null) { + for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { + ret = tryFind(en, file); + if (ret != null) { + lastEn.set(en); + break; + } + } + } + if (ret != null) { + //Еще раз проверим корректность хеша + //Возможно эта проверка избыточна + //if(file.isSame(ret, true)) + { + Path source = request.getDir().resolve(path); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Copy file %s to %s", ret.toAbsolutePath().toString(), source.toAbsolutePath().toString()); + } + //Let's go! + Files.deleteIfExists(source); + Files.copy(ret, source); + try (InputStream input = IOHelper.newInput(ret)) { + IOHelper.transfer(input, source); + } + entry.flag = true; + //removed.add(path.replace('\\', '/')); + } + } + return HashedDir.WalkAction.CONTINUE; + }); } public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) throws IOException { diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java deleted file mode 100644 index 78a27999..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java +++ /dev/null @@ -1,34 +0,0 @@ -package pro.gravit.launcher.console; - -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class FeatureCommand extends Command { - @Override - public String getArgsDescription() { - return "[feature] [true/false]"; - } - - @Override - public String getUsageDescription() { - return "Enable or disable feature"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 2); - boolean enabled = Boolean.parseBoolean(args[1]); - switch (args[0]) { - case "store": { - SettingsManager.settings.featureStore = enabled; - break; - } - default: { - LogHelper.info("Features: [store]"); - return; - } - } - LogHelper.info("Feature %s %s", args[0], enabled ? "enabled" : "disabled"); - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java deleted file mode 100644 index 763855ac..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -package pro.gravit.launcher.console.store; - -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class CopyStoreDirCommand extends Command { - @Override - public String getArgsDescription() { - return "[index] [overwrite(true/false)]"; - } - - @Override - public String getUsageDescription() { - return "Copy dir in GravitLauncherStore"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 2); - int ind = 1; - int index = Integer.parseInt(args[0]); - boolean overwrite = Boolean.parseBoolean(args[1]); - for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { - if (ind == index) { - LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name); - Path path = Paths.get(e.fullPath); - if (!Files.isDirectory(path)) { - LogHelper.error("Directory %s not found", path.toAbsolutePath().toString()); - return; - } - Path target = Paths.get(SettingsManager.settings.updatesDirPath).resolve(e.name); - if (Files.exists(target) && !overwrite) { - LogHelper.error("Directory %s found, flag overwrite not found", target.toAbsolutePath().toString()); - return; - } - Files.copy(path, target); - } - ind++; - } - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java deleted file mode 100644 index 35120f31..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -package pro.gravit.launcher.console.store; - -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class LinkStoreDirCommand extends Command { - - @Override - public String getArgsDescription() { - return "[index]"; - } - - @Override - public String getUsageDescription() { - return "Create symlink to GravitLauncherStore directory"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 1); - int ind = 1; - int index = Integer.parseInt(args[0]); - for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { - if (ind == index) { - LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name); - Path path = Paths.get(e.fullPath); - if (!Files.isDirectory(path)) { - LogHelper.error("Directory %s not found", path.toAbsolutePath().toString()); - return; - } - Path target = Paths.get(SettingsManager.settings.updatesDirPath).resolve(e.name); - if (Files.exists(target)) { - LogHelper.error("Directory %s already exists", target.toAbsolutePath().toString()); - return; - } - Files.createSymbolicLink(path, target); - } - ind++; - } - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java deleted file mode 100644 index 3ed81fc7..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package pro.gravit.launcher.console.store; - -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class StoreListCommand extends Command { - @Override - public String getArgsDescription() { - return null; - } - - @Override - public String getUsageDescription() { - return "List GravitLauncherStore"; - } - - @Override - public void invoke(String... args) { - int ind = 1; - for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { - LogHelper.info("[%d] FullPath: %s name: %s", ind, e.fullPath, e.name); - ind++; - } - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java index 07b41d72..19098f36 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java @@ -1,13 +1,9 @@ package pro.gravit.launcher.managers; import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.console.FeatureCommand; import pro.gravit.launcher.console.UnlockCommand; import pro.gravit.launcher.console.admin.ExecCommand; import pro.gravit.launcher.console.admin.LogListenerCommand; -import pro.gravit.launcher.console.store.CopyStoreDirCommand; -import pro.gravit.launcher.console.store.LinkStoreDirCommand; -import pro.gravit.launcher.console.store.StoreListCommand; import pro.gravit.utils.command.BaseCommandCategory; import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.JLineCommandHandler; @@ -57,16 +53,10 @@ public static boolean checkUnlockKey(String key) { public static void unlock() { handler.registerCommand("debug", new DebugCommand()); - handler.registerCommand("feature", new FeatureCommand()); BaseCommandCategory admin = new BaseCommandCategory(); admin.registerCommand("exec", new ExecCommand()); admin.registerCommand("logListen", new LogListenerCommand()); handler.registerCategory(new CommandHandler.Category(admin, "admin", "Server admin commands")); - BaseCommandCategory store = new BaseCommandCategory(); - store.registerCommand("storeList", new StoreListCommand()); - store.registerCommand("copyStoreDir", new CopyStoreDirCommand()); - store.registerCommand("linkStoreDir", new LinkStoreDirCommand()); - handler.registerCategory(new CommandHandler.Category(admin, "store", "Store admin commands")); isConsoleUnlock = true; } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java index 55921ab5..edf1dfe6 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java @@ -42,8 +42,6 @@ public SettingsManager() { @LauncherAPI @Override public NewLauncherSettings getConfig() { - if (settings.updatesDir != null) - settings.updatesDirPath = settings.updatesDir.toString(); return settings; } @@ -57,8 +55,6 @@ public NewLauncherSettings getDefaultConfig() { @Override public void setConfig(NewLauncherSettings config) { settings = config; - if (settings.updatesDirPath != null) - settings.updatesDir = Paths.get(settings.updatesDirPath); if (settings.consoleUnlockKey != null && !ConsoleManager.isConsoleUnlock) { if (ConsoleManager.checkUnlockKey(settings.consoleUnlockKey)) { ConsoleManager.unlock();