[FEATURE] Начальные команды управления GravitLauncherStorage

This commit is contained in:
Gravit 2019-05-20 04:55:57 +07:00
parent 17ede8b98f
commit 5e1fb46aec
4 changed files with 138 additions and 0 deletions

View file

@ -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++;
}
}
}

View file

@ -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++;
}
}
}

View file

@ -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++;
}
}
}

View file

@ -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"));
}
}