Compare commits

...
4 Commits
Author SHA1 Message Date
南宫临风 130b950878 update version 2016-08-29 17:13:00 +08:00
南宫临风 c0b935e3f1 迁移崩溃收集
改进推荐内容关闭策略
2016-08-25 14:33:40 +08:00
南宫临风 90451e6da9 最大限度的捕获异常,防止客户端崩溃
添加关闭推荐内容按钮
2016-08-24 13:46:06 +08:00
南宫临风 6db34fcdc7 修正地址解析问题 2016-08-22 10:23:27 +08:00
7 changed files with 158 additions and 56 deletions

No files matched your search

+2 -2
View File
@@ -85,9 +85,9 @@ if (buildnumber == null)
if (buildnumber == null)
buildnumber = readBuildNumber()
def versionroot = System.getenv("VERSION_ROOT")
def versionroot = System.getenv("HMCL_VERSION_ROOT")
if (versionroot == null)
versionroot = "2.5.2"
versionroot = "2.5.3"
String mavenGroupId = 'HMCL'
String mavenVersion = versionroot + '.' + buildnumber
@@ -112,14 +112,16 @@ public class DynamicDownloadProvider extends MojangDownloadProvider {
@Override
public String getParsedDownloadURL(String str) {
if (StrUtils.isNotBlank(librariesAddr)) {
str = str.replace("https://libraries.minecraft.net", librariesAddr);
}
if (StrUtils.isNotBlank(launcherMetaAddr)) {
str = str.replace("https://launchermeta.mojang.com", launcherMetaAddr);
}
if (StrUtils.isNotBlank(launcherAddr)) {
str = str.replace("https://launcher.mojang.com", launcherAddr);
if (str != null) {
if (StrUtils.isNotBlank(librariesAddr)) {
str = str.replace("https://libraries.minecraft.net", librariesAddr);
}
if (StrUtils.isNotBlank(launcherMetaAddr)) {
str = str.replace("https://launchermeta.mojang.com", launcherMetaAddr);
}
if (StrUtils.isNotBlank(launcherAddr)) {
str = str.replace("https://launcher.mojang.com", launcherAddr);
}
}
return super.getParsedDownloadURL(str);
}
@@ -142,8 +144,7 @@ public class DynamicDownloadProvider extends MojangDownloadProvider {
try {
String providerInfo = NetUtils.get(PROVIDER_ADDR);
Map<String, String> addrInfo = null;
addrInfo = C.GSON.fromJson(providerInfo, new TypeToken<Map<String, String>>() {
}.getType());
addrInfo = C.GSON.fromJson(providerInfo, new TypeToken<Map<String, String>>() {}.getType());
if (addrInfo != null) {
setLibrariesAddr(getValue(addrInfo, "libraries"));
setAssetsAddr(getValue(addrInfo, "assets"));
@@ -151,7 +152,7 @@ public class DynamicDownloadProvider extends MojangDownloadProvider {
setLauncherAddr(getValue(addrInfo, "launcher"));
setVersionManifestAddr(getValue(addrInfo, "versionManifest"));
}
} catch (IOException ex) {
} catch (Throwable t) {
}
}
@@ -21,8 +21,10 @@ import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
@@ -76,6 +78,16 @@ public final class Config implements Cloneable {
private Map<String, Map> auth;
@SerializedName("ignoreUpdateVersion")
private String ignoreUpdateVersion;
@SerializedName("ignoreRecommend")
private Set<String> ignoreRecommend;
public Set<String> getIgnoreRecommend() {
if (ignoreRecommend == null) {
ignoreRecommend = new HashSet<>();
Settings.save();
}
return ignoreRecommend;
}
public List<JdkVersion> getJava() {
return java == null ? java = new ArrayList<>() : java;
@@ -19,7 +19,6 @@ package org.jackhuang.hellominecraft.launcher.ui;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@@ -36,9 +35,13 @@ import java.util.ArrayList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.util.NetUtils;
import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
/**
@@ -49,12 +52,21 @@ public class RecommendPanel extends JPanel {
private static final int SWITCH_INTERVAL = 10;
private static final int SPACE = 10;
private static final int TOP_POSITION = 2;
private JButton closeButton;
private Image currImage;
private String imageKey = null;
private boolean ignoreSwitch = false;
private List<RecommendInfo> recommends;
public ScheduledExecutorService scheduledexec = Executors.newScheduledThreadPool(1);
public final ScheduledExecutorService scheduledexec = Executors.newScheduledThreadPool(1);
public RecommendPanel() {
initComponents();
recommends = new ArrayList<RecommendInfo>();
new LoadImages().execute();
setCursor(new Cursor(Cursor.HAND_CURSOR));
@@ -67,12 +79,42 @@ public class RecommendPanel extends JPanel {
});
}
private void initComponents() {
this.setLayout(null);
closeButton = new JButton(Main.getIcon("re_close.png"));
closeButton.setRolloverIcon(Main.getIcon("re_close_enter.png"));
closeButton.setBorder(BorderFactory.createEmptyBorder());
closeButton.setContentAreaFilled(false);
closeButton.addActionListener((e) -> ignoreTheRecommend(imageKey));
closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
closeButton.setFocusable(false);
closeButton.setBounds(0, 0, 12, 12);
closeButton.setVisible(false);
this.add(closeButton);
}
private void ignoreTheRecommend(String url) {
synchronized(RecommendPanel.class) {
if (StrUtils.isNotBlank(url)) {
Settings.getInstance().getIgnoreRecommend().add(url);
Settings.save();
ignoreSwitch = true;
showNext();
}
}
}
private void MouseClicked(MouseEvent evt) {
if (imageKey == null) {
return;
}
RecommendInfo info = recommends.get(getCurrentImageIndex());
if (info.link != null && !info.link.equals("")) {
if (StrUtils.isNotBlank(info.link)) {
if (info.once) {
ignoreTheRecommend(info.url);
}
SwingUtils.openLink(info.link);
}
}
@@ -86,13 +128,14 @@ public class RecommendPanel extends JPanel {
@Override
public void run() {
for (RecommendInfo info : recommends) {
try {
File tempFile = File.createTempFile("hmcl", "png");
String tempPath = tempFile.getCanonicalPath();
if (NetUtils.download(info.url, tempPath)) {
info.image = ImageIO.read(tempFile);
}
} catch (IOException ex) {
if (!ignoreShowUrl(info.url)) {
try {
File tempFile = File.createTempFile("hmcl", "png");
String tempPath = tempFile.getCanonicalPath();
if (NetUtils.download(info.url, tempPath)) {
info.image = ImageIO.read(tempFile);
}
} catch (Throwable t) { }
}
}
@@ -105,9 +148,13 @@ public class RecommendPanel extends JPanel {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
int showIndex = getNextImageIndex();
RecommendInfo info = recommends.get(showIndex);
RecommendPanel.this.setImage(info.url, info.image);
synchronized(RecommendPanel.class) {
if (ignoreSwitch) {
ignoreSwitch = false;
} else {
showNext();
}
}
}
});
}
@@ -142,25 +189,49 @@ public class RecommendPanel extends JPanel {
}
return true;
}
private void showNext() {
if (getCanShowImageCount() == 0) {
setVisible(false);
scheduledexec.shutdown();
} else {
int showIndex = getNextImageIndex();
RecommendInfo info = recommends.get(showIndex);
setImage(info.url, info.image);
}
}
private boolean ignoreShowUrl(String url) {
if (StrUtils.isBlank(url)) {
return true;
}
return Settings.getInstance().getIgnoreRecommend().contains(url);
}
public int getCanShowImageCount() {
int imageCount = 0;
for (RecommendInfo recommend : recommends) {
if (recommend.image != null && !ignoreShowUrl(recommend.url)) {
imageCount++;
}
}
return imageCount;
}
public int getNextImageIndex(int showIndex) {
if (showIndex >= recommends.size()) {
showIndex = 0;
}
RecommendInfo info = recommends.get(showIndex);
if (info.image == null) {
showIndex = getNextImageIndex(++showIndex);
if (info.image == null || ignoreShowUrl(info.url)) {
showIndex = getNextImageIndex(++showIndex);
}
return showIndex;
}
public int getNextImageIndex() {
int showIndex = 0;
if (imageKey != null) {
showIndex = getCurrentImageIndex();
showIndex++;
}
if (showIndex >= recommends.size()) {
int showIndex = getCurrentImageIndex();
if (++showIndex >= recommends.size()) {
showIndex = 0;
}
showIndex = getNextImageIndex(showIndex);
@@ -171,43 +242,49 @@ public class RecommendPanel extends JPanel {
int currIndex = 0;
for (int i = 0; i < recommends.size(); i++) {
RecommendInfo info = recommends.get(i);
if (imageKey != null && info.url.equals(imageKey)) {
if (StrUtils.isNotBlank(imageKey) && info.url.equals(imageKey)) {
currIndex = i;
break;
}
}
return currIndex;
}
public void setImage(String key, Image image) {
this.imageKey = key;
this.currImage = image;
//setToolTipText(C.i18n("ui.message.recommend_tip"));
setSize(image.getWidth(this), image.getHeight(this));
int btnWidth = closeButton.getWidth();
setSize(image.getWidth(this) + SPACE + btnWidth, image.getHeight(this));
closeButton.setLocation(getWidth() - btnWidth, TOP_POSITION);
closeButton.setVisible(true);
SwingUtilities.updateComponentTreeUI(this.getRootPane());
}
@Override
public void paintComponent(Graphics g) {
if (null == currImage) {
return;
if (currImage != null) {
g.drawImage(currImage, 0, 0, currImage.getWidth(this), currImage.getHeight(this), this);
}
g.drawImage(currImage, 0, 0, currImage.getWidth(this), currImage.getHeight(this), this);
super.paintComponent(g);
}
static class RecommendInfo {
String url;
String link;
boolean once;
Image image;
}
class LoadImages extends SwingWorker<List<Map<String, String>>, Void> {
class LoadImages extends SwingWorker<List<Map<String, Object>>, Void> {
private static final String RECOMMEND_URL = "http://client.api.mcgogogo.com:81/recommend.php";
@Override
protected List<Map<String, String>> doInBackground() throws Exception {
List<Map<String, String>> infos = null;
protected List<Map<String, Object>> doInBackground() throws Exception {
List<Map<String, Object>> infos = null;
do {
String content = NetUtils.get(RECOMMEND_URL);
if (content == null || content.equals("")) {
@@ -215,13 +292,12 @@ public class RecommendPanel extends JPanel {
}
Map<String, Object> data = new Gson().fromJson(content,
new TypeToken<Map<String, Object>>() {
}.getType());
new TypeToken<Map<String, Object>>() {}.getType());
if (data == null) {
break;
}
infos = (List<Map<String, String>>) data.get("data");
infos = (List<Map<String, Object>>) data.get("data");
} while (false);
return infos;
}
@@ -229,14 +305,27 @@ public class RecommendPanel extends JPanel {
@Override
protected void done() {
try {
List<Map<String, String>> infos = this.get();
List<Map<String, Object>> infos = this.get();
if (infos == null) {
return;
}
for (Map<String, String> info : infos) {
for (Map<String, Object> info : infos) {
RecommendInfo recommend = new RecommendInfo();
recommend.url = info.get("url");
recommend.link = info.get("link");
if (info.get("url") != null) {
recommend.url = (String) info.get("url");
} else {
recommend.url = "";
}
if (info.get("link") != null) {
recommend.link = (String) info.get("link");
} else {
recommend.link = "";
}
if (info.get("once") != null) {
recommend.once = (boolean) info.get("once");
} else {
recommend.once = false;
}
recommend.image = null;
recommends.add(recommend);
}
@@ -138,9 +138,9 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
HashMap<String, String> map = new HashMap<>();
map.put("CrashReport", text);
try {
NetUtils.post(NetUtils.constantURL("http://huangyuhui.duapp.com/crash.php"), map);
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Failed to post HMCL server.", ex);
NetUtils.post(NetUtils.constantURL("http://client.api.mcgogogo.com:81/crash_report.php"), map);
} catch (Throwable error) {
LOGGER.log(Level.SEVERE, "Failed to post HMCL server.", error);
}
});
t.setDaemon(true);
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB