[FEATURE] SaveProfilesCommand

This commit is contained in:
Gravit 2020-03-27 12:32:00 +07:00
parent a9867d57c4
commit 3201d2fc4f
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 76 additions and 0 deletions

View file

@ -52,6 +52,7 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand
updates.registerCommand("syncBinaries", new SyncBinariesCommand(server)); updates.registerCommand("syncBinaries", new SyncBinariesCommand(server));
updates.registerCommand("syncUpdates", new SyncUpdatesCommand(server)); updates.registerCommand("syncUpdates", new SyncUpdatesCommand(server));
updates.registerCommand("syncProfiles", new SyncProfilesCommand(server)); updates.registerCommand("syncProfiles", new SyncProfilesCommand(server));
updates.registerCommand("saveProfiles", new SaveProfilesCommand(server));
Category updatesCategory = new Category(updates, "updates", "Update and Sync Management"); Category updatesCategory = new Category(updates, "updates", "Update and Sync Management");
handler.registerCategory(updatesCategory); handler.registerCategory(updatesCategory);

View file

@ -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);
}
}
}

View file

@ -5,6 +5,7 @@
import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hasher.HashedDir;
import pro.gravit.launcher.profiles.optional.OptionalDepend; import pro.gravit.launcher.profiles.optional.OptionalDepend;
import pro.gravit.launcher.profiles.optional.OptionalFile; import pro.gravit.launcher.profiles.optional.OptionalFile;
import pro.gravit.launcher.profiles.optional.OptionalTrigger;
import pro.gravit.launcher.profiles.optional.OptionalType; import pro.gravit.launcher.profiles.optional.OptionalType;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.VerifyHelper; import pro.gravit.utils.helper.VerifyHelper;
@ -444,6 +445,16 @@ public void verify() {
if (s == null) if (s == null)
throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.dependenciesFile", f.name)); 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));
}
}
} }
} }