From 5e1fb46aece8435f99c9151428bfaf8c198a4d49 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 20 May 2019 04:55:57 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=9D=D0=B0=D1=87=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D1=8B=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20GravitLauncherStorage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../console/store/CopyStoreDirCommand.java | 51 +++++++++++++++++++ .../console/store/LinkStoreDirCommand.java | 51 +++++++++++++++++++ .../console/store/StoreListCommand.java | 28 ++++++++++ .../launcher/managers/ConsoleManager.java | 8 +++ 4 files changed, 138 insertions(+) create mode 100644 Launcher/src/main/java/ru/gravit/launcher/console/store/CopyStoreDirCommand.java create mode 100644 Launcher/src/main/java/ru/gravit/launcher/console/store/LinkStoreDirCommand.java create mode 100644 Launcher/src/main/java/ru/gravit/launcher/console/store/StoreListCommand.java diff --git a/Launcher/src/main/java/ru/gravit/launcher/console/store/CopyStoreDirCommand.java b/Launcher/src/main/java/ru/gravit/launcher/console/store/CopyStoreDirCommand.java new file mode 100644 index 00000000..9731dba5 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/console/store/CopyStoreDirCommand.java @@ -0,0 +1,51 @@ +package ru.gravit.launcher.console.store; + +import ru.gravit.launcher.NewLauncherSettings; +import ru.gravit.launcher.managers.SettingsManager; +import ru.gravit.utils.command.Command; +import ru.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.valueOf(args[0]); + boolean overwrite = Boolean.valueOf(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/ru/gravit/launcher/console/store/LinkStoreDirCommand.java b/Launcher/src/main/java/ru/gravit/launcher/console/store/LinkStoreDirCommand.java new file mode 100644 index 00000000..a107e6d3 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/console/store/LinkStoreDirCommand.java @@ -0,0 +1,51 @@ +package ru.gravit.launcher.console.store; + +import ru.gravit.launcher.NewLauncherSettings; +import ru.gravit.launcher.managers.SettingsManager; +import ru.gravit.utils.command.Command; +import ru.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.valueOf(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/ru/gravit/launcher/console/store/StoreListCommand.java b/Launcher/src/main/java/ru/gravit/launcher/console/store/StoreListCommand.java new file mode 100644 index 00000000..14a68524 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/console/store/StoreListCommand.java @@ -0,0 +1,28 @@ +package ru.gravit.launcher.console.store; + +import ru.gravit.launcher.NewLauncherSettings; +import ru.gravit.launcher.managers.SettingsManager; +import ru.gravit.utils.command.Command; +import ru.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) throws Exception { + 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/ru/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java index 0324de64..582764fa 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java @@ -3,6 +3,9 @@ import ru.gravit.launcher.console.UnlockCommand; import ru.gravit.launcher.console.admin.ExecCommand; import ru.gravit.launcher.console.admin.LogListenerCommand; +import ru.gravit.launcher.console.store.CopyStoreDirCommand; +import ru.gravit.launcher.console.store.LinkStoreDirCommand; +import ru.gravit.launcher.console.store.StoreListCommand; import ru.gravit.utils.command.BaseCommandCategory; import ru.gravit.utils.command.CommandHandler; import ru.gravit.utils.command.JLineCommandHandler; @@ -55,5 +58,10 @@ public static void unlock() { 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")); } }