Try to fix some problems

This commit is contained in:
huanghongxun
2015-12-10 14:06:56 +08:00
parent 52c43bde06
commit e91d4c5477
20 changed files with 1920 additions and 1264 deletions

View File

@@ -31,8 +31,6 @@ import org.jackhuang.hellominecraft.utils.system.Compressor;
import org.jackhuang.hellominecraft.utils.MessageBox; import org.jackhuang.hellominecraft.utils.MessageBox;
public class DefaultGameLauncher extends GameLauncher { public class DefaultGameLauncher extends GameLauncher {
private boolean fuckingFlag;
public DefaultGameLauncher(Profile version, LoginInfo info, IAuthenticator lg) { public DefaultGameLauncher(Profile version, LoginInfo info, IAuthenticator lg) {
super(version, info, lg); super(version, info, lg);
@@ -46,23 +44,12 @@ public class DefaultGameLauncher extends GameLauncher {
for (DownloadLibraryJob s : t) for (DownloadLibraryJob s : t)
parallelTask.addDependsTask(new LibraryDownloadTask(s)); parallelTask.addDependsTask(new LibraryDownloadTask(s));
dw.addTask(parallelTask); dw.addTask(parallelTask);
Runnable r = () -> { boolean flag = true;
boolean flag = true; if (t.size() > 0)
if (t.size() > 0) flag = dw.start();
flag = dw.start(); if (!flag && MessageBox.Show(C.i18n("launch.not_finished_downloading_libraries"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
if (!flag && MessageBox.Show(C.i18n("launch.not_finished_downloading_libraries"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) flag = true;
flag = true; return flag;
synchronized(DefaultGameLauncher.this) {
fuckingFlag = flag;
}
};
try {
SwingUtilities.invokeAndWait(r);
} catch (Exception e) {
HMCLog.err("InvokeAndWait failed.", e);
r.run();
}
return fuckingFlag;
}); });
decompressNativesEvent.register((sender, value) -> { decompressNativesEvent.register((sender, value) -> {
if (value == null) if (value == null)

View File

@@ -85,7 +85,6 @@ public abstract class IMinecraftProvider {
* *
* @see org.jackhuang.hellominecraft.launcher.launch.IMinecraftLoader * @see org.jackhuang.hellominecraft.launcher.launch.IMinecraftLoader
* @param p player informations, including username & auth_token * @param p player informations, including username & auth_token
* @param type where to download
* *
* @return what you want * @return what you want
* *

View File

@@ -77,15 +77,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) { if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
IAssetsHandler.ASSETS_HANDLER.getList(version, provider).subscribe(a -> { IAssetsHandler.ASSETS_HANDLER.getList(version, provider).subscribe(a -> {
}); });
Runnable r = () TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(provider.profile.getDownloadType().getProvider())).start();
-> TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(provider.profile.getDownloadType().getProvider())).start();
try {
SwingUtilities.invokeAndWait(r);
} catch (Exception e) {
HMCLog.err("Failed invokeAndWait", e);
r.run();
}
} }
String game_assets = reconstructAssets().getAbsolutePath(); String game_assets = reconstructAssets().getAbsolutePath();

View File

@@ -120,8 +120,11 @@ public final class Config {
} }
public TreeMap<String, Profile> getConfigurations() { public TreeMap<String, Profile> getConfigurations() {
if (configurations == null) if (configurations == null) {
configurations = new TreeMap<>(); configurations = new TreeMap<>();
Profile profile = new Profile();
configurations.put(profile.getName(), profile);
}
return configurations; return configurations;
} }
@@ -147,9 +150,6 @@ public final class Config {
clientToken = UUID.randomUUID().toString(); clientToken = UUID.randomUUID().toString();
username = ""; username = "";
logintype = downloadtype = 0; logintype = downloadtype = 0;
configurations = new TreeMap<>();
Profile profile = new Profile();
configurations.put(profile.getName(), profile);
enableShadow = false; enableShadow = false;
theme = 0; theme = 0;
} }

View File

@@ -119,6 +119,7 @@ public final class Settings {
} }
public static Profile getProfile(String name) { public static Profile getProfile(String name) {
if (name == null) return getProfiles().get("Default");
return getProfiles().get(name); return getProfiles().get(name);
} }

View File

@@ -62,7 +62,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
t.printStackTrace(); t.printStackTrace();
} }
return false; return false;
} else if (s.contains("java.lang.NoClassDefFoundError") || s.contains("java.lang.IncompatibleClassChangeError") || s.contains("java.lang.ClassFormatError")) { } else if (s.contains("java.lang.NoClassDefFoundError") || s.contains("java.lang.VerifyError") || s.contains("java.lang.NoSuchMethodError") || s.contains("java.lang.IncompatibleClassChangeError") || s.contains("java.lang.ClassFormatError")) {
System.out.println(C.i18n("crash.NoClassDefFound")); System.out.println(C.i18n("crash.NoClassDefFound"));
try { try {
MessageBox.Show(C.i18n("crash.NoClassDefFound")); MessageBox.Show(C.i18n("crash.NoClassDefFound"));
@@ -98,7 +98,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
else else
System.out.println(text); System.out.println(text);
if (checkThrowable(e)) { if (checkThrowable(e) && !System.getProperty("java.vm.name").contains("OpenJDK")) {
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, s); reportToServer(text, s);

View File

@@ -33,7 +33,6 @@ import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.VersionNumber; import org.jackhuang.hellominecraft.utils.VersionNumber;
import rx.Observable; import rx.Observable;
import rx.Observer; import rx.Observer;
import rx.subscriptions.Subscriptions;
/** /**
* *
@@ -47,10 +46,10 @@ public class AssetsMojangLoader extends IAssetsHandler {
@Override @Override
public Observable<String[]> getList(MinecraftVersion mv, IMinecraftProvider mp) { public Observable<String[]> getList(MinecraftVersion mv, IMinecraftProvider mp) {
return Observable.<String[]>create((Observer<String[]> t1) -> { return Observable.<String[]>createWithEmptySubscription((Observer<String[]> t1) -> {
if (mv == null) { if (mv == null) {
t1.onError(null); t1.onError(null);
return Subscriptions.empty(); return;
} }
String assetsId = mv.assets == null ? "legacy" : mv.assets; String assetsId = mv.assets == null ? "legacy" : mv.assets;
File assets = mp.getAssetService().getAssets(); File assets = mp.getAssetService().getAssets();
@@ -58,7 +57,7 @@ public class AssetsMojangLoader extends IAssetsHandler {
File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json")); File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json"));
if (!f.exists() && !mp.getAssetService().downloadMinecraftAssetsIndex(assetsId)) { if (!f.exists() && !mp.getAssetService().downloadMinecraftAssetsIndex(assetsId)) {
t1.onError(null); t1.onError(null);
return Subscriptions.empty(); return;
} }
String result; String result;
@@ -67,12 +66,12 @@ public class AssetsMojangLoader extends IAssetsHandler {
} catch (IOException ex) { } catch (IOException ex) {
HMCLog.warn("Failed to read index json: " + f, ex); HMCLog.warn("Failed to read index json: " + f, ex);
t1.onError(null); t1.onError(null);
return Subscriptions.empty(); return;
} }
if (StrUtils.isBlank(result)) { if (StrUtils.isBlank(result)) {
HMCLog.err("Index json is empty, please redownload it!"); HMCLog.err("Index json is empty, please redownload it!");
t1.onError(null); t1.onError(null);
return Subscriptions.empty(); return;
} }
AssetsIndex o; AssetsIndex o;
try { try {
@@ -80,7 +79,7 @@ public class AssetsMojangLoader extends IAssetsHandler {
} catch (Exception e) { } catch (Exception e) {
HMCLog.err("Failed to parse index json, please redownload it!", e); HMCLog.err("Failed to parse index json, please redownload it!", e);
t1.onError(null); t1.onError(null);
return Subscriptions.empty(); return;
} }
assetsDownloadURLs = new ArrayList<>(); assetsDownloadURLs = new ArrayList<>();
assetsLocalNames = new ArrayList<>(); assetsLocalNames = new ArrayList<>();
@@ -100,7 +99,6 @@ public class AssetsMojangLoader extends IAssetsHandler {
t1.onNext(al.toArray(new String[1])); t1.onNext(al.toArray(new String[1]));
t1.onCompleted(); t1.onCompleted();
return Subscriptions.empty();
}); });
} }

View File

@@ -207,7 +207,9 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
@Override @Override
public GameLauncher.DecompressLibraryJob getDecompressLibraries() { public GameLauncher.DecompressLibraryJob getDecompressLibraries() {
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this); MinecraftVersion v = getSelectedMinecraftVersion();
if (v == null) return null;
v = v.resolve(this);
if (v.libraries == null) if (v.libraries == null)
return null; return null;
ArrayList<File> unzippings = new ArrayList<>(); ArrayList<File> unzippings = new ArrayList<>();

View File

@@ -38,7 +38,6 @@ import javax.swing.JMenuItem;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelEvent;
@@ -48,7 +47,6 @@ import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility; import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList; import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion; import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
import org.jackhuang.hellominecraft.launcher.settings.Profile; import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings; import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.utils.FileNameFilter; import org.jackhuang.hellominecraft.launcher.utils.FileNameFilter;
@@ -67,6 +65,7 @@ import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.SwingUtils; import org.jackhuang.hellominecraft.utils.SwingUtils;
import org.jackhuang.hellominecraft.utils.system.Java; import org.jackhuang.hellominecraft.utils.system.Java;
import org.jackhuang.hellominecraft.views.LogWindow; import org.jackhuang.hellominecraft.views.LogWindow;
import rx.Observable;
import rx.concurrency.Schedulers; import rx.concurrency.Schedulers;
/** /**
@@ -75,6 +74,11 @@ import rx.concurrency.Schedulers;
*/ */
public final class GameSettingsPanel extends javax.swing.JPanel implements DropTargetListener { public final class GameSettingsPanel extends javax.swing.JPanel implements DropTargetListener {
boolean isLoading = false;
public MinecraftVersionRequest minecraftVersion;
InstallerHelper forge, optifine, liteloader;
String mcVersion;
/** /**
* Creates new form GameSettingsPanel * Creates new form GameSettingsPanel
*/ */
@@ -96,7 +100,7 @@ public final class GameSettingsPanel extends javax.swing.JPanel implements DropT
dropTarget = new DropTarget(lstExternalMods, DnDConstants.ACTION_COPY_OR_MOVE, this); dropTarget = new DropTarget(lstExternalMods, DnDConstants.ACTION_COPY_OR_MOVE, this);
} }
void initExplorationMenu() { void initExplorationMenu() {
ppmExplore = new JPopupMenu(); ppmExplore = new JPopupMenu();
class ImplementedActionListener implements ActionListener { class ImplementedActionListener implements ActionListener {
@@ -133,7 +137,7 @@ public final class GameSettingsPanel extends javax.swing.JPanel implements DropT
itm.addActionListener(new ImplementedActionListener("screenshots")); itm.addActionListener(new ImplementedActionListener("screenshots"));
ppmExplore.add(itm); ppmExplore.add(itm);
} }
void initManagementMenu() { void initManagementMenu() {
ppmManage = new JPopupMenu(); ppmManage = new JPopupMenu();
JMenuItem itm = new JMenuItem(C.i18n("versions.manage.rename")); JMenuItem itm = new JMenuItem(C.i18n("versions.manage.rename"));
@@ -170,7 +174,7 @@ public final class GameSettingsPanel extends javax.swing.JPanel implements DropT
}); });
ppmManage.add(itm); ppmManage.add(itm);
} }
void initExternalModsTable() { void initExternalModsTable() {
if (lstExternalMods.getColumnModel().getColumnCount() > 0) { if (lstExternalMods.getColumnModel().getColumnCount() > 0) {
lstExternalMods.getColumnModel().getColumn(0).setMinWidth(17); lstExternalMods.getColumnModel().getColumn(0).setMinWidth(17);
@@ -179,7 +183,7 @@ public final class GameSettingsPanel extends javax.swing.JPanel implements DropT
} }
lstExternalMods.getSelectionModel().addListSelectionListener(e -> { lstExternalMods.getSelectionModel().addListSelectionListener(e -> {
int row = lstExternalMods.getSelectedRow(); int row = lstExternalMods.getSelectedRow();
List<ModInfo> mods = profile.getMinecraftProvider().getModService().getMods(); List<ModInfo> mods = getProfile().getMinecraftProvider().getModService().getMods();
if (mods != null && 0 <= row && row < mods.size()) { if (mods != null && 0 <= row && row < mods.size()) {
ModInfo m = mods.get(row); ModInfo m = mods.get(row);
boolean hasLink = m.url != null; boolean hasLink = m.url != null;
@@ -199,13 +203,13 @@ public final class GameSettingsPanel extends javax.swing.JPanel implements DropT
((DefaultTableModel) lstExternalMods.getModel()).addTableModelListener(e -> { ((DefaultTableModel) lstExternalMods.getModel()).addTableModelListener(e -> {
if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == 0) { if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == 0) {
int row = lstExternalMods.getSelectedRow(); int row = lstExternalMods.getSelectedRow();
List<ModInfo> mods = profile.getMinecraftProvider().getModService().getMods(); List<ModInfo> mods = getProfile().getMinecraftProvider().getModService().getMods();
if (mods != null && mods.size() > row && row >= 0) if (mods != null && mods.size() > row && row >= 0)
mods.get(row).reverseModState(); mods.get(row).reverseModState();
} }
}); });
} }
void initTabs() { void initTabs() {
tabVersionEdit.addChangeListener(new ChangeListener() { tabVersionEdit.addChangeListener(new ChangeListener() {
boolean a = false, b = false; boolean a = false, b = false;
@@ -1110,12 +1114,9 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged
if (isLoading) if (isLoading)
return; return;
profile = getProfile(); if (getProfile().getMinecraftProvider().getVersionCount() <= 0)
if (profile == null) versionChanged(null);
return; prepare(getProfile());
if (profile.getMinecraftProvider().getVersionCount() <= 0)
versionChanged(profile, null);
prepare(profile);
}//GEN-LAST:event_cboProfilesItemStateChanged }//GEN-LAST:event_cboProfilesItemStateChanged
private void btnNewProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewProfileActionPerformed private void btnNewProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewProfileActionPerformed
@@ -1125,17 +1126,14 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}//GEN-LAST:event_btnNewProfileActionPerformed }//GEN-LAST:event_btnNewProfileActionPerformed
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed
if (profile == null) if (getProfile() == null)
return; return;
if (MessageBox.Show(C.i18n("ui.message.sure_remove", profile.getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION) if (MessageBox.Show(C.i18n("ui.message.sure_remove", getProfile().getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION)
return; return;
if (Settings.delProfile(profile)) { if (Settings.delProfile(getProfile())) {
cboProfiles.removeItem(profile.getName()); cboProfiles.removeItem(getProfile().getName());
profile = Settings.getOneProfile(); prepare(getProfile());
if (profile != null) { loadVersions();
prepare(profile);
loadVersions();
}
} }
}//GEN-LAST:event_btnRemoveProfileActionPerformed }//GEN-LAST:event_btnRemoveProfileActionPerformed
@@ -1144,7 +1142,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
return; return;
String mcv = (String) cboVersions.getSelectedItem(); String mcv = (String) cboVersions.getSelectedItem();
loadMinecraftVersion(mcv); loadMinecraftVersion(mcv);
versionChanged(getProfile(), mcv); versionChanged(mcv);
getProfile().setSelectedMinecraftVersion(mcv); getProfile().setSelectedMinecraftVersion(mcv);
cboVersions.setToolTipText(mcv); cboVersions.setToolTipText(mcv);
}//GEN-LAST:event_cboVersionsItemStateChanged }//GEN-LAST:event_cboVersionsItemStateChanged
@@ -1212,76 +1210,76 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}//GEN-LAST:event_btnModifyMouseClicked }//GEN-LAST:event_btnModifyMouseClicked
private void txtJavaArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaArgsFocusLost private void txtJavaArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaArgsFocusLost
profile.setJavaArgs(txtJavaArgs.getText()); getProfile().setJavaArgs(txtJavaArgs.getText());
}//GEN-LAST:event_txtJavaArgsFocusLost }//GEN-LAST:event_txtJavaArgsFocusLost
private void txtMinecraftArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMinecraftArgsFocusLost private void txtMinecraftArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMinecraftArgsFocusLost
profile.setMinecraftArgs(txtMinecraftArgs.getText()); getProfile().setMinecraftArgs(txtMinecraftArgs.getText());
}//GEN-LAST:event_txtMinecraftArgsFocusLost }//GEN-LAST:event_txtMinecraftArgsFocusLost
private void txtPermSizeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPermSizeFocusLost private void txtPermSizeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPermSizeFocusLost
profile.setPermSize(txtPermSize.getText()); getProfile().setPermSize(txtPermSize.getText());
}//GEN-LAST:event_txtPermSizeFocusLost }//GEN-LAST:event_txtPermSizeFocusLost
private void chkDebugFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkDebugFocusLost private void chkDebugFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkDebugFocusLost
profile.setDebug(chkDebug.isSelected()); getProfile().setDebug(chkDebug.isSelected());
}//GEN-LAST:event_chkDebugFocusLost }//GEN-LAST:event_chkDebugFocusLost
private void chkNoJVMArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkNoJVMArgsFocusLost private void chkNoJVMArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkNoJVMArgsFocusLost
profile.setNoJVMArgs(chkNoJVMArgs.isSelected()); getProfile().setNoJVMArgs(chkNoJVMArgs.isSelected());
}//GEN-LAST:event_chkNoJVMArgsFocusLost }//GEN-LAST:event_chkNoJVMArgsFocusLost
private void chkCancelWrapperFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkCancelWrapperFocusLost private void chkCancelWrapperFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkCancelWrapperFocusLost
profile.setCanceledWrapper(chkCancelWrapper.isSelected()); getProfile().setCanceledWrapper(chkCancelWrapper.isSelected());
}//GEN-LAST:event_chkCancelWrapperFocusLost }//GEN-LAST:event_chkCancelWrapperFocusLost
private void txtPrecalledCommandFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPrecalledCommandFocusLost private void txtPrecalledCommandFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPrecalledCommandFocusLost
profile.setPrecalledCommand(txtPrecalledCommand.getText()); getProfile().setPrecalledCommand(txtPrecalledCommand.getText());
}//GEN-LAST:event_txtPrecalledCommandFocusLost }//GEN-LAST:event_txtPrecalledCommandFocusLost
private void txtServerIPFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtServerIPFocusLost private void txtServerIPFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtServerIPFocusLost
profile.setServerIp(txtServerIP.getText()); getProfile().setServerIp(txtServerIP.getText());
}//GEN-LAST:event_txtServerIPFocusLost }//GEN-LAST:event_txtServerIPFocusLost
private void cboGameDirTypeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cboGameDirTypeFocusLost private void cboGameDirTypeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cboGameDirTypeFocusLost
if (cboGameDirType.getSelectedIndex() >= 0) if (cboGameDirType.getSelectedIndex() >= 0)
profile.setGameDirType(GameDirType.values()[cboGameDirType.getSelectedIndex()]); getProfile().setGameDirType(GameDirType.values()[cboGameDirType.getSelectedIndex()]);
}//GEN-LAST:event_cboGameDirTypeFocusLost }//GEN-LAST:event_cboGameDirTypeFocusLost
private void cboLauncherVisibilityFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cboLauncherVisibilityFocusLost private void cboLauncherVisibilityFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cboLauncherVisibilityFocusLost
if (cboLauncherVisibility.getSelectedIndex() >= 0) if (cboLauncherVisibility.getSelectedIndex() >= 0)
profile.setLauncherVisibility(LauncherVisibility.values()[cboLauncherVisibility.getSelectedIndex()]); getProfile().setLauncherVisibility(LauncherVisibility.values()[cboLauncherVisibility.getSelectedIndex()]);
}//GEN-LAST:event_cboLauncherVisibilityFocusLost }//GEN-LAST:event_cboLauncherVisibilityFocusLost
private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed
if (mcVersion != null && profile != null) if (mcVersion != null && getProfile() != null)
profile.getMinecraftProvider().getAssetService().downloadAssets(mcVersion).run(); getProfile().getMinecraftProvider().getAssetService().downloadAssets(mcVersion).run();
}//GEN-LAST:event_btnDownloadAllAssetsActionPerformed }//GEN-LAST:event_btnDownloadAllAssetsActionPerformed
private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost
profile.setMaxMemory(txtMaxMemory.getText()); getProfile().setMaxMemory(txtMaxMemory.getText());
}//GEN-LAST:event_txtMaxMemoryFocusLost }//GEN-LAST:event_txtMaxMemoryFocusLost
private void txtJavaDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaDirFocusLost private void txtJavaDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaDirFocusLost
profile.setJavaDir(txtJavaDir.getText()); getProfile().setJavaDir(txtJavaDir.getText());
}//GEN-LAST:event_txtJavaDirFocusLost }//GEN-LAST:event_txtJavaDirFocusLost
private void chkFullscreenFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkFullscreenFocusLost private void chkFullscreenFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkFullscreenFocusLost
profile.setFullscreen(chkFullscreen.isSelected()); getProfile().setFullscreen(chkFullscreen.isSelected());
}//GEN-LAST:event_chkFullscreenFocusLost }//GEN-LAST:event_chkFullscreenFocusLost
private void txtHeightFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtHeightFocusLost private void txtHeightFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtHeightFocusLost
profile.setHeight(txtHeight.getText()); getProfile().setHeight(txtHeight.getText());
}//GEN-LAST:event_txtHeightFocusLost }//GEN-LAST:event_txtHeightFocusLost
private void txtWidthFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWidthFocusLost private void txtWidthFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWidthFocusLost
profile.setWidth(txtWidth.getText()); getProfile().setWidth(txtWidth.getText());
}//GEN-LAST:event_txtWidthFocusLost }//GEN-LAST:event_txtWidthFocusLost
private void txtGameDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtGameDirFocusLost private void txtGameDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtGameDirFocusLost
if (profile == null) if (getProfile() == null)
return; return;
profile.setGameDir(txtGameDir.getText()); getProfile().setGameDir(txtGameDir.getText());
loadVersions(); loadVersions();
}//GEN-LAST:event_txtGameDirFocusLost }//GEN-LAST:event_txtGameDirFocusLost
@@ -1301,7 +1299,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
try { try {
String path = fc.getSelectedFile().getCanonicalPath(); String path = fc.getSelectedFile().getCanonicalPath();
txtJavaDir.setText(path); txtJavaDir.setText(path);
profile.setJavaDir(txtJavaDir.getText()); getProfile().setJavaDir(txtJavaDir.getText());
} catch (IOException e) { } catch (IOException e) {
HMCLog.warn("Failed to set java path.", e); HMCLog.warn("Failed to set java path.", e);
MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage()); MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage());
@@ -1314,9 +1312,9 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
int idx = cboJava.getSelectedIndex(); int idx = cboJava.getSelectedIndex();
if (idx != -1) { if (idx != -1) {
Java j = Settings.JAVA.get(idx); Java j = Settings.JAVA.get(idx);
profile.setJava(j); getProfile().setJava(j);
txtJavaDir.setEnabled(idx == 1); txtJavaDir.setEnabled(idx == 1);
txtJavaDir.setText(j.getHome() == null ? profile.getSettingsJavaDir() : j.getJava()); txtJavaDir.setText(j.getHome() == null ? getProfile().getSettingsJavaDir() : j.getJava());
} }
}//GEN-LAST:event_cboJavaItemStateChanged }//GEN-LAST:event_cboJavaItemStateChanged
@@ -1329,14 +1327,14 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
return; return;
boolean flag = false; boolean flag = false;
for (File f : fc.getSelectedFiles()) for (File f : fc.getSelectedFiles())
flag |= !profile.getMinecraftProvider().getModService().addMod(f); flag |= !getProfile().getMinecraftProvider().getModService().addMod(f);
reloadMods(); reloadMods();
if (flag) if (flag)
MessageBox.Show(C.I18N.getString("mods.failed")); MessageBox.Show(C.I18N.getString("mods.failed"));
}//GEN-LAST:event_btnAddModActionPerformed }//GEN-LAST:event_btnAddModActionPerformed
private void btnRemoveModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveModActionPerformed private void btnRemoveModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveModActionPerformed
profile.getMinecraftProvider().getModService().removeMod(lstExternalMods.getSelectedRows()); getProfile().getMinecraftProvider().getModService().removeMod(lstExternalMods.getSelectedRows());
reloadMods(); reloadMods();
}//GEN-LAST:event_btnRemoveModActionPerformed }//GEN-LAST:event_btnRemoveModActionPerformed
@@ -1347,8 +1345,8 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
private void lblModInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModInfoMouseClicked private void lblModInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModInfoMouseClicked
int idx = lstExternalMods.getSelectedRow(); int idx = lstExternalMods.getSelectedRow();
if (idx > 0 && idx < profile.getMinecraftProvider().getModService().getMods().size()) if (idx > 0 && idx < getProfile().getMinecraftProvider().getModService().getMods().size())
profile.getMinecraftProvider().getModService().getMods().get(idx).showURL(); getProfile().getMinecraftProvider().getModService().getMods().get(idx).showURL();
}//GEN-LAST:event_lblModInfoMouseClicked }//GEN-LAST:event_lblModInfoMouseClicked
private void btnChoosingGameDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingGameDirActionPerformed private void btnChoosingGameDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingGameDirActionPerformed
@@ -1362,7 +1360,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
try { try {
String path = fc.getSelectedFile().getCanonicalPath(); String path = fc.getSelectedFile().getCanonicalPath();
txtGameDir.setText(path); txtGameDir.setText(path);
profile.setGameDir(path); getProfile().setGameDir(path);
} catch (IOException e) { } catch (IOException e) {
HMCLog.warn("Failed to set game dir.", e); HMCLog.warn("Failed to set game dir.", e);
MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage()); MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage());
@@ -1378,7 +1376,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}//GEN-LAST:event_btnShowLogActionPerformed }//GEN-LAST:event_btnShowLogActionPerformed
private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed
profile.getMinecraftProvider().cleanFolder(); getProfile().getMinecraftProvider().cleanFolder();
}//GEN-LAST:event_btnCleanGameActionPerformed }//GEN-LAST:event_btnCleanGameActionPerformed
// </editor-fold> // </editor-fold>
@@ -1404,10 +1402,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
isLoading = false; isLoading = false;
if (index < cboProfiles.getItemCount()) { if (index < cboProfiles.getItemCount()) {
cboProfiles.setSelectedIndex(index); cboProfiles.setSelectedIndex(index);
profile = selectedProfile; prepare(getProfile());
if (profile == null)
profile = firstProfile;
prepare(profile);
loadVersions(); loadVersions();
} }
} }
@@ -1416,7 +1411,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
if (cboProfiles.getSelectedIndex() >= 0) if (cboProfiles.getSelectedIndex() >= 0)
return Settings.getProfile(cboProfiles.getSelectedItem().toString()); return Settings.getProfile(cboProfiles.getSelectedItem().toString());
else else
return null; return Settings.getProfile(null);
} }
void prepare(Profile profile) { void prepare(Profile profile) {
@@ -1449,14 +1444,14 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
} }
void loadVersions() { void loadVersions() {
if (profile == null) if (getProfile() == null)
return; return;
isLoading = true; isLoading = true;
cboVersions.removeAllItems(); cboVersions.removeAllItems();
int index = 0, i = 0; int index = 0, i = 0;
MinecraftVersion selVersion = profile.getSelectedMinecraftVersion(); MinecraftVersion selVersion = getProfile().getSelectedMinecraftVersion();
String selectedMC = selVersion == null ? null : selVersion.id; String selectedMC = selVersion == null ? null : selVersion.id;
for (MinecraftVersion each : profile.getMinecraftProvider().getVersions()) { for (MinecraftVersion each : getProfile().getMinecraftProvider().getVersions()) {
cboVersions.addItem(each.id); cboVersions.addItem(each.id);
if (each.id.equals(selectedMC)) if (each.id.equals(selectedMC))
index = i; index = i;
@@ -1470,15 +1465,16 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
} }
void loadMinecraftVersion() { void loadMinecraftVersion() {
loadMinecraftVersion(profile.getSelectedMinecraftVersion()); loadMinecraftVersion(getProfile().getSelectedMinecraftVersion());
} }
void loadMinecraftVersion(String v) { void loadMinecraftVersion(String v) {
loadMinecraftVersion(profile.getMinecraftProvider().getVersionById(v)); loadMinecraftVersion(getProfile().getMinecraftProvider().getVersionById(v));
} }
/** /**
* Anaylze the jar of selected minecraft version of current profile to get * Anaylze the jar of selected minecraft version of current getProfile() to
* get
* the version. * the version.
* *
* @param v * @param v
@@ -1487,17 +1483,15 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
txtMinecraftVersion.setText(""); txtMinecraftVersion.setText("");
if (v == null) if (v == null)
return; return;
minecraftVersion = MinecraftVersionRequest.minecraftVersion(v.getJar(profile.getGameDirFile())); minecraftVersion = MinecraftVersionRequest.minecraftVersion(v.getJar(getProfile().getGameDirFile()));
txtMinecraftVersion.setText(MinecraftVersionRequest.getResponse(minecraftVersion)); txtMinecraftVersion.setText(MinecraftVersionRequest.getResponse(minecraftVersion));
} }
//</editor-fold> //</editor-fold>
// <editor-fold defaultstate="collapsed" desc="Game Download"> // <editor-fold defaultstate="collapsed" desc="Game Download">
public void refreshDownloads() { public void refreshDownloads() {
DefaultTableModel model = (DefaultTableModel) lstDownloads.getModel(); DefaultTableModel model = SwingUtils.clearDefaultTable(lstDownloads);
while (model.getRowCount() > 0) getProfile().getMinecraftProvider().getDownloadService().getRemoteVersions()
model.removeRow(0);
profile.getMinecraftProvider().getDownloadService().getRemoteVersions()
.observeOn(Schedulers.eventQueue()).subscribeOn(Schedulers.newThread()) .observeOn(Schedulers.eventQueue()).subscribeOn(Schedulers.newThread())
.subscribe((ver) -> model.addRow(new Object[] {ver.id, ver.time, .subscribe((ver) -> model.addRow(new Object[] {ver.id, ver.time,
StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type}), StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type}),
@@ -1508,12 +1502,12 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
} }
void downloadMinecraft() { void downloadMinecraft() {
if (profile == null || lstDownloads.getSelectedRow() < 0) { if (getProfile() == null || lstDownloads.getSelectedRow() < 0) {
MessageBox.Show(C.i18n("gamedownload.not_refreshed")); MessageBox.Show(C.i18n("gamedownload.not_refreshed"));
return; return;
} }
String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0); String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0);
profile.getMinecraftProvider().getDownloadService().downloadMinecraft(id); getProfile().getMinecraftProvider().getDownloadService().downloadMinecraft(id);
} }
// </editor-fold> // </editor-fold>
@@ -1530,7 +1524,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
Transferable tr = dtde.getTransferable(); Transferable tr = dtde.getTransferable();
List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
for (File file : files) for (File file : files)
profile.getMinecraftProvider().getModService().addMod(file); getProfile().getMinecraftProvider().getModService().addMod(file);
} catch (Exception ex) { } catch (Exception ex) {
HMCLog.warn("Failed to drop file.", ex); HMCLog.warn("Failed to drop file.", ex);
} }
@@ -1586,7 +1580,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
MessageBox.Show(C.i18n("install.not_refreshed")); MessageBox.Show(C.i18n("install.not_refreshed"));
return; return;
} }
profile.getInstallerService().download(getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run(); getProfile().getInstallerService().download(getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run();
} }
private List<InstallerVersionList.InstallerVersion> loadVersions(InstallerVersionList list, JTable table) { private List<InstallerVersionList.InstallerVersion> loadVersions(InstallerVersionList list, JTable table) {
@@ -1615,36 +1609,21 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
loadVersions(); loadVersions();
} }
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Variables">
boolean isLoading = false;
Profile profile;
public MinecraftVersionRequest minecraftVersion;
InstallerHelper forge, optifine, liteloader;
String mcVersion;
// </editor-fold> // </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Mods"> // <editor-fold defaultstate="collapsed" desc="Mods">
private final Object lockMod = new Object(); private final Object lockMod = new Object();
private void reloadMods() { private void reloadMods() {
new Thread(() -> { DefaultTableModel model = SwingUtils.clearDefaultTable(lstExternalMods);
synchronized (lockMod) { Observable.<List<ModInfo>>createWithEmptySubscription(
profile.getMinecraftProvider().getModService().recacheMods(); t -> t.onNext(getProfile().getMinecraftProvider().getModService().recacheMods()))
SwingUtilities.invokeLater(() -> { .subscribeOn(Schedulers.newThread()).observeOn(Schedulers.eventQueue())
synchronized (lockMod) { .flatMap(t -> Observable.from(t))
SwingUtils.clearDefaultTable(lstExternalMods); .subscribe(t -> model.addRow(new Object[] {t.isActive(), t.getFileName(), t.version}));
DefaultTableModel model = (DefaultTableModel) lstExternalMods.getModel();
for (ModInfo info : profile.getMinecraftProvider().getModService().getMods())
model.addRow(new Object[] {info.isActive(), info.getFileName(), info.version});
}
});
}
}).start();
} }
// </editor-fold> // </editor-fold>
public void versionChanged(Profile profile, String version) { public void versionChanged(String version) {
this.mcVersion = version; this.mcVersion = version;
forge.loadVersions(); forge.loadVersions();
optifine.loadVersions(); optifine.loadVersions();
@@ -1655,12 +1634,12 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
public void onSelected() { public void onSelected() {
loadProfiles(); loadProfiles();
if (profile == null) if (getProfile() == null)
return; return;
if (profile.getMinecraftProvider().getVersionCount() <= 0) if (getProfile().getMinecraftProvider().getVersionCount() <= 0)
versionChanged(profile, null); versionChanged(null);
else else
versionChanged(getProfile(), (String) cboVersions.getSelectedItem()); versionChanged((String) cboVersions.getSelectedItem());
} }
public void showGameDownloads() { public void showGameDownloads() {

View File

@@ -293,7 +293,7 @@ public final class MainFrame extends DraggableFrame {
backgroundLabel.setIcon(background); backgroundLabel.setIcon(background);
centralPanel.add(backgroundLabel, -1); centralPanel.add(backgroundLabel, -1);
} else } else
HMCLog.warn("No Background Image, the background will be white!"); HMCLog.warn("No Background Image, the background will be empty!");
} }
public JPanel getTitleBar() { public JPanel getTitleBar() {

View File

@@ -25,7 +25,7 @@ import org.jackhuang.hellominecraft.logging.logger.Logger;
*/ */
public class HMCLog { public class HMCLog {
public static Logger logger = new Logger("HMC"); public static Logger logger = new Logger("Hello Minecraft!");
public static void log(String message) { public static void log(String message) {
logger.info(message); logger.info(message);

View File

@@ -17,6 +17,7 @@
*/ */
package org.jackhuang.hellominecraft.tasks; package org.jackhuang.hellominecraft.tasks;
import java.awt.EventQueue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@@ -31,13 +32,13 @@ import org.jackhuang.hellominecraft.utils.SwingUtils;
* @author huangyuhui * @author huangyuhui
*/ */
public class TaskWindow extends javax.swing.JDialog public class TaskWindow extends javax.swing.JDialog
implements ProgressProviderListener, Runnable, DoingDoneListener<Task> { implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
private static final TaskWindow instance = new TaskWindow(); private static final TaskWindow INSTANCE = new TaskWindow();
private static TaskWindow inst() { private static TaskWindow inst() {
instance.clean(); INSTANCE.clean();
return instance; return INSTANCE;
} }
public static TaskWindowFactory getInstance() { public static TaskWindowFactory getInstance() {
@@ -200,12 +201,13 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
private javax.swing.JScrollPane srlDownload; private javax.swing.JScrollPane srlDownload;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
ArrayList<Task> tasks = new ArrayList<>(); final ArrayList<Task> tasks = new ArrayList<>();
ArrayList<Integer> progresses = new ArrayList<>(); final ArrayList<Integer> progresses = new ArrayList<>();
@Override @Override
public void setProgress(Task task, int progress, int max) { public void setProgress(Task task, int progress, int max) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
if (task == null) return;
int idx = tasks.indexOf(task); int idx = tasks.indexOf(task);
if (idx == -1) if (idx == -1)
return; return;
@@ -229,7 +231,7 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
task.setProgressProviderListener(this); task.setProgressProviderListener(this);
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
if (taskList == null) if (taskList == null || task == null)
return; return;
tasks.add(task); tasks.add(task);
progresses.add(0); progresses.add(0);
@@ -245,7 +247,7 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
@Override @Override
public void onDone(Task task) { public void onDone(Task task) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
if (taskList == null) if (taskList == null || task == null)
return; return;
pgsTotal.setMaximum(taskList.taskCount()); pgsTotal.setMaximum(taskList.taskCount());
pgsTotal.setValue(pgsTotal.getValue() + 1); pgsTotal.setValue(pgsTotal.getValue() + 1);
@@ -261,7 +263,7 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
@Override @Override
public void onFailed(Task task) { public void onFailed(Task task) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
if (taskList == null) if (taskList == null || task == null)
return; return;
failReasons.add(task.getInfo() + ": " + (null == task.getFailReason() ? "No exception" : (StrUtils.isBlank(task.getFailReason().getLocalizedMessage()) ? task.getFailReason().getClass().getSimpleName() : task.getFailReason().getLocalizedMessage()))); failReasons.add(task.getInfo() + ": " + (null == task.getFailReason() ? "No exception" : (StrUtils.isBlank(task.getFailReason().getLocalizedMessage()) ? task.getFailReason().getClass().getSimpleName() : task.getFailReason().getLocalizedMessage())));
pgsTotal.setMaximum(taskList.taskCount()); pgsTotal.setMaximum(taskList.taskCount());
@@ -283,7 +285,7 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
@Override @Override
public void setStatus(Task task, String sta) { public void setStatus(Task task, String sta) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
if (taskList == null) if (taskList == null || task == null)
return; return;
int idx = tasks.indexOf(task); int idx = tasks.indexOf(task);
if (idx == -1) if (idx == -1)
@@ -295,6 +297,7 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
public static class TaskWindowFactory { public static class TaskWindowFactory {
LinkedList<Task> ll = new LinkedList<>(); LinkedList<Task> ll = new LinkedList<>();
boolean flag;
public TaskWindowFactory addTask(Task t) { public TaskWindowFactory addTask(Task t) {
ll.add(t); ll.add(t);
@@ -302,14 +305,28 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
} }
public boolean start() { public boolean start() {
synchronized (instance) { Runnable r = () -> {
if (instance.isVisible()) synchronized (INSTANCE) {
return false; if (INSTANCE.isVisible()) {
TaskWindow tw = inst(); flag = false;
for (Task t : ll) return;
tw.addTask(t); }
return tw.start(); TaskWindow tw = inst();
} for (Task t : ll)
tw.addTask(t);
flag = tw.start();
}
};
if (EventQueue.isDispatchThread())
r.run();
else
try {
EventQueue.invokeAndWait(r);
} catch (Exception e) {
HMCLog.err("Failed to invokeAndWait, the UI will work abnormally.", e);
r.run();
}
return flag;
} }
} }
} }

View File

@@ -30,7 +30,6 @@ import java.util.Map;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.system.IOUtils; import org.jackhuang.hellominecraft.utils.system.IOUtils;
import rx.Observable; import rx.Observable;
import rx.subscriptions.Subscriptions;
/** /**
* *
@@ -160,13 +159,12 @@ public final class NetUtils {
} }
public static Observable<String> getRx(String url) { public static Observable<String> getRx(String url) {
return Observable.create(t1 -> { return Observable.createWithEmptySubscription(t1 -> {
try { try {
t1.onNext(get(url)); t1.onNext(get(url));
} catch(Exception e) { } catch(Exception e) {
t1.onError(e); t1.onError(e);
} }
return Subscriptions.empty();
}); });
} }
} }

View File

@@ -131,12 +131,15 @@ public class SwingUtils {
* Clear the JTable * Clear the JTable
* *
* @param table JTable with DefaultTableModel. * @param table JTable with DefaultTableModel.
*
* @return To make the code succinct
*/ */
public static void clearDefaultTable(JTable table) { public static DefaultTableModel clearDefaultTable(JTable table) {
DefaultTableModel model = (DefaultTableModel) table.getModel(); DefaultTableModel model = (DefaultTableModel) table.getModel();
while (model.getRowCount() > 0) while (model.getRowCount() > 0)
model.removeRow(0); model.removeRow(0);
table.updateUI(); table.updateUI();
return model;
} }
public static void appendLast(JTable table, Object... elements) { public static void appendLast(JTable table, Object... elements) {

View File

@@ -93,9 +93,10 @@ public final class Utils {
return new ImageIcon(i.getImage().getScaledInstance(x, y, Image.SCALE_SMOOTH)); return new ImageIcon(i.getImage().getScaledInstance(x, y, Image.SCALE_SMOOTH));
} }
public static ImageIcon searchBackgroundImage(ImageIcon background, String bgpath, int width, int height) { public static ImageIcon searchBackgroundImage(ImageIcon init, String bgpath, int width, int height) {
Random r = new Random(); Random r = new Random();
boolean loaded = false; boolean loaded = false;
ImageIcon background = init;
// bgpath // bgpath
if (StrUtils.isNotBlank(bgpath) && !loaded) { if (StrUtils.isNotBlank(bgpath) && !loaded) {
@@ -142,6 +143,7 @@ public final class Utils {
} }
} }
if (background == null) return init;
return background; return background;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -240,7 +240,7 @@ mainwindow.enter_script_name=\u8f93\u5165\u8981\u751f\u6210\u811a\u672c\u7684\u6
mainwindow.make_launch_succeed=\u542f\u52a8\u811a\u672c\u5df2\u751f\u6210\u5b8c\u6bd5: mainwindow.make_launch_succeed=\u542f\u52a8\u811a\u672c\u5df2\u751f\u6210\u5b8c\u6bd5:
mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u8fdb\u5165\u6e38\u620f\u4e0b\u8f7d\uff1f mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u8fdb\u5165\u6e38\u620f\u4e0b\u8f7d\uff1f
launcher.about=<html>\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002<br/>\u5173\u4e8e\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002<br/>\u672c\u542f\u52a8\u5668\u5728GPLv2\u534f\u8bae\u4e0b\u5f00\u6e90:http://github.com/huanghongxun/HMCL/</html> launcher.about=<html>\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002<br/>\u5173\u4e8e\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002<br/>\u672c\u542f\u52a8\u5668\u5728GPLv3\u534f\u8bae\u4e0b\u5f00\u6e90:http://github.com/huanghongxun/HMCL/<br/>\u672c\u8f6f\u4ef6\u4f7f\u7528\u4e86\u57fa\u4e8eApache License 2.0\u7684RxJava\u548cGson\u9879\u76ee\uff0c\u611f\u8c22\u8d21\u732e\u8005\u3002</html>
launcher.download_source=\u4e0b\u8f7d\u6e90 launcher.download_source=\u4e0b\u8f7d\u6e90
launcher.background_location=\u80cc\u666f\u5730\u5740 launcher.background_location=\u80cc\u666f\u5730\u5740
launcher.exit_failed=\u5f3a\u5236\u9000\u51fa\u5931\u8d25\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5bfc\u81f4\u7684\uff0c\u65e0\u6cd5\u89e3\u51b3\u3002 launcher.exit_failed=\u5f3a\u5236\u9000\u51fa\u5931\u8d25\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5bfc\u81f4\u7684\uff0c\u65e0\u6cd5\u89e3\u51b3\u3002

View File

@@ -240,7 +240,7 @@ mainwindow.enter_script_name=Enter the script name.
mainwindow.make_launch_succeed=Finished script creation. mainwindow.make_launch_succeed=Finished script creation.
mainwindow.no_version=No version found. Switch to Game Downloads Tab? mainwindow.no_version=No version found. Switch to Game Downloads Tab?
launcher.about=<html>About Author<br/>\nEmail\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\nCopyright (c) 2013 huangyuhui<br/>Opened source under GPL v2 licence:http://github.com/huanghongxun/HMCL/</html> launcher.about=<html>About Author<br/>\nEmail\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\nCopyright (c) 2013 huangyuhui<br/>Opened source under GPL v3 license:http://github.com/huanghongxun/HMCL/<br/>This software used project RxJava and Gson which is under Apache License 2.0, thanks contributors.</html>
launcher.download_source=Download Source launcher.download_source=Download Source
launcher.background_location=Background Location launcher.background_location=Background Location
launcher.exit_failed=Failed to shutdown. launcher.exit_failed=Failed to shutdown.

View File

@@ -240,7 +240,7 @@ mainwindow.enter_script_name=\u8f38\u5165\u8981\u751f\u6210\u8173\u672c\u7684\u6
mainwindow.make_launch_succeed=\u555f\u52d5\u8173\u672c\u5df2\u751f\u6210\u5b8c\u7562: mainwindow.make_launch_succeed=\u555f\u52d5\u8173\u672c\u5df2\u751f\u6210\u5b8c\u7562:
mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u9032\u5165\u904a\u6232\u4e0b\u8f09\uff1f mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u9032\u5165\u904a\u6232\u4e0b\u8f09\uff1f
launcher.about=<html>\u9ed8\u8a8d\u80cc\u666f\u5716\u4f86\u81eaLiberty Dome\u670d\u52d9\u5668\u3002 <br/>\u95dc\u65bc\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90f5\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br />\n\u6b61\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8cac\u8072\u660e\uff1aMinecraft\u8edf\u4ef6\u7248\u6b0a\u6b78Mojang AB\u6240\u6709\uff0c\u904a\u6232\u7531\u65bc\u8aa4\u64cd\u4f5c\u672c\u555f\u52d5\u5668\u800c\u4e1f\u5931\u6578\u64da\u7684\u6982\u4e0d\u8ca0\u8cac\u3002 <br/>\u672c\u555f\u52d5\u5668\u5728GPLv2\u5354\u8b70\u4e0b\u958b\u6e90:http://github.com/huanghongxun/HMCL/</html> launcher.about=<html>\u9ed8\u8a8d\u80cc\u666f\u5716\u4f86\u81eaLiberty Dome\u670d\u52d9\u5668\u3002 <br/>\u95dc\u65bc\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90f5\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br />\n\u6b61\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8cac\u8072\u660e\uff1aMinecraft\u8edf\u4ef6\u7248\u6b0a\u6b78Mojang AB\u6240\u6709\uff0c\u904a\u6232\u7531\u65bc\u8aa4\u64cd\u4f5c\u672c\u555f\u52d5\u5668\u800c\u4e1f\u5931\u6578\u64da\u7684\u6982\u4e0d\u8ca0\u8cac\u3002 <br/>\u672c\u555f\u52d5\u5668\u5728GPLv3\u5354\u8b70\u4e0b\u958b\u6e90:http://github.com/huanghongxun/HMCL/<br/>\u672c\u8edf\u4ef6\u4f7f\u7528\u4e86\u57fa\u65bcApache License 2.0\u7684RxJava\u548cGson\u9805\u76ee\uff0c\u611f\u8b1d\u8ca2\u737b\u8005\u3002</html>
launcher.download_source=\u4e0b\u8f09\u6e90 launcher.download_source=\u4e0b\u8f09\u6e90
launcher.background_location=\u80cc\u666f\u5730\u5740 launcher.background_location=\u80cc\u666f\u5730\u5740
launcher.exit_failed=\u5f37\u5236\u9000\u51fa\u5931\u6557\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5c0e\u81f4\u7684\uff0c\u7121\u6cd5\u89e3\u6c7a\u3002 launcher.exit_failed=\u5f37\u5236\u9000\u51fa\u5931\u6557\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5c0e\u81f4\u7684\uff0c\u7121\u6cd5\u89e3\u6c7a\u3002

View File

@@ -237,7 +237,7 @@ mainwindow.enter_script_name=\u8f93\u5165\u8981\u751f\u6210\u811a\u672c\u7684\u6
mainwindow.make_launch_succeed=\u542f\u52a8\u811a\u672c\u5df2\u751f\u6210\u5b8c\u6bd5: mainwindow.make_launch_succeed=\u542f\u52a8\u811a\u672c\u5df2\u751f\u6210\u5b8c\u6bd5:
mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u8fdb\u5165\u6e38\u620f\u4e0b\u8f7d\uff1f mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u8fdb\u5165\u6e38\u620f\u4e0b\u8f7d\uff1f
launcher.about=<html>\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002<br/>\u5173\u4e8e\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002<br/>\u672c\u542f\u52a8\u5668\u5728GPLv2\u534f\u8bae\u4e0b\u5f00\u6e90:http://github.com/huanghongxun/HMCL/</html> launcher.about=<html>\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002<br/>\u5173\u4e8e\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002<br/>\u672c\u542f\u52a8\u5668\u5728GPLv3\u534f\u8bae\u4e0b\u5f00\u6e90:http://github.com/huanghongxun/HMCL/<br/>\u672c\u8f6f\u4ef6\u4f7f\u7528\u4e86\u57fa\u4e8eApache License 2.0\u7684RxJava\u548cGson\u9879\u76ee\uff0c\u611f\u8c22\u8d21\u732e\u8005\u3002</html>
launcher.download_source=\u4e0b\u8f7d\u6e90 launcher.download_source=\u4e0b\u8f7d\u6e90
launcher.background_location=\u80cc\u666f\u5730\u5740 launcher.background_location=\u80cc\u666f\u5730\u5740
launcher.exit_failed=\u5f3a\u5236\u9000\u51fa\u5931\u8d25\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5bfc\u81f4\u7684\uff0c\u65e0\u6cd5\u89e3\u51b3\u3002 launcher.exit_failed=\u5f3a\u5236\u9000\u51fa\u5931\u8d25\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5bfc\u81f4\u7684\uff0c\u65e0\u6cd5\u89e3\u51b3\u3002