diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java index 8a6c032e..7eb27214 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java @@ -52,6 +52,7 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand updates.registerCommand("syncBinaries", new SyncBinariesCommand(server)); updates.registerCommand("syncUpdates", new SyncUpdatesCommand(server)); updates.registerCommand("syncProfiles", new SyncProfilesCommand(server)); + updates.registerCommand("saveProfiles", new SaveProfilesCommand(server)); Category updatesCategory = new Category(updates, "updates", "Update and Sync Management"); handler.registerCategory(updatesCategory); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java new file mode 100644 index 00000000..d22e7d3a --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java @@ -0,0 +1,64 @@ +package pro.gravit.launchserver.command.hash; + +import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + +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.UUID; + +public class SaveProfilesCommand extends Command { + public SaveProfilesCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[profile names...]"; + } + + @Override + public String getUsageDescription() { + return "load and save profile"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 1); + if(args.length > 0) + { + for(String profileName : args) + { + Path profilePath = server.profilesDir.resolve(profileName.concat(".json")); + if(!Files.exists(profilePath)) + { + LogHelper.error("Profile %s not found", profilePath.toString()); + return; + } + ClientProfile profile; + try(Reader reader = IOHelper.newReader(profilePath)) + { + profile = Launcher.gsonManager.configGson.fromJson(reader, ClientProfile.class); + } + saveProfile(profile, profilePath); + LogHelper.info("Profile %s save successful", profilePath.toString()); + } + server.syncProfilesDir(); + } + } + public static void saveProfile(ClientProfile profile, Path path) throws IOException + { + if(profile.getUUID() == null) profile.setUUID(UUID.randomUUID()); + try(Writer w = IOHelper.newWriter(path)) + { + Launcher.gsonManager.configGson.toJson(profile, w); + } + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index c24186d0..59a2c7ee 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -5,6 +5,7 @@ import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.profiles.optional.OptionalDepend; import pro.gravit.launcher.profiles.optional.OptionalFile; +import pro.gravit.launcher.profiles.optional.OptionalTrigger; import pro.gravit.launcher.profiles.optional.OptionalType; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.VerifyHelper; @@ -444,6 +445,16 @@ public void verify() { if (s == null) throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.dependenciesFile", f.name)); } + if(f.triggers != null) + { + for(OptionalTrigger trigger : f.triggers) + { + if(trigger == null) + throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.triggers", f.name)); + if(trigger.type == null) + throw new IllegalArgumentException(String.format("trigger.type must not be null in updateOptional.%s.triggers", f.name)); + } + } } }