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

Set better memory defaults.

This commit is contained in:
sk89q 2015-08-03 14:16:23 -07:00
parent c3c6febdbd
commit 4c8a65d8a3
2 changed files with 31 additions and 4 deletions

View File

@ -25,8 +25,8 @@ public class Configuration {
private String jvmPath;
private String jvmArgs;
private int minMemory = 1024;
private int maxMemory = 1024;
private int permGen = 128;
private int maxMemory = 0; // Updated in Launcher
private int permGen = 256;
private int windowWidth = 854;
private int widowHeight = 480;
private boolean proxyEnabled = false;

View File

@ -23,6 +23,7 @@ import com.skcraft.launcher.update.UpdateManager;
import com.skcraft.launcher.util.HttpRequest;
import com.skcraft.launcher.util.SharedLocale;
import com.skcraft.launcher.util.SimpleLogFormatter;
import com.sun.management.OperatingSystemMXBean;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
@ -35,6 +36,7 @@ import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Locale;
@ -87,13 +89,14 @@ public final class Launcher {
SharedLocale.loadBundle("com.skcraft.launcher.lang.Launcher", Locale.getDefault());
this.baseDir = baseDir;
this.properties = LauncherUtils.loadProperties(Launcher.class,
"launcher.properties", "com.skcraft.launcher.propertiesFile");
this.properties = LauncherUtils.loadProperties(Launcher.class, "launcher.properties", "com.skcraft.launcher.propertiesFile");
this.instances = new InstanceList(this);
this.assets = new AssetsRoot(new File(baseDir, "assets"));
this.config = Persistence.load(new File(configDir, "config.json"), Configuration.class);
this.accounts = Persistence.load(new File(configDir, "accounts.dat"), AccountList.class);
setDefaultConfig();
if (accounts.getSize() > 0) {
accounts.setSelectedItem(accounts.getElementAt(0));
}
@ -108,6 +111,30 @@ public final class Launcher {
updateManager.checkForUpdate();
}
/**
* Updates any incorrect / unset configuration settings with defaults.
*/
public void setDefaultConfig() {
double configMax = config.getMaxMemory() / 1024.0;
double suggestedMax = 2;
double available = Double.MAX_VALUE;
try {
OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
available = bean.getTotalPhysicalMemorySize() / 1024.0 / 1024.0 / 1024.0;
if (available <= 6) {
suggestedMax = available * 0.48;
} else {
suggestedMax = 4;
}
} catch (Exception ignored) {
}
if (config.getMaxMemory() <= 0 || configMax >= available - 1) {
config.setMaxMemory((int) (suggestedMax * 1024));
}
}
/**
* Get the launcher version.
*