Fixed many bugs

This commit is contained in:
huanghongxun
2015-11-15 16:19:10 +08:00
parent f508645496
commit 990f830300
30 changed files with 187 additions and 196 deletions

View File

@@ -29,7 +29,19 @@ public final class C {
public static final Gson gsonPrettyPrinting = new GsonBuilder().setPrettyPrinting().create();
public static final Gson gson = new Gson();
public static final ResourceBundle I18N = ResourceBundle.getBundle("org/jackhuang/hellominecraft/launcher/I18N");
public static final ResourceBundle I18N;
static {
ResourceBundle rb = null;
try {
rb = ResourceBundle.getBundle("org/jackhuang/hellominecraft/launcher/I18N");
} catch(Throwable t) {
rb = null;
System.out.println("Did you delete I18N.properties?");
t.printStackTrace();
}
I18N = rb;
}
//http://repo1.maven.org/maven2
public static final String URL_PUBLISH = "http://www.mcbbs.net/thread-142335-1-1.html";

View File

@@ -71,16 +71,15 @@ public class TaskWindow extends javax.swing.JDialog
return this;
}
public void clean() {
public synchronized void clean() {
if (isVisible()) return;
taskList = null;
taskList = new TaskList();
taskList.addTaskListener(this);
taskList.addAllDoneListener(this);
}
public boolean start() {
if (isVisible() || taskList.isAlive()) return false;
if (isVisible() || taskList == null || taskList.isAlive()) return false;
pgsTotal.setValue(0);
suc = false;
SwingUtils.clearDefaultTable(lstDownload);
@@ -179,7 +178,8 @@ public class TaskWindow extends javax.swing.JDialog
}
if (!suc) {
SwingUtilities.invokeLater(taskList::abort);
if (taskList != null)
SwingUtilities.invokeLater(taskList::abort);
HMCLog.log("Tasks have been canceled by user.");
}
taskList = null;
@@ -205,7 +205,7 @@ public class TaskWindow extends javax.swing.JDialog
int idx = tasks.indexOf(task);
if (idx == -1) return;
int pgs = progress * 100 / max;
if (progresses.get(idx) != pgs) {
if (progresses.contains(idx) && progresses.get(idx) != pgs && lstDownload.getRowCount() > idx) {
SwingUtils.setValueAt(lstDownload, pgs + "%", idx, 1);
progresses.set(idx, pgs);
}
@@ -281,8 +281,6 @@ public class TaskWindow extends javax.swing.JDialog
}
public static class TaskWindowFactory {
public static final Object obj = new Object();
LinkedList<Task> ll = new LinkedList<>();
public TaskWindowFactory addTask(Task t) {
@@ -291,7 +289,8 @@ public class TaskWindow extends javax.swing.JDialog
}
public boolean start() {
synchronized(obj) {
synchronized(instance) {
if (instance.isVisible()) return false;
TaskWindow tw = inst();
for(Task t : ll) tw.addTask(t);
return tw.start();

View File

@@ -30,7 +30,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
@@ -93,7 +92,7 @@ public final class Utils {
try {
Desktop.getDesktop().browse(new URI(url));
return true;
} catch (URISyntaxException | IOException ex) {
} catch (Exception ex) {
HMCLog.warn("Failed to open link:" + url, ex);
return false;
}
@@ -166,7 +165,8 @@ public final class Utils {
}
/**
* In order to fight against the permission manager.
* In order to fight against the permission manager by Minecraft Forge.
* @param status exit code
*/
public static void shutdownForcely(int status) {
try {

View File

@@ -435,6 +435,7 @@ public class FileUtils {
public static File[] searchSuffix(File dir, String suffix) {
ArrayList<File> al = new ArrayList();
File[] files = dir.listFiles();
if (files == null) return new File[0];
for (File f : files)
if (f.getName().endsWith(suffix)) al.add(f);
return al.toArray(new File[0]);

View File

@@ -57,12 +57,14 @@ public final class JdkVersion {
public boolean equals(Object obj) {
if (!(obj instanceof JdkVersion)) return false;
JdkVersion b = (JdkVersion) obj;
if(b.location == null || location == null)
return b.location == location;
return new File(b.location).equals(new File(location));
}
@Override
public int hashCode() {
return new File(location).hashCode();
return location == null ? 0 : new File(location).hashCode();
}
public JdkVersion(String location) {

View File

@@ -24,7 +24,7 @@ import org.jackhuang.hellominecraft.C;
*/
public class MessageBox {
private static String Title = C.i18n("message.info");
private static final String TITLE = C.i18n("message.info");
/**
* Buttons: OK
*/
@@ -110,7 +110,7 @@ public class MessageBox {
* @return User Operation
*/
public static int Show(String Msg, int Option) {
return Show(Msg, Title, Option);
return Show(Msg, TITLE, Option);
}
/**
@@ -120,6 +120,6 @@ public class MessageBox {
* @return User Operation
*/
public static int Show(String Msg) {
return Show(Msg, Title, INFORMATION_MESSAGE);
return Show(Msg, TITLE, INFORMATION_MESSAGE);
}
}