mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
Перевод конфигов на Json часть 2
Не комплируется
This commit is contained in:
parent
49b085278c
commit
7c35cb0a34
4 changed files with 23 additions and 31 deletions
|
@ -5,10 +5,6 @@
|
|||
import ru.gravit.launcher.hasher.HashedDir;
|
||||
import ru.gravit.launcher.managers.GarbageManager;
|
||||
import ru.gravit.launcher.profiles.ClientProfile;
|
||||
import ru.gravit.launcher.serialize.config.ConfigObject;
|
||||
import ru.gravit.launcher.serialize.config.TextConfigReader;
|
||||
import ru.gravit.launcher.serialize.config.TextConfigWriter;
|
||||
import ru.gravit.launcher.serialize.config.entry.*;
|
||||
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
|
||||
import ru.gravit.launchserver.auth.AuthLimiter;
|
||||
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
||||
|
@ -138,9 +134,9 @@ public static class ExeConf {
|
|||
}
|
||||
|
||||
private final class ProfilesFileVisitor extends SimpleFileVisitor<Path> {
|
||||
private final Collection<SignedObjectHolder<ClientProfile>> result;
|
||||
private final Collection<ClientProfile> result;
|
||||
|
||||
private ProfilesFileVisitor(Collection<SignedObjectHolder<ClientProfile>> result) {
|
||||
private ProfilesFileVisitor(Collection<ClientProfile> result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
@ -151,12 +147,12 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
// Read profile
|
||||
ClientProfile profile;
|
||||
try (BufferedReader reader = IOHelper.newReader(file)) {
|
||||
profile = new ClientProfile(TextConfigReader.read(reader, true));
|
||||
profile = Launcher.gson.fromJson(reader,ClientProfile.class);
|
||||
}
|
||||
profile.verify();
|
||||
|
||||
// Add SIGNED profile to result list
|
||||
result.add(new SignedObjectHolder<>(profile, privateKey));
|
||||
result.add(profile);
|
||||
return super.visitFile(file, attrs);
|
||||
}
|
||||
}
|
||||
|
@ -240,7 +236,7 @@ public static void main(String... args) throws Throwable {
|
|||
private final AtomicBoolean started = new AtomicBoolean(false);
|
||||
|
||||
// Updates and profiles
|
||||
private volatile List<SignedObjectHolder<ClientProfile>> profilesList;
|
||||
private volatile List<ClientProfile> profilesList;
|
||||
|
||||
public volatile Map<String, SignedObjectHolder<HashedDir>> updatesDirMap;
|
||||
|
||||
|
@ -308,7 +304,7 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException {
|
|||
generateConfigIfNotExists();
|
||||
LogHelper.info("Reading LaunchServer config file");
|
||||
try (BufferedReader reader = IOHelper.newReader(configFile)) {
|
||||
config = new Config(TextConfigReader.read(reader, true), dir, this);
|
||||
config = Launcher.gson.fromJson(reader,Config.class);
|
||||
}
|
||||
config.verify();
|
||||
|
||||
|
@ -399,7 +395,7 @@ private void generateConfigIfNotExists() throws IOException {
|
|||
LogHelper.info("Creating LaunchServer config");
|
||||
Config newConfig;
|
||||
try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL("ru/gravit/launchserver/defaults/config.cfg"))) {
|
||||
newConfig = new Config(TextConfigReader.read(reader, false), dir, this);
|
||||
newConfig = Launcher.gson.fromJson(reader,Config.class);
|
||||
}
|
||||
|
||||
// Set server address
|
||||
|
@ -409,13 +405,13 @@ private void generateConfigIfNotExists() throws IOException {
|
|||
// Write LaunchServer config
|
||||
LogHelper.info("Writing LaunchServer config file");
|
||||
try (BufferedWriter writer = IOHelper.newWriter(configFile)) {
|
||||
TextConfigWriter.write(newConfig.block, writer, true);
|
||||
Launcher.gson.toJson(newConfig,writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("ReturnOfCollectionOrArrayField")
|
||||
public Collection<SignedObjectHolder<ClientProfile>> getProfiles() {
|
||||
public Collection<ClientProfile> getProfiles() {
|
||||
return profilesList;
|
||||
}
|
||||
|
||||
|
@ -464,11 +460,11 @@ public void syncLauncherBinaries() throws IOException {
|
|||
|
||||
public void syncProfilesDir() throws IOException {
|
||||
LogHelper.info("Syncing profiles dir");
|
||||
List<SignedObjectHolder<ClientProfile>> newProfies = new LinkedList<>();
|
||||
List<ClientProfile> newProfies = new LinkedList<>();
|
||||
IOHelper.walk(profilesDir, new ProfilesFileVisitor(newProfies), false);
|
||||
|
||||
// Sort and set new profiles
|
||||
newProfies.sort(Comparator.comparing(a -> a.object));
|
||||
newProfies.sort(Comparator.comparing(a -> a));
|
||||
profilesList = Collections.unmodifiableList(newProfies);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,9 @@ public final class ProfilesRequest extends Request<ProfilesRequest.Result> {
|
|||
|
||||
public static final class Result {
|
||||
@LauncherAPI
|
||||
public final List<SignedObjectHolder<ClientProfile>> profiles;
|
||||
public final List<ClientProfile> profiles;
|
||||
|
||||
private Result(List<SignedObjectHolder<ClientProfile>> profiles) {
|
||||
private Result(List<ClientProfile> profiles) {
|
||||
this.profiles = Collections.unmodifiableList(profiles);
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ protected Result requestDo(HInput input, HOutput output) throws Exception {
|
|||
readError(input);
|
||||
|
||||
int count = input.readLength(0);
|
||||
List<SignedObjectHolder<ClientProfile>> profiles = new ArrayList<>(count);
|
||||
List<ClientProfile> profiles = new ArrayList<>(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
profiles.add(new SignedObjectHolder<>(input, config.publicKey, ClientProfile.RO_ADAPTER));
|
||||
|
||||
|
|
|
@ -8,14 +8,6 @@
|
|||
import ru.gravit.launcher.profiles.ClientProfile;
|
||||
import ru.gravit.launcher.request.auth.AuthServerRequest;
|
||||
import ru.gravit.launcher.request.update.ProfilesRequest;
|
||||
import ru.gravit.launcher.serialize.config.ConfigObject;
|
||||
import ru.gravit.launcher.serialize.config.TextConfigReader;
|
||||
import ru.gravit.launcher.serialize.config.TextConfigWriter;
|
||||
import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry;
|
||||
import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry;
|
||||
import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry;
|
||||
import ru.gravit.launcher.serialize.config.entry.StringConfigEntry;
|
||||
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
|
||||
import ru.gravit.utils.PublicURLClassLoader;
|
||||
import ru.gravit.utils.helper.CommonHelper;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
|
@ -50,11 +42,11 @@ public static boolean auth(ServerWrapper wrapper) {
|
|||
Boolean auth = new AuthServerRequest(cfg, config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), 0, config.title).request();
|
||||
if (auth == null) throw new Exception("Non auth!"); // security check
|
||||
ProfilesRequest.Result result = new ProfilesRequest(cfg).request();
|
||||
for (SignedObjectHolder<ClientProfile> p : result.profiles) {
|
||||
LogHelper.debug("Get profile: %s", p.object.getTitle());
|
||||
if (p.object.getTitle().equals(config.title)) {
|
||||
wrapper.profile = p.object;
|
||||
Launcher.profile = p.object;
|
||||
for (ClientProfile p : result.profiles) {
|
||||
LogHelper.debug("Get profile: %s", p.getTitle());
|
||||
if (p.getTitle().equals(config.title)) {
|
||||
wrapper.profile = p;
|
||||
Launcher.profile = p;
|
||||
LogHelper.debug("Found profile: %s", Launcher.profile.getTitle());
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ru.gravit.launcher;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import ru.gravit.launcher.modules.ModulesManagerInterface;
|
||||
import ru.gravit.launcher.profiles.ClientProfile;
|
||||
import ru.gravit.launcher.serialize.HInput;
|
||||
|
@ -61,6 +63,8 @@ public final class Launcher {
|
|||
public static int PATCH = 0;
|
||||
public static int BUILD = 3;
|
||||
public static Version.Type RELEASE = Version.Type.DEV;
|
||||
public static GsonBuilder gsonBuilder;
|
||||
public static Gson gson;
|
||||
|
||||
@LauncherAPI
|
||||
public static LauncherConfig getConfig() {
|
||||
|
|
Loading…
Reference in a new issue