mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FIX] Фиксы настроек и LogHelper
This commit is contained in:
parent
ae0e178d43
commit
f7091bf074
7 changed files with 104 additions and 88 deletions
|
@ -443,7 +443,7 @@ var serverHolder = {
|
|||
};
|
||||
|
||||
/* ======== Scenes scripts ======== */
|
||||
launcher.loadScript("api/settings.js");
|
||||
launcher.loadScript("engine/settings.js");
|
||||
launcher.loadScript("dialog/overlay/debug/debug.js");
|
||||
launcher.loadScript("dialog/overlay/processing/processing.js");
|
||||
launcher.loadScript("dialog/overlay/settings/settings.js");
|
||||
|
|
|
@ -17,5 +17,5 @@ var settingsManagerClass = Java.extend(SettingsManagerClass.static, {
|
|||
},
|
||||
});
|
||||
|
||||
var settingsManager = new settingsManager;
|
||||
var settingsManager = new settingsManagerClass;
|
||||
var settings = SettingsManager.settings;
|
|
@ -5,7 +5,8 @@ var LauncherApp = Java.extend(JSApplication, {
|
|||
init: function() {
|
||||
app = JSApplication.getInstance();
|
||||
cliParams.init(app.getParameters());
|
||||
settings.load();
|
||||
settingsManager.loadConfig();
|
||||
settings = SettingsManager.settings;
|
||||
cliParams.applySettings();
|
||||
}, start: function(primaryStage) {
|
||||
stage = primaryStage;
|
||||
|
@ -39,7 +40,7 @@ var LauncherApp = Java.extend(JSApplication, {
|
|||
initLauncher();
|
||||
|
||||
}, stop: function() {
|
||||
settings.save();
|
||||
settingsManager.saveConfig();
|
||||
options.save();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -19,6 +19,7 @@ public SettingsManager() {
|
|||
@LauncherAPI
|
||||
@Override
|
||||
public NewLauncherSettings getConfig() {
|
||||
if(settings.updatesDir != null)
|
||||
settings.updatesDirPath = settings.updatesDir.toString();
|
||||
return settings;
|
||||
}
|
||||
|
@ -31,6 +32,7 @@ public NewLauncherSettings getDefaultConfig() {
|
|||
@Override
|
||||
public void setConfig(NewLauncherSettings config) {
|
||||
settings = config;
|
||||
if(settings.updatesDirPath != null)
|
||||
settings.updatesDir = Paths.get(settings.updatesDirPath);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
import ru.gravit.utils.command.Command;
|
||||
import ru.gravit.utils.command.CommandException;
|
||||
import ru.gravit.utils.command.CommandHandler;
|
||||
import ru.gravit.utils.helper.FormatHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
@ -13,8 +14,8 @@ public final class HelpCommand extends Command {
|
|||
private static void printCommand(String name, Command command) {
|
||||
String args = command.getArgsDescription();
|
||||
//LogHelper.subInfo("%s %s - %s", name, args == null ? "[nothing]" : args, command.getUsageDescription());
|
||||
LogHelper.rawLog(() -> LogHelper.rawFormat(LogHelper.Level.INFO, LogHelper.getDataTime(), true) + String.format("%s %s - %s", name, args == null ? "[nothing]" : args, command.getUsageDescription()), () -> {
|
||||
Ansi ansi = LogHelper.rawAnsiFormat(LogHelper.Level.INFO, LogHelper.getDataTime(), true);
|
||||
LogHelper.rawLog(() -> FormatHelper.rawFormat(LogHelper.Level.INFO, LogHelper.getDataTime(), true) + String.format("%s %s - %s", name, args == null ? "[nothing]" : args, command.getUsageDescription()), () -> {
|
||||
Ansi ansi = FormatHelper.rawAnsiFormat(LogHelper.Level.INFO, LogHelper.getDataTime(), true);
|
||||
ansi.fgBright(Ansi.Color.GREEN);
|
||||
ansi.a(name + " ");
|
||||
ansi.fgBright(Ansi.Color.CYAN);
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
package ru.gravit.utils.helper;
|
||||
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import ru.gravit.launcher.Launcher;
|
||||
|
||||
/*
|
||||
* Nashorn при инициализации LogHelper пытается инициализировтаь все доступные в нем методы.
|
||||
* При попытке инициализировать rawAnsiFormat он пытается найти класс org.fusesource.jansi.Ansi
|
||||
* И есстественно крашится с ClassNotFound
|
||||
* В итоге любой вызов LogHelper.* приводит к ClassNotFound org.fusesource.jansi.Ansi
|
||||
* Поэтому rawAnsiFormat вынесен в отдельный Helper
|
||||
*/
|
||||
public class FormatHelper {
|
||||
public static Ansi rawAnsiFormat(LogHelper.Level level, String dateTime, boolean sub)
|
||||
{
|
||||
Ansi.Color levelColor;
|
||||
boolean bright = level != LogHelper.Level.DEBUG;
|
||||
switch (level) {
|
||||
case WARNING:
|
||||
levelColor = Ansi.Color.YELLOW;
|
||||
break;
|
||||
case ERROR:
|
||||
levelColor = Ansi.Color.RED;
|
||||
break;
|
||||
default: // INFO, DEBUG, Unknown
|
||||
levelColor = Ansi.Color.WHITE;
|
||||
break;
|
||||
}
|
||||
|
||||
// Date-time
|
||||
Ansi ansi = new Ansi();
|
||||
ansi.fg(Ansi.Color.WHITE).a(dateTime);
|
||||
|
||||
// Level
|
||||
ansi.fgBright(Ansi.Color.WHITE).a(" [").bold();
|
||||
if (bright) {
|
||||
ansi.fgBright(levelColor);
|
||||
} else {
|
||||
ansi.fg(levelColor);
|
||||
}
|
||||
ansi.a(level).boldOff().fgBright(Ansi.Color.WHITE).a("] ");
|
||||
|
||||
// Message
|
||||
if (bright) {
|
||||
ansi.fgBright(levelColor);
|
||||
} else {
|
||||
ansi.fg(levelColor);
|
||||
}
|
||||
if (sub) {
|
||||
ansi.a(' ').a(Ansi.Attribute.ITALIC);
|
||||
}
|
||||
|
||||
// Finish with reset code
|
||||
return ansi;
|
||||
}
|
||||
|
||||
static String ansiFormatVersion(String product) {
|
||||
return new Ansi().bold(). // Setup
|
||||
fgBright(Ansi.Color.MAGENTA).a("GravitLauncher "). // sashok724's
|
||||
fgBright(Ansi.Color.BLUE).a("(fork sashok724's Launcher) ").
|
||||
fgBright(Ansi.Color.CYAN).a(product). // Product
|
||||
fgBright(Ansi.Color.WHITE).a(" v").fgBright(Ansi.Color.BLUE).a(Launcher.getVersion().toString()). // Version
|
||||
fgBright(Ansi.Color.WHITE).a(" (build #").fgBright(Ansi.Color.RED).a(Launcher.getVersion().build).fgBright(Ansi.Color.WHITE).a(')'). // Build#
|
||||
reset().toString(); // To file
|
||||
}
|
||||
|
||||
static String ansiFormatLicense(String product) {
|
||||
return new Ansi().bold(). // Setup
|
||||
fgBright(Ansi.Color.MAGENTA).a("License for "). // sashok724's
|
||||
fgBright(Ansi.Color.CYAN).a(product). // Product
|
||||
fgBright(Ansi.Color.WHITE).a(" GPLv3").fgBright(Ansi.Color.WHITE).a(". SourceCode: "). // Version
|
||||
fgBright(Ansi.Color.YELLOW).a("https://github.com/GravitLauncher/Launcher").
|
||||
reset().toString(); // To file
|
||||
}
|
||||
|
||||
public static String rawFormat(LogHelper.Level level, String dateTime, boolean sub)
|
||||
{
|
||||
return dateTime + " [" + level.name + (sub ? "] " : "] ");
|
||||
}
|
||||
|
||||
static String formatVersion(String product) {
|
||||
return String.format("GravitLauncher (fork sashok724's Launcher) %s v%s", product, Launcher.getVersion().toString());
|
||||
}
|
||||
|
||||
static String formatLicense(String product) {
|
||||
return String.format("License for %s GPLv3. SourceCode: https://github.com/GravitLauncher/Launcher", product);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,8 @@
|
|||
package ru.gravit.utils.helper;
|
||||
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.Ansi.Color;
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
import org.fusesource.jansi.AnsiOutputStream;
|
||||
import ru.gravit.launcher.Launcher;
|
||||
import ru.gravit.launcher.LauncherAPI;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -245,7 +243,7 @@ public static void printVersion(String product) {
|
|||
continue;
|
||||
}
|
||||
|
||||
jansiString = ansiFormatVersion(product);
|
||||
jansiString = FormatHelper.ansiFormatVersion(product);
|
||||
output.output.println(jansiString);
|
||||
} else {
|
||||
if (plainString != null) {
|
||||
|
@ -253,7 +251,7 @@ public static void printVersion(String product) {
|
|||
continue;
|
||||
}
|
||||
|
||||
plainString = formatVersion(product);
|
||||
plainString = FormatHelper.formatVersion(product);
|
||||
output.output.println(plainString);
|
||||
}
|
||||
}
|
||||
|
@ -269,7 +267,7 @@ public static void printLicense(String product) {
|
|||
continue;
|
||||
}
|
||||
|
||||
jansiString = ansiFormatLicense(product);
|
||||
jansiString = FormatHelper.ansiFormatLicense(product);
|
||||
output.output.println(jansiString);
|
||||
} else {
|
||||
if (plainString != null) {
|
||||
|
@ -277,7 +275,7 @@ public static void printLicense(String product) {
|
|||
continue;
|
||||
}
|
||||
|
||||
plainString = formatLicense(product);
|
||||
plainString = FormatHelper.formatLicense(product);
|
||||
output.output.println(plainString);
|
||||
}
|
||||
}
|
||||
|
@ -349,54 +347,12 @@ public static void warning(String format, Object... args) {
|
|||
|
||||
private static String ansiFormatLog(Level level, String dateTime, String message, boolean sub) {
|
||||
|
||||
Ansi ansi = rawAnsiFormat(level, dateTime, sub);
|
||||
Ansi ansi = FormatHelper.rawAnsiFormat(level, dateTime, sub);
|
||||
ansi.a(message);
|
||||
|
||||
// Finish with reset code
|
||||
return ansi.reset().toString();
|
||||
}
|
||||
public static Ansi rawAnsiFormat(Level level, String dateTime, boolean sub)
|
||||
{
|
||||
Color levelColor;
|
||||
boolean bright = level != Level.DEBUG;
|
||||
switch (level) {
|
||||
case WARNING:
|
||||
levelColor = Color.YELLOW;
|
||||
break;
|
||||
case ERROR:
|
||||
levelColor = Color.RED;
|
||||
break;
|
||||
default: // INFO, DEBUG, Unknown
|
||||
levelColor = Color.WHITE;
|
||||
break;
|
||||
}
|
||||
|
||||
// Date-time
|
||||
Ansi ansi = new Ansi();
|
||||
ansi.fg(Color.WHITE).a(dateTime);
|
||||
|
||||
// Level
|
||||
ansi.fgBright(Color.WHITE).a(" [").bold();
|
||||
if (bright) {
|
||||
ansi.fgBright(levelColor);
|
||||
} else {
|
||||
ansi.fg(levelColor);
|
||||
}
|
||||
ansi.a(level).boldOff().fgBright(Color.WHITE).a("] ");
|
||||
|
||||
// Message
|
||||
if (bright) {
|
||||
ansi.fgBright(levelColor);
|
||||
} else {
|
||||
ansi.fg(levelColor);
|
||||
}
|
||||
if (sub) {
|
||||
ansi.a(' ').a(Ansi.Attribute.ITALIC);
|
||||
}
|
||||
|
||||
// Finish with reset code
|
||||
return ansi;
|
||||
}
|
||||
|
||||
public static String htmlFormatLog(Level level, String dateTime, String message, boolean sub)
|
||||
{
|
||||
|
@ -422,40 +378,8 @@ public static String htmlFormatLog(Level level, String dateTime, String message,
|
|||
return String.format("%s <span class=\"gravitlauncher-log %s\">[%s] %s</span>", dateTime, levelColor, level.toString(), sub ? ' ' + message : message);
|
||||
}
|
||||
|
||||
private static String ansiFormatVersion(String product) {
|
||||
return new Ansi().bold(). // Setup
|
||||
fgBright(Color.MAGENTA).a("GravitLauncher "). // sashok724's
|
||||
fgBright(Color.BLUE).a("(fork sashok724's Launcher) ").
|
||||
fgBright(Color.CYAN).a(product). // Product
|
||||
fgBright(Color.WHITE).a(" v").fgBright(Color.BLUE).a(Launcher.getVersion().toString()). // Version
|
||||
fgBright(Color.WHITE).a(" (build #").fgBright(Color.RED).a(Launcher.getVersion().build).fgBright(Color.WHITE).a(')'). // Build#
|
||||
reset().toString(); // To file
|
||||
}
|
||||
|
||||
private static String ansiFormatLicense(String product) {
|
||||
return new Ansi().bold(). // Setup
|
||||
fgBright(Color.MAGENTA).a("License for "). // sashok724's
|
||||
fgBright(Color.CYAN).a(product). // Product
|
||||
fgBright(Color.WHITE).a(" GPLv3").fgBright(Color.WHITE).a(". SourceCode: "). // Version
|
||||
fgBright(Color.YELLOW).a("https://github.com/GravitLauncher/Launcher").
|
||||
reset().toString(); // To file
|
||||
}
|
||||
|
||||
private static String formatLog(Level level, String message, String dateTime, boolean sub) {
|
||||
return rawFormat(level, dateTime, sub) + message;
|
||||
}
|
||||
|
||||
public static String rawFormat(Level level, String dateTime, boolean sub)
|
||||
{
|
||||
return dateTime + " [" + level.name + (sub ? "] " : "] ");
|
||||
}
|
||||
|
||||
private static String formatVersion(String product) {
|
||||
return String.format("GravitLauncher (fork sashok724's Launcher) %s v%s", product, Launcher.getVersion().toString());
|
||||
}
|
||||
|
||||
private static String formatLicense(String product) {
|
||||
return String.format("License for %s GPLv3. SourceCode: https://github.com/GravitLauncher/Launcher", product);
|
||||
return FormatHelper.rawFormat(level, dateTime, sub) + message;
|
||||
}
|
||||
|
||||
static {
|
||||
|
|
Loading…
Reference in a new issue