mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
Оптимизация хранения ClientProfile
This commit is contained in:
parent
4c4ff840d4
commit
2bff9a4e18
1 changed files with 40 additions and 42 deletions
|
@ -66,15 +66,15 @@ public String toString() {
|
||||||
private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher(
|
private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher(
|
||||||
new String[0], new String[]{"indexes", "objects"}, new String[0]);
|
new String[0], new String[]{"indexes", "objects"}, new String[0]);
|
||||||
// Version
|
// Version
|
||||||
private final StringConfigEntry version;
|
private String version;
|
||||||
|
|
||||||
private final StringConfigEntry assetIndex;
|
private final String assetIndex;
|
||||||
// Client
|
// Client
|
||||||
private final IntegerConfigEntry sortIndex;
|
private final int sortIndex;
|
||||||
private final StringConfigEntry title;
|
private String title;
|
||||||
private final StringConfigEntry serverAddress;
|
private final String serverAddress;
|
||||||
|
|
||||||
private final IntegerConfigEntry serverPort;
|
private final int serverPort;
|
||||||
|
|
||||||
public static class MarkedString {
|
public static class MarkedString {
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -112,30 +112,30 @@ public int hashCode() {
|
||||||
private final List<String> updateShared = new ArrayList<>();
|
private final List<String> updateShared = new ArrayList<>();
|
||||||
private final List<String> updateVerify = new ArrayList<>();
|
private final List<String> updateVerify = new ArrayList<>();
|
||||||
private final Set<MarkedString> updateOptional = new HashSet<>();
|
private final Set<MarkedString> updateOptional = new HashSet<>();
|
||||||
private final BooleanConfigEntry updateFastCheck;
|
private final boolean updateFastCheck;
|
||||||
|
|
||||||
private final BooleanConfigEntry useWhitelist;
|
private final boolean useWhitelist;
|
||||||
// Client launcher
|
// Client launcher
|
||||||
private final StringConfigEntry mainClass;
|
private final String mainClass;
|
||||||
private final List<String> jvmArgs = new ArrayList<>();
|
private final List<String> jvmArgs = new ArrayList<>();
|
||||||
private final ListConfigEntry classPath;
|
private final List<String> classPath = new ArrayList<>();
|
||||||
private final ListConfigEntry clientArgs;
|
private final List<String> clientArgs = new ArrayList<>();
|
||||||
|
|
||||||
private final ListConfigEntry whitelist;
|
private final List<String> whitelist = new ArrayList<>();
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public ClientProfile(BlockConfigEntry block) {
|
public ClientProfile(BlockConfigEntry block) {
|
||||||
super(block);
|
super(block);
|
||||||
|
|
||||||
// Version
|
// Version
|
||||||
version = block.getEntry("version", StringConfigEntry.class);
|
version = block.getEntryValue("version", StringConfigEntry.class);
|
||||||
assetIndex = block.getEntry("assetIndex", StringConfigEntry.class);
|
assetIndex = block.getEntryValue("assetIndex", StringConfigEntry.class);
|
||||||
|
|
||||||
// Client
|
// Client
|
||||||
sortIndex = block.getEntry("sortIndex", IntegerConfigEntry.class);
|
sortIndex = block.getEntryValue("sortIndex", IntegerConfigEntry.class);
|
||||||
title = block.getEntry("title", StringConfigEntry.class);
|
title = block.getEntryValue("title", StringConfigEntry.class);
|
||||||
serverAddress = block.getEntry("serverAddress", StringConfigEntry.class);
|
serverAddress = block.getEntryValue("serverAddress", StringConfigEntry.class);
|
||||||
serverPort = block.getEntry("serverPort", IntegerConfigEntry.class);
|
serverPort = block.getEntryValue("serverPort", IntegerConfigEntry.class);
|
||||||
|
|
||||||
// Updater and client watch service
|
// Updater and client watch service
|
||||||
block.getEntry("update", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(update::add);
|
block.getEntry("update", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(update::add);
|
||||||
|
@ -144,15 +144,15 @@ public ClientProfile(BlockConfigEntry block) {
|
||||||
block.getEntry("updateOptional", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(e -> updateOptional.add(new MarkedString(e)));
|
block.getEntry("updateOptional", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(e -> updateOptional.add(new MarkedString(e)));
|
||||||
block.getEntry("updateExclusions", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(updateExclusions::add);
|
block.getEntry("updateExclusions", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(updateExclusions::add);
|
||||||
block.getEntry("enabledOptional", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(e -> updateOptional.stream().anyMatch(e1 -> e.equals(e1.string) && (e1.mark = true)));
|
block.getEntry("enabledOptional", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(e -> updateOptional.stream().anyMatch(e1 -> e.equals(e1.string) && (e1.mark = true)));
|
||||||
updateFastCheck = block.getEntry("updateFastCheck", BooleanConfigEntry.class);
|
updateFastCheck = block.getEntryValue("updateFastCheck", BooleanConfigEntry.class);
|
||||||
useWhitelist = block.getEntry("useWhitelist", BooleanConfigEntry.class);
|
useWhitelist = block.getEntryValue("useWhitelist", BooleanConfigEntry.class);
|
||||||
|
|
||||||
// Client launcher
|
// Client launcher
|
||||||
mainClass = block.getEntry("mainClass", StringConfigEntry.class);
|
mainClass = block.getEntryValue("mainClass", StringConfigEntry.class);
|
||||||
classPath = block.getEntry("classPath", ListConfigEntry.class);
|
block.getEntry("classPath", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(classPath::add);
|
||||||
block.getEntry("jvmArgs", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(jvmArgs::add);
|
block.getEntry("jvmArgs", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(jvmArgs::add);
|
||||||
clientArgs = block.getEntry("clientArgs", ListConfigEntry.class);
|
block.getEntry("clientArgs", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(clientArgs::add);
|
||||||
whitelist = block.getEntry("whitelist", ListConfigEntry.class);
|
block.getEntry("whitelist", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(whitelist::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -167,7 +167,7 @@ public int compareTo(ClientProfile o) {
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public String getAssetIndex() {
|
public String getAssetIndex() {
|
||||||
return assetIndex.getValue();
|
return assetIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -177,12 +177,12 @@ public FileNameMatcher getAssetUpdateMatcher() {
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public String[] getClassPath() {
|
public String[] getClassPath() {
|
||||||
return classPath.stream(StringConfigEntry.class).toArray(String[]::new);
|
return classPath.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public String[] getClientArgs() {
|
public String[] getClientArgs() {
|
||||||
return clientArgs.stream(StringConfigEntry.class).toArray(String[]::new);
|
return clientArgs.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -209,12 +209,12 @@ public String[] getJvmArgs() {
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public String getMainClass() {
|
public String getMainClass() {
|
||||||
return mainClass.getValue();
|
return mainClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public String getServerAddress() {
|
public String getServerAddress() {
|
||||||
return serverAddress.getValue();
|
return serverAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -248,7 +248,7 @@ public void pushOptional(HashedDir dir, boolean digest) throws IOException {
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public int getServerPort() {
|
public int getServerPort() {
|
||||||
return serverPort.getValue();
|
return serverPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -258,43 +258,43 @@ public InetSocketAddress getServerSocketAddress() {
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public int getSortIndex() {
|
public int getSortIndex() {
|
||||||
return sortIndex.getValue();
|
return sortIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title.getValue();
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public Version getVersion() {
|
public Version getVersion() {
|
||||||
return Version.byName(version.getValue());
|
return Version.byName(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public boolean isUpdateFastCheck() {
|
public boolean isUpdateFastCheck() {
|
||||||
return updateFastCheck.getValue();
|
return updateFastCheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public boolean isWhitelistContains(String username) {
|
public boolean isWhitelistContains(String username) {
|
||||||
if (!useWhitelist.getValue()) return true;
|
if (!useWhitelist) return true;
|
||||||
return whitelist.stream(StringConfigEntry.class).anyMatch(e -> e.equals(username));
|
return whitelist.stream().anyMatch(e -> e.equals(username));
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title.setValue(title);
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public void setVersion(Version version) {
|
public void setVersion(Version version) {
|
||||||
this.version.setValue(version.name);
|
this.version = version.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return title.getValue();
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -309,8 +309,6 @@ public void verify() {
|
||||||
VerifyHelper.verifyInt(getServerPort(), VerifyHelper.range(0, 65535), "Illegal server port: " + getServerPort());
|
VerifyHelper.verifyInt(getServerPort(), VerifyHelper.range(0, 65535), "Illegal server port: " + getServerPort());
|
||||||
|
|
||||||
// Client launcher
|
// Client launcher
|
||||||
classPath.verifyOfType(ConfigEntry.Type.STRING);
|
|
||||||
clientArgs.verifyOfType(ConfigEntry.Type.STRING);
|
|
||||||
VerifyHelper.verify(getTitle(), VerifyHelper.NOT_EMPTY, "Main class can't be empty");
|
VerifyHelper.verify(getTitle(), VerifyHelper.NOT_EMPTY, "Main class can't be empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue