mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Profile clone command
This commit is contained in:
parent
80fc2900c8
commit
0b59d6c0ed
6 changed files with 108 additions and 5 deletions
|
@ -5,6 +5,9 @@
|
|||
import pro.gravit.launchserver.command.hash.*;
|
||||
import pro.gravit.launchserver.command.modules.LoadModuleCommand;
|
||||
import pro.gravit.launchserver.command.modules.ModulesCommand;
|
||||
import pro.gravit.launchserver.command.profiles.MakeProfileCommand;
|
||||
import pro.gravit.launchserver.command.profiles.ProfilesCommand;
|
||||
import pro.gravit.launchserver.command.profiles.SaveProfilesCommand;
|
||||
import pro.gravit.launchserver.command.service.*;
|
||||
import pro.gravit.launchserver.command.sync.*;
|
||||
import pro.gravit.launchserver.command.tools.SignDirCommand;
|
||||
|
@ -37,8 +40,7 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand
|
|||
updates.registerCommand("downloadAsset", new DownloadAssetCommand(server));
|
||||
updates.registerCommand("downloadClient", new DownloadClientCommand(server));
|
||||
updates.registerCommand("sync", new SyncCommand(server));
|
||||
updates.registerCommand("saveProfiles", new SaveProfilesCommand(server));
|
||||
updates.registerCommand("makeProfile", new MakeProfileCommand(server));
|
||||
updates.registerCommand("profile", new ProfilesCommand(server));
|
||||
Category updatesCategory = new Category(updates, "updates", "Update and Sync Management");
|
||||
handler.registerCategory(updatesCategory);
|
||||
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package pro.gravit.launchserver.command.profiles;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launcher.base.Launcher;
|
||||
import pro.gravit.launcher.base.profiles.ClientProfile;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CloneProfileCommand extends Command {
|
||||
private final transient Logger logger = LogManager.getLogger(CloneProfileCommand.class);
|
||||
public CloneProfileCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return "[profile file name] [new profile title]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return "clone profile and profile dir";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 2);
|
||||
var profilePath = server.profilesDir.resolve(args[0].concat(".json"));
|
||||
if(!Files.exists(profilePath)) {
|
||||
logger.error("File {} not found", profilePath);
|
||||
}
|
||||
ClientProfile profile;
|
||||
try(Reader reader = IOHelper.newReader(profilePath)) {
|
||||
profile = Launcher.gsonManager.gson.fromJson(reader, ClientProfile.class);
|
||||
}
|
||||
profile.setTitle(args[1]);
|
||||
profile.setUUID(UUID.randomUUID());
|
||||
if(profile.getServers().size() == 1) {
|
||||
profile.getServers().getFirst().name = args[1];
|
||||
}
|
||||
logger.info("Copy {} to {}", profile.getDir(), args[1]);
|
||||
var src = server.updatesDir.resolve(profile.getDir());
|
||||
var dest = server.updatesDir.resolve(args[1]);
|
||||
try (Stream<Path> stream = Files.walk(src)) {
|
||||
stream.forEach(source -> {
|
||||
try {
|
||||
IOHelper.copy(source, dest.resolve(src.relativize(source)));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
profile.setDir(args[1]);
|
||||
var targetPath = server.profilesDir.resolve(args[1].concat(".json"));
|
||||
try(Writer writer = IOHelper.newWriter(targetPath)) {
|
||||
Launcher.gsonManager.gson.toJson(profile, writer);
|
||||
}
|
||||
logger.info("Profile {} cloned from {}", args[1], args[0]);
|
||||
server.syncProfilesDir();
|
||||
server.syncUpdatesDir(List.of(args[1]));
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package pro.gravit.launchserver.command.hash;
|
||||
package pro.gravit.launchserver.command.profiles;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
|
@ -0,0 +1,28 @@
|
|||
package pro.gravit.launchserver.command.profiles;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
|
||||
public class ProfilesCommand extends Command {
|
||||
public ProfilesCommand(LaunchServer server) {
|
||||
super(server);
|
||||
this.childCommands.put("make", new MakeProfileCommand(server));
|
||||
this.childCommands.put("save", new SaveProfilesCommand(server));
|
||||
this.childCommands.put("clone", new CloneProfileCommand(server));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return "[subcommand] [args...]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return "manage profiles";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
invokeSubcommands(args);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package pro.gravit.launchserver.command.hash;
|
||||
package pro.gravit.launchserver.command.profiles;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit cd920b0eda048771ea3c225074db32943d27503b
|
||||
Subproject commit 1c3646c8161f38c44d6578ba7aeabce27823556f
|
Loading…
Reference in a new issue