Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

old diff #1

Open
wants to merge 8 commits into
base: old
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
liberapay: offbeatwitch
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ subprojects {
apply plugin: 'maven'

group = 'com.skcraft'
version = '4.5-SNAPSHOT'
version = '4.6-SNAPSHOT'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@

package com.skcraft.launcher.creator.controller;

import com.google.common.base.Optional;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.skcraft.concurrency.Deferred;
import com.skcraft.concurrency.Deferreds;
import com.skcraft.concurrency.SettableProgress;
import com.skcraft.launcher.Instance;
import com.skcraft.launcher.InstanceList;
import com.skcraft.launcher.Launcher;
import com.skcraft.launcher.auth.OfflineSession;
Expand All @@ -22,6 +25,7 @@
import com.skcraft.launcher.builder.FnPatternList;
import com.skcraft.launcher.creator.Creator;
import com.skcraft.launcher.creator.controller.task.*;
import com.skcraft.launcher.creator.dialog.AboutDialog;
import com.skcraft.launcher.creator.dialog.*;
import com.skcraft.launcher.creator.dialog.BuildDialog.BuildOptions;
import com.skcraft.launcher.creator.dialog.DeployServerDialog.DeployOptions;
Expand All @@ -30,10 +34,7 @@
import com.skcraft.launcher.creator.server.TestServer;
import com.skcraft.launcher.creator.server.TestServerBuilder;
import com.skcraft.launcher.creator.swing.PackDirectoryFilter;
import com.skcraft.launcher.dialog.AccountSelectDialog;
import com.skcraft.launcher.dialog.ConfigurationDialog;
import com.skcraft.launcher.dialog.ConsoleFrame;
import com.skcraft.launcher.dialog.ProgressDialog;
import com.skcraft.launcher.dialog.*;
import com.skcraft.launcher.model.modpack.LaunchModifier;
import com.skcraft.launcher.persistence.Persistence;
import com.skcraft.launcher.swing.PopupMouseAdapter;
Expand All @@ -55,6 +56,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;

public class PackManagerController {
Expand Down Expand Up @@ -177,10 +179,10 @@ public Optional<Pack> getPackFromIndex(int selectedIndex, boolean requireLoaded)
if (selectedIndex >= 0) {
Pack pack = workspace.getPacks().get(selectedIndex);
if (pack != null && (!requireLoaded || checkPackLoaded(pack))) {
return Optional.fromNullable(pack);
return Optional.of(pack);
}
}
return Optional.absent();
return Optional.empty();
}

public Optional<Pack> getSelectedPack(boolean requireLoaded) {
Expand All @@ -190,12 +192,12 @@ public Optional<Pack> getSelectedPack(boolean requireLoaded) {
selectedIndex = table.convertRowIndexToModel(selectedIndex);
Pack pack = workspace.getPacks().get(selectedIndex);
if (pack != null && (!requireLoaded || checkPackLoaded(pack))) {
return Optional.fromNullable(pack);
return Optional.of(pack);
}
}

SwingHelper.showErrorDialog(frame, "Please select a modpack from the list.", "Error");
return Optional.absent();
return Optional.empty();
}

public boolean writeWorkspace() {
Expand Down Expand Up @@ -456,11 +458,9 @@ protected void showPopup(MouseEvent e) {
});

frame.getOpenFolderMenuItem().addActionListener(e -> {
Optional<Pack> optional = getSelectedPack(true);
Optional<Pack> selectedPack = getSelectedPack(true);

if (optional.isPresent()) {
SwingHelper.browseDir(optional.get().getDirectory(), frame);
}
selectedPack.ifPresent(pack -> SwingHelper.browseDir(pack.getDirectory(), frame));
});

frame.getCheckProblemsMenuItem().addActionListener(e -> {
Expand Down Expand Up @@ -498,6 +498,45 @@ protected void showPopup(MouseEvent e) {
configDialog.setVisible(true);
});

frame.getInstanceOptionsMenuItem().addActionListener(e -> {
Optional<Pack> selectedPack = getSelectedPack(true);

selectedPack.ifPresent(pack -> {
InstanceList.Enumerator instanceList = launcher.getInstances().createEnumerator();

ListenableFuture<InstanceList> future = executor.submit(instanceList);
Futures.addCallback(future, new FutureCallback<InstanceList>() {
@Override
public void onSuccess(InstanceList result) {
Instance found = null;

for (Instance instance : result.getInstances()) {
if (instance.getName().equals(pack.getCachedConfig().getName())) {
found = instance;
break;
}
}

if (found == null) {
SwingHelper.showErrorDialog(frame, "No instance found for that pack - you need " +
"to test the pack first.", "Not Found");
return;
}

InstanceSettingsDialog.open(frame, found);
}

@Override
public void onFailure(Throwable ignored) {
}
}, SwingExecutor.INSTANCE);

ProgressDialog.showProgress(frame, future, instanceList, "Enumerating instances...",
"Enumerating instances...");
SwingHelper.addErrorDialogCallback(frame, future);
});
});

frame.getClearInstanceMenuItem().addActionListener(e -> {
DirectoryDeleter deleter = new DirectoryDeleter(launcher.getInstancesDir());
Deferred<?> deferred = Deferreds.makeDeferred(executor.submit(deleter), executor);
Expand Down Expand Up @@ -629,6 +668,10 @@ private void popupPackMenu(Component component, int x, int y, Pack pack) {
menuItem.addActionListener(e -> frame.getTestOnlineMenuItem().doClick());
popup.add(menuItem);

menuItem = new JMenuItem("Instance settings...");
menuItem.addActionListener(e -> frame.getInstanceOptionsMenuItem().doClick());
popup.add(menuItem);

menuItem = new JMenuItem("Build...");
menuItem.addActionListener(e -> frame.getBuildMenuItem().doClick());
popup.add(menuItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class PackManagerFrame extends JFrame {
@Getter private final JMenuItem testMenuItem = new JMenuItem("Test");
@Getter private final JMenuItem testOnlineMenuItem = new JMenuItem("Test Online");
@Getter private final JMenuItem optionsMenuItem = new JMenuItem("Test Launcher Options...");
@Getter private final JMenuItem instanceOptionsMenuItem = new JMenuItem("Test Instance Options...");
@Getter private final JMenuItem clearInstanceMenuItem = new JMenuItem("Delete Test Launcher Instances");
@Getter private final JMenuItem clearWebRootMenuItem = new JMenuItem("Empty Test Web Server");
@Getter private final JMenuItem buildMenuItem = new JMenuItem("Build Pack...");
Expand Down Expand Up @@ -163,6 +164,7 @@ private void initMenu() {
menu.add(testOnlineMenuItem);
menu.addSeparator();
menu.add(optionsMenuItem);
menu.add(instanceOptionsMenuItem);
menu.addSeparator();
menu.add(clearInstanceMenuItem);
menu.add(clearWebRootMenuItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import com.skcraft.launcher.util.FileUtils;
import lombok.extern.java.Log;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.net.URL;
import java.util.List;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -61,6 +58,12 @@ public LoaderResult process(File loaderJar, Manifest manifest, ObjectMapper mapp
version.getArguments().getGameArguments().addAll(gameArguments);
}

// Copy JVM arguments
List<GameArgument> jvmArguments = info.getArguments().getJvmArguments();
if (jvmArguments != null) {
version.getArguments().getJvmArguments().addAll(jvmArguments);
}

// Add libraries
List<Library> libraries = info.getLibraries();
if (libraries != null) {
Expand Down Expand Up @@ -101,11 +104,13 @@ public LoaderResult process(File loaderJar, Manifest manifest, ObjectMapper mapp

// Extract the data files
List<DownloadableFile> extraFiles = Lists.newArrayList();
File objectsDir = new File(baseDir, manifest.getObjectsLocation());

ZipEntry clientBinpatch = BuilderUtils.getZipEntry(jarFile, "data/client.lzma");
if (clientBinpatch != null) {
DownloadableFile entry = FileUtils.saveStreamToObjectsDir(
closer.register(jarFile.getInputStream(clientBinpatch)),
new File(baseDir, manifest.getObjectsLocation()));
objectsDir);

entry.setName("client.lzma");
entry.setSide(Side.CLIENT);
Expand All @@ -117,14 +122,28 @@ public LoaderResult process(File loaderJar, Manifest manifest, ObjectMapper mapp
if (serverBinpatch != null) {
DownloadableFile entry = FileUtils.saveStreamToObjectsDir(
closer.register(jarFile.getInputStream(serverBinpatch)),
new File(baseDir, manifest.getObjectsLocation()));
objectsDir);

entry.setName("server.lzma");
entry.setSide(Side.SERVER);
extraFiles.add(entry);
profile.getData().get("BINPATCH").setServer("&" + entry.getName() + "&");
}

// Forge install profile spec version 1 and above.
if (profile.getSpec() >= 1) {
// Add the installer itself to the extra files.
// This is for a server-only task like above, but hey.
DownloadableFile entry = FileUtils.saveStreamToObjectsDir(
closer.register(new FileInputStream(loaderJar)), objectsDir);

entry.setName(loaderJar.getName());
entry.setSide(Side.SERVER);
extraFiles.add(entry);

profile.getData().put("INSTALLER", SidedData.of("&" + entry.getName() + "&"));
}

// Add extra sided data
profile.getData().put("SIDE", SidedData.create("client", "server"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public LoaderResult process(File loaderJar, Manifest manifest, ObjectMapper mapp
ZipEntry libraryEntry = BuilderUtils.getZipEntry(jarFile, filePath);

if (libraryEntry != null) {
File librariesDir = new File(baseDir, manifest.getLibrariesLocation());
File librariesDir = new File(baseDir, "libraries");
File extractPath = new File(librariesDir, Library.mavenNameToPath(libraryPath));

Files.createParentDirs(extractPath);
Expand Down
13 changes: 12 additions & 1 deletion launcher/src/main/java/com/skcraft/launcher/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package com.skcraft.launcher;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.skcraft.launcher.launch.JavaRuntime;
import com.skcraft.launcher.launch.JavaRuntimeFinder;
import lombok.Data;

/**
Expand All @@ -22,7 +24,7 @@
public class Configuration {

private boolean offlineEnabled = false;
private String jvmPath;
private JavaRuntime javaRuntime;
private String jvmArgs;
private int minMemory = 1024;
private int maxMemory = 0; // Updated in Launcher
Expand Down Expand Up @@ -55,4 +57,13 @@ public int hashCode() {
public void setWidowHeight(int height) {
this.windowHeight = height;
}

/**
* Backwards compatibility for old configs with jvmPaths
*/
public void setJvmPath(String jvmPath) {
if (jvmPath != null) {
this.javaRuntime = JavaRuntimeFinder.getRuntimeFromPath(jvmPath);
}
}
}
1 change: 1 addition & 0 deletions launcher/src/main/java/com/skcraft/launcher/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Instance implements Comparable<Instance> {
private Date lastAccessed;
@JsonProperty("launch")
private LaunchModifier launchModifier;
private InstanceSettings settings = new InstanceSettings();

@JsonIgnore private File dir;
@JsonIgnore private URL manifestURL;
Expand Down
14 changes: 14 additions & 0 deletions launcher/src/main/java/com/skcraft/launcher/InstanceSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.skcraft.launcher;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.skcraft.launcher.launch.JavaRuntime;
import com.skcraft.launcher.launch.MemorySettings;
import lombok.Data;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class InstanceSettings {
private JavaRuntime runtime;
private MemorySettings memorySettings;
private String customJvmArgs;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import com.skcraft.launcher.Configuration;
import com.skcraft.launcher.Launcher;
import com.skcraft.launcher.dialog.component.BetterComboBox;
import com.skcraft.launcher.launch.JavaRuntime;
import com.skcraft.launcher.launch.JavaRuntimeFinder;
import com.skcraft.launcher.persistence.Persistence;
import com.skcraft.launcher.swing.*;
import com.skcraft.launcher.util.SharedLocale;
Expand All @@ -29,7 +32,7 @@ public class ConfigurationDialog extends JDialog {
private final JPanel tabContainer = new JPanel(new BorderLayout());
private final JTabbedPane tabbedPane = new JTabbedPane();
private final FormPanel javaSettingsPanel = new FormPanel();
private final JTextField jvmPathText = new JTextField();
private final JComboBox<JavaRuntime> jvmRuntime = new BetterComboBox<>();
private final JTextField jvmArgsText = new JTextField();
private final JSpinner minMemorySpinner = new JSpinner();
private final JSpinner maxMemorySpinner = new JSpinner();
Expand Down Expand Up @@ -70,7 +73,10 @@ public ConfigurationDialog(Window owner, @NonNull Launcher launcher) {
setResizable(false);
setLocationRelativeTo(owner);

mapper.map(jvmPathText, "jvmPath");
JavaRuntime[] javaRuntimes = JavaRuntimeFinder.getAvailableRuntimes().toArray(new JavaRuntime[0]);
jvmRuntime.setModel(new DefaultComboBoxModel<>(javaRuntimes));
jvmRuntime.setSelectedItem(config.getJavaRuntime());

mapper.map(jvmArgsText, "jvmArgs");
mapper.map(minMemorySpinner, "minMemory");
mapper.map(maxMemorySpinner, "maxMemory");
Expand All @@ -88,7 +94,7 @@ public ConfigurationDialog(Window owner, @NonNull Launcher launcher) {
}

private void initComponents() {
javaSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.jvmPath")), jvmPathText);
javaSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.jvmPath")), jvmRuntime);
javaSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.jvmArguments")), jvmArgsText);
javaSettingsPanel.addRow(Box.createVerticalStrut(15));
javaSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.64BitJavaWarning")));
Expand Down Expand Up @@ -157,6 +163,8 @@ public void actionPerformed(ActionEvent e) {
*/
public void save() {
mapper.copyFromSwing();
config.setJavaRuntime((JavaRuntime) jvmRuntime.getSelectedItem());

Persistence.commitAndForget(config);
dispose();
}
Expand Down
Loading