mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-18 19:39:09 +00:00
add an early low memory error to GTNH
This commit is contained in:
1 parent
55ccf763b0
commit
bd177ae0bc
3 files changed
+70
-7
No files matched your search
@@ -1,9 +1,12 @@
|
||||
package codechicken.core.launch;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.CharacterIterator;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.StringCharacterIterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.jar.Attributes;
|
||||
@@ -16,6 +19,7 @@ import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
|
||||
import codechicken.core.asm.*;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.CoreModManager;
|
||||
|
||||
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
|
||||
@@ -91,6 +95,64 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
||||
}
|
||||
}
|
||||
|
||||
public static long parseSize(String text) {
|
||||
double d = Double.parseDouble(text.replaceAll("[GMK]B?$", ""));
|
||||
long l = Math.round(d * 1024 * 1024 * 1024L);
|
||||
switch (text.replaceAll("\\d?","").toUpperCase().charAt(0)) {
|
||||
default: l /= 1024;
|
||||
case 'K': l /= 1024;
|
||||
case 'M': l /= 1024;
|
||||
case 'G': return l;
|
||||
}
|
||||
}
|
||||
|
||||
public static String humanReadableByteCountBin(long bytes) {
|
||||
long absB = bytes == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(bytes);
|
||||
if (absB < 1024) {
|
||||
return bytes + " B";
|
||||
}
|
||||
long value = absB;
|
||||
CharacterIterator ci = new StringCharacterIterator("KMGTPE");
|
||||
for (int i = 40; i >= 0 && absB > 0xfffccccccccccccL >> i; i -= 10) {
|
||||
value >>= 10;
|
||||
ci.next();
|
||||
}
|
||||
value *= Long.signum(bytes);
|
||||
return String.format("%.1f %ciB", value / 1024.0, ci.current());
|
||||
}
|
||||
|
||||
public static void systemCheck(String minRAM) {
|
||||
long minBytes = parseSize(minRAM);
|
||||
if (Runtime.getRuntime().maxMemory() < minBytes) {
|
||||
String err = "You should have at least " + minRAM + "of RAM but you have only allocated " + humanReadableByteCountBin(Runtime.getRuntime().maxMemory()) + ".";
|
||||
logger.error(err);
|
||||
|
||||
JEditorPane ep = new JEditorPane("text/html",
|
||||
"<html>" +
|
||||
err +
|
||||
"<br>GTNH seriously won't run without enough RAM. See <a href=\"https://gtnh.miraheze.org/m/3S2\">the Wiki</a> for details." +
|
||||
"<br>Recommended values are between 4GB and 6GB. Check your launcher's JVM arguments." +
|
||||
"</html>");
|
||||
|
||||
ep.setEditable(false);
|
||||
ep.setOpaque(false);
|
||||
ep.addHyperlinkListener(new HyperlinkListener()
|
||||
{
|
||||
@Override
|
||||
public void hyperlinkUpdate(HyperlinkEvent event) {
|
||||
try {
|
||||
if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
|
||||
Desktop.getDesktop().browse(event.getURL().toURI());
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
});
|
||||
|
||||
if (!GraphicsEnvironment.isHeadless())
|
||||
JOptionPane.showMessageDialog(null, ep, "lol nope", JOptionPane.ERROR_MESSAGE);
|
||||
FMLCommonHandler.instance().exitJava(-99, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
versionCheck(mcVersion, "CodeChickenCore");
|
||||
@@ -124,6 +186,7 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook
|
||||
@Override
|
||||
public Void call() {
|
||||
CodeChickenCoreModContainer.loadConfig();
|
||||
systemCheck(CodeChickenCoreModContainer.config.getTag("minRAM").getValue("3GB"));
|
||||
TweakTransformer.load();
|
||||
scanCodeChickenMods();
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook {
|
||||
}
|
||||
});
|
||||
|
||||
JOptionPane.showMessageDialog(null, ep, "A download error has occured", JOptionPane.ERROR_MESSAGE);
|
||||
JOptionPane.showMessageDialog(null, ep, "A download error has occurred", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user