Compare commits

..
3 Commits
35 .. 38
Author SHA1 Message Date
huanghongxun 2f7f692b84 Merge pull request #51 from tsl0922/master
Fix cpu ratio for mac
2016-03-25 19:19:46 +08:00
Shuanglei Tao 721df1d17c Fix cpu ratio for mac 2016-03-24 21:29:48 +08:00
huangyuhui 7a2e43f949 Fixed #50 2016-03-19 19:55:42 +08:00
9 changed files with 44 additions and 11 deletions

No files matched your search

@@ -103,8 +103,10 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
initExternalModsTable();
initTabs();
isLoading = true;
for (Java j : Java.JAVA)
cboJava.addItem(j.getLocalizedName());
isLoading = false;
Settings.profileLoadingEvent.register(onLoadingProfiles);
Settings.profileChangedEvent.register(onSelectedProfilesChanged);
@@ -53,20 +53,16 @@ public class DefaultPlugin implements IPlugin {
OFFLINE_LOGIN.onLoadSettings(Settings.getInstance().getAuthenticatorConfig(OFFLINE_LOGIN.id()));
YGGDRASIL_LOGIN = new YggdrasilAuthenticator(clientToken);
YGGDRASIL_LOGIN.onLoadSettings(Settings.getInstance().getAuthenticatorConfig(YGGDRASIL_LOGIN.id()));
SKINME_LOGIN = new SkinmeAuthenticator(clientToken);
SKINME_LOGIN.onLoadSettings(Settings.getInstance().getAuthenticatorConfig(SKINME_LOGIN.id()));
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Settings.getInstance().setAuthenticatorConfig(OFFLINE_LOGIN.id(), OFFLINE_LOGIN.onSaveSettings());
Settings.getInstance().setAuthenticatorConfig(YGGDRASIL_LOGIN.id(), YGGDRASIL_LOGIN.onSaveSettings());
Settings.getInstance().setAuthenticatorConfig(SKINME_LOGIN.id(), SKINME_LOGIN.onSaveSettings());
}
});
apply.accept(OFFLINE_LOGIN);
apply.accept(YGGDRASIL_LOGIN);
apply.accept(SKINME_LOGIN);
}
@Override
@@ -364,7 +364,7 @@ setupwindow.no_empty_name=名字不可为空
setupwindow.clean=清理游戏文件
update.no_browser=无法打开浏览器,网址已经复制到剪贴板了,您可以手动粘贴网址打开页面
update.should_open_link=是否前往发布页面更新?
update.should_open_link=是否更新?
update.newest_version=最新版本为:
update.failed=检查更新失败
update.found=(发现更新!)
@@ -364,7 +364,7 @@ setupwindow.no_empty_name=\u540d\u5b57\u4e0d\u53ef\u4e3a\u7a7a
setupwindow.clean=\u6e05\u7406\u6e38\u620f\u6587\u4ef6
update.no_browser=\u65e0\u6cd5\u6253\u5f00\u6d4f\u89c8\u5668\uff0c\u7f51\u5740\u5df2\u7ecf\u590d\u5236\u5230\u526a\u8d34\u677f\u4e86\uff0c\u60a8\u53ef\u4ee5\u624b\u52a8\u7c98\u8d34\u7f51\u5740\u6253\u5f00\u9875\u9762
update.should_open_link=\u662f\u5426\u524d\u5f80\u53d1\u5e03\u9875\u9762\u66f4\u65b0\uff1f
update.should_open_link=\u662f\u5426\u66f4\u65b0\uff1f
update.newest_version=\u6700\u65b0\u7248\u672c\u4e3a\uff1a
update.failed=\u68c0\u67e5\u66f4\u65b0\u5931\u8d25
update.found=(\u53d1\u73b0\u66f4\u65b0!)
@@ -364,7 +364,7 @@ setupwindow.no_empty_name=Version name cannot be empty.
setupwindow.clean=Clean game files
update.no_browser=Cannot open any browser. The link has been copied to the clipboard. You can paste it to the address bar.
update.should_open_link=Are you willing to open the update link?
update.should_open_link=Are you willing to upgrade this app?
update.newest_version=Newest version:
update.failed=Failed to check for updates.
update.found=(Found Update!)
@@ -364,7 +364,7 @@ setupwindow.no_empty_name=Version name cannot be empty.
setupwindow.clean=Clean game files
update.no_browser=Cannot open any browser. The link has been copied to the clipboard. You can paste it to the address bar.
update.should_open_link=Are you willing to open the update link?
update.should_open_link=Are you willing to upgrade this app?
update.newest_version=Newest version:
update.failed=Failed to check for updates.
update.found=(Found Update!)
@@ -364,7 +364,7 @@ setupwindow.no_empty_name=名字不可為空
setupwindow.clean=清理遊戲資料
update.no_browser=無法打開瀏覽器,網址已經復製到剪貼板了,您可以手動粘貼網址打開頁面
update.should_open_link=是否前往發布頁面更新?
update.should_open_link=是否更新?
update.newest_version=最新版本為:
update.failed=檢查更新失敗
update.found=(發現更新!)
@@ -364,7 +364,7 @@ setupwindow.no_empty_name=\u540d\u5b57\u4e0d\u53ef\u70ba\u7a7a
setupwindow.clean=\u6e05\u7406\u904a\u6232\u8cc7\u6599
update.no_browser=\u7121\u6cd5\u6253\u958b\u700f\u89bd\u5668\uff0c\u7db2\u5740\u5df2\u7d93\u5fa9\u88fd\u5230\u526a\u8cbc\u677f\u4e86\uff0c\u60a8\u53ef\u4ee5\u624b\u52d5\u7c98\u8cbc\u7db2\u5740\u6253\u958b\u9801\u9762
update.should_open_link=\u662f\u5426\u524d\u5f80\u767c\u5e03\u9801\u9762\u66f4\u65b0\uff1f
update.should_open_link=\u662f\u5426\u66f4\u65b0\uff1f
update.newest_version=\u6700\u65b0\u7248\u672c\u70ba\uff1a
update.failed=\u6aa2\u67e5\u66f4\u65b0\u5931\u6557
update.found=(\u767c\u73fe\u66f4\u65b0!)
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.lang.management.ManagementFactory;
import java.util.StringTokenizer;
import com.sun.management.OperatingSystemMXBean;
import org.jackhuang.hellominecraft.util.StrUtils;
@@ -56,7 +57,7 @@ public class MonitorServiceImpl implements IMonitorService {
long freeMemory = Runtime.getRuntime().freeMemory() / kb;
// 最大可使用内存
long maxMemory = Runtime.getRuntime().maxMemory() / kb;
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) java.lang.management.ManagementFactory.getOperatingSystemMXBean();
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
// 操作系统
String osName = System.getProperty("os.name");
// 总的物理内存
@@ -72,6 +73,8 @@ public class MonitorServiceImpl implements IMonitorService {
double cpuRatio = 0;
if (osName.toLowerCase().startsWith("windows"))
cpuRatio = this.getCpuRatioForWindows();
else if (osName.toLowerCase().startsWith("mac"))
cpuRatio = this.getCpuRatioForMac();
else
cpuRatio = getCpuRateForLinux();
// 构造返回对象
@@ -137,7 +140,39 @@ public class MonitorServiceImpl implements IMonitorService {
}
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
return 1;
} finally {
freeResource(is, isr, brStat);
}
}
private double getCpuRatioForMac() {
InputStream is = null;
InputStreamReader isr = null;
BufferedReader brStat = null;
StringTokenizer tokenStat;
try {
Process process = Runtime.getRuntime().exec("top -l 1");
is = process.getInputStream();
isr = new InputStreamReader(is);
brStat = new BufferedReader(isr);
brStat.readLine();
brStat.readLine();
brStat.readLine();
tokenStat = new StringTokenizer(brStat.readLine());
tokenStat.nextToken();
tokenStat.nextToken();
String user = tokenStat.nextToken();
tokenStat.nextToken();
String system = tokenStat.nextToken();
tokenStat.nextToken();
user = user.substring(0, user.indexOf("%"));
system = system.substring(0, system.indexOf("%"));
float userUsage = new Float(user);
float systemUsage = new Float(system);
return (userUsage + systemUsage) / 100;
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
return 1;
} finally {
freeResource(is, isr, brStat);