[FEATURE] Удалено большинство настроек, относвщихся к рантайму

This commit is contained in:
Gravit 2019-12-05 01:22:07 +07:00
parent f839691c87
commit 4136f4a6e8
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
8 changed files with 52 additions and 250 deletions

View file

@ -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<ClientProfile> lastProfiles = new LinkedList<>();
@LauncherAPI
public Map<String, UserSettings> userSettings = new HashMap<>();
@LauncherAPI
public boolean featureStore;
public List<String> features = new ArrayList<>();
@LauncherAPI
public String consoleUnlockKey;

View file

@ -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<NewLauncherSettings.HashedStoreEntry> lastEn = new AtomicReference<>(null);
//ArrayList<String> 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<NewLauncherSettings.HashedStoreEntry> lastEn = new AtomicReference<>(null);
//ArrayList<String> 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 {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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();