1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-24 12:16:28 +01:00

Added launch modifier to packages.

This commit is contained in:
sk89q 2014-01-09 17:33:03 -08:00
parent fc964d0d66
commit 79bbc9c252
7 changed files with 71 additions and 4 deletions

View File

@ -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<Instance> {
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<Instance> {
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");

View File

@ -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<FeaturePattern> 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) {

View File

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

View File

@ -99,7 +99,7 @@ public class Runner implements Callable<Process>, 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<Process>, 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<Process>, ProgressObservable {
return processBuilder.start();
}
/**
* Call the manifest launch modifier.
*/
private void callLaunchModifier() {
instance.modify(builder);
}
/**
* Add platform-specific arguments.
*/

View File

@ -0,0 +1,26 @@
/*
* SK's Minecraft Launcher
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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<String> flags;
public void modify(JavaProcessBuilder builder) {
if (flags != null) {
for (String flag : flags) {
builder.getFlags().add(flag);
}
}
}
}

View File

@ -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<Feature> features = new ArrayList<Feature>();
@JsonManagedReference("manifest")
private List<ManifestEntry> tasks = new ArrayList<ManifestEntry>();
@ -80,4 +84,8 @@ public class Manifest extends BaseManifest {
setGameVersion(gameVersion);
}
}
public void update(Instance instance) {
instance.setLaunchModifier(getLaunchModifier());
}
}

View File

@ -140,6 +140,9 @@ public class Updater extends BaseUpdater implements Callable<Instance>, 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"));