mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-28 12:57:07 +01:00
[Creator] Add test online option.
This commit is contained in:
parent
a3d0626db5
commit
815383a3a8
@ -20,20 +20,19 @@ import com.skcraft.launcher.auth.OfflineSession;
|
|||||||
import com.skcraft.launcher.auth.Session;
|
import com.skcraft.launcher.auth.Session;
|
||||||
import com.skcraft.launcher.builder.BuilderConfig;
|
import com.skcraft.launcher.builder.BuilderConfig;
|
||||||
import com.skcraft.launcher.builder.FnPatternList;
|
import com.skcraft.launcher.builder.FnPatternList;
|
||||||
import com.skcraft.launcher.creator.model.creator.Pack;
|
import com.skcraft.launcher.creator.Creator;
|
||||||
|
import com.skcraft.launcher.creator.model.creator.*;
|
||||||
import com.skcraft.launcher.creator.controller.task.*;
|
import com.skcraft.launcher.creator.controller.task.*;
|
||||||
import com.skcraft.launcher.creator.dialog.*;
|
import com.skcraft.launcher.creator.dialog.*;
|
||||||
import com.skcraft.launcher.creator.dialog.BuildDialog.BuildOptions;
|
import com.skcraft.launcher.creator.dialog.BuildDialog.BuildOptions;
|
||||||
import com.skcraft.launcher.creator.dialog.DeployServerDialog.DeployOptions;
|
import com.skcraft.launcher.creator.dialog.DeployServerDialog.DeployOptions;
|
||||||
import com.skcraft.launcher.creator.model.creator.ManifestEntry;
|
|
||||||
import com.skcraft.launcher.creator.model.creator.Problem;
|
|
||||||
import com.skcraft.launcher.creator.model.creator.Workspace;
|
|
||||||
import com.skcraft.launcher.creator.model.swing.PackTableModel;
|
import com.skcraft.launcher.creator.model.swing.PackTableModel;
|
||||||
import com.skcraft.launcher.creator.server.TestServer;
|
import com.skcraft.launcher.creator.server.TestServer;
|
||||||
import com.skcraft.launcher.creator.server.TestServerBuilder;
|
import com.skcraft.launcher.creator.server.TestServerBuilder;
|
||||||
import com.skcraft.launcher.creator.swing.PackDirectoryFilter;
|
import com.skcraft.launcher.creator.swing.PackDirectoryFilter;
|
||||||
import com.skcraft.launcher.dialog.ConfigurationDialog;
|
import com.skcraft.launcher.dialog.ConfigurationDialog;
|
||||||
import com.skcraft.launcher.dialog.ConsoleFrame;
|
import com.skcraft.launcher.dialog.ConsoleFrame;
|
||||||
|
import com.skcraft.launcher.dialog.LoginDialog;
|
||||||
import com.skcraft.launcher.dialog.ProgressDialog;
|
import com.skcraft.launcher.dialog.ProgressDialog;
|
||||||
import com.skcraft.launcher.model.modpack.LaunchModifier;
|
import com.skcraft.launcher.model.modpack.LaunchModifier;
|
||||||
import com.skcraft.launcher.persistence.Persistence;
|
import com.skcraft.launcher.persistence.Persistence;
|
||||||
@ -64,6 +63,7 @@ public class PackManagerController {
|
|||||||
private static final Pattern FILENAME_SANITIZE = Pattern.compile("[^a-z0-9_\\-\\.]+");
|
private static final Pattern FILENAME_SANITIZE = Pattern.compile("[^a-z0-9_\\-\\.]+");
|
||||||
|
|
||||||
@Getter private final File workspaceDir;
|
@Getter private final File workspaceDir;
|
||||||
|
@Getter private final Creator creator;
|
||||||
@Getter private final File workspaceFile;
|
@Getter private final File workspaceFile;
|
||||||
@Getter private final File dataDir;
|
@Getter private final File dataDir;
|
||||||
@Getter private final File distDir;
|
@Getter private final File distDir;
|
||||||
@ -78,19 +78,22 @@ public class PackManagerController {
|
|||||||
private final PackManagerFrame frame;
|
private final PackManagerFrame frame;
|
||||||
private PackTableModel packTableModel;
|
private PackTableModel packTableModel;
|
||||||
|
|
||||||
public PackManagerController(PackManagerFrame frame, File workspaceDir) throws IOException {
|
public PackManagerController(PackManagerFrame frame, File workspaceDir, Creator creator) throws IOException {
|
||||||
this.workspaceDir = workspaceDir;
|
this.workspaceDir = workspaceDir;
|
||||||
|
this.creator = creator;
|
||||||
this.dataDir = Workspace.getDataDir(workspaceDir);
|
this.dataDir = Workspace.getDataDir(workspaceDir);
|
||||||
workspaceFile = Workspace.getWorkspaceFile(workspaceDir);
|
workspaceFile = Workspace.getWorkspaceFile(workspaceDir);
|
||||||
|
|
||||||
this.distDir = new File(workspaceDir, "_upload");
|
this.distDir = new File(workspaceDir, "_upload");
|
||||||
File launcherDir = new File(dataDir, "staging/launcher");
|
File launcherDir = new File(dataDir, "staging/launcher");
|
||||||
|
File launcherConfigDir = new File(creator.getDataDir(), "launcher");
|
||||||
this.webRoot = new File(dataDir, "staging/www");
|
this.webRoot = new File(dataDir, "staging/www");
|
||||||
|
|
||||||
launcherDir.mkdirs();
|
launcherDir.mkdirs();
|
||||||
|
launcherConfigDir.mkdirs();
|
||||||
webRoot.mkdirs();
|
webRoot.mkdirs();
|
||||||
|
|
||||||
this.launcher = new Launcher(launcherDir);
|
this.launcher = new Launcher(launcherDir, creator.getDataDir());
|
||||||
this.executor = launcher.getExecutor();
|
this.executor = launcher.getExecutor();
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
|
|
||||||
@ -215,6 +218,23 @@ public class PackManagerController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isOfflineEnabled() {
|
||||||
|
CreatorConfig config = creator.getConfig();
|
||||||
|
|
||||||
|
if (config.isOfflineEnabled()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Session session = LoginDialog.showLoginRequest(frame, launcher);
|
||||||
|
if (session != null) {
|
||||||
|
config.setOfflineEnabled(true);
|
||||||
|
Persistence.commitAndForget(config);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canAddPackDir(File dir) {
|
public boolean canAddPackDir(File dir) {
|
||||||
try {
|
try {
|
||||||
if (dir.exists() && !dir.isDirectory()) {
|
if (dir.exists() && !dir.isDirectory()) {
|
||||||
@ -315,7 +335,7 @@ public class PackManagerController {
|
|||||||
if (e.isControlDown()) {
|
if (e.isControlDown()) {
|
||||||
SwingHelper.browseDir(optional.get().getDirectory(), frame);
|
SwingHelper.browseDir(optional.get().getDirectory(), frame);
|
||||||
} else {
|
} else {
|
||||||
startTest(optional.get());
|
startTest(optional.get(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,7 +479,16 @@ public class PackManagerController {
|
|||||||
|
|
||||||
if (optional.isPresent()) {
|
if (optional.isPresent()) {
|
||||||
Pack pack = optional.get();
|
Pack pack = optional.get();
|
||||||
startTest(pack);
|
startTest(pack, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
frame.getTestOnlineMenuItem().addActionListener(e -> {
|
||||||
|
Optional<Pack> optional = getSelectedPack(true);
|
||||||
|
|
||||||
|
if (optional.isPresent()) {
|
||||||
|
Pack pack = optional.get();
|
||||||
|
startTest(pack, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -508,7 +537,8 @@ public class PackManagerController {
|
|||||||
ServerDeploy deploy = new ServerDeploy(pack.getSourceDir(), options);
|
ServerDeploy deploy = new ServerDeploy(pack.getSourceDir(), options);
|
||||||
Deferred<?> deferred = Deferreds.makeDeferred(executor.submit(deploy), executor)
|
Deferred<?> deferred = Deferreds.makeDeferred(executor.submit(deploy), executor)
|
||||||
.handleAsync(r -> SwingHelper.showMessageDialog(frame, "Server deployment complete!", "Success", null, JOptionPane.INFORMATION_MESSAGE),
|
.handleAsync(r -> SwingHelper.showMessageDialog(frame, "Server deployment complete!", "Success", null, JOptionPane.INFORMATION_MESSAGE),
|
||||||
ex -> {},
|
ex -> {
|
||||||
|
},
|
||||||
SwingExecutor.INSTANCE);
|
SwingExecutor.INSTANCE);
|
||||||
ProgressDialog.showProgress(frame, deferred, deploy, "Deploying files...", "Deploying server files...");
|
ProgressDialog.showProgress(frame, deferred, deploy, "Deploying files...", "Deploying server files...");
|
||||||
SwingHelper.addErrorDialogCallback(frame, deferred);
|
SwingHelper.addErrorDialogCallback(frame, deferred);
|
||||||
@ -525,7 +555,8 @@ public class PackManagerController {
|
|||||||
GenerateListingController controller = new GenerateListingController(dialog, workspace, loaded, executor);
|
GenerateListingController controller = new GenerateListingController(dialog, workspace, loaded, executor);
|
||||||
controller.setOutputDir(distDir);
|
controller.setOutputDir(distDir);
|
||||||
controller.show();
|
controller.show();
|
||||||
}, ex -> {}, SwingExecutor.INSTANCE);
|
}, ex -> {
|
||||||
|
}, SwingExecutor.INSTANCE);
|
||||||
ProgressDialog.showProgress(frame, deferred, new SettableProgress("Searching...", -1), "Searching for manifests...", "Searching for manifests...");
|
ProgressDialog.showProgress(frame, deferred, new SettableProgress("Searching...", -1), "Searching for manifests...", "Searching for manifests...");
|
||||||
SwingHelper.addErrorDialogCallback(frame, deferred);
|
SwingHelper.addErrorDialogCallback(frame, deferred);
|
||||||
});
|
});
|
||||||
@ -575,6 +606,10 @@ public class PackManagerController {
|
|||||||
menuItem.addActionListener(e -> frame.getTestMenuItem().doClick());
|
menuItem.addActionListener(e -> frame.getTestMenuItem().doClick());
|
||||||
popup.add(menuItem);
|
popup.add(menuItem);
|
||||||
|
|
||||||
|
menuItem = new JMenuItem("Test Online");
|
||||||
|
menuItem.addActionListener(e -> frame.getTestOnlineMenuItem().doClick());
|
||||||
|
popup.add(menuItem);
|
||||||
|
|
||||||
menuItem = new JMenuItem("Build...");
|
menuItem = new JMenuItem("Build...");
|
||||||
menuItem.addActionListener(e -> frame.getBuildMenuItem().doClick());
|
menuItem.addActionListener(e -> frame.getBuildMenuItem().doClick());
|
||||||
popup.add(menuItem);
|
popup.add(menuItem);
|
||||||
@ -676,8 +711,22 @@ public class PackManagerController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startTest(Pack pack) {
|
private void startTest(Pack pack, boolean online) {
|
||||||
Session session = new OfflineSession("Player");
|
Session session;
|
||||||
|
|
||||||
|
if (online) {
|
||||||
|
session = LoginDialog.showLoginRequest(frame, launcher);
|
||||||
|
if (session == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!isOfflineEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
session = new OfflineSession("Player");
|
||||||
|
}
|
||||||
|
|
||||||
String version = generateVersionFromDate();
|
String version = generateVersionFromDate();
|
||||||
|
|
||||||
PackBuilder builder = new PackBuilder(pack, webRoot, version, "staging.json", false);
|
PackBuilder builder = new PackBuilder(pack, webRoot, version, "staging.json", false);
|
||||||
|
@ -53,7 +53,7 @@ public class WelcomeController {
|
|||||||
private boolean openWorkspace(File dir) {
|
private boolean openWorkspace(File dir) {
|
||||||
try {
|
try {
|
||||||
PackManagerFrame frame = new PackManagerFrame();
|
PackManagerFrame frame = new PackManagerFrame();
|
||||||
PackManagerController controller = new PackManagerController(frame, dir);
|
PackManagerController controller = new PackManagerController(frame, dir, creator);
|
||||||
addRecentEntry(dir);
|
addRecentEntry(dir);
|
||||||
controller.show();
|
controller.show();
|
||||||
return true;
|
return true;
|
||||||
|
@ -38,7 +38,8 @@ public class PackManagerFrame extends JFrame {
|
|||||||
@Getter private final JMenuItem editConfigMenuItem = new JMenuItem("Edit modpack.json...");
|
@Getter private final JMenuItem editConfigMenuItem = new JMenuItem("Edit modpack.json...");
|
||||||
@Getter private final JMenuItem openFolderMenuItem = new JMenuItem("Open Directory");
|
@Getter private final JMenuItem openFolderMenuItem = new JMenuItem("Open Directory");
|
||||||
@Getter private final JMenuItem checkProblemsMenuItem = new JMenuItem("Scan for Problems...");
|
@Getter private final JMenuItem checkProblemsMenuItem = new JMenuItem("Scan for Problems...");
|
||||||
@Getter private final JMenuItem testMenuItem = new JMenuItem("Test Pack");
|
@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 optionsMenuItem = new JMenuItem("Test Launcher Options...");
|
||||||
@Getter private final JMenuItem clearInstanceMenuItem = new JMenuItem("Delete Test Launcher Instances");
|
@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 clearWebRootMenuItem = new JMenuItem("Empty Test Web Server");
|
||||||
@ -105,6 +106,7 @@ public class PackManagerFrame extends JFrame {
|
|||||||
editConfigMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, Event.CTRL_MASK));
|
editConfigMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, Event.CTRL_MASK));
|
||||||
openFolderMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK | Event.SHIFT_MASK));
|
openFolderMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK | Event.SHIFT_MASK));
|
||||||
testMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
|
testMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
|
||||||
|
testOnlineMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0));
|
||||||
buildMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F10, Event.SHIFT_MASK));
|
buildMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F10, Event.SHIFT_MASK));
|
||||||
deployServerMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F9, Event.SHIFT_MASK));
|
deployServerMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F9, Event.SHIFT_MASK));
|
||||||
docsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
|
docsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
|
||||||
@ -141,6 +143,7 @@ public class PackManagerFrame extends JFrame {
|
|||||||
menu.setMnemonic('t');
|
menu.setMnemonic('t');
|
||||||
menuBar.add(menu);
|
menuBar.add(menu);
|
||||||
menu.add(testMenuItem);
|
menu.add(testMenuItem);
|
||||||
|
menu.add(testOnlineMenuItem);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
menu.add(optionsMenuItem);
|
menu.add(optionsMenuItem);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
@ -15,6 +15,7 @@ import java.util.List;
|
|||||||
public class CreatorConfig {
|
public class CreatorConfig {
|
||||||
|
|
||||||
private List<RecentEntry> recentEntries = Lists.newArrayList();
|
private List<RecentEntry> recentEntries = Lists.newArrayList();
|
||||||
|
private boolean offlineEnabled;
|
||||||
|
|
||||||
public void setRecentEntries(List<RecentEntry> recentEntries) {
|
public void setRecentEntries(List<RecentEntry> recentEntries) {
|
||||||
this.recentEntries = recentEntries != null ? recentEntries : Lists.newArrayList();
|
this.recentEntries = recentEntries != null ? recentEntries : Lists.newArrayList();
|
||||||
|
@ -70,6 +70,18 @@ public final class Launcher {
|
|||||||
* @throws java.io.IOException on load error
|
* @throws java.io.IOException on load error
|
||||||
*/
|
*/
|
||||||
public Launcher(@NonNull File baseDir) throws IOException {
|
public Launcher(@NonNull File baseDir) throws IOException {
|
||||||
|
this(baseDir, baseDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new launcher instance with the given base and configuration
|
||||||
|
* directories.
|
||||||
|
*
|
||||||
|
* @param baseDir the base directory
|
||||||
|
* @param configDir the config directory
|
||||||
|
* @throws java.io.IOException on load error
|
||||||
|
*/
|
||||||
|
public Launcher(@NonNull File baseDir, @NonNull File configDir) throws IOException {
|
||||||
SharedLocale.loadBundle("com.skcraft.launcher.lang.Launcher", Locale.getDefault());
|
SharedLocale.loadBundle("com.skcraft.launcher.lang.Launcher", Locale.getDefault());
|
||||||
|
|
||||||
this.baseDir = baseDir;
|
this.baseDir = baseDir;
|
||||||
@ -77,8 +89,8 @@ public final class Launcher {
|
|||||||
"launcher.properties", "com.skcraft.launcher.propertiesFile");
|
"launcher.properties", "com.skcraft.launcher.propertiesFile");
|
||||||
this.instances = new InstanceList(this);
|
this.instances = new InstanceList(this);
|
||||||
this.assets = new AssetsRoot(new File(baseDir, "assets"));
|
this.assets = new AssetsRoot(new File(baseDir, "assets"));
|
||||||
this.config = Persistence.load(new File(baseDir, "config.json"), Configuration.class);
|
this.config = Persistence.load(new File(configDir, "config.json"), Configuration.class);
|
||||||
this.accounts = Persistence.load(new File(baseDir, "accounts.dat"), AccountList.class);
|
this.accounts = Persistence.load(new File(configDir, "accounts.dat"), AccountList.class);
|
||||||
|
|
||||||
if (accounts.getSize() > 0) {
|
if (accounts.getSize() > 0) {
|
||||||
accounts.setSelectedItem(accounts.getElementAt(0));
|
accounts.setSelectedItem(accounts.getElementAt(0));
|
||||||
|
Loading…
Reference in New Issue
Block a user