From 79bbc9c2528dae88877cda299f30ba8ff24c1b1c Mon Sep 17 00:00:00 2001 From: sk89q Date: Thu, 9 Jan 2014 17:33:03 -0800 Subject: [PATCH] Added launch modifier to packages. --- .../java/com/skcraft/launcher/Instance.java | 11 ++++++++ .../launcher/builder/BuilderConfig.java | 12 +++++++++ .../launcher/builder/PackageBuilder.java | 4 +-- .../com/skcraft/launcher/launch/Runner.java | 11 +++++++- .../model/modpack/LaunchModifier.java | 26 +++++++++++++++++++ .../launcher/model/modpack/Manifest.java | 8 ++++++ .../com/skcraft/launcher/update/Updater.java | 3 +++ 7 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/skcraft/launcher/model/modpack/LaunchModifier.java diff --git a/src/main/java/com/skcraft/launcher/Instance.java b/src/main/java/com/skcraft/launcher/Instance.java index a8092e9..490b04b 100644 --- a/src/main/java/com/skcraft/launcher/Instance.java +++ b/src/main/java/com/skcraft/launcher/Instance.java @@ -7,6 +7,9 @@ package com.skcraft.launcher; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.skcraft.launcher.launch.JavaProcessBuilder; +import com.skcraft.launcher.model.modpack.LaunchModifier; import lombok.Data; import java.io.File; @@ -22,6 +25,8 @@ public class Instance implements Comparable { private boolean updatePending; private boolean installed; private Date lastAccessed; + @JsonProperty("launch") + private LaunchModifier launchModifier; @JsonIgnore private File dir; @JsonIgnore private URL manifestURL; @@ -33,6 +38,12 @@ public class Instance implements Comparable { return title != null ? title : name; } + public void modify(JavaProcessBuilder builder) { + if (launchModifier != null) { + launchModifier.modify(builder); + } + } + @JsonIgnore public File getContentDir() { return new File(dir, "minecraft"); diff --git a/src/main/java/com/skcraft/launcher/builder/BuilderConfig.java b/src/main/java/com/skcraft/launcher/builder/BuilderConfig.java index d629fcb..658d619 100644 --- a/src/main/java/com/skcraft/launcher/builder/BuilderConfig.java +++ b/src/main/java/com/skcraft/launcher/builder/BuilderConfig.java @@ -6,6 +6,9 @@ package com.skcraft.launcher.builder; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.skcraft.launcher.model.modpack.LaunchModifier; +import com.skcraft.launcher.model.modpack.Manifest; import lombok.Data; import java.util.List; @@ -19,9 +22,18 @@ public class BuilderConfig { private String name; private String title; private String gameVersion; + @JsonProperty("launch") + private LaunchModifier launchModifier; private List features; private FnPatternList userFiles; + public void update(Manifest manifest) { + manifest.updateName(getName()); + manifest.updateTitle(getTitle()); + manifest.updateGameVersion(getGameVersion()); + manifest.setLaunchModifier(getLaunchModifier()); + } + public void registerProperties(PropertiesApplicator applicator) { if (features != null) { for (FeaturePattern feature : features) { diff --git a/src/main/java/com/skcraft/launcher/builder/PackageBuilder.java b/src/main/java/com/skcraft/launcher/builder/PackageBuilder.java index ffe3ecd..f9f9c7f 100644 --- a/src/main/java/com/skcraft/launcher/builder/PackageBuilder.java +++ b/src/main/java/com/skcraft/launcher/builder/PackageBuilder.java @@ -79,9 +79,7 @@ public class PackageBuilder { public void readConfig(File path) throws IOException { if (path != null) { BuilderConfig config = read(path, BuilderConfig.class); - manifest.updateName(config.getName()); - manifest.updateTitle(config.getTitle()); - manifest.updateGameVersion(config.getGameVersion()); + config.update(manifest); config.registerProperties(applicator); } } diff --git a/src/main/java/com/skcraft/launcher/launch/Runner.java b/src/main/java/com/skcraft/launcher/launch/Runner.java index 56757d9..7f5d426 100644 --- a/src/main/java/com/skcraft/launcher/launch/Runner.java +++ b/src/main/java/com/skcraft/launcher/launch/Runner.java @@ -99,7 +99,7 @@ public class Runner implements Callable, ProgressObservable { builder = new JavaProcessBuilder(); assetsRoot = launcher.getAssets(); - // Load versionManifest and assets index + // Load manifiests versionManifest = mapper.readValue(instance.getVersionPath(), VersionManifest.class); // Load assets index @@ -141,6 +141,8 @@ public class Runner implements Callable, ProgressObservable { builder.classPath(getJarPath()); builder.setMainClass(versionManifest.getMainClass()); + callLaunchModifier(); + ProcessBuilder processBuilder = new ProcessBuilder(builder.buildCommand()); processBuilder.directory(instance.getContentDir()); Runner.log.info("Launching: " + builder); @@ -151,6 +153,13 @@ public class Runner implements Callable, ProgressObservable { return processBuilder.start(); } + /** + * Call the manifest launch modifier. + */ + private void callLaunchModifier() { + instance.modify(builder); + } + /** * Add platform-specific arguments. */ diff --git a/src/main/java/com/skcraft/launcher/model/modpack/LaunchModifier.java b/src/main/java/com/skcraft/launcher/model/modpack/LaunchModifier.java new file mode 100644 index 0000000..e8b961a --- /dev/null +++ b/src/main/java/com/skcraft/launcher/model/modpack/LaunchModifier.java @@ -0,0 +1,26 @@ +/* + * SK's Minecraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher.model.modpack; + +import com.skcraft.launcher.launch.JavaProcessBuilder; +import lombok.Data; + +import java.util.List; + +@Data +public class LaunchModifier { + + private List flags; + + public void modify(JavaProcessBuilder builder) { + if (flags != null) { + for (String flag : flags) { + builder.getFlags().add(flag); + } + } + } +} diff --git a/src/main/java/com/skcraft/launcher/model/modpack/Manifest.java b/src/main/java/com/skcraft/launcher/model/modpack/Manifest.java index 3595e59..ec42a7b 100644 --- a/src/main/java/com/skcraft/launcher/model/modpack/Manifest.java +++ b/src/main/java/com/skcraft/launcher/model/modpack/Manifest.java @@ -8,7 +8,9 @@ package com.skcraft.launcher.model.modpack; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonManagedReference; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Strings; +import com.skcraft.launcher.Instance; import com.skcraft.launcher.LauncherUtils; import com.skcraft.launcher.model.minecraft.VersionManifest; import com.skcraft.launcher.install.Installer; @@ -30,6 +32,8 @@ public class Manifest extends BaseManifest { private String librariesLocation; private String objectsLocation; private String gameVersion; + @JsonProperty("launch") + private LaunchModifier launchModifier; private List features = new ArrayList(); @JsonManagedReference("manifest") private List tasks = new ArrayList(); @@ -80,4 +84,8 @@ public class Manifest extends BaseManifest { setGameVersion(gameVersion); } } + + public void update(Instance instance) { + instance.setLaunchModifier(getLaunchModifier()); + } } diff --git a/src/main/java/com/skcraft/launcher/update/Updater.java b/src/main/java/com/skcraft/launcher/update/Updater.java index 5b78211..49f55c8 100644 --- a/src/main/java/com/skcraft/launcher/update/Updater.java +++ b/src/main/java/com/skcraft/launcher/update/Updater.java @@ -140,6 +140,9 @@ public class Updater extends BaseUpdater implements Callable, Progress progress = new DefaultProgress(-1, _("instanceUpdater.readingManifest")); Manifest manifest = installPackage(installer, instance); + // Update instance from manifest + manifest.update(instance); + // Read version manifest log.info("Reading version manifest..."); progress = new DefaultProgress(-1, _("instanceUpdater.readingVersion"));