Фикс опциональных модов

This commit is contained in:
Gravit 2018-12-27 14:09:13 +07:00
parent 19fa135a61
commit 005507a3a3
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
7 changed files with 89 additions and 94 deletions

View file

@ -68,7 +68,7 @@ public void build() throws IOException {
private void setConfig() { private void setConfig() {
Config config = new Config(); Config config = new Config();
// Set string options // Set file options
config.setChdir("."); config.setChdir(".");
config.setErrTitle("JVM Error"); config.setErrTitle("JVM Error");
config.setDownloadUrl(DOWNLOAD_URL); config.setDownloadUrl(DOWNLOAD_URL);

View file

@ -68,7 +68,7 @@ private static String[] parse(CharSequence line) throws CommandException {
if (wasQuoted || builder.length() > 0) if (wasQuoted || builder.length() > 0)
result.add(builder.toString()); result.add(builder.toString());
// Reset string builder // Reset file builder
wasQuoted = false; wasQuoted = false;
builder.setLength(0); builder.setLength(0);
continue; continue;

View file

@ -93,38 +93,22 @@ var options = {
nodelist.forEach(function(node,i,arr) { nodelist.forEach(function(node,i,arr) {
holder.getChildren().remove(node); holder.getChildren().remove(node);
}); });
var profile = profilesList[serverHolder.old].object; var profile = profilesList[serverHolder.old];
var list = profile.getOptional(); var list = profile.getOptional();
var checkBoxList = new java.util.ArrayList; var checkBoxList = new java.util.ArrayList;
var modConfigKeys = Object.keys(optModNames.modInfo);
var dModsIds = []; var dModsIds = [];
modConfigKeys.forEach(function(key, id) {//По умолчанию индекс у ветви = 1. Выставляем его у всех неуказанных. list.forEach(function(modFile) {
if(optModNames.modInfo[key].subTreeLevel == null) dModsIds.push(modFile.string);
optModNames.modInfo[key].subTreeLevel = 1;
});
for (var ik = 0, l = modConfigKeys.length + 1; ik <= l; ik++) { var modName = modFile.file, modDescription = "", subLevel = 1;
list.forEach(function(modFile) {
if((modConfigKeys[ik] === modFile.string) || (ik == modConfigKeys.length+1 && dModsIds.indexOf(modFile.string) == -1)) {
dModsIds.push(modFile.string);
var modName = modFile.string, modDescription = "", subLevel = 1; if(modFile.name != null)//Есть ли у модификации имя?
if(optModNames.modInfo[modFile.string] != null){//Есть ли хоть какое-нибудь представление описания модификации? modName = modFile.name;
var optModN = optModNames.modInfo[modFile.string]; if(modFile.info != null) //Есть ли описание?
if(optModN.name != null)//Есть ли у модификации имя? modDescription = modFile.info;
modName = optModN.name; if(modFile.subTreeLevel != null && modFile.subTreeLevel > 1)//Это суб-модификация?
if(optModN.description != null) //Есть ли описание? subLevel = modFile.subTreeLevel;
modDescription = optModN.description;
if(optModN.subTreeLevel != null && optModN.subTreeLevel > 1)//Это суб-модификация?
subLevel = optModN.subTreeLevel;
} else if(optModNames.optAutoModName) {
//Попытка автоматически создать представляемое имя модификации.
modName = modName.replace(new RegExp("(.*?(\/))",'g'),'');
modName = modName.replace(new RegExp("(-|_|[\\d]|\\+).*",'g'),'');
//Первая буква - заглавная
modName = modName[0].toUpperCase() + modName.slice(1);
}
var testMod = new javafx.scene.control.CheckBox(modName); var testMod = new javafx.scene.control.CheckBox(modName);
if(subLevel > 1) if(subLevel > 1)
@ -136,15 +120,15 @@ var options = {
var isSelected = event.getSource().isSelected(); var isSelected = event.getSource().isSelected();
if(isSelected) if(isSelected)
{ {
profile.markOptional(modFile.string); profile.markOptional(modFile.file);
LogHelper.debug("Selected mod %s", modFile.string); LogHelper.debug("Selected mod %s", modFile.file);
options.treeToggle(true, modFile.string); options.treeToggle(true, modFile.file);
} }
else else
{ {
profile.unmarkOptional(modFile.string); profile.unmarkOptional(modFile.file);
LogHelper.debug("Unselected mod %s", modFile.string); LogHelper.debug("Unselected mod %s", modFile.file);
options.treeToggle(false, modFile.string); options.treeToggle(false, modFile.file);
} }
options.update(); options.update();
}); });
@ -168,31 +152,27 @@ var options = {
sep = new javafx.scene.control.Separator(); sep = new javafx.scene.control.Separator();
sep.getStyleClass().add("separator"); sep.getStyleClass().add("separator");
checkBoxList.add(sep); checkBoxList.add(sep);
}
}); });
}
holder.getChildren().clear(); holder.getChildren().clear();
holder.getChildren().addAll(checkBoxList); holder.getChildren().addAll(checkBoxList);
}, },
treeToggle: function(enable, ImodFile) { treeToggle: function(enable, ImodFile) {
var profile = profilesList[serverHolder.old].object; var profile = profilesList[serverHolder.old];
if(optModNames.modInfo[ImodFile] != null) { var modInfo = profile.getOptionalFile(ImodFile);
var modInfo = optModNames.modInfo[ImodFile]; var modList = profile.getOptional();
var modList = optModNames.modInfo;
var modIDs = Object.keys(modList);
if(modInfo.subTreeLevel != null) { if(modInfo.subTreeLevel != null) {
if(modInfo.subTreeLevel >= 1){//Отключение core-модификации if(modInfo.subTreeLevel >= 1){//Отключение core-модификации
var stop = false; var stop = false;
modIDs.forEach(function(key, id) { modList.forEach(function(elem, id) {
if(modList[key] != null && modList[key].subTreeLevel != null) { if(elem != null && elem.subTreeLevel != null) {
if( modList[key].subTreeLevel > modInfo.subTreeLevel && modIDs.indexOf(key) > modIDs.indexOf(ImodFile) && enable == false && stop == false) { if( elem.subTreeLevel > modInfo.subTreeLevel && enable == false && stop == false) {
if(options.modExists(key)){ if(options.modExists(elem.file)){
profile.unmarkOptional(key); profile.unmarkOptional(elem.file);
LogHelper.debug("Unselected subMod %s", key); LogHelper.debug("Unselected subMod %s", elem.file);
} }
} else if(modIDs.indexOf(key) > modIDs.indexOf(ImodFile) && modList[key].subTreeLevel <= modInfo.subTreeLevel && stop == false) { } else if(elem.subTreeLevel <= modInfo.subTreeLevel && stop == false) {
//LogHelper.debug("STOP disable!! " + key); //LogHelper.debug("STOP disable!! " + key);
stop = true; stop = true;
} }
@ -201,27 +181,26 @@ var options = {
} }
if(modInfo.onlyOne == true){//Включение onlyOne-модификации (Все onlyOne-модификации с той же группой будут отключены. К примеру 2 миникарты) if(modInfo.onlyOne == true){//Включение onlyOne-модификации (Все onlyOne-модификации с той же группой будут отключены. К примеру 2 миникарты)
modIDs.forEach(function(key, id) { modList.forEach(function(elem, id) {
if(modList[key] != null && modList[key].onlyOneGroup != null) { if(elem != null && elem.onlyOneGroup != null) {
if(modList[key].onlyOneGroup == modInfo.onlyOneGroup && modList[key].onlyOne == true && enable == true && key != ImodFile) { if(elem.onlyOneGroup == modInfo.onlyOneGroup && elem.onlyOne == true && enable == true && key != ImodFile) {
if(options.modExists(key)) { if(options.modExists(elem.file)) {
profile.unmarkOptional(key); profile.unmarkOptional(elem.file);
LogHelper.debug("Unselected Mod (onlyOne toggle) %s", key); LogHelper.debug("Unselected Mod (onlyOne toggle) %s", elem.file);
} }
options.treeToggle(false, key); //И все его подмодификации канут в Лету.. options.treeToggle(false, elem.file); //И все его подмодификации канут в Лету..
} }
} }
}); });
} }
if(modInfo.subTreeLevel > 1){//Включение суб-модификации (Без core суб-моды работать не будут, так что его нужно включать) (Включаем всю ветку зависимости) if(modInfo.subTreeLevel > 1){//Включение суб-модификации (Без core суб-моды работать не будут, так что его нужно включать) (Включаем всю ветку зависимости)
var reverseModList = Object.keys(modList).reverse();
var tsl = modInfo.subTreeLevel-1; var tsl = modInfo.subTreeLevel-1;
reverseModList.forEach(function(key, id) { modList.forEach(function(elem, id) {
if(modList[key] != null && modList[key].subTreeLevel != null) { if(elem != null && elem.subTreeLevel != null) {
if(modList[key].subTreeLevel == tsl && modIDs.indexOf(key) < modIDs.indexOf(ImodFile) && enable == true) { if(elem.subTreeLevel == tsl && enable == true) {
if(options.modExists(key)) { if(options.modExists(elem)) {
profile.markOptional(key); profile.markOptional(elem.file);
LogHelper.debug("Selected coreMod %s", key); LogHelper.debug("Selected coreMod %s", key);
} }
options.treeToggle(true, key); //Для срабатывания onlyOne-модификаций. options.treeToggle(true, key); //Для срабатывания onlyOne-модификаций.
@ -232,14 +211,13 @@ var options = {
} }
} }
}
}, },
modExists: function(key){ modExists: function(key){
var profile = profilesList[serverHolder.old].object; var profile = profilesList[serverHolder.old];
var list = profile.getOptional(); var list = profile.getOptional();
var result = false; var result = false;
list.forEach(function(modFile) { list.forEach(function(modFile) {
if(modFile.string === key) { if(modFile.file === key) {
result = true; result = true;
} }
}); });

View file

@ -66,7 +66,7 @@ public static final class Params extends StreamObject {
@LauncherAPI @LauncherAPI
public final PlayerProfile pp; public final PlayerProfile pp;
@LauncherAPI @LauncherAPI
public final Set<ClientProfile.MarkedString> updateOptional; public final Set<ClientProfile.OptionalFile> updateOptional;
@LauncherAPI @LauncherAPI
public final String accessToken; public final String accessToken;
@LauncherAPI @LauncherAPI
@ -86,7 +86,7 @@ public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfil
boolean autoEnter, boolean fullScreen, int ram, int width, int height) { boolean autoEnter, boolean fullScreen, int ram, int width, int height) {
this.launcherDigest = launcherDigest.clone(); this.launcherDigest = launcherDigest.clone();
this.updateOptional = new HashSet<>(); this.updateOptional = new HashSet<>();
for (ClientProfile.MarkedString s : Launcher.profile.getOptional()) { for (ClientProfile.OptionalFile s : Launcher.profile.getOptional()) {
if (s.mark) updateOptional.add(s); if (s.mark) updateOptional.add(s);
} }
// Client paths // Client paths
@ -111,7 +111,7 @@ public Params(HInput input) throws Exception {
updateOptional = new HashSet<>(); updateOptional = new HashSet<>();
int len = input.readLength(128); int len = input.readLength(128);
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
updateOptional.add(new ClientProfile.MarkedString(input.readString(512), true)); updateOptional.add(new ClientProfile.OptionalFile(input.readString(512), true));
} }
// Client params // Client params
pp = new PlayerProfile(input); pp = new PlayerProfile(input);
@ -132,8 +132,8 @@ public void write(HOutput output) throws IOException {
output.writeString(assetDir.toString(), 0); output.writeString(assetDir.toString(), 0);
output.writeString(clientDir.toString(), 0); output.writeString(clientDir.toString(), 0);
output.writeLength(updateOptional.size(), 128); output.writeLength(updateOptional.size(), 128);
for (ClientProfile.MarkedString s : updateOptional) { for (ClientProfile.OptionalFile s : updateOptional) {
output.writeString(s.string, 512); output.writeString(s.file, 512);
} }
// Client params // Client params
pp.write(output); pp.write(output);
@ -459,9 +459,9 @@ public static void main(String... args) throws Throwable {
// Verify current state of all dirs // Verify current state of all dirs
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
HashedDir hdir = clientHDir.object; HashedDir hdir = clientHDir.object;
for (ClientProfile.MarkedString s : Launcher.profile.getOptional()) { for (ClientProfile.OptionalFile s : Launcher.profile.getOptional()) {
if (params.updateOptional.contains(s)) s.mark = true; if (params.updateOptional.contains(s)) s.mark = true;
else hdir.removeR(s.string); else hdir.removeR(s.file);
} }
verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest); verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest);
verifyHDir(params.clientDir, hdir, clientMatcher, digest); verifyHDir(params.clientDir, hdir, clientMatcher, digest);
@ -498,9 +498,9 @@ public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHol
// Verify current state of all dirs // Verify current state of all dirs
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
HashedDir hdir = clientHDir.object; HashedDir hdir = clientHDir.object;
for (ClientProfile.MarkedString s : Launcher.profile.getOptional()) { for (ClientProfile.OptionalFile s : Launcher.profile.getOptional()) {
if (params.updateOptional.contains(s)) s.mark = true; if (params.updateOptional.contains(s)) s.mark = true;
else hdir.removeR(s.string); else hdir.removeR(s.file);
} }
verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest); verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest);
verifyHDir(params.clientDir, hdir, clientMatcher, digest); verifyHDir(params.clientDir, hdir, clientMatcher, digest);

View file

@ -130,7 +130,7 @@ private Result legacyPing(HInput input, HOutput output, boolean mc16) throws IOE
// Verify all parts // Verify all parts
String magic = splitted[0]; String magic = splitted[0];
if (!magic.equals(LEGACY_PING_HOST_MAGIC)) if (!magic.equals(LEGACY_PING_HOST_MAGIC))
throw new IOException("Magic string mismatch: " + magic); throw new IOException("Magic file mismatch: " + magic);
int protocol = Integer.parseInt(splitted[1]); int protocol = Integer.parseInt(splitted[1]);
if (protocol != version.protocol) if (protocol != version.protocol)
throw new IOException("Protocol mismatch: " + protocol); throw new IOException("Protocol mismatch: " + protocol);

View file

@ -94,19 +94,29 @@ public String toString() {
@LauncherAPI @LauncherAPI
private int serverPort; private int serverPort;
public static class MarkedString { public static class OptionalFile {
@LauncherAPI @LauncherAPI
public String string; public String file;
@LauncherAPI @LauncherAPI
public boolean mark; public boolean mark;
@LauncherAPI
public String name;
@LauncherAPI
public String info;
@LauncherAPI
public int sunTreeLevel = 1;
@LauncherAPI
public boolean onlyOne = false;
@LauncherAPI
public int onlyOneGroup = 1;
public MarkedString(String string, boolean mark) { public OptionalFile(String file, boolean mark) {
this.string = string; this.file = file;
this.mark = mark; this.mark = mark;
} }
public MarkedString(String string) { public OptionalFile(String file) {
this.string = string; this.file = file;
this.mark = false; this.mark = false;
} }
@ -114,13 +124,13 @@ public MarkedString(String string) {
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
MarkedString that = (MarkedString) o; OptionalFile that = (OptionalFile) o;
return Objects.equals(string, that.string); return Objects.equals(file, that.file);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(string); return Objects.hash(file);
} }
} }
@ -134,7 +144,7 @@ public int hashCode() {
@LauncherAPI @LauncherAPI
private final List<String> updateVerify = new ArrayList<>(); private final List<String> updateVerify = new ArrayList<>();
@LauncherAPI @LauncherAPI
private final Set<MarkedString> updateOptional = new HashSet<>(); private final Set<OptionalFile> updateOptional = new HashSet<>();
@LauncherAPI @LauncherAPI
private boolean updateFastCheck; private boolean updateFastCheck;
@LauncherAPI @LauncherAPI
@ -221,9 +231,16 @@ public String getServerAddress() {
} }
@LauncherAPI @LauncherAPI
public Set<MarkedString> getOptional() { public Set<OptionalFile> getOptional() {
return updateOptional; return updateOptional;
} }
@LauncherAPI
public OptionalFile getOptionalFile(String file)
{
for(OptionalFile f : updateOptional)
if(f.file.equals(file)) return f;
return null;
}
@LauncherAPI @LauncherAPI
public Collection<String> getShared() { public Collection<String> getShared() {
@ -232,25 +249,25 @@ public Collection<String> getShared() {
@LauncherAPI @LauncherAPI
public void markOptional(String opt) { public void markOptional(String opt) {
if (!updateOptional.contains(new MarkedString(opt))) if (!updateOptional.contains(new OptionalFile(opt)))
throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt)); throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt));
updateOptional.forEach(e -> { updateOptional.forEach(e -> {
if (e.string.equals(opt)) e.mark = true; if (e.file.equals(opt)) e.mark = true;
}); });
} }
@LauncherAPI @LauncherAPI
public void unmarkOptional(String opt) { public void unmarkOptional(String opt) {
if (!updateOptional.contains(new MarkedString(opt))) if (!updateOptional.contains(new OptionalFile(opt)))
throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt)); throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt));
updateOptional.forEach(e -> { updateOptional.forEach(e -> {
if (e.string.equals(opt)) e.mark = false; if (e.file.equals(opt)) e.mark = false;
}); });
} }
public void pushOptional(HashedDir dir, boolean digest) throws IOException { public void pushOptional(HashedDir dir, boolean digest) throws IOException {
for (MarkedString opt : updateOptional) { for (OptionalFile opt : updateOptional) {
if (!opt.mark) dir.removeR(opt.string); if (!opt.mark) dir.removeR(opt.file);
} }
} }

View file

@ -252,7 +252,7 @@ private static String ansiFormatVersion(String product) {
fgBright(Color.CYAN).a(product). // Product fgBright(Color.CYAN).a(product). // Product
fgBright(Color.WHITE).a(" v").fgBright(Color.BLUE).a(Launcher.getVersion().toString()). // Version 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# fgBright(Color.WHITE).a(" (build #").fgBright(Color.RED).a(Launcher.getVersion().build).fgBright(Color.WHITE).a(')'). // Build#
reset().toString(); // To string reset().toString(); // To file
} }
private static String ansiFormatLicense(String product) { private static String ansiFormatLicense(String product) {
@ -261,7 +261,7 @@ private static String ansiFormatLicense(String product) {
fgBright(Color.CYAN).a(product). // Product fgBright(Color.CYAN).a(product). // Product
fgBright(Color.WHITE).a(" GPLv3").fgBright(Color.WHITE).a(". SourceCode: "). // Version fgBright(Color.WHITE).a(" GPLv3").fgBright(Color.WHITE).a(". SourceCode: "). // Version
fgBright(Color.YELLOW).a("https://github.com/GravitLauncher/Launcher"). fgBright(Color.YELLOW).a("https://github.com/GravitLauncher/Launcher").
reset().toString(); // To string reset().toString(); // To file
} }
private static String formatLog(Level level, String message, String dateTime, boolean sub) { private static String formatLog(Level level, String message, String dateTime, boolean sub) {