Added in some dialogs when things don't go so well

This commit is contained in:
Christian 2012-07-29 22:55:53 -04:00
parent ba28161f16
commit b53ce2aa90
2 changed files with 100 additions and 14 deletions

View file

@ -2,13 +2,22 @@ package cpw.mods.fml.relauncher;
import java.applet.Applet;
import java.applet.AppletStub;
import java.awt.Dialog.ModalityType;
import java.awt.HeadlessException;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLClassLoader;
import java.util.Arrays;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.ProgressMonitorInputStream;
import net.minecraft.src.WorldSettings;
public class FMLEmbeddingRelauncher
@ -18,18 +27,21 @@ public class FMLEmbeddingRelauncher
private Object newApplet;
private Class<? super Object> appletClass;
private JDialog popupWindow;
public static void relaunch(ArgsWrapper wrap)
{
instance().relaunchClient(wrap);
}
private static FMLEmbeddingRelauncher instance()
static FMLEmbeddingRelauncher instance()
{
if (INSTANCE == null)
{
INSTANCE = new FMLEmbeddingRelauncher();
}
return INSTANCE;
}
private FMLEmbeddingRelauncher()
@ -37,15 +49,38 @@ public class FMLEmbeddingRelauncher
URLClassLoader ucl = (URLClassLoader)getClass().getClassLoader();
clientLoader = new RelaunchClassLoader(ucl.getURLs());
try
{
popupWindow = new JDialog(null, "FML Initial Setup", ModalityType.MODELESS);
JOptionPane optPane = new JOptionPane("<html><font size=\"+1\">FML Setup</font><br/><br/>FML is performing some configuration, please wait</html>", JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[0]);
popupWindow.add(optPane);
popupWindow.pack();
popupWindow.setLocationRelativeTo(null);
popupWindow.setVisible(true);
}
catch (Exception e)
{
popupWindow = null;
}
}
private void relaunchClient(ArgsWrapper wrap)
{
File minecraftHome = setupHome();
// Now we re-inject the home into the "new" minecraft under our control
Class<? super Object> client = ReflectionHelper.getClass(clientLoader, "net.minecraft.client.Minecraft");
ReflectionHelper.setPrivateValue(client, null, minecraftHome, "field_6275_Z", "ap", "minecraftDir");
Class<? super Object> client;
try
{
File minecraftHome = setupHome();
client = ReflectionHelper.getClass(clientLoader, "net.minecraft.client.Minecraft");
ReflectionHelper.setPrivateValue(client, null, minecraftHome, "field_6275_Z", "ap", "minecraftDir");
}
finally
{
popupWindow.setVisible(false);
popupWindow.dispose();
}
try
{
@ -75,7 +110,28 @@ public class FMLEmbeddingRelauncher
FMLLog.minecraftHome = minecraftHome;
FMLLog.info("FML relaunch active");
RelaunchLibraryManager.handleLaunch(minecraftHome, clientLoader);
try
{
RelaunchLibraryManager.handleLaunch(minecraftHome, clientLoader);
}
catch (Throwable t)
{
try
{
String logFile = new File(minecraftHome,"ForgeModLoader-0.log").getCanonicalPath();
JOptionPane.showMessageDialog(popupWindow,
String.format("<html><div align=\"center\"><font size=\"+1\">There was a fatal error starting up minecraft and FML</font></div><br/>" +
"Minecraft cannot launch in it's current configuration<br/>" +
"Please consult the file <i><a href=\"file:///%s\">%s</a></i> for further information</html>", logFile, logFile
), "Fatal FML error", JOptionPane.ERROR_MESSAGE);
}
catch (Exception ex)
{
// ah well, we tried
}
throw new RuntimeException(t);
}
return minecraftHome;
}
@ -148,4 +204,16 @@ public class FMLEmbeddingRelauncher
}
return;
}
public InputStream wrapStream(InputStream inputStream, String infoString)
{
if (popupWindow!=null)
{
return new ProgressMonitorInputStream(popupWindow, infoString, inputStream);
}
else
{
return inputStream;
}
}
}

View file

@ -25,6 +25,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.ProgressMonitorInputStream;
import cpw.mods.fml.common.discovery.ModCandidate;
@ -102,15 +103,23 @@ public class RelaunchLibraryManager
}
String fileChecksum = generateChecksum(libFile);
if (!checksum.equals(fileChecksum))
// bad checksum and I did not download this file
if (!checksum.equals(fileChecksum) && !download)
{
caughtErrors.add(new RuntimeException(String.format("The file %s has an invalid checksum %s (expecting %s) - delete it and try again.", libName, fileChecksum, checksum)));
caughtErrors.add(new RuntimeException(String.format("The file %s was found in your lib directory and has an invalid checksum %s (expecting %s) - it is unlikely to be the correct download, please move it out of the way and try again.", libName, fileChecksum, checksum)));
continue;
}
// bad checksum but file was downloaded this session
else if (!checksum.equals(fileChecksum))
{
caughtErrors.add(new RuntimeException(String.format("The downloaded file %s has an invalid checksum %s (expecting %s). The download did not succeed correctly and the file has been deleted. Please try launching again.", libName, fileChecksum, checksum)));
libFile.delete();
continue;
}
if (!download)
{
System.out.printf("Found library file %s present and correct in lib dir\n", libName);
System.out.printf("Found library file %s present and correct in lib dir", libName);
}
else
{
@ -149,7 +158,13 @@ public class RelaunchLibraryManager
"They may help you diagnose and resolve the issue");
for (Throwable t : caughtErrors)
{
FMLLog.log(Level.SEVERE, t, "Fatal error");
FMLLog.severe(t.getMessage());
}
FMLLog.severe("<<< ==== >>>");
FMLLog.severe("The following is diagnostic information for developers to review.");
for (Throwable t : caughtErrors)
{
FMLLog.log(Level.SEVERE, t, "Error details");
}
throw new RuntimeException("A fatal error occured and FML cannot continue");
}
@ -228,16 +243,18 @@ public class RelaunchLibraryManager
try
{
URL libDownload = new URL(String.format(rootUrl,libFile.getName()));
FMLLog.info("Downloading %s", libDownload.toString());
InputStream urlConn = libDownload.openStream();
ReadableByteChannel urlChannel = Channels.newChannel(urlConn);
String infoString = String.format("Downloading file %s", libDownload.toString());
FMLLog.info(infoString);
InputStream urlStream = libDownload.openStream();
urlStream = FMLEmbeddingRelauncher.instance().wrapStream(urlStream, infoString);
ReadableByteChannel urlChannel = Channels.newChannel(urlStream);
FileOutputStream libFileStream = new FileOutputStream(libFile);
FileChannel libFileChannel = libFileStream.getChannel();
libFileChannel.transferFrom(urlChannel, 0, 1<<24);
libFileChannel.close();
libFileStream.close();
urlChannel.close();
urlConn.close();
urlStream.close();
FMLLog.info("Download complete");
}
catch (Exception e)
@ -245,6 +262,7 @@ public class RelaunchLibraryManager
FMLLog.severe("There was a problem downloading the file %s automatically. Perhaps you" +
"have an environment without internet access. You will need to download " +
"the file manually\n", libFile.getName());
libFile.delete();
throw new RuntimeException("A download error occured", e);
}
}