mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 18:45:09 +00:00
Extreme headless mode is back!
This commit is contained in:
1 parent
dd7502a051
commit
f0837070d6
5 files changed
+115
-18
No files matched your search
@@ -16,7 +16,7 @@ import javax.swing.JProgressBar;
|
|||||||
|
|
||||||
import cpw.mods.fml.common.FMLLog;
|
import cpw.mods.fml.common.FMLLog;
|
||||||
|
|
||||||
public class Downloader extends JOptionPane
|
public class Downloader extends JOptionPane implements IDownloadDisplay
|
||||||
{
|
{
|
||||||
private JDialog container;
|
private JDialog container;
|
||||||
private JLabel currentActivity;
|
private JLabel currentActivity;
|
||||||
@@ -45,7 +45,7 @@ public class Downloader extends JOptionPane
|
|||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
JDialog makeDialog()
|
public JDialog makeDialog()
|
||||||
{
|
{
|
||||||
setMessageType(JOptionPane.INFORMATION_MESSAGE);
|
setMessageType(JOptionPane.INFORMATION_MESSAGE);
|
||||||
setMessage(makeProgressPanel());
|
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);
|
FMLLog.finest(progressUpdate, data);
|
||||||
if (currentActivity!=null)
|
if (currentActivity!=null)
|
||||||
@@ -103,7 +103,7 @@ public class Downloader extends JOptionPane
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetProgress(int sizeGuess)
|
public void resetProgress(int sizeGuess)
|
||||||
{
|
{
|
||||||
if (progress!=null)
|
if (progress!=null)
|
||||||
{
|
{
|
||||||
@@ -111,7 +111,7 @@ public class Downloader extends JOptionPane
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateProgress(int fullLength)
|
public void updateProgress(int fullLength)
|
||||||
{
|
{
|
||||||
if (progress!=null)
|
if (progress!=null)
|
||||||
{
|
{
|
||||||
@@ -119,10 +119,22 @@ public class Downloader extends JOptionPane
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void makeHeadless()
|
public void makeHeadless()
|
||||||
{
|
{
|
||||||
container = null;
|
container = null;
|
||||||
progress = null;
|
progress = null;
|
||||||
currentActivity = 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; }
|
if (RelaunchLibraryManager.downloadMonitor != null) { return; }
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RelaunchLibraryManager.downloadMonitor = new Downloader();
|
|
||||||
if (showIt)
|
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)
|
if (RelaunchLibraryManager.downloadMonitor == null)
|
||||||
{
|
{
|
||||||
|
RelaunchLibraryManager.downloadMonitor = new DummyDownloader();
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RelaunchLibraryManager.downloadMonitor.makeHeadless();
|
||||||
|
}
|
||||||
popupWindow = null;
|
popupWindow = null;
|
||||||
RelaunchLibraryManager.downloadMonitor.makeHeadless();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +102,7 @@ public class FMLRelauncher
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RelaunchLibraryManager.downloadMonitor.stopIt)
|
if (RelaunchLibraryManager.downloadMonitor.shouldStopIt())
|
||||||
{
|
{
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
@@ -284,7 +292,7 @@ public class FMLRelauncher
|
|||||||
popupWindow.setVisible(false);
|
popupWindow.setVisible(false);
|
||||||
popupWindow.dispose();
|
popupWindow.dispose();
|
||||||
}
|
}
|
||||||
if (RelaunchLibraryManager.downloadMonitor.stopIt)
|
if (RelaunchLibraryManager.downloadMonitor.shouldStopIt())
|
||||||
{
|
{
|
||||||
System.exit(1);
|
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
|
finally
|
||||||
{
|
{
|
||||||
if (downloadMonitor.stopIt)
|
if (downloadMonitor.shouldStopIt())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -433,7 +433,7 @@ public class RelaunchLibraryManager
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
if (downloadMonitor.stopIt)
|
if (downloadMonitor.shouldStopIt())
|
||||||
{
|
{
|
||||||
FMLRelaunchLog.warning("You have stopped the downloading operation before it could complete");
|
FMLRelaunchLog.warning("You have stopped the downloading operation before it could complete");
|
||||||
return;
|
return;
|
||||||
@@ -454,7 +454,7 @@ public class RelaunchLibraryManager
|
|||||||
|
|
||||||
private static final String HEXES = "0123456789abcdef";
|
private static final String HEXES = "0123456789abcdef";
|
||||||
private static ByteBuffer downloadBuffer = ByteBuffer.allocateDirect(1 << 22);
|
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)
|
private static void performDownload(InputStream is, int sizeGuess, String validationHash, File target)
|
||||||
{
|
{
|
||||||
@@ -469,19 +469,19 @@ public class RelaunchLibraryManager
|
|||||||
downloadMonitor.resetProgress(sizeGuess);
|
downloadMonitor.resetProgress(sizeGuess);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
downloadMonitor.pokeThread = Thread.currentThread();
|
downloadMonitor.setPokeThread(Thread.currentThread());
|
||||||
byte[] smallBuffer = new byte[1024];
|
byte[] smallBuffer = new byte[1024];
|
||||||
while ((bytesRead = is.read(smallBuffer)) >= 0) {
|
while ((bytesRead = is.read(smallBuffer)) >= 0) {
|
||||||
downloadBuffer.put(smallBuffer, 0, bytesRead);
|
downloadBuffer.put(smallBuffer, 0, bytesRead);
|
||||||
fullLength += bytesRead;
|
fullLength += bytesRead;
|
||||||
if (downloadMonitor.stopIt)
|
if (downloadMonitor.shouldStopIt())
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
downloadMonitor.updateProgress(fullLength);
|
downloadMonitor.updateProgress(fullLength);
|
||||||
}
|
}
|
||||||
is.close();
|
is.close();
|
||||||
downloadMonitor.pokeThread = null;
|
downloadMonitor.setPokeThread(null);
|
||||||
downloadBuffer.limit(fullLength);
|
downloadBuffer.limit(fullLength);
|
||||||
downloadBuffer.position(0);
|
downloadBuffer.position(0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user