1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-27 12:46:22 +01:00

Improved handling of broken instances.

This commit is contained in:
sk89q 2014-01-09 09:41:24 -08:00
parent 152538e2b8
commit 0645de7f20
10 changed files with 87 additions and 30 deletions

View File

@ -62,4 +62,9 @@ public class OfflineSession implements Session {
return UserType.LEGACY;
}
@Override
public boolean isOnline() {
return false;
}
}

View File

@ -64,4 +64,11 @@ public interface Session {
*/
UserType getUserType();
/**
* Return true if the user is in an online session.
*
* @return true if online
*/
boolean isOnline();
}

View File

@ -118,6 +118,11 @@ public class YggdrasilLoginService implements LoginService {
public UserType getUserType() {
return legacy ? UserType.LEGACY : UserType.MOJANG;
}
@Override
public boolean isOnline() {
return true;
}
}
}

View File

@ -14,7 +14,7 @@ import com.skcraft.launcher.Instance;
import com.skcraft.launcher.InstanceList;
import com.skcraft.launcher.Launcher;
import com.skcraft.launcher.auth.Session;
import com.skcraft.launcher.launch.InstanceLauncher;
import com.skcraft.launcher.launch.Runner;
import com.skcraft.launcher.launch.LaunchProcessHandler;
import com.skcraft.launcher.persistence.Persistence;
import com.skcraft.launcher.selfupdate.UpdateChecker;
@ -430,6 +430,7 @@ public class LauncherFrame extends JFrame {
if (update) {
// Execute the updater
Updater updater = new Updater(launcher, instance);
updater.setOnline(session.isOnline());
ObservableFuture<Instance> future = new ObservableFuture<Instance>(
launcher.getExecutor().submit(updater), updater);
@ -469,7 +470,7 @@ public class LauncherFrame extends JFrame {
final File extractDir = launcher.createExtractDir();
// Get the process
InstanceLauncher task = new InstanceLauncher(launcher, instance, session, extractDir);
Runner task = new Runner(launcher, instance, session, extractDir);
ObservableFuture<Process> processFuture = new ObservableFuture<Process>(
launcher.getExecutor().submit(task), task);

View File

@ -135,7 +135,7 @@ public class HttpDownloader implements Downloader {
synchronized (this) {
if (failed.size() > 0) {
throw new IOException(failed.size() + "files could not be downloaded");
throw new IOException(failed.size() + " files could not be downloaded");
}
}
} finally {

View File

@ -12,10 +12,7 @@ import com.google.common.base.Strings;
import com.google.common.io.Files;
import com.skcraft.concurrency.DefaultProgress;
import com.skcraft.concurrency.ProgressObservable;
import com.skcraft.launcher.AssetsRoot;
import com.skcraft.launcher.Configuration;
import com.skcraft.launcher.Instance;
import com.skcraft.launcher.Launcher;
import com.skcraft.launcher.*;
import com.skcraft.launcher.auth.Session;
import com.skcraft.launcher.install.ZipExtract;
import com.skcraft.launcher.model.minecraft.AssetsIndex;
@ -43,9 +40,9 @@ import static com.skcraft.launcher.util.SharedLocale._;
* Handles the launching of an instance.
*/
@Log
public class InstanceLauncher implements Callable<Process>, ProgressObservable {
public class Runner implements Callable<Process>, ProgressObservable {
private ProgressObservable progress = new DefaultProgress(0, _("instanceLauncher.preparing"));
private ProgressObservable progress = new DefaultProgress(0, _("runner.preparing"));
private final ObjectMapper mapper = new ObjectMapper();
private final Launcher launcher;
@ -69,7 +66,7 @@ public class InstanceLauncher implements Callable<Process>, ProgressObservable {
* @param session the session
* @param extractDir the directory to extract to
*/
public InstanceLauncher(@NonNull Launcher launcher, @NonNull Instance instance,
public Runner(@NonNull Launcher launcher, @NonNull Instance instance,
@NonNull Session session, @NonNull File extractDir) {
this.launcher = launcher;
this.instance = instance;
@ -92,6 +89,10 @@ public class InstanceLauncher implements Callable<Process>, ProgressObservable {
@Override
public Process call() throws Exception {
if (!instance.isInstalled()) {
throw new LauncherException("Update required", _("runner.updateRequired"));
}
config = launcher.getConfig();
builder = new JavaProcessBuilder();
assetsRoot = launcher.getAssets();
@ -105,7 +106,7 @@ public class InstanceLauncher implements Callable<Process>, ProgressObservable {
progress = assetsBuilder;
virtualAssetsDir = assetsBuilder.build();
progress = new DefaultProgress(0.9, _("instanceLauncher.collectingArgs"));
progress = new DefaultProgress(0.9, _("runner.collectingArgs"));
addJvmArgs();
addLibraries();
@ -119,10 +120,10 @@ public class InstanceLauncher implements Callable<Process>, ProgressObservable {
ProcessBuilder processBuilder = new ProcessBuilder(builder.buildCommand());
processBuilder.directory(instance.getContentDir());
log.info("Launching: " + builder);
Runner.log.info("Launching: " + builder);
checkInterrupted();
progress = new DefaultProgress(1, _("instanceLauncher.startingJava"));
progress = new DefaultProgress(1, _("runner.startingJava"));
return processBuilder.start();
}

View File

@ -20,12 +20,15 @@ public class InstanceTableModel extends AbstractTableModel {
private final InstanceList instances;
private final ImageIcon instanceIcon;
private final ImageIcon customInstanceIcon;
private final ImageIcon downloadIcon;
public InstanceTableModel(InstanceList instances) {
this.instances = instances;
instanceIcon = new ImageIcon(SwingHelper.readIconImage(Launcher.class, "instance_icon.png")
.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
customInstanceIcon = new ImageIcon(SwingHelper.readIconImage(Launcher.class, "custom_instance_icon.png")
.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
downloadIcon = new ImageIcon(SwingHelper.readIconImage(Launcher.class, "download_icon.png")
.getScaledInstance(14, 14, Image.SCALE_SMOOTH));
}
@ -95,11 +98,19 @@ public class InstanceTableModel extends AbstractTableModel {
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Instance instance;
switch (columnIndex) {
case 0:
return instances.get(rowIndex).isLocal() ? instanceIcon : downloadIcon;
instance = instances.get(rowIndex);
if (!instance.isLocal()) {
return downloadIcon;
} else if (instance.getManifestURL() != null) {
return instanceIcon;
} else {
return customInstanceIcon;
}
case 1:
Instance instance = instances.get(rowIndex);
instance = instances.get(rowIndex);
return "<html>" + SwingHelper.htmlEscape(instance.getTitle()) + getAddendum(instance) + "</html>";
default:
return null;

View File

@ -12,12 +12,15 @@ import com.skcraft.concurrency.ProgressFilter;
import com.skcraft.concurrency.ProgressObservable;
import com.skcraft.launcher.Instance;
import com.skcraft.launcher.Launcher;
import com.skcraft.launcher.LauncherException;
import com.skcraft.launcher.install.Installer;
import com.skcraft.launcher.model.minecraft.VersionManifest;
import com.skcraft.launcher.model.modpack.Manifest;
import com.skcraft.launcher.persistence.Persistence;
import com.skcraft.launcher.util.HttpRequest;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.extern.java.Log;
import java.io.File;
@ -40,11 +43,13 @@ public class Updater extends BaseUpdater implements Callable<Instance>, Progress
private final Launcher launcher;
private final Instance instance;
@Getter @Setter
private boolean online;
private List<URL> librarySources = new ArrayList<URL>();
private List<URL> assetsSources = new ArrayList<URL>();
private ProgressObservable progress = new DefaultProgress(
-1, _("instanceUpdater.preparingUpdate"));
private ProgressObservable progress = new DefaultProgress(-1, _("instanceUpdater.preparingUpdate"));
public Updater(@NonNull Launcher launcher, @NonNull Instance instance) {
super(launcher);
@ -59,16 +64,34 @@ public class Updater extends BaseUpdater implements Callable<Instance>, Progress
@Override
public Instance call() throws Exception {
Updater.log.info("Checking for an update for '" + instance.getName() + "'...");
if (instance.getManifestURL() == null) {
Updater.log.log(Level.INFO,
"No URL set for {0}, so it can't be updated (the modpack may be removed from the server)",
new Object[] { instance });
} else if (instance.isUpdatePending() || !instance.isInstalled()) {
Updater.log.log(Level.INFO, "Updating {0}...", new Object[]{instance});
log.info("Checking for an update for '" + instance.getName() + "'...");
boolean updateRequired = !instance.isInstalled();
boolean updateDesired = (instance.isUpdatePending() || updateRequired);
boolean updateCapable = (instance.getManifestURL() != null);
if (!online && updateRequired) {
log.info("Can't update " + instance.getTitle() + " because offline");
String message = _("updater.updateRequiredButOffline");
throw new LauncherException("Update required but currently offline", message);
}
if (updateDesired && !updateCapable) {
if (updateRequired) {
log.info("Update required for " + instance.getTitle() + " but there is no manifest");
String message = _("updater.updateRequiredButNoManifest");
throw new LauncherException("Update required but no manifest", message);
} else {
log.info("Can't update " + instance.getTitle() + ", but update is not required");
return instance; // Can't update
}
}
if (updateDesired) {
log.info("Updating " + instance.getTitle() + "...");
update(instance);
} else {
Updater.log.log(Level.INFO, "No update found for {0}.", new Object[] { instance });
log.info("No update found for " + instance.getTitle());
}
return instance;
@ -146,7 +169,7 @@ public class Updater extends BaseUpdater implements Callable<Instance>, Progress
instance.setLocal(true);
Persistence.commitAndForget(instance);
Updater.log.log(Level.INFO, instance.getName() +
log.log(Level.INFO, instance.getName() +
" has been updated to version " + manifest.getVersion() + ".");
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -142,6 +142,8 @@ installer.copyingFile=Copying from {0} to {1}
installer.movingFile=Moving {0} to {1}
updater.updating=Updating launcher...
updater.updateRequiredButOffline=An update is required but you need to be in online mode.
updater.updateRequiredButNoManifest=An update is required but update information for this instance is no longer available.
instanceUpdater.preparingUpdate=Preparing to update...
instanceUpdater.readingManifest=Reading package manifest...
@ -151,9 +153,11 @@ instanceDeleter.deleting=Deleting {0}...
instanceResetter.resetting=Resetting {0}...
instanceLoader.loadingLocal=Loading local instances from disk...
instanceLoader.checkingRemote=Checking for new modpacks...
instanceLauncher.preparing=Preparing for launch...
instanceLauncher.collectingArgs=Collecting arguments...
instanceLauncher.startingJava=Starting java...
runner.preparing=Preparing for launch...
runner.collectingArgs=Collecting arguments...
runner.startingJava=Starting java...
runner.updateRequired=This instance must be updated before it can be run.
assets.expanding1=Expanding {0} asset... ({1} remaining)
assets.expandingN=Expanding {0} assets... ({1} remaining)