mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] SaveProfilesCommand
This commit is contained in:
parent
a9867d57c4
commit
3201d2fc4f
3 changed files with 76 additions and 0 deletions
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue