fix bugs with Swing.

This commit is contained in:
huanghongxun
2015-08-13 20:54:42 +08:00
parent f63f888daf
commit a5388e790f
22 changed files with 760 additions and 695 deletions

View File

@@ -62,11 +62,11 @@ dependencies {
} }
retrolambda { retrolambda {
javaVersion = JavaVersion.VERSION_1_7 javaVersion = JavaVersion.VERSION_1_6
} }
jar { jar {
jar.classifier = 'base' //jar.classifier = 'base'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest { manifest {
@@ -117,7 +117,7 @@ task makeExecutable(dependsOn: jar) << {
launch4j { launch4j {
launch4jCmd = 'D:\\Develop\\Java\\Launch4j\\launch4j.exe' launch4jCmd = 'D:\\Develop\\Java\\Launch4j\\launch4j.exe'
supportUrl = 'http://www.mcbbs.net/thread-142335-1-1.html' supportUrl = 'http://www.mcbbs.net/thread-142335-1-1.html'
jreMinVersion = '1.7.0' jreMinVersion = '1.6.0'
mainClassName = mainClass mainClassName = mainClass
icon = new File(project.buildDir, '../icon.ico').absolutePath icon = new File(project.buildDir, '../icon.ico').absolutePath
@@ -136,6 +136,6 @@ processResources {
} }
} }
build.dependsOn proguard //build.dependsOn proguard
//makeExecutable.dependsOn proguard //makeExecutable.dependsOn proguard
//build.dependsOn makeExecutable //build.dependsOn makeExecutable

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,7 @@
*/ */
package org.jackhuang.hellominecraft.launcher.launch; package org.jackhuang.hellominecraft.launcher.launch;
import com.google.gson.JsonSyntaxException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@@ -146,7 +147,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
// If the scale new format existent file is lower then 0.1, use the old format. // If the scale new format existent file is lower then 0.1, use the old format.
if (cnt * 10 < tot) return assetsDir; if (cnt * 10 < tot) return assetsDir;
} }
} catch (IOException e) { } catch (IOException | JsonSyntaxException e) {
HMCLog.warn("Failed to create virutal assets.", e); HMCLog.warn("Failed to create virutal assets.", e);
} }

View File

@@ -172,6 +172,7 @@ public final class Profile {
} }
public File getFolder(String folder) { public File getFolder(String folder) {
if (getSelectedMinecraftVersion() == null) return new File(getCanonicalGameDirFile(), folder);
return new File(getMinecraftProvider().getRunDirectory(getSelectedMinecraftVersion().id), folder); return new File(getMinecraftProvider().getRunDirectory(getSelectedMinecraftVersion().id), folder);
} }

View File

@@ -24,7 +24,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.jackhuang.hellominecraft.C; import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.Main; import org.jackhuang.hellominecraft.launcher.Main;
@@ -77,6 +76,8 @@ public final class Settings {
temp.add(new Java("Custom", null)); temp.add(new Java("Custom", null));
if (OS.os() == OS.WINDOWS) if (OS.os() == OS.WINDOWS)
temp.addAll(Java.queryAllJavaHomeInWindowsByReg()); temp.addAll(Java.queryAllJavaHomeInWindowsByReg());
if (OS.os() == OS.OSX)
temp.addAll(Java.queryAllJDKInMac());
JAVA = Collections.unmodifiableList(temp); JAVA = Collections.unmodifiableList(temp);
} }
@@ -124,7 +125,6 @@ public final class Settings {
} }
public static void setVersion(Profile ver) { public static void setVersion(Profile ver) {
Objects.requireNonNull(ver);
getVersions().put(ver.getName(), ver); getVersions().put(ver.getName(), ver);
} }

View File

@@ -19,6 +19,7 @@ package org.jackhuang.hellominecraft.launcher.utils;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.Main; import org.jackhuang.hellominecraft.launcher.Main;
@@ -60,7 +61,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
else System.out.println(text); else System.out.println(text);
SwingUtilities.invokeLater(() -> LogWindow.instance.showAsCrashWindow(UpdateChecker.OUT_DATED)); SwingUtilities.invokeLater(() -> LogWindow.instance.showAsCrashWindow(UpdateChecker.OUT_DATED));
if (!UpdateChecker.OUT_DATED) if (!UpdateChecker.OUT_DATED)
reportToServer(text); reportToServer(text, e);
} catch (Throwable ex) { } catch (Throwable ex) {
try { try {
MessageBox.Show(e.getMessage() + "\n" + ex.getMessage(), "ERROR", MessageBox.ERROR_MESSAGE); MessageBox.Show(e.getMessage() + "\n" + ex.getMessage(), "ERROR", MessageBox.ERROR_MESSAGE);
@@ -71,7 +72,12 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
} }
} }
void reportToServer(String text) { private static final HashSet<String> throwableSet = new HashSet<>();
void reportToServer(String text, Throwable t) {
String s = StrUtils.getStackTrace(t);
if (throwableSet.contains(s)) return;
throwableSet.add(s);
new Thread(() -> { new Thread(() -> {
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
map.put("CrashReport", text); map.put("CrashReport", text);

View File

@@ -72,6 +72,11 @@ public class BMCLAPIDownloadProvider implements IDownloadProvider {
return "http://bmclapi2.bangbang93.com/assets/"; return "http://bmclapi2.bangbang93.com/assets/";
} }
@Override
public String getParsedLibraryDownloadURL(String str) {
return str.replace("http://files.minecraftforge.net/maven", "http://bmclapi2.bangbang93.com/maven");
}
@Override @Override
public boolean isAllowedToUseSelfURL() { public boolean isAllowedToUseSelfURL() {
return false; return false;

View File

@@ -41,6 +41,8 @@ public interface IDownloadProvider {
String getVersionsListDownloadURL(); String getVersionsListDownloadURL();
String getAssetsDownloadURL(); String getAssetsDownloadURL();
String getParsedLibraryDownloadURL(String str);
boolean isAllowedToUseSelfURL(); boolean isAllowedToUseSelfURL();
} }

View File

@@ -77,4 +77,9 @@ public class MojangDownloadProvider implements IDownloadProvider {
return true; return true;
} }
@Override
public String getParsedLibraryDownloadURL(String str) {
return str;
}
} }

View File

@@ -24,10 +24,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue;
import java.util.TreeMap; import java.util.TreeMap;
import org.jackhuang.hellominecraft.C; import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
@@ -223,23 +221,26 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
@Override @Override
public List<ModInfo> listMods() { public List<ModInfo> listMods() {
if (profile.getSelectedMinecraftVersion() == null) return Arrays.asList(); if (profile.getSelectedMinecraftVersion() == null) return new ArrayList<>();
File modsFolder = new File(getRunDirectory(profile.getSelectedMinecraftVersion().id), "mods"); File modsFolder = new File(getRunDirectory(profile.getSelectedMinecraftVersion().id), "mods");
ArrayList<ModInfo> mods = new ArrayList<>(); ArrayList<ModInfo> mods = new ArrayList<>();
Queue<File> queue = new LinkedList<>(); File[] fs = modsFolder.listFiles();
queue.add(modsFolder); if (fs != null)
while (!queue.isEmpty()) { for (File f : fs)
File dir = queue.poll(); if (ModInfo.isFileMod(f)) {
File[] fs = dir.listFiles(); ModInfo m = ModInfo.readModInfo(f);
if (fs != null) if (m != null)
for (File f : fs) mods.add(m);
if (ModInfo.isFileMod(f)) { } else if (f.isDirectory()) {
ModInfo m = ModInfo.readModInfo(f); File[] ss = f.listFiles();
if (m != null) if (ss != null)
mods.add(m); for (File ff : ss)
} else if (f.isDirectory()) if (ModInfo.isFileMod(ff)) {
queue.add(f); ModInfo m = ModInfo.readModInfo(ff);
} if (m != null)
mods.add(m);
}
}
Collections.sort(mods); Collections.sort(mods);
return mods; return mods;
} }
@@ -255,7 +256,7 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
File ff = l.getFilePath(baseFolder); File ff = l.getFilePath(baseFolder);
if (!ff.exists()) { if (!ff.exists()) {
String libURL = downloadType.getProvider().getLibraryDownloadURL() + "/"; String libURL = downloadType.getProvider().getLibraryDownloadURL() + "/";
libURL = l.getDownloadURL(libURL, downloadType); libURL = downloadType.getProvider().getParsedLibraryDownloadURL(l.getDownloadURL(libURL, downloadType));
if (libURL != null) if (libURL != null)
downloadLibraries.add(new DownloadLibraryJob(l.name, libURL, ff)); downloadLibraries.add(new DownloadLibraryJob(l.name, libURL, ff));
} }

View File

@@ -175,7 +175,6 @@ public class GameSettingsPanel extends javax.swing.JPanel implements DropTargetL
ppmManage.add(itm); ppmManage.add(itm);
//</editor-fold> //</editor-fold>
lstExternalMods.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
if (lstExternalMods.getColumnModel().getColumnCount() > 0) { if (lstExternalMods.getColumnModel().getColumnCount() > 0) {
lstExternalMods.getColumnModel().getColumn(0).setMinWidth(17); lstExternalMods.getColumnModel().getColumn(0).setMinWidth(17);
lstExternalMods.getColumnModel().getColumn(0).setPreferredWidth(17); lstExternalMods.getColumnModel().getColumn(0).setPreferredWidth(17);
@@ -1143,11 +1142,12 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
String url; String url;
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar"); File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar");
if (v.installer != null) { if (v.installer != null) {
url = v.installer; url = Settings.getInstance().getDownloadSource().getProvider().getParsedLibraryDownloadURL(v.installer);
TaskWindow.getInstance() TaskWindow.getInstance()
.addTask(new FileDownloadTask(url, filepath).setTag("forge")) .addTask(new FileDownloadTask(url, filepath).setTag("forge"))
.addTask(new ForgeInstaller(profile.getMinecraftProvider(), filepath, v)) .addTask(new ForgeInstaller(profile.getMinecraftProvider(), filepath, v))
.start(); .start();
refreshVersions();
} }
}//GEN-LAST:event_btnDownloadForgeActionPerformed }//GEN-LAST:event_btnDownloadForgeActionPerformed
@@ -1169,6 +1169,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
.addTask(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine")) .addTask(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine"))
.addTask(new OptiFineInstaller(profile, v.selfVersion, filepath)) .addTask(new OptiFineInstaller(profile, v.selfVersion, filepath))
.start(); .start();
refreshVersions();
} }
}//GEN-LAST:event_btnDownloadOptifineActionPerformed }//GEN-LAST:event_btnDownloadOptifineActionPerformed
@@ -1186,6 +1187,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
TaskWindow.getInstance() TaskWindow.getInstance()
.addTask(task).addTask(new LiteLoaderInstaller(profile, (LiteLoaderInstallerVersion) v).registerPreviousResult(task)) .addTask(task).addTask(new LiteLoaderInstaller(profile, (LiteLoaderInstallerVersion) v).registerPreviousResult(task))
.start(); .start();
refreshVersions();
}//GEN-LAST:event_btnInstallLiteLoaderActionPerformed }//GEN-LAST:event_btnInstallLiteLoaderActionPerformed
private void btnRefreshLiteLoaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshLiteLoaderActionPerformed private void btnRefreshLiteLoaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshLiteLoaderActionPerformed
@@ -1369,6 +1371,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
try { try {
if (!ModInfo.isFileMod(f) || mods == null) return false; if (!ModInfo.isFileMod(f) || mods == null) return false;
File newf = profile.getFolder("mods"); File newf = profile.getFolder("mods");
if(newf == null) return false;
newf.mkdirs(); newf.mkdirs();
newf = new File(newf, f.getName()); newf = new File(newf, f.getName());
FileUtils.copyFile(f, newf); FileUtils.copyFile(f, newf);
@@ -1537,7 +1540,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
if (mcVersion == null || profile == null) return; if (mcVersion == null || profile == null) return;
type.getList((value) -> { type.getList((value) -> {
if (value != null) if (value != null)
TaskWindow.getInstance().addTask(type.getDownloadTask(Settings.getInstance().getDownloadSource().getProvider())).start(); SwingUtilities.invokeLater(() -> TaskWindow.getInstance().addTask(type.getDownloadTask(Settings.getInstance().getDownloadSource().getProvider())).start());
}); });
} }
@@ -1694,13 +1697,22 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
// </editor-fold> // </editor-fold>
// <editor-fold> // <editor-fold>
List<ModInfo> mods; List<ModInfo> mods;
private final Object lockMod = new Object();
private void reloadMods() { private void reloadMods() {
mods = profile.getMinecraftProvider().listMods(); new Thread(() -> {
SwingUtils.clearDefaultTable(lstExternalMods); synchronized (lockMod) {
DefaultTableModel model = (DefaultTableModel) lstExternalMods.getModel(); mods = profile.getMinecraftProvider().listMods();
for (ModInfo info : mods) SwingUtilities.invokeLater(() -> {
model.addRow(new Object[]{info.isActive(), info.getFileName(), info.version}); synchronized (lockMod) {
SwingUtils.clearDefaultTable(lstExternalMods);
DefaultTableModel model = (DefaultTableModel) lstExternalMods.getModel();
for (ModInfo info : mods)
model.addRow(new Object[]{info.isActive(), info.getFileName(), info.version});
}
});
}
}).start();
} }
// </editor-fold> // </editor-fold>

View File

@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.jackhuang.hellominecraft.logging.logger.Logger; import org.jackhuang.hellominecraft.logging.logger.Logger;
import org.jackhuang.hellominecraft.utils.StrUtils; import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.mojang.authlib.properties.Property; import org.jackhuang.mojang.authlib.properties.Property;
@@ -30,7 +29,6 @@ public abstract class BaseUserAuthentication
private UserType userType; private UserType userType;
protected BaseUserAuthentication(AuthenticationService authenticationService) { protected BaseUserAuthentication(AuthenticationService authenticationService) {
Objects.requireNonNull(authenticationService);
this.authenticationService = authenticationService; this.authenticationService = authenticationService;
} }

View File

@@ -9,10 +9,10 @@ import java.net.Proxy;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.jackhuang.hellominecraft.logging.logger.Logger; import org.jackhuang.hellominecraft.logging.logger.Logger;
import org.jackhuang.hellominecraft.utils.system.IOUtils; import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.utils.NetUtils; import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.utils.Utils;
public abstract class HttpAuthenticationService extends BaseAuthenticationService { public abstract class HttpAuthenticationService extends BaseAuthenticationService {
@@ -20,7 +20,6 @@ public abstract class HttpAuthenticationService extends BaseAuthenticationServic
private final Proxy proxy; private final Proxy proxy;
protected HttpAuthenticationService(Proxy proxy) { protected HttpAuthenticationService(Proxy proxy) {
Objects.requireNonNull(proxy);
this.proxy = proxy; this.proxy = proxy;
} }
@@ -29,7 +28,6 @@ public abstract class HttpAuthenticationService extends BaseAuthenticationServic
} }
protected HttpURLConnection createUrlConnection(URL url) throws IOException { protected HttpURLConnection createUrlConnection(URL url) throws IOException {
Objects.requireNonNull(url);
LOGGER.debug("Opening connection to " + url); LOGGER.debug("Opening connection to " + url);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(this.proxy); HttpURLConnection connection = (HttpURLConnection) url.openConnection(this.proxy);
connection.setConnectTimeout(15000); connection.setConnectTimeout(15000);
@@ -39,9 +37,9 @@ public abstract class HttpAuthenticationService extends BaseAuthenticationServic
} }
public String performPostRequest(URL url, String post, String contentType) throws IOException { public String performPostRequest(URL url, String post, String contentType) throws IOException {
Objects.requireNonNull(url); Utils.requireNonNull(url);
Objects.requireNonNull(post); Utils.requireNonNull(post);
Objects.requireNonNull(contentType); Utils.requireNonNull(contentType);
HttpURLConnection connection = createUrlConnection(url); HttpURLConnection connection = createUrlConnection(url);
byte[] postAsBytes = post.getBytes("UTF-8"); byte[] postAsBytes = post.getBytes("UTF-8");
@@ -90,7 +88,7 @@ public abstract class HttpAuthenticationService extends BaseAuthenticationServic
public String performGetRequest(URL url) public String performGetRequest(URL url)
throws IOException { throws IOException {
Objects.requireNonNull(url); Utils.requireNonNull(url);
HttpURLConnection connection = createUrlConnection(url); HttpURLConnection connection = createUrlConnection(url);
LOGGER.debug("Reading data from " + url); LOGGER.debug("Reading data from " + url);

View File

@@ -31,5 +31,5 @@ buildscript {
} }
retrolambda { retrolambda {
javaVersion = JavaVersion.VERSION_1_7 javaVersion = JavaVersion.VERSION_1_6
} }

View File

@@ -30,8 +30,6 @@
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="lblTotalProgress" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="pgsTotal" max="32767" attributes="0"/> <Component id="pgsTotal" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
@@ -44,14 +42,11 @@
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="srlDownload" pref="289" max="32767" attributes="0"/> <Component id="srlDownload" pref="291" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="btnCancel" alignment="1" min="-2" pref="22" max="-2" attributes="0"/> <Component id="btnCancel" alignment="1" min="-2" pref="22" max="-2" attributes="0"/>
<Group type="103" alignment="1" groupAlignment="3" attributes="0"> <Component id="pgsTotal" alignment="1" min="-2" pref="22" max="-2" attributes="0"/>
<Component id="pgsTotal" alignment="3" min="-2" pref="22" max="-2" attributes="0"/>
<Component id="lblTotalProgress" alignment="3" min="-2" pref="22" max="-2" attributes="0"/>
</Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@@ -69,13 +64,6 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCancelActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCancelActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JLabel" name="lblTotalProgress">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="taskwindow.total_progress" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JProgressBar" name="pgsTotal"> <Component class="javax.swing.JProgressBar" name="pgsTotal">
<Properties> <Properties>
<Property name="stringPainted" type="boolean" value="true"/> <Property name="stringPainted" type="boolean" value="true"/>

View File

@@ -16,7 +16,6 @@
*/ */
package org.jackhuang.hellominecraft.tasks; package org.jackhuang.hellominecraft.tasks;
import java.awt.EventQueue;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.C; import org.jackhuang.hellominecraft.C;
@@ -52,6 +51,13 @@ public class TaskWindow extends javax.swing.JDialog
initComponents(); initComponents();
setLocationRelativeTo(null); setLocationRelativeTo(null);
if (lstDownload.getColumnModel().getColumnCount() > 1) {
int i = 35;
lstDownload.getColumnModel().getColumn(1).setMinWidth(i);
lstDownload.getColumnModel().getColumn(1).setMaxWidth(i);
lstDownload.getColumnModel().getColumn(1).setPreferredWidth(i);
}
setModal(true); setModal(true);
} }
@@ -96,7 +102,6 @@ public class TaskWindow extends javax.swing.JDialog
private void initComponents() { private void initComponents() {
btnCancel = new javax.swing.JButton(); btnCancel = new javax.swing.JButton();
lblTotalProgress = new javax.swing.JLabel();
pgsTotal = new javax.swing.JProgressBar(); pgsTotal = new javax.swing.JProgressBar();
srlDownload = new javax.swing.JScrollPane(); srlDownload = new javax.swing.JScrollPane();
lstDownload = new javax.swing.JTable(); lstDownload = new javax.swing.JTable();
@@ -117,8 +122,6 @@ public class TaskWindow extends javax.swing.JDialog
} }
}); });
lblTotalProgress.setText(bundle.getString("taskwindow.total_progress")); // NOI18N
pgsTotal.setStringPainted(true); pgsTotal.setStringPainted(true);
lstDownload.setModel(SwingUtils.makeDefaultTableModel(new String[]{C.i18n("taskwindow.file_name"), C.i18n("taskwindow.download_progress")}, new Class[]{String.class, String.class}, new boolean[]{false,false}) lstDownload.setModel(SwingUtils.makeDefaultTableModel(new String[]{C.i18n("taskwindow.file_name"), C.i18n("taskwindow.download_progress")}, new Class[]{String.class, String.class}, new boolean[]{false,false})
@@ -133,8 +136,6 @@ public class TaskWindow extends javax.swing.JDialog
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addComponent(lblTotalProgress)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pgsTotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(pgsTotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel) .addComponent(btnCancel)
@@ -144,13 +145,11 @@ public class TaskWindow extends javax.swing.JDialog
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(srlDownload, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE) .addComponent(srlDownload, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnCancel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnCancel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(pgsTotal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(pgsTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblTotalProgress, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap()) .addContainerGap())
); );
@@ -166,19 +165,18 @@ public class TaskWindow extends javax.swing.JDialog
tasks.clear(); tasks.clear();
if (!this.failReasons.isEmpty()) { if (!this.failReasons.isEmpty()) {
MessageBox.Show(StrUtils.parseParams("", failReasons.toArray(), "\n"), C.i18n("message.error"), MessageBox.ERROR_MESSAGE); SwingUtilities.invokeLater(() -> MessageBox.Show(StrUtils.parseParams("", failReasons.toArray(), "\n"), C.i18n("message.error"), MessageBox.ERROR_MESSAGE));
failReasons.clear(); failReasons.clear();
} }
if (!suc) { if (!suc) {
EventQueue.invokeLater(taskList::abort); SwingUtilities.invokeLater(taskList::abort);
HMCLog.log("Tasks have been canceled by user."); HMCLog.log("Tasks have been canceled by user.");
} }
}//GEN-LAST:event_formWindowClosed }//GEN-LAST:event_formWindowClosed
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel; private javax.swing.JButton btnCancel;
private javax.swing.JLabel lblTotalProgress;
private javax.swing.JTable lstDownload; private javax.swing.JTable lstDownload;
private javax.swing.JProgressBar pgsTotal; private javax.swing.JProgressBar pgsTotal;
private javax.swing.JScrollPane srlDownload; private javax.swing.JScrollPane srlDownload;
@@ -197,7 +195,6 @@ public class TaskWindow extends javax.swing.JDialog
SwingUtils.setValueAt(lstDownload, pgs + "%", idx, 1); SwingUtils.setValueAt(lstDownload, pgs + "%", idx, 1);
progresses.set(idx, pgs); progresses.set(idx, pgs);
} }
if (task.isParallelExecuting()) return;
}); });
} }

View File

@@ -228,7 +228,7 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
@Override @Override
public String getInfo() { public String getInfo() {
return C.i18n("download") + ": " + url + " " + filePath; return C.i18n("download") + ": " + url;
} }
@Override @Override

View File

@@ -21,6 +21,7 @@ import org.jackhuang.hellominecraft.utils.system.MessageBox;
import org.jackhuang.hellominecraft.C; import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.utils.functions.NonConsumer; import org.jackhuang.hellominecraft.utils.functions.NonConsumer;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.system.OS;
/** /**
* *

View File

@@ -186,4 +186,8 @@ public final class Utils {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static void requireNonNull(Object o) {
if (o == null) throw new NullPointerException("Oh dear, there is a problem...");
}
} }

View File

@@ -16,6 +16,7 @@
*/ */
package org.jackhuang.hellominecraft.utils.system; package org.jackhuang.hellominecraft.utils.system;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -59,9 +60,30 @@ public class Java {
return name.hashCode(); return name.hashCode();
} }
/*
-----------------------------------
MAC OS X
-----------------------------------
*/
public static List<Java> queryAllJDKInMac() {
List<Java> ans = new ArrayList<>();
if (new File("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home").exists())
ans.add(new Java("JRE", "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"));
File f = new File("/Library/Java/JavaVirtualMachines/");
if (f.exists())
for (File a : f.listFiles())
ans.add(new Java(a.getName(), new File(a, "Contents/Home").getAbsolutePath()));
return ans;
}
/*
-----------------------------------
WINDOWS
-----------------------------------
*/
public static List<Java> queryAllJavaHomeInWindowsByReg() { public static List<Java> queryAllJavaHomeInWindowsByReg() {
List<Java> ans = new ArrayList<>();
try { try {
List<Java> ans = new ArrayList<>();
List<String> javas = queryRegSubFolders("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment"); List<String> javas = queryRegSubFolders("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment");
for (String java : javas) { for (String java : javas) {
int s = 0; int s = 0;
@@ -82,21 +104,19 @@ public class Java {
if (javahome != null) if (javahome != null)
ans.add(new Java(java.substring("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\".length()), javahome)); ans.add(new Java(java.substring("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\".length()), javahome));
} }
return ans;
} catch (IOException | InterruptedException ex) { } catch (IOException | InterruptedException ex) {
HMCLog.err("Faield to query java", ex); HMCLog.err("Faield to query java", ex);
return null;
} }
return ans;
} }
private static List<String> queryRegSubFolders(String location) throws IOException, InterruptedException { private static List<String> queryRegSubFolders(String location) throws IOException, InterruptedException {
String[] cmd = new String[]{"cmd", "/c", "reg", "query", location}; String[] cmd = new String[]{"cmd", "/c", "reg", "query", location};
List<String> l = IOUtils.readProcessByInputStream(cmd); List<String> l = IOUtils.readProcessByInputStream(cmd);
List<String> ans = new ArrayList<>(); List<String> ans = new ArrayList<>();
for (String line : l) { for (String line : l)
if (line.startsWith(location) && !line.equals(location)) if (line.startsWith(location) && !line.equals(location))
ans.add(line); ans.add(line);
}
return ans; return ans;
} }
@@ -104,20 +124,20 @@ public class Java {
String[] cmd = new String[]{"cmd", "/c", "reg", "query", location, "/v", name}; String[] cmd = new String[]{"cmd", "/c", "reg", "query", location, "/v", name};
List<String> l = IOUtils.readProcessByInputStream(cmd); List<String> l = IOUtils.readProcessByInputStream(cmd);
boolean last = false; boolean last = false;
for(String s : l) { for (String s : l) {
if(s.trim().isEmpty()) continue; if (s.trim().isEmpty()) continue;
if (last == true && s.trim().startsWith(name)) { if (last == true && s.trim().startsWith(name)) {
int begins = s.indexOf(name); int begins = s.indexOf(name);
if(begins > 0) { if (begins > 0) {
s = s.substring(begins + name.length()); s = s.substring(begins + name.length());
begins = s.indexOf("REG_SZ"); begins = s.indexOf("REG_SZ");
if(begins > 0) { if (begins > 0) {
s = s.substring(begins + "REG_SZ".length()); s = s.substring(begins + "REG_SZ".length());
return s.trim(); return s.trim();
} }
} }
} }
if(s.trim().equals(location)) last = true; if (s.trim().equals(location)) last = true;
} }
return null; return null;
} }

View File

@@ -52,7 +52,7 @@ configure(install.repositories.mavenInstaller) {
} }
retrolambda { retrolambda {
javaVersion = JavaVersion.VERSION_1_7 javaVersion = JavaVersion.VERSION_1_6
} }
dependencies { dependencies {

View File

@@ -31,5 +31,5 @@ buildscript {
} }
retrolambda { retrolambda {
javaVersion = JavaVersion.VERSION_1_7 javaVersion = JavaVersion.VERSION_1_6
} }