Extreme headless mode is back!
This commit is contained in:
parent
eb034416ae
commit
7dbda77f10
|
@ -16,7 +16,7 @@ import javax.swing.JProgressBar;
|
|||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
public class Downloader extends JOptionPane
|
||||
public class Downloader extends JOptionPane implements IDownloadDisplay
|
||||
{
|
||||
private JDialog container;
|
||||
private JLabel currentActivity;
|
||||
|
@ -45,7 +45,7 @@ public class Downloader extends JOptionPane
|
|||
return box;
|
||||
}
|
||||
|
||||
JDialog makeDialog()
|
||||
public JDialog makeDialog()
|
||||
{
|
||||
setMessageType(JOptionPane.INFORMATION_MESSAGE);
|
||||
setMessage(makeProgressPanel());
|
||||
|
@ -94,7 +94,7 @@ public class Downloader extends JOptionPane
|
|||
}
|
||||
}
|
||||
|
||||
void updateProgressString(String progressUpdate, Object... data)
|
||||
public void updateProgressString(String progressUpdate, Object... data)
|
||||
{
|
||||
FMLLog.finest(progressUpdate, data);
|
||||
if (currentActivity!=null)
|
||||
|
@ -103,7 +103,7 @@ public class Downloader extends JOptionPane
|
|||
}
|
||||
}
|
||||
|
||||
void resetProgress(int sizeGuess)
|
||||
public void resetProgress(int sizeGuess)
|
||||
{
|
||||
if (progress!=null)
|
||||
{
|
||||
|
@ -111,7 +111,7 @@ public class Downloader extends JOptionPane
|
|||
}
|
||||
}
|
||||
|
||||
void updateProgress(int fullLength)
|
||||
public void updateProgress(int fullLength)
|
||||
{
|
||||
if (progress!=null)
|
||||
{
|
||||
|
@ -119,10 +119,22 @@ public class Downloader extends JOptionPane
|
|||
}
|
||||
}
|
||||
|
||||
void makeHeadless()
|
||||
public void makeHeadless()
|
||||
{
|
||||
container = null;
|
||||
progress = null;
|
||||
currentActivity = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPokeThread(Thread currentThread)
|
||||
{
|
||||
this.pokeThread = currentThread;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldStopIt()
|
||||
{
|
||||
return stopIt;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package cpw.mods.fml.relauncher;
|
||||
|
||||
public class DummyDownloader implements IDownloadDisplay
|
||||
{
|
||||
|
||||
@Override
|
||||
public void resetProgress(int sizeGuess)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPokeThread(Thread currentThread)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgress(int fullLength)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldStopIt()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressString(String string, Object... data)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object makeDialog()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void makeHeadless()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -56,20 +56,28 @@ public class FMLRelauncher
|
|||
if (RelaunchLibraryManager.downloadMonitor != null) { return; }
|
||||
try
|
||||
{
|
||||
RelaunchLibraryManager.downloadMonitor = new Downloader();
|
||||
if (showIt)
|
||||
{
|
||||
popupWindow = RelaunchLibraryManager.downloadMonitor.makeDialog();
|
||||
RelaunchLibraryManager.downloadMonitor = new Downloader();
|
||||
popupWindow = (JDialog) RelaunchLibraryManager.downloadMonitor.makeDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
RelaunchLibraryManager.downloadMonitor = new DummyDownloader();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Throwable e)
|
||||
{
|
||||
if (RelaunchLibraryManager.downloadMonitor == null)
|
||||
{
|
||||
RelaunchLibraryManager.downloadMonitor = new DummyDownloader();
|
||||
e.printStackTrace();
|
||||
}
|
||||
else
|
||||
{
|
||||
RelaunchLibraryManager.downloadMonitor.makeHeadless();
|
||||
}
|
||||
popupWindow = null;
|
||||
RelaunchLibraryManager.downloadMonitor.makeHeadless();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +102,7 @@ public class FMLRelauncher
|
|||
}
|
||||
}
|
||||
|
||||
if (RelaunchLibraryManager.downloadMonitor.stopIt)
|
||||
if (RelaunchLibraryManager.downloadMonitor.shouldStopIt())
|
||||
{
|
||||
System.exit(1);
|
||||
}
|
||||
|
@ -284,7 +292,7 @@ public class FMLRelauncher
|
|||
popupWindow.setVisible(false);
|
||||
popupWindow.dispose();
|
||||
}
|
||||
if (RelaunchLibraryManager.downloadMonitor.stopIt)
|
||||
if (RelaunchLibraryManager.downloadMonitor.shouldStopIt())
|
||||
{
|
||||
System.exit(1);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package cpw.mods.fml.relauncher;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
|
||||
public interface IDownloadDisplay
|
||||
{
|
||||
|
||||
void resetProgress(int sizeGuess);
|
||||
|
||||
void setPokeThread(Thread currentThread);
|
||||
|
||||
void updateProgress(int fullLength);
|
||||
|
||||
boolean shouldStopIt();
|
||||
|
||||
void updateProgressString(String string, Object ... data);
|
||||
|
||||
Object makeDialog();
|
||||
|
||||
void makeHeadless();
|
||||
|
||||
}
|
|
@ -154,7 +154,7 @@ public class RelaunchLibraryManager
|
|||
}
|
||||
finally
|
||||
{
|
||||
if (downloadMonitor.stopIt)
|
||||
if (downloadMonitor.shouldStopIt())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -433,7 +433,7 @@ public class RelaunchLibraryManager
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (downloadMonitor.stopIt)
|
||||
if (downloadMonitor.shouldStopIt())
|
||||
{
|
||||
FMLRelaunchLog.warning("You have stopped the downloading operation before it could complete");
|
||||
return;
|
||||
|
@ -454,7 +454,7 @@ public class RelaunchLibraryManager
|
|||
|
||||
private static final String HEXES = "0123456789abcdef";
|
||||
private static ByteBuffer downloadBuffer = ByteBuffer.allocateDirect(1 << 22);
|
||||
static Downloader downloadMonitor;
|
||||
static IDownloadDisplay downloadMonitor;
|
||||
|
||||
private static void performDownload(InputStream is, int sizeGuess, String validationHash, File target)
|
||||
{
|
||||
|
@ -469,19 +469,19 @@ public class RelaunchLibraryManager
|
|||
downloadMonitor.resetProgress(sizeGuess);
|
||||
try
|
||||
{
|
||||
downloadMonitor.pokeThread = Thread.currentThread();
|
||||
downloadMonitor.setPokeThread(Thread.currentThread());
|
||||
byte[] smallBuffer = new byte[1024];
|
||||
while ((bytesRead = is.read(smallBuffer)) >= 0) {
|
||||
downloadBuffer.put(smallBuffer, 0, bytesRead);
|
||||
fullLength += bytesRead;
|
||||
if (downloadMonitor.stopIt)
|
||||
if (downloadMonitor.shouldStopIt())
|
||||
{
|
||||
break;
|
||||
}
|
||||
downloadMonitor.updateProgress(fullLength);
|
||||
}
|
||||
is.close();
|
||||
downloadMonitor.pokeThread = null;
|
||||
downloadMonitor.setPokeThread(null);
|
||||
downloadBuffer.limit(fullLength);
|
||||
downloadBuffer.position(0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue