[FEATURE][EXPERIMENTAL] Конвертация опциональных модов в новый формат

This commit is contained in:
Gravit 2020-09-12 16:12:39 +07:00
parent 2271b91653
commit 72a8325a15
No known key found for this signature in database
GPG key ID: 98A079490768CCE5
7 changed files with 77 additions and 5 deletions

View file

@ -2,6 +2,8 @@
import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.optional.OptionalFile;
import pro.gravit.launcher.profiles.optional.actions.*;
import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command;
import pro.gravit.utils.helper.IOHelper;
@ -12,6 +14,9 @@
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
public class SaveProfilesCommand extends Command {
@ -31,6 +36,37 @@ public static void saveProfile(ClientProfile profile, Path path) throws IOExcept
serverProfile.serverPort = profile.getServerPort();
profile.getServers().add(serverProfile);
}
for(OptionalFile file : profile.getOptional())
{
if(file.list != null)
{
String[] list = file.list;
file.list = null;
if(file.actions == null) file.actions = new ArrayList<>(2);
OptionalAction action;
switch (file.type)
{
case FILE:
OptionalActionFile result = new OptionalActionFile(new HashMap<>());
for(String s : list) result.files.put(s, "");
action = result;
break;
case CLASSPATH:
action = new OptionalActionClassPath(list);
break;
case JVMARGS:
action = new OptionalActionJvmArgs(Arrays.asList(list));
break;
case CLIENTARGS:
action = new OptionalActionClientArgs(Arrays.asList(list));
break;
default:
LogHelper.warning("Not converted optional %s with type %s. Type unknown", file.name, file.type.toString());
continue;
}
file.actions.add(action);
}
}
try (Writer w = IOHelper.newWriter(path)) {
Launcher.gsonManager.configGson.toJson(profile, w);
}

View file

@ -184,16 +184,23 @@ public void updateOptionalGraph() {
}
}
}
@Deprecated
public OptionalFile getOptionalFile(String file, OptionalType type) {
for (OptionalFile f : updateOptional)
if (f.type.equals(type) && f.name.equals(file)) return f;
return null;
}
public OptionalFile getOptionalFile(String file) {
for (OptionalFile f : updateOptional)
if (f.name.equals(file)) return f;
return null;
}
public Collection<String> getShared() {
return updateShared;
}
@Deprecated
public void markOptional(OptionalFile file) {

View file

@ -4,8 +4,6 @@
import pro.gravit.launcher.profiles.optional.actions.OptionalAction;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class OptionalView {

View file

@ -1,8 +1,18 @@
package pro.gravit.launcher.profiles.optional.actions;
import java.util.List;
public class OptionalActionClassPath extends OptionalAction {
public String[] args;
public boolean useAltClasspath = false;
public OptionalActionClassPath() {
}
public OptionalActionClassPath(String[] args) {
this.args = args;
}
public OptionalActionClassPath(String[] args, boolean useAltClasspath) {
this.args = args;
this.useAltClasspath = useAltClasspath;
}
}

View file

@ -4,4 +4,11 @@
public class OptionalActionClientArgs extends OptionalAction {
public List<String> args;
public OptionalActionClientArgs() {
}
public OptionalActionClientArgs(List<String> args) {
this.args = args;
}
}

View file

@ -29,4 +29,11 @@ public void disableInHashedDir(HashedDir dir)
firstPath.parent.remove(firstPath.name);
});
}
public OptionalActionFile() {
}
public OptionalActionFile(Map<String, String> files) {
this.files = files;
}
}

View file

@ -4,4 +4,11 @@
public class OptionalActionJvmArgs extends OptionalAction {
public List<String> args;
public OptionalActionJvmArgs() {
}
public OptionalActionJvmArgs(List<String> args) {
this.args = args;
}
}